:root {
  color-scheme: light;
  --bg: #f7f8fa; --surface: #fff; --text: #293431; --muted: #687772;
  --line: #e0e6e3; --grid: #b5c4bd; --accent: #286b56; --soft: #e8f2ec;
  --covered: #dce9e1; --hover: #cbded2; --opened: #f8fbf9;
  --red: #b64e44; --red-soft: #fae9e6; --blue: #3a75b1; --blue-soft: #e8effa;
  --amber: #a57a2b; --amber-soft: #f5eddb; --focus: #316dd1;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1d2321; --surface: #242c28; --text: #e5eee8; --muted: #a2b0a9;
  --line: #3c4941; --grid: #64796c; --accent: #98cdb0; --soft: #30463a;
  --covered: #374d40; --hover: #45624f; --opened: #29332d;
  --red: #ef9a8d; --red-soft: #57332e; --blue: #9cbfe8; --blue-soft: #304459;
  --amber: #d6b76e; --amber-soft: #453e2d; --focus: #98bdff;
}
* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; -webkit-font-smoothing: antialiased; }
body[data-variant="fog"] { --covered: #dfe8ed; --hover: #cedee6; --opened: #f7fafb; }
:root[data-theme="dark"] body[data-variant="fog"] { --covered: #35464c; --hover: #425b66; --opened: #273337; }
button, select { font: inherit; color: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .35; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button, a { -webkit-touch-callout: none; }
a { color: inherit; text-decoration: none; }
button { border: 0; background: none; }
svg { width: 19px; height: 19px; flex-shrink: 0; vertical-align: middle; pointer-events: none; }
.lab-shell { width: min(1060px, calc(100% - 64px)); margin: auto; }
.lab-header { min-height: 96px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.lab-brand { display: flex; align-items: center; gap: 12px; }
.lab-brand img { width: 42px; height: 42px; }
.lab-brand strong { display: block; font-size: 20px; font-weight: 650; }
.lab-brand small { display: block; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; gap: 12px; align-items: center; }
.help-trigger { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px; border-radius: 5px; color: var(--accent); font-size: 12px; white-space: nowrap; }
.help-trigger svg { width: 17px; height: 17px; }
.help-trigger:hover { background: var(--soft); }
.back-link { color: var(--muted); font-size: 12px; display: flex; gap: 7px; align-items: center; }
.back-link:hover { color: var(--accent); }
.tool { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 6px; position: relative; flex-shrink: 0; }
.tool:hover:not(:disabled) { background: var(--soft); color: var(--accent); }
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 8; width: max-content; max-width: 180px; padding: 5px 8px; background: var(--text); color: var(--surface); border-radius: 4px; font-size: 11px; font-weight: 400; opacity: 0; pointer-events: none; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; }
.lab-header [data-tip]::after { top: calc(100% + 7px); bottom: auto; }
.lab-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.lab-tabs a { padding: 17px 18px; display: flex; gap: 12px; align-items: center; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--muted); }
.lab-tabs a small { font: 12px ui-monospace, monospace; opacity: .7; }
.lab-tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); background: var(--soft); font-weight: 600; }
.lab-tabs a:hover { color: var(--accent); }
.lab-main { padding: 30px 0 38px; }
.game-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.game-heading h1 { margin: 0; font-size: 25px; font-weight: 600; }
.game-heading p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.puzzle-picker { display: flex; gap: 8px; align-items: center; }
.puzzle-picker select { appearance: auto; border: 1px solid var(--line); background: var(--surface); padding: 9px 30px 9px 12px; border-radius: 6px; max-width: 185px; font-size: 12px; }
.play-layout { display: grid; grid-template-columns: minmax(0, 570px) minmax(230px, 1fr); gap: 58px; align-items: start; }
.play-column { min-width: 0; }
.board-toolbar { display: flex; justify-content: space-between; align-items: center; padding-left: 25px; margin-bottom: 18px; gap: 20px; }
.stat { display: flex; align-items: center; gap: 10px; min-width: 85px; }
.stat > svg { color: var(--red); width: 22px; height: 22px; }
.stat.clock > svg { color: var(--blue); }
.stat small { display: block; color: var(--muted); font-size: 10px; }
.stat strong { display: block; font: 500 23px/1.3 ui-monospace, SFMono-Regular, monospace; font-variant-numeric: tabular-nums; }
.progress-stat { text-align: center; color: var(--muted); font-size: 11px; }
.progress-stat strong { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.progress-track { margin-top: 7px; height: 3px; width: 90px; background: var(--line); }
.progress-track span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.board-frame { display: grid; grid-template-columns: 25px minmax(0, 1fr); grid-template-rows: 24px auto; width: 100%; max-width: 440px; margin: 0 auto; }
.column-labels { grid-column: 2; display: grid; grid-template-columns: repeat(var(--size), minmax(0, 1fr)); }
.row-labels { grid-column: 1; grid-row: 2; display: grid; grid-template-rows: repeat(var(--size), minmax(0, 1fr)); }
.column-labels span, .row-labels span { display: grid; place-items: center; font: 11px ui-monospace, monospace; color: var(--muted); }
.matrix { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(var(--size), minmax(0, 1fr)); gap: 1px; background: var(--grid); border: 2px solid var(--grid); border-radius: 3px; overflow: hidden; user-select: none; -webkit-user-select: none; }
.matrix-row { display: contents; }
.tile { padding: 0; position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; width: 100%; min-width: 0; background: var(--covered); font: 600 24px ui-rounded, -apple-system, sans-serif; color: var(--text); transition: background .12s; }
.tile.box-right { border-right: 2px solid var(--grid); }
.tile.box-bottom { border-bottom: 2px solid var(--grid); }
.tile.open { background: var(--opened); }
.tile:not(.open):hover { background: var(--hover); }
.tile.open:hover { background: var(--soft); }
.tile.selected { box-shadow: inset 0 0 0 2px var(--focus); z-index: 1; }
.tile:focus-visible { outline-offset: -4px; z-index: 2; }
.tile.source { background: var(--blue-soft); }
.tile.hint-target { box-shadow: inset 0 0 0 3px var(--amber); z-index: 1; }
.tile.mine { background: var(--red-soft); color: var(--red); }
.tile.flagged { color: var(--red); }
.tile .flag-icon { width: 25px; height: 25px; }
.tile[data-number="1"] .adjacent-main { color: var(--blue); }
.tile[data-number="2"] .adjacent-main { color: var(--accent); }
.tile[data-number="3"] .adjacent-main { color: var(--red); }
.tile[data-number="4"] .adjacent-main { color: #81649c; }
:root[data-theme="dark"] .tile[data-number="4"] .adjacent-main { color: #c8abd9; }
.zero { width: 4px; height: 4px; background: var(--grid); border-radius: 50%; }
.tile .adjacent-corner { position: absolute; bottom: 4px; right: 5px; font: 500 12px ui-monospace, monospace; display: flex; gap: 2px; align-items: center; color: var(--blue); }
.adjacent-corner svg { width: 10px; height: 10px; }
.digit-code { color: var(--muted); }
.open .digit-code { color: var(--accent); }
.flagged .digit-code { position: absolute; bottom: 4px; left: 6px; font-size: 12px; }
.tile .pencil-notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 72%; height: 64%; align-content: center; gap: 3px; font: 400 12px ui-monospace, monospace; color: var(--muted); }
.pencil-notes span { height: 15px; text-align: center; }
.cage-boundary { position: absolute; inset: 3px; border: 0 dashed var(--amber); pointer-events: none; }
.cage-name { position: absolute; top: 4px; left: 7px; font: 500 10px ui-monospace, monospace; color: var(--amber); }
.tile.cage-selected { background: var(--amber-soft); }
body[data-variant="fog"] .board-frame, body[data-variant="cage"] .board-frame { max-width: 430px; }
.mobile-cage-picker { display: none; }
.board-actions { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 0 25px; gap: 12px; }
.modes { display: flex; border: 1px solid var(--line); background: var(--surface); padding: 3px; border-radius: 7px; gap: 2px; }
.modes button { display: flex; align-items: center; justify-content: center; min-height: 34px; padding: 6px 11px; gap: 7px; border-radius: 4px; font-size: 12px; white-space: nowrap; }
.modes button[aria-pressed="true"] { background: var(--accent); color: var(--surface); }
:root[data-theme="dark"] .modes button[aria-pressed="true"] { color: var(--bg); }
.history-actions { display: flex; gap: 2px; }
.redo svg { transform: scaleX(-1); }
.notes-bar { display: flex; align-items: center; gap: 10px; margin: 18px 0 0 25px; }
.notes-bar > span { font-size: 11px; color: var(--muted); }
.note-keys { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); flex: 1; gap: 5px; }
.note-key { border: 1px solid var(--line); background: var(--surface); border-radius: 4px; height: 37px; font: 500 16px ui-monospace, monospace; }
.note-key[aria-pressed="true"] { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.note-key.danger { color: var(--red); }
.game-state { margin: 20px 0 0 25px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.state-label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.state-label svg { color: var(--accent); width: 17px; height: 17px; }
.game-state[data-state="lost"] .state-label, .game-state[data-state="lost"] svg { color: var(--red); }
.game-state small { color: var(--muted); white-space: nowrap; }
.command { display: inline-flex; justify-content: center; align-items: center; gap: 7px; padding: 9px 12px; min-height: 36px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; }
.command:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.command.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
:root[data-theme="dark"] .command.primary { color: var(--bg); }
.command svg { width: 16px; height: 16px; }
.side-section { padding: 20px 0; border-top: 1px solid var(--line); }
.side-section:first-child { padding-top: 0; border-top: 0; }
.side-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.side-heading h2 { font-size: 13px; font-weight: 600; margin: 0; }
.side-heading > span { color: var(--muted); font: 11px ui-monospace, monospace; }
.rule-list { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 10px; font-size: 12px; }
.rule-list dt { color: var(--muted); }
.rule-list dd { margin: 0; text-align: right; }
.identity-set { display: inline-flex; gap: 7px; font: 500 13px ui-monospace, monospace; }
.safe-identity { color: var(--accent); }
.danger-identity { color: var(--red); }
.selection-head { color: var(--accent); font: 500 16px ui-monospace, monospace; }
.selection-list { display: flex; justify-content: space-between; gap: 9px; margin: 12px 0 0; color: var(--muted); font-size: 11px; }
.selection-list strong { display: block; margin-top: 4px; color: var(--text); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.selection-meta { min-height: 22px; font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.cages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.cage-choice { padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; border-radius: 4px; min-height: 58px; }
.cage-choice strong { color: var(--amber); font: 600 12px ui-monospace, monospace; }
.cage-choice span { font-size: 10px; color: var(--muted); }
.cage-choice[aria-pressed="true"] { background: var(--amber-soft); }
.cage-choice:hover { background: var(--amber-soft); }
.hint-trigger { width: 100%; }
.hint-content { border-left: 2px solid var(--amber); padding-left: 12px; margin-bottom: 13px; }
.hint-content strong { font-size: 12px; color: var(--amber); }
.hint-content p { font-size: 12px; margin: 8px 0 12px; line-height: 1.75; overflow-wrap: anywhere; }
.hint-actions { display: flex; gap: 6px; align-items: center; }
.hint-actions .command { flex: 1; }
.lab-footer { border-top: 1px solid var(--line); min-height: 58px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); gap: 15px; font-size: 10px; }
.lab-footer a:hover { color: var(--accent); }
.instructions-open { overflow: hidden; }
.game-help-dialog { padding: 0; width: min(600px, calc(100% - 32px)); max-height: calc(100dvh - 32px); margin: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); overflow: hidden; }
.game-help-dialog[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.game-help-dialog::backdrop { background: #10271f66; backdrop-filter: blur(2px); }
.help-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.help-header > div > span { font-size: 11px; color: var(--muted); }
.help-header h2 { margin: 4px 0 0; font-size: 21px; font-weight: 600; }
.help-body { padding: 0 24px 24px; overflow: auto; overscroll-behavior: contain; min-height: 0; }
.help-body section { padding-top: 20px; }
.help-body h3 { margin: 0 0 9px; color: var(--accent); font-size: 14px; font-weight: 600; }
.help-body p, .help-body li, .help-controls { font-size: 13px; line-height: 1.8; overflow-wrap: anywhere; }
.help-body p { margin: 8px 0 0; }
.help-body ol { margin: 0; padding-left: 21px; }
.help-body li + li { margin-top: 7px; }
.help-legend { display: flex; align-items: center; gap: 15px; margin: 16px 0 0; }
.help-sample { width: 66px; height: 66px; flex: 0 0 66px; position: relative; display: grid; place-items: center; background: var(--opened); border: 1px solid var(--grid); border-radius: 3px; color: var(--accent); font: 600 25px ui-rounded, -apple-system, sans-serif; }
.help-sample.covered { background: var(--covered); color: var(--muted); }
.help-sample small { position: absolute; right: 4px; bottom: 4px; display: flex; align-items: center; gap: 2px; font: 500 12px ui-monospace, monospace; color: var(--blue); }
.help-sample small svg { width: 11px; height: 11px; }
.help-legend figcaption { font-size: 12px; line-height: 1.8; }
.help-body .help-reminder { color: var(--muted); font-size: 12px; }
.help-controls { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: 12px 14px; margin: 0; }
.help-controls dt { display: flex; align-items: flex-start; gap: 6px; font-weight: 500; }
.help-controls dt svg { width: 15px; height: 15px; margin-top: 4px; }
.help-controls dd { margin: 0; }
.help-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--line); }
.help-footer > span { color: var(--muted); font-size: 11px; }
.help-footer .command { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (min-width: 1500px) { .lab-shell { margin-top: 18px; } .lab-main { padding-top: 40px; } }
@media (max-width: 850px) {
  .lab-shell { width: calc(100% - 40px); }
  .play-layout { gap: 28px; grid-template-columns: minmax(0, 1fr) 210px; }
  .tile { font-size: 21px; }
  .modes button { padding: 6px 8px; }
  .board-actions { gap: 4px; }
}
@media (max-width: 690px) {
  .lab-shell { width: calc(100% - 32px); }
  .lab-header { min-height: 80px; }
  .lab-brand img { width: 35px; height: 35px; }
  .lab-brand strong { font-size: 18px; }
  .back-link { font-size: 11px; }
  .header-actions { gap: 6px; }
  .lab-tabs a { padding: 13px 5px; gap: 5px; justify-content: center; font-size: 12px; }
  .lab-tabs a small { font-size: 10px; }
  .lab-main { padding: 23px 0 26px; }
  .game-heading { margin-bottom: 22px; gap: 10px; }
  .game-heading h1 { font-size: 22px; }
  .puzzle-picker { gap: 2px; }
  .puzzle-picker select { padding: 8px 4px; max-width: 134px; font-size: 12px; }
  .play-layout { display: block; }
  .board-toolbar { padding-left: 20px; gap: 10px; margin-bottom: 9px; }
  .stat { min-width: 72px; gap: 7px; }
  .stat strong { font-size: 21px; }
  .board-frame { grid-template-columns: 20px minmax(0, 1fr); }
  .tile { font-size: 19px; }
  .tile .flag-icon { width: 21px; height: 21px; }
  .board-actions, .game-state, .notes-bar { margin-left: 20px; }
  .board-actions { margin-top: 17px; }
  .modes button { min-height: 38px; }
  .tool { width: 40px; height: 40px; }
  .sidebar { margin-top: 28px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; border-top: 1px solid var(--line); }
  .side-section:first-child { padding-top: 20px; }
  .side-section:nth-child(2) { border-top: 0; }
  .side-section.hint-section { grid-column: 1 / -1; order: -1; border-top: 0; }
  .side-section.cage-section { display: none; }
  .mobile-cage-picker { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 13px 0 11px 20px; padding: 7px 10px; background: var(--amber-soft); color: var(--text); font-size: 12px; }
  .mobile-cage-picker select { min-width: 0; max-width: 180px; border: 0; border-radius: 0; background: transparent; padding: 3px; font-size: 16px; }
  .cages { grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 0; }
  .cage-choice span { font-size: 10px; }
  .cage-choice { padding: 7px 0; }
  .side-heading { margin-bottom: 12px; }
  .tile .adjacent-corner { bottom: 3px; right: 4px; font-size: 11px; }
}
@media (max-width: 370px) {
  .lab-shell { width: calc(100% - 20px); }
  .lab-tabs a { font-size: 11px; gap: 4px; }
  .back-link span { display: none; }
  .game-heading h1 { font-size: 20px; }
  .game-heading p { font-size: 11px; }
  .puzzle-picker select { max-width: 112px; }
  .tile { font-size: 17px; }
  body[data-variant="fog"] .tile, body[data-variant="cage"] .tile { font-size: 21px; }
  .modes button { padding: 6px 8px; gap: 5px; }
  .modes button svg { width: 15px; height: 15px; }
  .sidebar { column-gap: 17px; }
  .cages { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
  .progress-track { width: 64px; }
  .stat > svg { width: 18px; height: 18px; }
  .stat strong { font-size: 19px; }
}
@media (max-width: 620px) {
  .game-help-dialog { width: calc(100% - 20px); max-height: calc(100dvh - 20px); }
  .help-header { padding: 15px 16px; }
  .help-body { padding: 0 16px 20px; }
  .help-header h2 { font-size: 20px; }
  .help-controls { grid-template-columns: 1fr; gap: 3px; }
  .help-controls dt:not(:first-child) { margin-top: 10px; }
  .help-footer { padding: 13px 16px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
