:root {
  color-scheme: light;
  --bg: #f7f4fb;
  --surface: #ffffff;
  --surface-soft: #eeebf5;
  --surface-raised: #fbfaff;
  --ink: #383744;
  --muted: #6c6b7e;
  --muted-strong: #686879;
  --accent: #b7cff3;
  --accent-strong: #819bbf;
  --accent-ink: #49698f;
  --good: #e7effa;
  --cell: #f8f6fc;
  --grid-line: #9299ad;
  --grid-strong: #81899e;
  --cross: #858b9b;
  --border: rgba(100, 101, 128, .16);
  --glass: rgba(255, 255, 255, .44);
  --glass-border: rgba(255, 255, 255, .78);
  --shadow: 0 16px 42px rgba(42, 42, 68, .13);
  --hero-title: #688bb8;
  --heart: #ff5f91;
  font-family: Inter, "Avenir Next", "sans-serif-light", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
:root[data-theme="ocean"] {
  --bg: #eff8fc; --surface: #ffffff; --surface-soft: #e3f1f7; --surface-raised: #f8fcfe;
  --ink: #263d49; --muted: #5b7380; --muted-strong: #4f6e7b; --accent: #8fc6d9;
  --accent-strong: #438da7; --accent-ink: #246d87; --good: #dceff6; --cell: #f5fbfd;
  --grid-line: #91adbb; --grid-strong: #718b9a; --cross: #6e8995; --border: rgba(53, 112, 133, .17);
  --hero-title: #327e98; --heart: #ff5f91; --shadow: 0 16px 42px rgba(30, 78, 94, .12);
  --glass: rgba(255,255,255,.5); --glass-border: rgba(255,255,255,.8);
}
:root[data-theme="rose"] {
  --bg: #fff4f6; --surface: #ffffff; --surface-soft: #f9e8ed; --surface-raised: #fffafb;
  --ink: #49343c; --muted: #826775; --muted-strong: #785c68; --accent: #e4b1c1;
  --accent-strong: #b66c89; --accent-ink: #8c4965; --good: #f8e4eb; --cell: #fff9fb;
  --grid-line: #9693a4; --grid-strong: #7f8092; --cross: #9b7786; --border: rgba(140, 78, 105, .16);
  --hero-title: #a85e78; --heart: #ff5f91; --shadow: 0 16px 42px rgba(105, 53, 75, .12);
  --glass: rgba(255,255,255,.5); --glass-border: rgba(255,255,255,.82);
}
:root[data-theme="forest"] {
  --bg: #f1f7f1; --surface: #ffffff; --surface-soft: #e7f0e6; --surface-raised: #fbfdfb;
  --ink: #304237; --muted: #647466; --muted-strong: #5b7061; --accent: #a9cbb1;
  --accent-strong: #628e6d; --accent-ink: #426d4d; --good: #e0eee2; --cell: #f8fbf8;
  --grid-line: #97ad9b; --grid-strong: #7e9684; --cross: #748c79; --border: rgba(68, 116, 77, .16);
  --hero-title: #527b5c; --heart: #ff5f91; --shadow: 0 16px 42px rgba(44, 76, 49, .11);
  --glass: rgba(255,255,255,.48); --glass-border: rgba(255,255,255,.82);
}
:root[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #171a27; --surface: #222638; --surface-soft: #2a3044; --surface-raised: #252b3e;
  --ink: #edf0fa; --muted: #a3abc1; --muted-strong: #c1c8da; --accent: #9bbde9;
  --accent-strong: #8bb2e6; --accent-ink: #c2dbff; --good: #303d56; --cell: #202638;
  --grid-line: #71809b; --grid-strong: #98a8c7; --cross: #a4aec4; --border: rgba(194, 207, 235, .16);
  --hero-title: #a9c7ed; --heart: #ff5f91; --shadow: 0 18px 54px rgba(0, 0, 0, .35);
  --glass: rgba(49,56,77,.52); --glass-border: rgba(210,222,246,.13);
}
:root[data-theme="amoled"] {
  color-scheme: dark;
  --bg: #000000; --surface: #090b10; --surface-soft: #111722; --surface-raised: #0b0f16;
  --ink: #f5f7fb; --muted: #a9b1c0; --muted-strong: #d1d7e2; --accent: #8dbbff;
  --accent-strong: #79aaff; --accent-ink: #b7d4ff; --good: #15243a; --cell: #050609;
  --grid-line: #5d6f8c; --grid-strong: #8fa3c6; --cross: #b0bacb; --border: rgba(207, 220, 242, .2);
  --hero-title: #91baff; --heart: #ff5f91; --shadow: 0 18px 54px rgba(0, 0, 0, .72);
  --glass: rgba(14,19,28,.72); --glass-border: rgba(207,220,242,.16);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body { min-height: 100dvh; overscroll-behavior: none; transition: background-color .22s ease, color .22s ease; }
button { font: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 3px; }
.app-shell {
  width: min(100%, 760px); height: 100dvh; margin-inline: auto;
  padding: max(7px, env(safe-area-inset-top)) max(env(safe-area-inset-right), clamp(11px, 3.3vw, 22px)) 0 max(env(safe-area-inset-left), clamp(11px, 3.3vw, 22px));
  display: flex; flex-direction: column; gap: clamp(5px, .9vh, 10px);
}
.topbar {
  min-height: 64px; flex: 0 0 64px; display: grid;
  grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px;
}
.brand-title {
  min-width: 0; margin: 0; color: var(--hero-title); font-family: "Raleway", "Avenir Next", "sans-serif-light", Roboto, sans-serif; font-size: clamp(28px, 7.4vw, 41px);
  font-weight: 300; letter-spacing: -.065em; line-height: 1; white-space: nowrap;
}

.header-actions { justify-self: end; display: flex; align-items: center; gap: clamp(9px, 2.4vw, 14px); }
.icon-button {
  width: clamp(46px, 13vw, 52px); height: clamp(46px, 13vw, 52px); display: grid; place-items: center;
  padding: 0; border: 1px solid var(--glass-border); border-radius: 50%;
  background: var(--glass); color: var(--muted-strong); text-decoration: none; cursor: pointer;
  box-shadow: 0 5px 14px rgba(50,55,80,.06), inset 0 1px 0 rgba(255,255,255,.55);
  backdrop-filter: blur(16px) saturate(1.25); -webkit-backdrop-filter: blur(16px) saturate(1.25);
  transition: transform .18s cubic-bezier(.2,.8,.2,1), background-color .18s ease, box-shadow .18s ease;
}
.icon-button svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.brand-heart { color: var(--heart); box-shadow: 0 0 0 1px color-mix(in srgb, var(--heart) 18%, transparent), 0 5px 18px color-mix(in srgb, var(--heart) 18%, transparent), inset 0 1px 0 rgba(255,255,255,.55); }
.brand-heart svg { width: 25px; height: 25px; fill: var(--heart); stroke: var(--heart); stroke-width: .65; filter: drop-shadow(0 1px 4px color-mix(in srgb, var(--heart) 30%, transparent)); }
.icon-button:active { transform: scale(.9); box-shadow: inset 0 2px 5px rgba(40,45,65,.12); }
.game-area { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: flex-start; gap: 5px; }
.level-row { position: relative; min-height: 68px; flex: 0 0 68px; display: grid; grid-template-columns: 46px minmax(0,1fr) 46px; align-items: center; gap: 10px; }
.level-caption {
  display: grid; justify-items: center; align-content: center; gap: 7px; color: var(--muted);
  font-size: clamp(14px, 3.8vw, 18px); font-weight: 350; white-space: nowrap; line-height: 1.15;
}
.points-line { display: inline-flex; align-items: baseline; gap: 7px; padding: 8px 16px; border: 1px solid var(--glass-border); border-radius: 999px; background: var(--glass); color: var(--muted); font-size: 11px; font-weight: 450; font-variant-numeric: tabular-nums; box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 4px 12px rgba(50,55,80,.045); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); }
.points-line strong { color: var(--ink); font-size: 14px; font-weight: 720; }
.level-line { display: flex; justify-content: center; align-items: center; gap: 10px; padding-top: 1px; }
.level-caption strong { color: var(--muted-strong); font-weight: 600; }
.caption-separator { color: var(--accent-strong); opacity: .85; }
.clear-board-button {
  width: 50px; height: 50px; display: grid; place-items: center; padding: 0;
  border: 1px solid var(--glass-border); border-radius: 50%; background: var(--glass); color: var(--muted-strong);
  box-shadow: 0 5px 14px rgba(50,55,80,.06), inset 0 1px 0 rgba(255,255,255,.55);
  backdrop-filter: blur(16px) saturate(1.25); -webkit-backdrop-filter: blur(16px) saturate(1.25);
  cursor: pointer; transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}
.clear-board-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.clear-board-button:active:not(:disabled) { transform: scale(.9); }
.clear-board-button:disabled { opacity: .32; cursor: default; }
.hint-button {
  justify-self: end; width: 50px; height: 50px; display: grid; place-items: center; padding: 0;
  border: 1px solid var(--glass-border); border-radius: 50%; background: var(--glass); color: var(--accent-ink);
  box-shadow: 0 5px 14px rgba(50,55,80,.06), inset 0 1px 0 rgba(255,255,255,.55);
  backdrop-filter: blur(16px) saturate(1.25); -webkit-backdrop-filter: blur(16px) saturate(1.25);
  cursor: pointer; transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.hint-button svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.hint-button:active { transform: scale(.96); }
.hint-button:disabled { opacity: .35; cursor: default; }
.board-wrap { flex: 1 1 auto; min-width: 0; min-height: 0; width: 100%; display: grid; place-items: center; align-content: center; justify-content: center; overflow: hidden; container-type: size; padding: 0; }
.board {
  --n: 5; --cell-size: 32px; --row-clue-width: 38px; --column-clue-height: 42px; --clue-font-size: 11px; --grid-stroke: clamp(2.5px, .62vw, 4px);
  display: grid; grid-template-columns: var(--row-clue-width) repeat(var(--n), var(--cell-size));
  grid-template-rows: var(--column-clue-height) repeat(var(--n), var(--cell-size));
  width: calc(var(--row-clue-width) + var(--n) * var(--cell-size)); height: calc(var(--column-clue-height) + var(--n) * var(--cell-size));
  position: relative; max-width: 100%; max-height: 100%; gap: 0; touch-action: none; user-select: none; -webkit-user-select: none;
  transform-origin: center; transition: filter .2s ease;
}
.corner { grid-column: 1; grid-row: 1; }
.column-clues { display: grid; grid-template-columns: repeat(var(--n), var(--cell-size)); grid-column: 2; grid-row: 1; align-items: end; }
.row-clues { display: grid; grid-template-rows: repeat(var(--n), var(--cell-size)); grid-column: 1; grid-row: 2; align-items: center; }
.clue {
  min-width: 0; display: flex; justify-content: center; align-items: center; gap: 1px; overflow: hidden;
  color: var(--muted-strong); font-size: var(--clue-font-size); font-weight: 520; line-height: 1.16; letter-spacing: .005em; font-variant-numeric: tabular-nums;
}
.column-clue { flex-direction: column; gap: 2px; padding-bottom: 3px; }
.row-clue { justify-content: flex-end; gap: 3px; padding-right: 6px; white-space: nowrap; }
.clue.done { color: var(--muted); opacity: .64; text-decoration: line-through; text-decoration-thickness: 1.5px; }
.clue { transition: color .16s ease, opacity .16s ease; }
.cells {
  grid-column: 2; grid-row: 2; display: grid;
  grid-template-columns: repeat(var(--n), var(--cell-size)); grid-template-rows: repeat(var(--n), var(--cell-size));
  position: relative; background: var(--grid-strong); isolation: isolate;
}
.cell {
  position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; padding: 0;
  border: 0; border-right: var(--grid-stroke) solid var(--grid-line); border-bottom: var(--grid-stroke) solid var(--grid-line);
  border-radius: 0; background: var(--cell); color: var(--cross); touch-action: none; cursor: pointer;
  transition: background-color .09s linear, box-shadow .09s linear;
}
.cell:focus { outline: none; }
.cell:focus-visible { z-index: 2; outline: 2px solid var(--accent-strong); outline-offset: -3px; }
/* Paint the missing perimeter on the real first-row/first-column cells. This
   avoids relying on an overlay pseudo-element in mobile browser compositors. */
.cell[data-row="0"] { border-top: var(--grid-stroke) solid var(--grid-strong); }
.cell[data-col="0"] { border-left: var(--grid-stroke) solid var(--grid-strong); }
.cell.filled { background: color-mix(in srgb, var(--accent) 68%, var(--surface)); box-shadow: none; }
.cell.line-completing {
  z-index: 1;
  animation: lineCellComplete .30s ease-out both;
}
/* A restrained pastel-blue blink on cells in only the newly completed line.
   No clue animation, label, toast, layout shift or persistent decoration. */
@keyframes lineCellComplete {
  0%, 100% {
    box-shadow: inset 0 0 0 999px rgba(151, 190, 255, 0);
  }
  38% {
    box-shadow: inset 0 0 0 999px rgba(151, 190, 255, .20),
                inset 0 0 0 1px rgba(111, 160, 235, .24);
  }
  72% {
    box-shadow: inset 0 0 0 999px rgba(151, 190, 255, .08),
                inset 0 0 0 .5px rgba(111, 160, 235, .10);
  }
}
@media (hover: hover) { .cell:hover { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent-strong) 38%, transparent); } }
.cell.crossed::before, .cell.crossed::after {
  content: ""; position: absolute; width: 62%; height: clamp(3px, 7%, 7px); border-radius: 999px; background: var(--cross);
}
.cell.crossed::before { transform: rotate(-45deg); }
.cell.crossed::after { transform: rotate(45deg); }
.cell.hinted { z-index: 1; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent-strong) 65%, transparent); }
.cell.filled.hinted { outline: 2px solid var(--accent-strong); outline-offset: -2px; }

