@font-face {
  font-family: "DejaVu Sans Mono";
  src: local("DejaVu Sans Mono"), url("../../assets/fonts/DejaVuSansMono.ttf") format("truetype");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "DejaVu Sans Mono";
  src: local("DejaVu Sans Mono Bold"), url("../../assets/fonts/DejaVuSansMono-Bold.ttf") format("truetype");
  font-weight: 700; font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #faf9f6; --ink: #000; --pencil: #4a4a4a; --pencil-light: #8d8d8d;
  --hairline: #b9b9b9; --highlight: rgb(250 226 96 / 0.55);
  --lean-print: 0.9deg;
  --serif: Charter, "Bitstream Charter", "Charis SIL", Georgia, serif;
  --mono: "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --pane-h: 688px;
}
* { box-sizing: border-box; }
html, body { background: transparent; overflow-x: hidden; }
body {
  margin: 0; padding: 0.6rem 0.6rem 1.6rem; color: var(--ink);
  font-family: var(--serif); font-size: 1rem; line-height: 1.45;
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }

.app { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: 2.2rem; }
.side, .pane { min-width: 0; }

.side { --lean: -0.7deg; height: var(--pane-h); padding: 0.9rem 0.6rem 1.6rem 0.9rem; }
.side-scroll { height: 100%; overflow-y: auto; scrollbar-gutter: stable; padding-right: 0.2rem; }
#games { display: flex; flex-direction: column; gap: 0.15rem; }
.side-count { font-family: var(--mono); font-size: 0.72rem; color: inherit; opacity: 0.8; margin: 0 0 0.5rem; }
.empty { font-size: 0.9rem; color: inherit; margin: 0.2rem 0 0; }
#games button {
  border: 0; background: transparent; text-align: left; width: 100%;
  padding: 0.3rem 0.4rem 0.3rem 0; color: inherit;
  display: flex; align-items: center; gap: 0.6rem; font-size: 0.95rem;
}
#games .name { padding: 0.05rem 0.3rem; margin-left: -0.3rem; }
#games button:hover .name { color: var(--note-ink); }
#games button.active .name { color: var(--note-ink); background: #fff; }
#games .thumb { width: 2rem; flex: none; background: #fff; padding: 2px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.28); line-height: 0; }
#games .thumb img { width: 100%; height: auto; display: block; }

.panes {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr);
  gap: 2rem; min-width: 0;
}
.pane { height: var(--pane-h); display: flex; flex-direction: column; min-width: 0; }

.board-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 0.8rem 1.2rem; margin-bottom: 0.6rem; flex-wrap: wrap; flex: none;
}
.board-head h3 { margin: 0; font-size: 1.6rem; line-height: 1.1; font-weight: 700; }
.sub { margin: 0.25rem 0 0; font-family: var(--mono); font-size: 0.74rem; color: var(--pencil); }
.head-right { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.cells { display: flex; gap: 0.3rem; }
.cells button {
  font-family: var(--mono); font-size: 0.78rem; width: 1.7rem; height: 1.7rem;
  border: 1px solid var(--pencil); background: transparent; color: var(--pencil);
  padding: 0; line-height: 1;
}
.cells button:hover { border-color: var(--ink); color: var(--ink); }
.cells button.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.toggle {
  font-family: var(--mono); font-size: 0.76rem; color: var(--pencil);
  border: 0; background: transparent; padding: 0.2rem 0;
  display: inline-flex; align-items: center; gap: 0.45rem;
}
.toggle .box {
  width: 0.85rem; height: 0.85rem; border: 1px solid var(--pencil); flex: none;
}
.toggle:hover { color: var(--ink); }
.toggle:hover .box { border-color: var(--ink); }
.toggle[aria-pressed="true"] { color: var(--ink); }
.toggle[aria-pressed="true"] .box { background: var(--ink); border-color: var(--ink); }
.toggle:disabled { opacity: 0.4; cursor: default; }

.printwrap {
  flex: 1 1 auto; min-height: 0; display: grid; place-items: center;
  container-type: size; position: relative;
  margin-top: 1.7rem;
}
.imgbox {
  width: min(100cqw, 100cqh); aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: #fff; border: 9px solid #fff; padding: 14px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15), 0 16px 24px -14px rgb(0 0 0 / 0.5);
  transform: rotate(var(--lean-print));
}
.printwrap::before, .printwrap::after {
  content: ""; position: absolute; width: 86px; height: 24px; z-index: 2; pointer-events: none;
  background: var(--tape);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.35), 0 1px 2px rgb(0 0 0 / 0.12);
  top: calc(50% - min(50cqw, 50cqh) - 9px);
}
.printwrap::before { left: calc(50% - min(50cqw, 50cqh) - 20px); transform: rotate(-38deg); }
.printwrap::after  { right: calc(50% - min(50cqw, 50cqh) - 20px); transform: rotate(36deg); }
.imginner {
  position: relative; width: 320px; transition: width 0.22s ease; line-height: 0;
}
.imginner img { width: 100%; height: auto; display: block; }

