:root {
  color-scheme: light;
  --bg: #fff;
  --text: #1d1d1d;
  --muted: #6b6b6b;
  --line: #d4d4d4;
  --subtle: #f3f3f3;
  --shaded: #2b2b2b;
  --cell: #fff;
  --error: #a00000;
  --select: #cbcbcb;
  --same: #dcdcdc;
  --peer: #ececec;
  --block: #2b2b2b;
  --block-text: #fff;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --side-width: 200px;
  --header: 48px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161616;
  --text: #e2e2e2;
  --muted: #9a9a9a;
  --line: #424242;
  --subtle: #222;
  --shaded: #cfcfcf;
  --cell: #161616;
  --error: #ff8f8f;
  --select: #474747;
  --same: #363636;
  --peer: #272727;
  --block: #3a3a3a;
  --block-text: #e2e2e2;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-text-size-adjust: 100%; }
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 22px; line-height: 1.3; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 20px 0 10px; }
p { margin: 10px 0; }
kbd, code { font: 12px/1 var(--mono); }
[hidden] { display: none !important; }

/* Controls: one height, square-ish corners. */
button, input, select, textarea { font: inherit; color: inherit; }
button, input, select { height: 32px; border: 1px solid var(--line); border-radius: 2px; background: var(--bg); padding: 0 10px; }
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--muted); background: var(--subtle); }
button:disabled { color: var(--muted); opacity: .5; cursor: default; }
button.primary { border-color: var(--text); font-weight: 600; }
button.primary:hover:not(:disabled) { border-color: var(--text); }
input { width: 76px; }
input:hover:not(:disabled) { border-color: var(--muted); }
select { padding-right: 6px; max-width: 170px; }
input[type="checkbox"] { width: auto; height: auto; margin: 0; padding: 0; accent-color: var(--text); }
textarea { display: block; width: 100%; min-height: 120px; margin: 6px 0 10px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 2px; background: var(--bg); resize: vertical; font: 13px/1.5 var(--mono); }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.group { display: inline-flex; }
.group > button { border-radius: 0; }
.group > button:first-child { border-radius: 2px 0 0 2px; }
.group > button:last-child { border-radius: 0 2px 2px 0; }
.group > button + button { margin-left: -1px; }
.group > button:hover:not(:disabled), .group > button:focus-visible { position: relative; }
button.square { display: inline-flex; align-items: center; justify-content: center; width: 34px; padding: 0; }
button.icon, a.icon { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 2px; background: none; color: var(--muted); }
button.icon:hover:not(:disabled), a.icon:hover { color: var(--text); background: var(--subtle); border-color: transparent; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
svg.filled { fill: currentColor; stroke: none; }
@media (prefers-reduced-motion: no-preference) {
  button, select, input, a.icon { transition: background-color .12s, border-color .12s, color .12s; }
}

/* Header */
header { height: var(--header); position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); padding: 0 12px 0 18px; background: var(--bg); }
#trail { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
#trail a, #trail span { text-decoration: none; }
#trail a:hover { text-decoration: underline; }
#trail .sep { color: var(--line); }
#trail [aria-current] { color: var(--muted); }
.site-name { font-weight: 600; }
:root[data-theme="dark"] #theme .moon, :root:not([data-theme="dark"]) #theme .sun { display: none; }
#show-games { display: none; }

/* Directory */
aside { position: fixed; top: var(--header); bottom: 0; left: 0; width: var(--side-width); overflow-y: auto; border-right: 1px solid var(--line); padding: 18px 0; background: var(--bg); }
#directory, #project { display: flex; flex-direction: column; }
aside nav a { display: block; padding: 3px 16px 3px 14px; border-left: 2px solid transparent; text-decoration: none; }
aside nav a:hover { background: var(--subtle); }
aside nav a[aria-current="page"] { border-left-color: var(--text); font-weight: 600; }
aside .label { margin: 16px 16px 4px; font-size: 12px; color: var(--muted); }
#project { margin-top: 12px; }
#theme { display: flex; align-items: center; gap: 8px; width: 100%; height: auto; margin-top: 4px; padding: 3px 16px; border: 0; border-radius: 0; background: none; color: var(--muted); text-align: left; }
#theme:hover { background: var(--subtle); color: var(--text); }
#directory .modes a { padding-left: 30px; font-size: 14px; color: var(--muted); }
#directory .modes a[aria-current="page"] { color: var(--text); }
#directory .game.open > a { font-weight: 600; }
main { margin-left: var(--side-width); padding: 28px 32px 56px; max-width: 1180px; min-width: 0; }