.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.toolbar {
  min-height: calc(160px + env(safe-area-inset-bottom)); flex: 0 0 calc(160px + env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(16px, 6vw, 30px); align-items: center; justify-items: center;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom)); border-top: 0;
}
.tool-button {
  width: min(136px, 100%); aspect-ratio: 1; min-width: 0; max-width: 136px; display: grid; place-items: center;
  border: 1px solid var(--glass-border); border-radius: 50%; background: color-mix(in srgb, var(--surface) 76%, transparent); color: var(--muted-strong);
  cursor: pointer; touch-action: manipulation; box-shadow: 0 9px 22px rgba(50,55,80,.075), inset 0 1px 0 rgba(255,255,255,.72);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  transition: background-color .15s ease, color .15s ease, transform .16s cubic-bezier(.2,.8,.2,1), box-shadow .16s ease;
}
.tool-button span { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.tool-button svg { width: 56%; height: 56%; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tool-button.active { border-color: color-mix(in srgb, var(--accent-strong) 12%, var(--glass-border)); background: color-mix(in srgb, var(--accent) 42%, var(--surface)); color: var(--accent-ink); box-shadow: 0 7px 18px color-mix(in srgb, var(--accent-strong) 9%, transparent), inset 0 1px 0 rgba(255,255,255,.72); }
.tool-button:active:not(:disabled) { transform: scale(.92); box-shadow: inset 0 2px 7px rgba(40,45,65,.12); }
.tool-button:disabled { opacity: .42; cursor: default; }
#undoButton { background: color-mix(in srgb, var(--surface-soft) 68%, var(--surface)); color: var(--muted-strong); }
#undoButton:disabled { opacity: .72; }
[data-tool="fill"] svg { fill: currentColor; stroke: none; }
[data-tool="cross"] svg { stroke-width: 2.7; }
.dialog {
  position: relative; width: min(calc(100vw - 28px), 430px); max-height: min(86dvh, 760px); overflow: auto;
  padding: 26px 22px 22px; border: 1px solid var(--border); border-radius: 28px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--ink); box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.25); -webkit-backdrop-filter: blur(22px) saturate(1.25);
}
.dialog::backdrop { background: rgba(24, 25, 38, .34); backdrop-filter: blur(6px); }
.dialog h2 { margin: 2px 0 19px; font-size: 24px; letter-spacing: -.55px; font-weight: 650; }
.dialog p { color: var(--muted-strong); font-size: 13px; line-height: 1.6; }
.dialog-eyebrow { margin: 0; color: var(--accent-ink) !important; font-size: 9px !important; font-weight: 800; letter-spacing: 1.25px; }
.dialog-close { position: absolute; top: 14px; right: 15px; width: 38px; height: 38px; border: 1px solid var(--glass-border); border-radius: 50%; background: var(--glass); color: var(--muted-strong); font-size: 24px; line-height: 1; cursor: pointer; }
.settings-section { margin: 0 0 22px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-heading h3 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 700; }
.section-heading > span { color: var(--muted); font-size: 10px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-choice { min-width: 0; min-height: 58px; padding: 11px 12px; display: grid; grid-template-columns: 27px minmax(0, 1fr); align-items: center; gap: 0 9px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface-raised); color: var(--ink); text-align: left; cursor: pointer; transition: border-color .18s ease, background-color .18s ease, transform .18s ease; }
.theme-choice.active { border-color: var(--accent-strong); background: var(--good); }
.theme-choice:active { transform: scale(.97); }
.theme-swatch { grid-row: 1 / span 2; width: 27px; height: 27px; border: 1px solid rgba(80,80,100,.18); border-radius: 50%; }
.swatch-lavender { background: linear-gradient(135deg, #f7f4fb 50%, #b7cff3 50%); }
.swatch-ocean { background: linear-gradient(135deg, #eff8fc 50%, #438da7 50%); }
.swatch-rose { background: linear-gradient(135deg, #fff4f6 50%, #b66c89 50%); }
.swatch-forest { background: linear-gradient(135deg, #f1f7f1 50%, #628e6d 50%); }
.swatch-midnight { background: linear-gradient(135deg, #171a27 50%, #8bb2e6 50%); }
.swatch-amoled { background: linear-gradient(135deg, #000 50%, #79aaff 50%); }
.theme-choice > span:nth-child(2) { min-width: 0; overflow: visible; font-size: 12px; font-weight: 720; white-space: nowrap; }
.theme-choice small { color: var(--muted); font-size: 10px; }
.difficulty-switch { display: flex; align-items: center; gap: 4px; max-width: 100%; padding: 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); }
.difficulty-switch button { min-width: 0; flex: 1; border: 0; border-radius: 999px; padding: 10px 7px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 720; white-space: nowrap; cursor: pointer; transition: background-color .18s ease, color .18s ease, box-shadow .18s ease; }
.difficulty-switch button.active { background: var(--surface); color: var(--accent-ink); box-shadow: 0 2px 7px rgba(30,35,55,.12), inset 0 1px 0 rgba(255,255,255,.7); }
.about-link { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 2px 2px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.about-link span { display: grid; gap: 4px; }
.about-link strong { font-size: 12px; font-weight: 720; }
.about-link small { color: var(--muted); font-size: 10px; }
.about-link > svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.about-dialog h2 { margin-bottom: 10px; }
.about-dialog p { margin: 0 0 12px; }
.about-credit { display: flex; align-items: center; gap: 9px; margin: 20px 0 12px; color: var(--muted-strong); font-size: 12px; }
.credit-heart { color: #dc8fa6; font-size: 19px; line-height: 1; }
.repository-link { min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 15px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); color: var(--accent-ink); text-decoration: none; font-size: 12px; font-weight: 720; }
.repository-link svg { width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.repository-link .external-arrow { width: 17px; height: 17px; margin-left: auto; }
.dialog .dialog-note { margin: 14px 0 0; color: var(--muted) !important; font-size: 10px !important; }
@media (max-width: 360px) {
  .app-shell { padding-inline: 9px; gap: 3px; }
  .topbar { min-height: 48px; flex-basis: 48px; gap: 4px; }
  .brand-title { font-size: clamp(23px, 7vw, 29px); }
  .icon-button { width: 44px; height: 44px; }
  .icon-button svg { width: 23px; height: 23px; }
  .header-actions { gap: 7px; }
  .level-row { min-height: 64px; flex-basis: 64px; grid-template-columns: 42px minmax(0,1fr) 42px; }
  .level-caption { font-size: 14px; }
  .toolbar { min-height: calc(130px + env(safe-area-inset-bottom)); flex-basis: calc(130px + env(safe-area-inset-bottom)); gap: 14px; }
  .tool-button { width: min(100px, 100%); }
  .theme-grid { gap: 7px; }
  .theme-choice { padding-inline: 8px; grid-template-columns: 24px minmax(0,1fr); gap: 0 7px; }
  .theme-swatch { width: 24px; height: 24px; }
}
@media (max-height: 650px) and (orientation: portrait) {
  .app-shell { gap: 2px; }
  .topbar { min-height: 42px; flex-basis: 42px; }
  .brand-title { font-size: 25px; }
  .icon-button { width: 38px; height: 38px; }
  .level-row { min-height: 58px; flex-basis: 58px; grid-template-columns: 34px minmax(0,1fr) 34px; }
  .clear-board-button, .hint-button { width: 38px; height: 38px; }
  .toolbar { min-height: calc(100px + env(safe-area-inset-bottom)); flex-basis: calc(100px + env(safe-area-inset-bottom)); padding-block: 3px max(4px, env(safe-area-inset-bottom)); }
  .tool-button { width: min(86px, 24vw); }
  .tool-button svg { width: 50%; height: 50%; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .app-shell { width: min(100%, 900px); padding: max(3px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); display: grid; grid-template-columns: minmax(0, 1fr) 64px; grid-template-rows: 40px minmax(0,1fr); gap: 3px 10px; }
  .topbar { grid-column: 1 / -1; grid-row: 1; min-height: 40px; flex: none; }
  .brand-title { font-size: 25px; }
  .icon-button { width: 32px; height: 32px; }
  .icon-button svg { width: 18px; height: 18px; }
  .game-area { grid-column: 1; grid-row: 2; min-height: 0; }
  .level-row { min-height: 28px; flex-basis: 28px; }
  .level-caption { font-size: 12px; }
  .toolbar { grid-column: 2; grid-row: 2; min-height: 0; height: 100%; flex: none; grid-template-columns: 1fr; grid-template-rows: repeat(3,minmax(0,1fr)); gap: 4px; padding: 3px 0 max(3px, env(safe-area-inset-bottom)); border: 0; }
  .tool-button { width: min(58px, 14vh); min-height: 0; }
}
@media (max-height: 700px) {
  .toolbar { min-height: calc(124px + env(safe-area-inset-bottom)); flex-basis: calc(124px + env(safe-area-inset-bottom)); }
  .tool-button { width: min(112px, 100%); max-width: 112px; }
}


/* Lower-cost glass treatment on touch devices and modest GPUs. */
@media (hover: none), (pointer: coarse) {
  .icon-button, .clear-board-button, .hint-button, .points-line {
    -webkit-backdrop-filter: blur(7px) saturate(1.08);
    backdrop-filter: blur(7px) saturate(1.08);
  }
  .cell { transition: none; }
}
/* Completion dialog: plain stats, three clear choices, readable in every palette. */
.completion-dialog {
  width: min(calc(100vw - 28px), 448px);
  max-height: min(88dvh, 720px);
  padding: clamp(30px, 6vw, 42px) clamp(22px, 5vw, 34px);
  text-align: center;
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--accent-strong);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.completion-dialog[open] { animation: completionEnter .24s cubic-bezier(.2,.8,.25,1) both; }
@keyframes completionEnter { from { opacity: 0; transform: translateY(9px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
.completion-mark {
  width: 48px; height: 48px; margin: 0 auto 16px; display: grid; place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent-strong) 35%, transparent); border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 58%, var(--surface-raised)); color: var(--accent-ink);
  font-size: 25px; font-weight: 700; box-shadow: 0 5px 14px color-mix(in srgb, var(--accent-strong) 14%, transparent);
  animation: completionMarkPop .38s cubic-bezier(.18,.8,.25,1) .06s both;
}
@keyframes completionMarkPop { from { opacity: 0; transform: scale(.72); } 72% { opacity: 1; transform: scale(1.06); } to { opacity: 1; transform: scale(1); } }
.completion-dialog::backdrop {
  background: rgba(15, 18, 28, .54);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.completion-dialog h2 {
  margin: 2px 0 25px;
  color: var(--ink);
  font-size: clamp(31px, 7.8vw, 43px);
  line-height: 1.12;
  letter-spacing: -.8px;
  font-weight: 430;
  overflow-wrap: anywhere;
}
.completion-stats { margin: 0 0 30px; }
.completion-stat {
  margin: 8px 0;
  color: var(--muted-strong);
  font-size: clamp(17px, 4.4vw, 21px);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.completion-stat strong { color: var(--ink); font-weight: 700; }
.completion-actions { display: flex; flex-direction: column; gap: 13px; }
.completion-action {
  width: 100%; min-height: 68px; padding: 13px 18px;
  display: flex; align-items: center; justify-content: center; gap: 11px;
  border: 1px solid transparent; border-radius: 999px;
  font: inherit; font-size: clamp(19px, 4.8vw, 23px); font-weight: 680;
  line-height: 1.2; text-align: center; text-decoration: none;
  cursor: pointer; touch-action: manipulation;
  transition: transform .14s ease, filter .14s ease, background-color .14s ease;
}
.completion-next { background: var(--accent); color: #172436; }
.completion-replay { background: var(--surface-raised); border-color: var(--border); color: var(--ink); }
.completion-kofi { background: var(--good); border-color: var(--accent-strong); color: var(--accent-ink); }
.completion-kofi[hidden] { display: none !important; }
.completion-kofi svg { width: 27px; height: 27px; flex: 0 0 27px; }
.completion-action:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 3px; }
.completion-action:active { transform: scale(.985); }
@media (hover: hover) {
  .completion-action:hover { filter: brightness(.97); }
}
@media (max-width: 360px) {
  .completion-dialog { padding: 25px 17px 20px; }
  .completion-actions { gap: 10px; }
  .completion-action { min-height: 60px; }
}
@media (max-height: 600px) {
  .completion-dialog { padding-block: 20px; }
  .completion-dialog h2 { margin-bottom: 12px; }
  .completion-stats { margin-bottom: 16px; }
  .completion-stat { margin: 5px 0; }
  .completion-action { min-height: 52px; }
  .completion-actions { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .cell.line-completing, .clue.just-completed, .completion-dialog[open], .completion-mark, .completion-action { animation: none !important; transition: none !important; }
}