.overlay {
  position: absolute; pointer-events: none;
  background: var(--ov-fill, rgba(0,0,0,0.08));
  box-shadow: inset 0 0 0 3px var(--ov-color, #555);
}
#decode-cursor, #hover-box {
  position: absolute; pointer-events: none;
  background: var(--highlight);
  box-shadow: inset 0 0 0 2px var(--pencil);
}

.steplabel {
  font-family: var(--mono); font-size: 0.78rem; color: var(--ink);
  margin: 0.7rem 0 0; min-height: 1.3em; flex: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.transport {
  --lean: -0.5deg;
  flex: none; display: flex; align-items: flex-start; gap: 1.2rem;
  margin-top: 0.9rem; padding: 0.8rem 0.9rem 1.4rem; flex-wrap: wrap;
}
.buttons { display: flex; align-items: center; gap: 0.4rem; }
.buttons button, .textbtn {
  font-family: var(--mono); font-size: 0.76rem; padding: 0.3rem 0.65rem;
  border: 1px solid var(--note-pencil); background: rgb(255 255 255 / 0.38); color: var(--note-pencil);
}
.buttons button:hover, .textbtn:hover { border-color: var(--note-ink); color: var(--note-ink); background: rgb(255 255 255 / 0.6); }
.buttons .primary { color: var(--note-ink); border-color: var(--note-ink); min-width: 4.2rem; }

.timeline {
  display: grid; grid-template-columns: repeat(var(--cols, 15), minmax(0, 22px));
  gap: 2px; flex: 1 1 12rem; align-content: start; padding: 2px;
}
.timeline .cell {
  aspect-ratio: 1; border: 1px solid rgb(0 0 0 / 0.38); background: rgb(255 255 255 / 0.38);
  padding: 0; min-width: 0;
}
.timeline .cell:hover { border-color: var(--note-ink); }
.timeline .cell.done { background: var(--dc, var(--pencil)); border-color: var(--dc, var(--pencil)); }
.timeline .cell.current { box-shadow: 0 0 0 2px var(--ink); border-color: var(--ink); z-index: 1; }
.timeline:focus-visible { outline-offset: 4px; }

.tabs-pane { --lean: 0.6deg; padding: 1.1rem 1.1rem 1.7rem; }
.tabs { display: flex; gap: 1.2rem; margin-bottom: 0.9rem; flex: none; border-bottom: 1px solid rgb(0 0 0 / 0.28); }
.tabs button {
  font-family: var(--mono); font-size: 0.78rem; color: inherit; opacity: 0.85;
  background: transparent; border: 0; padding: 0.35rem 0 0.45rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--note-ink); opacity: 1; }
.tabs button.active { color: var(--note-ink); opacity: 1; border-bottom-color: var(--note-ink); }

.tabpane {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  scrollbar-gutter: stable; padding-right: 0.2rem;
}

