:root {
  color-scheme: dark light;
  --bg: light-dark(#f3f3f1, #060606);
  --panel: light-dark(#fbfbf9, #101010);
  --surface: light-dark(#efefec, #171717);
  --surface-hover: light-dark(#e8e8e4, #1d1d1d);
  --text: light-dark(#151515, #f4f4f2);
  --muted: light-dark(#595955, #a5a5a0);
  --line: light-dark(#deded9, #292929);
  --strong-line: light-dark(#c2c2bb, #4a4a46);
  --tile: #141414;
  --clue: light-dark(#686342, #cfc8a8);
  --success: light-dark(#3f552e, #c3d6aa);
  --success-bg: light-dark(#edf2e8, #1d2419);
  --success-line: light-dark(#bac9b1, #49583e);
  --wrong: light-dark(#873f38, #eab3a8);
  --radius: 24px;
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font: 16px/1.5 var(--font);
}

:root[data-theme='dark'] { color-scheme: dark; }
:root[data-theme='light'] { color-scheme: light; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled, [aria-disabled='true'] { cursor: default; }
button:focus-visible, a:focus-visible, h1:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }
h1, h2, p { margin: 0; }

.top { border-bottom: 1px solid var(--line); }
.top-inner, .game-shell { width: min(1056px, calc(100% - 64px)); margin-inline: auto; }
.top-inner { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-size: 1.2rem; font-weight: 720; letter-spacing: -.035em; border-radius: 8px; }
.brand img { display: block; }
.top-actions { display: flex; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: .9rem; font-weight: 590; transition: background-color 150ms, border-color 150ms; }
.button:hover { background: var(--surface-hover); border-color: var(--strong-line); }
.icon-button { width: 44px; padding: 0; }
.icon-button .moon { display: none; }
:root[data-theme='light'] .icon-button .sun { display: none; }
:root[data-theme='light'] .icon-button .moon { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .icon-button .sun { display: none; }
  :root:not([data-theme]) .icon-button .moon { display: block; }
}

.game-shell { padding-block: clamp(32px, 6vw, 68px) 28px; }
.level-heading { margin-bottom: clamp(20px, 3vw, 32px); }
.level-meta { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.eyebrow { color: var(--muted); font-size: .82rem; font-weight: 680; letter-spacing: .075em; text-transform: uppercase; white-space: nowrap; }
.level-meter { display: flex; align-items: center; gap: 4px; }
.level-meter span { width: 9px; height: 3px; border-radius: 9px; background: var(--strong-line); }
.level-meter .done { background: var(--clue); }
.level-meter .current { width: 15px; background: var(--text); }
h1 { width: fit-content; max-width: 100%; font-size: clamp(2.45rem, 5.3vw, 3.9rem); font-weight: 700; line-height: 1.02; letter-spacing: -.06em; text-wrap: balance; }
h2 { font-size: 1.08rem; line-height: 1.25; letter-spacing: -.025em; font-weight: 670; }
.lead { max-width: 64ch; margin-top: 12px; color: var(--muted); font-size: 1.02rem; text-wrap: pretty; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); align-items: start; gap: 16px; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.board { padding: clamp(17px, 2.4vw, 27px); }
.row-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 11px; }
.row-detail { color: var(--muted); font-size: .83rem; font-variant-numeric: tabular-nums; }
.piece-row { display: grid; grid-template-columns: repeat(var(--columns, 4), minmax(0, 1fr)); gap: clamp(6px, 1.1vw, 12px); }
.cell { display: grid; min-width: 0; place-items: center; gap: 5px; padding: 0; border: 0; background: none; text-align: center; }
.after-cell { border-radius: 12px; }
.piece, .cover { display: grid; position: relative; isolation: isolate; overflow: hidden; place-items: center; width: 100%; aspect-ratio: 1; border-radius: clamp(10px, 1.8vw, 19px); }
.piece { background: var(--tile); box-shadow: inset 0 0 0 1px #ffffff12; }
.piece-image { position: absolute; inset: 5%; background-image: url('./assets/pieces.webp'); background-size: 384% 256%; background-repeat: no-repeat; transform: rotate(var(--turn, 0deg)); }
.piece-ring { background-position: 7.22% 12.34%; }
.piece-wedge { background-position: 50.18% 12.34%; }
.piece-frame { background-position: 92.78% 12.34%; }
.piece-fork { background-position: 7.22% 87.82%; }
.piece-link { background-position: 50.18% 87.82%; }
.piece-wave { background-position: 92.78% 87.82%; }
.cover { border: 1px dashed var(--strong-line); background: var(--surface); color: var(--muted); font-size: clamp(1.34rem, 3.4vw, 2.15rem); font-weight: 520; transition: color 150ms, background-color 150ms, border-color 150ms; }
.after-cell:not([aria-disabled]):hover .cover { border-color: var(--muted); background: var(--surface-hover); color: var(--text); }
.clue .piece { outline: 1px solid var(--clue); outline-offset: -1px; }
.cell-number { color: var(--muted); font-size: .83rem; font-variant-numeric: tabular-nums; }
.clue .cell-number { color: var(--clue); font-weight: 660; }
.board-divider { height: 1px; background: var(--line); margin-block: 15px; }
.board-tip { margin-top: 13px; color: var(--muted); font-size: .87rem; }

.moves { padding: clamp(17px, 2.15vw, 25px); }
.moves h2 { font-size: 1.23rem; }
.moves > p:not(.feedback) { margin-top: 5px; color: var(--muted); font-size: .9rem; }
.move-list { display: grid; gap: 8px; margin-top: 16px; }
.move, .level-option { display: flex; align-items: center; width: 100%; min-height: 54px; gap: 10px; padding: 7px 10px; text-align: left; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); transition: background-color 150ms, border-color 150ms; }
.move:not(:disabled):hover, .level-option:not(:disabled):hover { background: var(--surface-hover); border-color: var(--strong-line); }
.move:disabled, .level-option:disabled { color: var(--muted); }
.move.correct { color: var(--success); background: var(--success-bg); border-color: var(--success-line); }
.move-letter { display: grid; place-items: center; flex: 0 0 30px; height: 30px; border: 1px solid var(--strong-line); border-radius: 8px; font-size: .83rem; font-weight: 650; color: var(--muted); }
.correct .move-letter { color: inherit; border-color: var(--success-line); }
.move-text { font-size: .93rem; line-height: 1.32; text-wrap: pretty; }
.feedback { margin-top: 12px; color: var(--muted); font-size: .87rem; }
.feedback:empty { margin: 0; }
.feedback.success { color: var(--success); }
.feedback.wrong { color: var(--wrong); }
.round-result { margin-top: 14px; }
.primary { width: 100%; background: var(--text); color: var(--bg); border-color: var(--text); }
.primary:hover { background: var(--text); border-color: var(--text); box-shadow: 0 0 0 3px var(--strong-line); }
.game-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px 16px; min-height: 54px; margin-top: 4px; color: var(--muted); font-size: .82rem; }
.subtle { background: transparent; border-color: transparent; color: var(--muted); font-weight: 540; }

.levels-dialog { box-sizing: border-box; width: min(550px, calc(100% - 32px)); max-height: min(85dvh, 760px); padding: 20px; border: 1px solid var(--strong-line); border-radius: var(--radius); color: var(--text); background: var(--panel); box-shadow: 0 22px 65px #0005; }
.levels-dialog::backdrop { background: #0008; backdrop-filter: blur(7px); }
.dialog-header { display: flex; justify-content: space-between; align-items: start; gap: 14px; margin-bottom: 15px; }
.dialog-header h2 { font-size: 1.5rem; }
.dialog-header p { color: var(--muted); font-size: .9rem; margin-top: 5px; }
.level-list { display: grid; gap: 7px; }
.level-option[aria-current] { border-color: var(--clue); }
.level-name { flex: 1; line-height: 1.25; font-size: .94rem; }
.level-status { flex: 0 0 auto; color: var(--muted); font-size: .78rem; }

@media (max-width: 720px) {
  .top-inner, .game-shell { width: min(530px, calc(100% - 32px)); }
  .top-inner { height: 64px; }
  .game-shell { padding-top: 30px; }
  .level-meta { gap: 10px; }
  .level-meter span { width: clamp(5px, 2vw, 9px); }
  .level-meter .current { width: clamp(9px, 3vw, 15px); }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .panel { border-radius: 20px; }
  .board-divider { margin-block: 11px; }
  .board-tip { margin-top: 9px; }
  .move-list { margin-top: 12px; }
  .move { min-height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
}