/* Overview */
.prose { max-width: 640px; }
main > h1 + .prose { margin-top: 12px; }
main > h2 { margin-top: 36px; }
.link-row { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 14px; }
.overview { width: 100%; margin-top: 8px; border-collapse: collapse; text-align: left; }
.overview th { font-size: 13px; font-weight: normal; color: var(--muted); border-bottom: 1px solid var(--line); }
.overview td, .overview th { padding: 9px 18px 9px 0; vertical-align: top; }
.overview td:first-child, .overview th:first-child { padding-left: 8px; }
.overview tbody tr { border-bottom: 1px solid var(--subtle); }
.overview tbody tr:hover { background: var(--subtle); }
.overview .game-name { white-space: nowrap; font-weight: 600; }
.overview .description { max-width: 460px; color: var(--muted); }
.overview .tools { white-space: nowrap; }
.overview .tools a + a { margin-left: 14px; }

/* Puzzle pages */
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 24px; margin-bottom: 22px; }
.mode-links { display: flex; gap: 18px; }
.mode-links a { color: var(--muted); text-decoration: none; padding-bottom: 3px; border-bottom: 2px solid transparent; }
.mode-links a:hover { color: var(--text); }
.mode-links a[aria-current="page"] { color: var(--text); border-bottom-color: var(--text); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
/* Player: settings across the top, board left, fixed-width control panel right.
   Below 900px the panel stacks under the board. Board cells scale to the space left (--avail). */
.player-layout { display: grid; justify-content: start; align-items: start; grid-template-columns: auto; grid-template-areas: "toolbar" "board" "side"; --avail: calc(100vw - 290px); }
.player-layout > .toolbar { grid-area: toolbar; }
.player-layout > .board-block { grid-area: board; width: fit-content; max-width: 100%; }
.player-layout > .side { grid-area: side; }
@media (min-width: 900px) {
  .player-layout { grid-template-columns: auto 252px; grid-template-areas: "toolbar toolbar" "board side"; column-gap: 40px; --avail: calc(100vw - 590px); }
  /* The top bar follows the board and panel widths instead of widening them. */
  .player-layout > .toolbar { contain: inline-size; }
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-bottom: 18px; }
.field { display: flex; align-items: center; gap: 7px; }
.field label { color: var(--muted); font-size: 14px; }
.stats { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats .solved { color: var(--text); font-weight: 600; }
.board-area { overflow-x: auto; max-width: 100%; padding: 2px; }
.board-caption { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-top: 8px; padding: 0 2px; contain: inline-size; font-size: 14px; }
.side { min-width: 0; padding-top: 2px; }
@media (max-width: 899px) { .side { margin-top: 20px; } }
@media (min-width: 701px) and (max-width: 899px) { .side { max-width: 420px; } .side .board-tools .push { margin-left: 8px; } }
.legend { display: flex; flex-direction: column; gap: 6px; margin: 0; font-size: 14px; color: var(--muted); }
.legend.digits { flex-direction: row; }
.legend.digits { flex-wrap: nowrap; align-items: flex-start; gap: 8px; }
.keypad { display: grid; grid-template-columns: repeat(var(--keypad-cols, 3), 40px); gap: 4px; }
.keypad button { padding: 0; font-variant-numeric: tabular-nums; }
.keypad-tools { display: flex; flex-direction: column; gap: 4px; }
.legend button { min-width: 34px; padding: 0 8px; color: var(--text); }
.legend button[aria-pressed="true"] { border-color: var(--text); background: var(--select); }
.keypad button.done { color: var(--muted); opacity: .45; }
.mark-tools { display: flex; flex-direction: column; gap: 2px; margin-left: -8px; }
.mark-tools button { display: inline-flex; align-items: center; justify-content: flex-start; height: 28px; padding: 0 8px; border-color: transparent; background: none; color: var(--muted); }
.legend .mark-tools button[aria-pressed="true"] { border-color: var(--line); background: var(--subtle); color: var(--text); }
.combos { margin: 12px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.legend > span { display: inline-flex; align-items: center; }
.swatch { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; border: 1px solid var(--muted); margin-right: 6px; font-size: 11px; line-height: 1; }
.swatch.shaded { background: var(--shaded); border-color: var(--shaded); }
.swatch.dot::after { content: ''; width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.swatch.cross { position: relative; }
.swatch.cross::before, .swatch.cross::after { content: ''; position: absolute; width: 9px; height: 1.5px; background: currentColor; transform: rotate(45deg); }
.swatch.cross::after { transform: rotate(-45deg); }
.board-tools { display: flex; align-items: center; gap: 8px; }
.board-tools .push { margin-left: auto; }
.assist { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-top: 14px; font-size: 14px; }
label.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.caption-tools { display: inline-flex; gap: 16px; }
.board-area { position: relative; }
#board.paused { visibility: hidden; }
#resume { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.rules { margin: 10px 0; padding-left: 20px; font-size: 14px; }
.rules li + li { margin-top: 4px; }
.status { margin: 12px 0 0; min-height: 24px; font-size: 14px; }
.status.error { color: var(--error); }
.status.success { font-weight: 600; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 14px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.keys dt { margin: 0; white-space: nowrap; }
.keys dd { margin: 0; }
kbd { display: inline-block; padding: 3px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 2px; color: var(--text); background: var(--bg); }
.finish-note { margin: 8px 0 18px; font-size: 13px; color: var(--muted); }
.finish-note:empty { margin: 0 0 18px; }
.link-button { height: auto; padding: 0; border: 0; background: none; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.link-button:hover:not(:disabled) { background: none; text-decoration-thickness: 2px; }
details { margin-top: 18px; max-width: 680px; }
section + details { margin-top: 32px; }
summary { cursor: pointer; width: fit-content; }
summary:hover { text-decoration: underline; text-underline-offset: 3px; }
details p { font-size: 14px; }
details label { display: block; margin: 10px 0 4px; font-size: 14px; color: var(--muted); }

/* Board */
.board { --size: clamp(24px, calc(var(--avail, 100vw - 290px) / var(--cols, 9)), 42px); border-collapse: collapse; table-layout: fixed; user-select: none; -webkit-user-select: none; }
.board.paint, .board.entry { touch-action: none; }
.board th { font-size: 13px; font-weight: normal; min-width: calc(var(--size) * .75); height: calc(var(--size) * .75); padding: 2px 6px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.board .clue { color: var(--text); }
.board th.hl { color: var(--text); font-weight: 600; background: var(--peer); }
.board td { padding: 0; border: 1px solid var(--line); background: var(--cell); min-width: var(--size); width: var(--size); height: var(--size); }
.board td.box-top { border-top: 2px solid var(--text); }
.board td.box-left { border-left: 2px solid var(--text); }
.board td.edge-top { border-top: 2px solid var(--text); }
.board td.edge-bottom { border-bottom: 2px solid var(--text); }
.board td.edge-left { border-left: 2px solid var(--text); }
.board td.edge-right { border-right: 2px solid var(--text); }
.cell { display: flex; align-items: center; justify-content: center; width: 100%; height: var(--size); padding: 0; border: 0; border-radius: 0; background: var(--cell); font-size: calc(var(--size) * .55); line-height: 1; color: var(--muted); }
button.cell:hover:not(:disabled) { background: var(--subtle); border: 0; }
.cell.given { font-weight: 600; color: var(--text); }
.cell.dot { font-size: 0; }
.cell.dot::after { content: ''; width: calc(var(--size) * .15); height: calc(var(--size) * .15); border-radius: 50%; background: currentColor; }
.cell.cross { position: relative; font-size: 0; }
.cell.cross::before, .cell.cross::after { content: ''; position: absolute; width: calc(var(--size) * .3); height: 2px; background: currentColor; transform: rotate(45deg); }
.cell.cross::after { transform: rotate(-45deg); }
.cell.labelled { font-weight: 600; color: var(--text); }
.cell.circled { position: relative; }
.cell.circled::after { content: ''; position: absolute; width: calc(var(--size) * .7); height: calc(var(--size) * .7); border: 2px solid currentColor; border-radius: 50%; box-sizing: border-box; }
.cell.shaded, button.cell.shaded:hover:not(:disabled) { background: var(--shaded); color: var(--bg); }
.board.paint .cell.same:not(.shaded) { background: var(--same); }
.cell:focus-visible { outline-offset: -3px; position: relative; }
.board.paint .cell.selected:not(:focus-visible) { outline: 2px solid var(--muted); outline-offset: -3px; position: relative; }
.board .cell.shaded:focus-visible, .board.paint .cell.shaded.selected { outline-color: var(--bg); }
.board .cell.wrong { color: var(--error); box-shadow: inset 0 0 0 2px var(--error); }
.board.entry .cell.peer { background: var(--peer); }
.board.entry .cell.same { background: var(--same); }
.board.entry .cell.selected, .board.entry button.cell.selected:hover:not(:disabled) { background: var(--select); }
.board .invalid { color: var(--error); text-decoration: underline; font-weight: 600; }
/* Blocks, split from the top-left to the bottom-right corner when they hold labels. */
.cell.block { position: relative; background: var(--block); color: var(--block-text); font-size: calc(var(--size) * .3); font-weight: 600; font-variant-numeric: tabular-nums; }
.cell.block.split { background: linear-gradient(to bottom left, var(--block) calc(50% - 1px), var(--bg) 50%, var(--block) calc(50% + 1px)); }
.cell.block .upper { position: absolute; top: 6%; right: 8%; }
.cell.block .lower { position: absolute; bottom: 6%; left: 8%; }
.cell.block .hl { margin: -1px -3px; padding: 1px 3px; border-radius: 2px; background: var(--block-text); color: var(--block); }
.board .cell.block.invalid { color: var(--block-text); text-decoration: none; box-shadow: inset 0 0 0 3px var(--error); }
.board.entry .cell.block.selected { box-shadow: inset 0 0 0 3px var(--select); }
.board td.invalid { outline: 1px solid var(--error); outline-offset: -1px; }
/* Boards with links (Hashi): no inner grid lines, circled cells, lines drawn over the table. */
.board-wrap { position: relative; width: fit-content; }
.board.linked td:not(.invalid) { border-color: transparent; }
.board.linked .cell, .board.linked button.cell:hover:not(:disabled) { background: transparent; }
.board.linked .cell.end { cursor: pointer; }
.board.linked .cell:focus-visible { outline: none; }
.board.linked .cell.selected .circle { background: var(--select); }
.board.linked .cell:focus-visible .circle { outline: 2px solid var(--text); outline-offset: 2px; }
.board.linked .cell.invalid { box-shadow: inset 0 0 0 2px var(--error); }
.board.linked .cell.complete .circle { border-color: var(--line); color: var(--muted); }
.board.linked .cell.over .circle { border-color: var(--error); color: var(--error); }
.cell .circle { display: flex; align-items: center; justify-content: center; width: 80%; height: 80%; border: 2px solid var(--text); border-radius: 50%; background: var(--cell); font-size: calc(var(--size) * .45); }
.links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.links .hit { stroke: transparent; }
.links .guide { stroke: transparent; stroke-width: 1.5; stroke-dasharray: 3 4; pointer-events: none; }
.links .editable { cursor: pointer; }
.links .editable .hit { pointer-events: stroke; }
.links .editable.empty:hover .guide { stroke: var(--muted); }
.links .bridge { stroke: var(--text); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.links .editable:hover .bridge { stroke-width: 3; }
.links .invalid .bridge, .links .wrong .bridge { stroke: var(--error); }
.links .invalid .hit { stroke: var(--error); stroke-opacity: .15; }
.swatch.line { border: 0; width: 16px; }
.swatch.line::before { content: ''; width: 100%; height: 0; border-top: 2px solid currentColor; }
.swatch.lines-0::before { border: 0; }
.swatch.lines-2::before { height: 2px; border-bottom: 2px solid currentColor; }
.notes { display: grid; grid-template-columns: repeat(var(--note-cols), 1fr); width: 100%; height: 100%; padding: 2px; font-size: calc(var(--size) * .26); line-height: 1; color: var(--muted); font-weight: normal; }
.notes span { display: flex; align-items: center; justify-content: center; }

/* Solver */
/* Solver: editor left, result right with rows aligned (toolbar/heading, grids, actions/ID).
   Below 1100px the result stacks under the editor. */
.solver-layout { display: grid; justify-content: start; grid-template-columns: auto; grid-template-areas: "toolbar" "editor" "actions" "status" "head" "result" "id"; --avail: calc(100vw - 290px); }
.solver-layout > .toolbar { grid-area: toolbar; }
.solver-layout > #editor-grid { grid-area: editor; }
.solver-layout > .actions { grid-area: actions; }
.solver-layout > .status { grid-area: status; }
.solver-layout > .result-head { grid-area: head; }
.solver-layout > #solutions { grid-area: result; }
.solver-layout > #result-id { grid-area: id; }
.solver-layout:not(.has-result) > .result-part { display: none; }
@media (min-width: 1100px) {
  .solver-layout { grid-template-columns: auto auto; grid-template-areas: "toolbar head" "editor result" "actions id" "status ."; column-gap: 56px; --avail: calc((100vw - 390px) / 2); }
}
.actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; padding: 0 2px; }
.result-head { display: flex; align-items: baseline; gap: 20px; margin-bottom: 18px; min-height: 32px; align-self: center; }
.result-head h2 { margin: 0; }
@media (max-width: 1099px) { .result-head { margin-top: 24px; } }
#result-id { margin: 14px 0 0; padding: 0 2px; }
.clue-input { width: 55px; padding: 0 2px; text-align: center; appearance: textfield; -moz-appearance: textfield; }
.clue-input::-webkit-inner-spin-button, .clue-input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.board td .clue-input { width: var(--size); height: var(--size); border: 0; border-radius: 0; background: transparent; }
.board th:has(.clue-input) { padding: 3px; }
.board th .clue-input { width: var(--size); height: calc(var(--size) - 8px); }
.board td .clue-input:hover:not(:disabled) { background: var(--subtle); }
.result-boards { display: flex; flex-wrap: wrap; gap: 28px; }
.result-board { overflow-x: auto; max-width: 100%; }
.progress, .small { color: var(--muted); font-size: 13px; }
.puzzle-id { font: 12px/1.5 var(--mono); color: var(--muted); overflow-wrap: anywhere; }

.skip-link { position: absolute; top: -80px; left: 10px; z-index: 4; padding: 6px; background: var(--bg); }
.skip-link:focus { top: 6px; }

@media (hover: none) and (pointer: coarse) { .keys { display: none; } }
@media (max-width: 700px) {
  header { padding: 0 8px 0 10px; gap: 10px; }
  #show-games { display: block; height: 30px; padding: 0 9px; font-size: 14px; }
  #trail .site-name ~ * { display: none; }
  aside { display: none; z-index: 2; width: 220px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .25); }
  body.directory-open aside { display: block; }
  main { margin-left: 0; padding: 20px 16px 40px; }
  .overview .description { display: none; }
  .player-layout, .solver-layout { grid-template-columns: 100%; --avail: calc(100vw - 44px); }
  .side { max-width: none; }
}