.logical {
  display: grid; gap: 1px; padding: 1px; width: 100%; max-width: 340px;
  background: rgb(0 0 0 / 0.5); font-family: var(--mono); margin-bottom: 0.8rem;
}
.logical span {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1; background: var(--note); font-size: 0.74rem;
  color: var(--note-pencil); overflow: hidden;
}
.logical span.given { color: var(--note-ink); font-weight: 700; }
.logical span.wall { background: var(--note-ink); color: #fff; font-weight: 700; }
.logical span.box { box-shadow: inset 0 0 0 2px var(--note-ink); background: #fff; color: var(--note-ink); font-weight: 700; }
.logical span.island {
  color: var(--note-ink); font-weight: 700;
  background: radial-gradient(circle at center, #fff 0 40%, var(--note-ink) 41% 49%, var(--note) 50%);
}
.logical span.island.hovered, .logical span.island.now {
  background: radial-gradient(circle at center, #fff 0 40%, var(--note-ink) 41% 49%, #fff 50%);
}
.logical span.heavy { font-weight: 700; color: var(--note-pencil); }
.logical.latticeview span.heavy { font-size: 0.9rem; line-height: 1; }
.textbtn:disabled { opacity: 0.4; cursor: default; }
.logical span.shaded, .logical span.filled, .logical span.water { background: var(--pencil); color: #fff; }
.logical span.mark { color: rgb(0 0 0 / 0.5); }
.logical span.pending { color: transparent; background: var(--note); }
.logical span.now, .logical span.hovered { background: #fff; }
.logical span.wall.now, .logical span.wall.hovered { background: var(--note-ink); box-shadow: inset 0 0 0 3px #fff; }
.logical span.shaded.now, .logical span.filled.now, .logical span.water.now,
.logical span.shaded.hovered, .logical span.filled.hovered, .logical span.water.hovered {
  background: var(--pencil); box-shadow: inset 0 0 0 3px #fff;
}
.logical.latticeview { background: transparent; gap: 0; padding: 0; }
.logical.latticeview span { aspect-ratio: auto; min-height: 0.9rem; background: transparent; }
.logical.latticeview span.cellslot { border: 1px solid rgb(0 0 0 / 0.45); min-height: 1.2rem; background: color-mix(in srgb, var(--note), #fff 30%); }
.logical.latticeview span.edge { color: var(--note-pencil); font-size: 0.68rem; }
.logical.latticeview span.pending { background: transparent; }
.logical.latticeview span.now, .logical.latticeview span.hovered { background: #fff; }
.logical.latticeview span.cellslot.shaded { background: var(--pencil); }
.logical.latticeview span.cellslot.wall { background: var(--note-ink); }
.logical.latticeview span.cellslot.shaded.now, .logical.latticeview span.cellslot.shaded.hovered,
.logical.latticeview span.cellslot.wall.now, .logical.latticeview span.cellslot.wall.hovered {
  box-shadow: inset 0 0 0 3px #fff;
}

.row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.hint { font-family: var(--mono); font-size: 0.72rem; color: inherit; margin: 0.5rem 0 0; }
#tab-state > p.hint { font-family: var(--serif); font-size: 0.86rem; margin-top: 0.7rem; }

.goal { font-size: 1rem; line-height: 1.45; margin: 0 0 0.7rem; color: var(--note-ink); }
.goal .runin { font-style: italic; }
.rules {
  list-style: none; counter-reset: rule; margin: 0; padding: 0.75rem 0 0;
  border-top: 1px solid rgb(0 0 0 / 0.25);
}
.rules li {
  counter-increment: rule; position: relative; padding-left: 1.7rem;
  margin: 0 0 0.5rem; font-size: 0.92rem; line-height: 1.42;
}
.rules li::before {
  content: counter(rule); position: absolute; left: 0.15rem; top: 0.12em;
  font-family: var(--mono); font-size: 0.78rem; font-weight: 700; color: var(--note-ink);
}
.example { margin-top: 0.6rem; padding-top: 0.7rem; border-top: 1px solid rgb(0 0 0 / 0.25); }
.example figure { flex: 1 1 8rem; max-width: 11.5rem; }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; }
.legend button {
  border: 0; background: transparent; padding: 0.15rem 0; color: inherit;
  font-size: 0.9rem; display: inline-flex; align-items: center; gap: 0.45rem;
}
.legend button .swatch {
  width: 0.8rem; height: 0.8rem; flex: none; background: rgb(255 255 255 / 0.5);
  box-shadow: inset 0 0 0 2px var(--tc, var(--pencil));
}
.legend button:hover { color: var(--note-ink); }
.legend button.active { color: var(--note-ink); font-weight: 700; }
.legend button.active .swatch { background: var(--tc, var(--pencil)); }

.prose { font-size: 0.9rem; line-height: 1.5; margin-top: 0.7rem; }
.prose p { margin: 0 0 0.45rem; }
.prose p b { color: var(--note-ink); font-weight: 700; }
.prose .runin { font-style: italic; font-weight: 400; color: var(--note-ink); }
.pair { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.9rem; padding: 0.3rem 0.3rem 0; }
.pair figure { margin: 0; flex: 1 1 8.5rem; max-width: 13rem; }
.pair figure:first-child .sheet { --lean: -0.8deg; }
.pair figure:last-child .sheet { --lean: 0.7deg; }
.pair .sheet { border-width: 3px; }
.pair figcaption { font-family: var(--mono); font-size: 0.7rem; color: inherit; padding-top: 0.35rem; }

@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); gap: 1.4rem; }
  .side { height: auto; padding: 0.8rem 0.8rem 1.5rem; }
  .side-scroll { height: auto; overflow-x: auto; overflow-y: hidden; padding-bottom: 0.3rem; }
  #games { flex-direction: row; flex-wrap: nowrap; gap: 0.2rem 1.1rem; width: max-content; }
  #games button { width: auto; padding-right: 0; white-space: nowrap; }
  .panes { grid-template-columns: 1fr; gap: 1.8rem; }
  .pane { height: auto; min-height: 520px; }
  .printwrap { container-type: inline-size; }
  .imgbox { width: min(100%, 440px); }
  .printwrap::before, .printwrap::after { top: calc(50% - min(50cqw, 220px) - 9px); }
  .printwrap::before { left: calc(50% - min(50cqw, 220px) - 20px); }
  .printwrap::after { right: calc(50% - min(50cqw, 220px) - 20px); }
  .tabpane { max-height: 480px; }
}

@media (prefers-reduced-motion: reduce) {
  .imginner { transition: none; }
}
