/* Sudoku: paper and ink. Colors are tokens on :root, redefined per theme. */

@font-face {
  /* Source Serif 4 (SIL OFL, fonts/OFL.txt), subset to 1–9 with its weight axis kept. */
  font-family: "Sudoku Digits";
  src: url("fonts/digits.woff2") format("woff2");
  font-weight: 300 700;
  font-display: block;
  unicode-range: U+0031-0039;
}

:root {
  --bg-1: #f8f5ef;
  --bg-2: #efe9de;
  --chrome-ink: #23272e;
  --surface: #fffdf9;
  --surface-2: #f5f1e9;
  --ink: #1e2229;
  --ink-2: #5b626c;
  --ink-3: #8c9199;
  --line: #e4ded2;
  --paper: #fffdf8;
  --grid-thin: #d9d2c4;
  --grid-thick: #2c3038;
  --given: #1e2229;
  --entry: #2a5cc8;
  --note: #636a75;
  --sel: #c9dbfb;
  --peer: #eef1f5;
  --same: #d9e5fb;
  --bad-ink: #c8352d;
  --bad-bg: #fbe3df;
  --sweep: rgba(42, 92, 200, 0.16);
  --accent: #2a5cc8;
  --accent-2: #234fae;
  --accent-ink: #ffffff;
  --gold: #b97d07;
  --hl-house: #fff5d6;
  --hl-cell: #ffe7a3;
  --hl-place: #d4f0da;
  --hl-target: #fde4e0;
  --n-key: #f5c33b;
  --n-on: #39a463;
  --n-off: #e0892e;
  --n-elim: #d23c2f;
  --n-a: #3b82f6;
  --n-b: #f97316;
  --shadow: 0 1px 2px rgba(40, 32, 18, 0.06), 0 6px 22px rgba(40, 32, 18, 0.09);
  --shadow-lg: 0 2px 6px rgba(20, 18, 12, 0.08), 0 24px 60px rgba(20, 18, 12, 0.22);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "New York", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --digits: "Sudoku Digits", "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --texture: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.3  0 0 0 0 0.25  0 0 0 0 0.15  0 0 0 0.07 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  --cell: 44px;
  --side: 300px;
  --ease: cubic-bezier(0.2, 0.75, 0.25, 1);
  color-scheme: light;
}

:root[data-theme="sage"] {
  --bg-1: #f1f4ee;
  --bg-2: #e3e9de;
  --paper: #fcfdf9;
  --surface: #fdfefb;
  --surface-2: #eef2ea;
  --line: #dce3d5;
  --grid-thin: #cfd8c8;
  --grid-thick: #2b3a32;
  --entry: #1f7a62;
  --accent: #1f7a62;
  --accent-2: #186350;
  --sel: #c6e6d9;
  --peer: #eef3ec;
  --same: #d5ebe1;
  --sweep: rgba(31, 122, 98, 0.16);
}

:root[data-theme="mist"] {
  --bg-1: #f2f5f9;
  --bg-2: #e2e8f0;
  --paper: #fcfdff;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --line: #dbe2ec;
  --grid-thin: #cfd7e3;
  --grid-thick: #27324a;
  --entry: #4b49c9;
  --accent: #4b49c9;
  --accent-2: #3d3bb0;
  --sel: #d6d6fb;
  --peer: #eef1f7;
  --same: #e0e0fb;
  --sweep: rgba(75, 73, 201, 0.15);
}

/* Night, by choice or (with the Automatic theme) by the system's dark mode. */
:root[data-theme="night"] {
  --bg-1: #191c22;
  --bg-2: #101216;
  --chrome-ink: #e9ebef;
  --surface: #1e2229;
  --surface-2: #262b33;
  --ink: #e9ebef;
  --ink-2: #a3aab5;
  --ink-3: #747c88;
  --line: #2f353f;
  --paper: #1b1f26;
  --grid-thin: #303742;
  --grid-thick: #8e98a8;
  --given: #eceef2;
  --entry: #86acff;
  --note: #a0a8b4;
  --sel: #2b4170;
  --peer: #222832;
  --same: #2c3b5c;
  --bad-ink: #ff8279;
  --bad-bg: #3d2325;
  --sweep: rgba(134, 172, 255, 0.18);
  --accent: #6f98f8;
  --accent-2: #86acff;
  --accent-ink: #0e1524;
  --gold: #f0b93d;
  --hl-house: #2d2817;
  --hl-cell: #4d3d12;
  --hl-place: #1d3b29;
  --hl-target: #3f2424;
  --n-key: #d6a321;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 26px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 70px rgba(0, 0, 0, 0.55);
  --texture: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-1: #191c22;
    --bg-2: #101216;
    --chrome-ink: #e9ebef;
    --surface: #1e2229;
    --surface-2: #262b33;
    --ink: #e9ebef;
    --ink-2: #a3aab5;
    --ink-3: #747c88;
    --line: #2f353f;
    --paper: #1b1f26;
    --grid-thin: #303742;
    --grid-thick: #8e98a8;
    --given: #eceef2;
    --entry: #86acff;
    --note: #a0a8b4;
    --sel: #2b4170;
    --peer: #222832;
    --same: #2c3b5c;
    --bad-ink: #ff8279;
    --bad-bg: #3d2325;
    --sweep: rgba(134, 172, 255, 0.18);
    --accent: #6f98f8;
    --accent-2: #86acff;
    --accent-ink: #0e1524;
    --gold: #f0b93d;
    --hl-house: #2d2817;
    --hl-cell: #4d3d12;
    --hl-place: #1d3b29;
    --hl-target: #3f2424;
    --n-key: #d6a321;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 26px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 70px rgba(0, 0, 0, 0.55);
    --texture: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-2);
  background-image: var(--texture), radial-gradient(130% 90% at 50% 12%, var(--bg-1) 35%, var(--bg-2));
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:disabled { cursor: default; }

svg { display: block; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- the top bar ------------------------------------------------------------------------- */

.bar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  height: 58px;
  padding: 0 14px;
  color: var(--chrome-ink);
}

.title-btn {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  text-align: left;
}
.title-btn:hover { background: var(--surface-2); }
.brand svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}
.brand rect { stroke-width: 2.2; }
.brand circle { fill: var(--accent); stroke: none; }
.title-text { display: grid; min-width: 0; }
.title {
  font: 600 20px/1.1 var(--serif);
  letter-spacing: 0.01em;
}
.subtitle {
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chev {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.clock {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 3px 3px 12px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, 0.04);
}
.time {
  min-width: 3.2em;
  font: 600 15px/1 var(--font);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
}
.timer-off .time { display: none; }
.timer-off .clock { padding-left: 3px; }

.bar-tools {
  justify-self: end;
  display: flex;
  gap: 2px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small svg { width: 17px; height: 17px; }
.clock .icon-btn { width: 30px; height: 30px; border-radius: 999px; }
.clock .icon-btn svg { width: 17px; height: 17px; }
#btn-pause .i-play { display: none; fill: currentColor; stroke: none; }
.paused #btn-pause .i-play { display: block; }
.paused #btn-pause .i-pause { display: none; }

/* --- the menu ------------------------------------------------------------------------------- */

.menu {
  position: fixed;
  z-index: 30;
  min-width: 240px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow-lg);
  animation: menu-in 140ms var(--ease);
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  color: var(--ink);
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- the play area ----------------------------------------------------------------------------- */

.play {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  justify-content: center;
  justify-items: center;
  gap: 16px;
  padding: 4px 16px 18px;
  opacity: 0;
  transition: opacity 200ms;
}
.ready .play { opacity: 1; }
.play:not(.wide) {
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  padding-top: 6px;
}
.play.wide {
  grid-template-rows: none;
  grid-template-columns: auto var(--side);
  align-items: center;
  gap: 32px;
}
.play.wide.left .side { order: -1; }

.board-wrap {
  position: relative;
  width: calc(var(--cell) * 9);
  height: calc(var(--cell) * 9);
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--grid-thick), var(--shadow);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-auto-rows: var(--cell);
  width: 100%;
  height: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper);
  outline: none;
  cursor: pointer;
}
/* Grid lines on top of the cells (their backgrounds would hide borders), crisp because
   --cell is a whole number of pixels. */
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--grid-thick) 2px, transparent 2px),
    linear-gradient(to bottom, var(--grid-thick) 2px, transparent 2px),
    linear-gradient(to right, var(--grid-thin) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-thin) 1px, transparent 1px);
  background-size: calc(var(--cell) * 3) 100%, 100% calc(var(--cell) * 3), var(--cell) 100%, 100% var(--cell);
  background-position: -1px 0, 0 -1px, 0 0, 0 0;
}
.board:focus-visible { box-shadow: 0 0 0 4px var(--accent); }

.grid-row { display: contents; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  transition: background-color 110ms;
}
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  background: var(--sweep);
  pointer-events: none;
}
.val {
  position: relative;
  font-family: var(--digits);
  font-size: calc(var(--cell) * 0.6);
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  transform: translateY(0.02em);
}
:root[data-size="large"] .val { font-size: calc(var(--cell) * 0.7); }
.given .val { color: var(--given); font-weight: 620; }
.entry .val { color: var(--entry); font-weight: 430; }

.notes {
  position: absolute;
  inset: 5%;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  font: 500 calc(var(--cell) * 0.215) / 1 var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--note);
  pointer-events: none;
}
:root[data-size="large"] .notes { font-size: calc(var(--cell) * 0.255); inset: 3%; }
.notes span {
  display: grid;
  place-items: center;
  border-radius: 50%;
  margin: 6%;
}
.notes .n-same { background: var(--same); color: var(--accent-2); font-weight: 700; }
.notes .n-key { background: color-mix(in srgb, var(--n-key) 45%, transparent); color: var(--ink); font-weight: 700; }
.notes .n-z { background: color-mix(in srgb, var(--n-off) 40%, transparent); color: var(--ink); font-weight: 700; }
.notes .n-on { background: color-mix(in srgb, var(--n-on) 38%, transparent); color: var(--ink); font-weight: 700; box-shadow: 0 0 0 1.5px var(--n-on); }
.notes .n-off { background: color-mix(in srgb, var(--n-off) 30%, transparent); color: var(--ink); font-weight: 700; box-shadow: 0 0 0 1.5px var(--n-off); }
.notes .n-a { background: color-mix(in srgb, var(--n-a) 35%, transparent); color: var(--ink); font-weight: 700; }
.notes .n-b { background: color-mix(in srgb, var(--n-b) 35%, transparent); color: var(--ink); font-weight: 700; }
.notes .n-elim { color: var(--n-elim); font-weight: 700; text-decoration: line-through 2px; box-shadow: 0 0 0 1.5px var(--n-elim); }

.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.same.given .val, .cell.same.entry .val { font-weight: 700; }
.cell.sel { background: var(--sel); }
.cell.bad { background: var(--bad-bg); }
.cell.bad.entry .val { color: var(--bad-ink); }
.cell.sel.bad { background: color-mix(in srgb, var(--bad-bg) 55%, var(--sel)); }
.cell.h-house { background: var(--hl-house); }
.cell.h-cell { background: var(--hl-cell); }
.cell.h-target { background: var(--hl-target); }
.cell.h-place { background: var(--hl-place); box-shadow: inset 0 0 0 2px var(--n-on); }
.cell.h-cell.h-target { background: linear-gradient(135deg, var(--hl-cell) 50%, var(--hl-target) 50%); }

.links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.links .link {
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: 0.85;
}
.links .strong { stroke: var(--n-on); }
.links .weak { stroke: var(--n-off); stroke-dasharray: 4 4; }

/* Animations. --delay is set per cell from script for sweeps and the win ripple. */
.a-pop .val { animation: pop 260ms var(--ease); }
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0.2; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}
.a-shake .val { animation: shake 340ms ease-in-out; }
@keyframes shake {
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}
.a-sweep::before { animation: sweep 640ms ease-out var(--delay, 0ms) both; }
@keyframes sweep {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}
.a-glint .val { animation: glint 560ms var(--ease) var(--delay, 0ms) both; }
@keyframes glint {
  40% { transform: scale(1.18); color: var(--gold); }
}
.a-ripple::before { animation: ripple 700ms ease-out var(--delay, 0ms) both; }
.a-ripple .val { animation: glint 600ms var(--ease) var(--delay, 0ms) both; }
@keyframes ripple {
  0% { opacity: 0; }
  35% { opacity: 1; background: color-mix(in srgb, var(--gold) 26%, transparent); }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .a-pop .val, .a-shake .val, .a-sweep::before, .a-glint .val, .a-ripple::before, .a-ripple .val { animation: none; }
}

.pause-cover {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pause-box { text-align: center; }

.notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow-lg);
  animation: rise 260ms var(--ease);
}
.notice p { margin: 0 0 10px; }
.notice-actions { display: flex; justify-content: flex-end; gap: 8px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* --- the side: coach and number pad ----------------------------------------------------------------- */

.side {
  position: relative;
  width: calc(var(--cell) * 9);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
}
.wide .side { width: var(--side); }

.coach {
  padding: 12px 14px 14px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow);
  animation: rise 220ms var(--ease);
}
/* With little room between grid and pad, the coach covers the pad instead. */
.play.tight .coach {
  position: absolute;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 100%;
  max-height: 46vh;
  overflow: auto;
}
.coach-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -2px -6px 2px 0;
}
.coach-title {
  margin: 0;
  font: 700 12px/1.2 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.coach-text { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink); -webkit-user-select: text; user-select: text; }
.coach-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.coach-actions:empty { display: none; }

.pad { display: flex; flex-direction: column; gap: 10px; }
.demo .pad { opacity: 0.45; pointer-events: none; }

.pad-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px 5px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
}
.tool svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.tool:active:not(:disabled) { transform: scale(0.96); }
.tool:disabled { opacity: 0.38; }
.tool.on { color: var(--accent); }
.badge {
  position: absolute;
  top: 2px;
  left: calc(50% + 8px);
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tool.on .badge { background: var(--accent); color: var(--accent-ink); }

.digits {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
}
.wide .digits { grid-template-columns: repeat(3, 1fr); gap: 10px; }

.key {
  position: relative;
  display: grid;
  place-items: center;
  height: var(--key-h, 56px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, 0.05);
  color: var(--entry);
  transition: transform 90ms, background-color 120ms, opacity 160ms;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
.wide .key { height: auto; aspect-ratio: 1.12; }
.key:hover { background: var(--surface-2); }
.key:active { transform: scale(0.95); }
.key .num {
  font: 450 clamp(24px, calc(var(--cell) * 0.66), 34px) / 1 var(--digits);
  font-variant-numeric: lining-nums;
}
.wide .key .num { font-size: clamp(28px, calc(var(--side) * 0.12), 40px); }
.key .left {
  position: absolute;
  right: 6px;
  bottom: 4px;
  font: 600 10px/1 var(--font);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.wide .key .left { font-size: 11.5px; right: 9px; bottom: 7px; }
.key.chosen { background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 40%, transparent); }
.key.chosen .left { color: color-mix(in srgb, var(--accent-ink) 75%, transparent); }
.key.done { opacity: 0.32; }
.key.done.chosen { opacity: 0.6; }

/* --- buttons -------------------------------------------------------------------------------------------- */

dialog button, .notice button, .coach-actions button, .pause-box button, .enter-status + * button {
  min-height: 38px;
  padding: 8px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font-weight: 600;
}
dialog button:hover:not(:disabled), .notice button:hover, .coach-actions button:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--line)); }
button.primary {
  background: var(--accent);
  box-shadow: none;
  color: var(--accent-ink);
}
button.primary:hover:not(:disabled) { background: var(--accent-2) !important; }
button.primary:disabled { opacity: 0.45; }
button.subtle { background: none; box-shadow: none; color: var(--accent); }
button.subtle:hover { background: var(--surface-2) !important; }
button.danger { color: var(--bad-ink); }
button.big { min-height: 46px; padding: 10px 26px; font-size: 16px; }
dialog .icon-btn { min-height: 0; padding: 0; background: none; box-shadow: none; }

.eyebrow {
  margin: 0 0 10px;
  font: 700 12px/1.2 var(--font);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* --- dialogs ---------------------------------------------------------------------------------------------- */

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  flex-direction: column;
}
dialog[open] { display: flex; animation: dialog-in 220ms var(--ease); }
dialog.wide { width: min(720px, calc(100vw - 24px)); }
dialog::backdrop {
  background: rgba(18, 20, 26, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 6px 24px;
}
.dialog-head h2, .win h2 {
  margin: 0;
  font: 600 23px/1.2 var(--serif);
}
.dialog-body {
  padding: 8px 24px 20px;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
}
.dialog-actions.split { justify-content: space-between; }
.fine { margin: 6px 0; font-size: 13.5px; color: var(--ink-2); }
.warn { margin: 12px 0 0; font-size: 13.5px; color: var(--bad-ink); }
h3 { margin: 22px 0 8px; font: 600 15px/1.3 var(--font); }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  box-shadow: inset 0 -1px 0 var(--line), 0 0 0 1px var(--line);
  font: 600 12px/1.6 var(--font);
  text-align: center;
}

/* New puzzle */
.new-body { padding-top: 4px; }
.daily {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, var(--surface)), var(--surface-2));
  box-shadow: inset 0 0 0 1px var(--line);
}
.daily-main { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.daily-badge {
  display: grid;
  flex: none;
  width: 58px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow);
  text-align: center;
}
.daily-badge span { padding: 3px 0 2px; background: var(--bad-ink); color: #fff; font: 700 10.5px/1.2 var(--font); letter-spacing: 0.1em; }
.daily-badge b { padding: 4px 0 6px; font: 600 26px/1 var(--serif); }
.daily-text { flex: 1; min-width: 150px; }
.daily-text h3 { margin: 0; font-size: 16px; }
.daily-level { color: var(--ink-2); font-weight: 500; }
.calendar { width: 196px; }
.cal-title { margin: 0 0 4px; font: 600 12px/1.2 var(--font); color: var(--ink-2); text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dow { font: 600 10px/20px var(--font); color: var(--ink-3); text-align: center; }
dialog .day {
  min-height: 0;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: none;
  box-shadow: none;
  font: 500 11.5px/26px var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
dialog .day:disabled { color: var(--ink-3); opacity: 0.45; }
dialog .day.today { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 700; }
dialog .day.solved { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-top: 16px;
}
dialog .level {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name bars" "note note" "stats stats";
  align-items: center;
  gap: 2px 10px;
  padding: 13px 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  text-align: left;
  font-weight: 400;
}
dialog .level:hover { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--accent); }
dialog .level.current { box-shadow: inset 0 0 0 2px var(--accent); }
.level-name { grid-area: name; font: 600 17px/1.2 var(--serif); }
.level-note { grid-area: note; font-size: 13px; color: var(--ink-2); }
.level-stats { grid-area: stats; margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.bars { grid-area: bars; display: flex; gap: 3px; }
.bars i { width: 5px; height: 14px; border-radius: 2px; background: var(--line); }
.bars i.on { background: var(--accent); }

/* Enter a puzzle */
#enter-text {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 500 14px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  resize: vertical;
}
#enter-text:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.enter-status { margin: 10px 0 0; font-size: 13.5px; color: var(--ink-2); }
.enter-status.bad { color: var(--bad-ink); }
.enter-status.good { color: var(--n-on); }

/* How to play */
.rules { margin: 6px 0 0; padding-left: 1.3em; }
.rules li { margin: 6px 0; padding-left: 4px; }
.rules li::marker { font: 600 15px var(--serif); color: var(--accent); }
.tips { margin: 0; padding-left: 1.2em; }
.tips li { margin: 7px 0; }
.keys { border-collapse: collapse; font-size: 13.5px; }
/* Touch screens without a keyboard don't need the key list. */
@media (hover: none) and (pointer: coarse) { .keys-section { display: none; } }
.keys td { padding: 5px 12px 5px 0; vertical-align: top; }
.keys td:nth-child(odd) { white-space: nowrap; }
.guide { display: grid; gap: 4px; }
.guide-level h4 { margin: 12px 0 4px; font: 600 15px/1.2 var(--serif); color: var(--accent); }
.guide-level ul { margin: 0; padding-left: 1.1em; font-size: 13.5px; color: var(--ink-2); }
.guide-level li { margin: 3px 0; }
.guide-level b { color: var(--ink); font-weight: 600; }

/* Settings */
.settings-body .group h3 { margin-top: 18px; }
.settings-body .group:first-child h3 { margin-top: 6px; }
.rows { border-radius: 14px; box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 50px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row-label { display: grid; flex: 1 1 auto; min-width: 0; font-weight: 500; }
.row-note { font-size: 12.5px; font-weight: 400; color: var(--ink-3); }
.seg {
  display: flex;
  flex: none;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
dialog .seg button {
  min-height: 30px;
  padding: 4px 11px;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
dialog .seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); font-weight: 600; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 160ms;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 180ms var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
dialog .swatch {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-height: 0;
  padding: 4px;
  border-radius: 10px;
  background: none;
  box-shadow: none;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
}
dialog .swatch[aria-checked="true"] { color: var(--ink); font-weight: 700; }
dialog .swatch[aria-checked="true"] .sw-grid { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.sw-grid {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--line);
  background-image:
    linear-gradient(to right, var(--sw-thick) 1.5px, transparent 1.5px),
    linear-gradient(to bottom, var(--sw-thick) 1.5px, transparent 1.5px),
    linear-gradient(135deg, var(--sw-paper) 55%, var(--sw-accent) 55%);
  background-size: 12.67px 100%, 100% 12.67px, 100% 100%;
  background-position: -0.75px 0, 0 -0.75px, 0 0;
}
.sw-auto { --sw-paper: #fffdf8; --sw-thick: #2c3038; --sw-accent: #1b1f26; }
.sw-paper { --sw-paper: #fffdf8; --sw-thick: #2c3038; --sw-accent: #2a5cc8; }
.sw-sage { --sw-paper: #fcfdf9; --sw-thick: #2b3a32; --sw-accent: #1f7a62; }
.sw-mist { --sw-paper: #fcfdff; --sw-thick: #27324a; --sw-accent: #4b49c9; }
.sw-night { --sw-paper: #1b1f26; --sw-thick: #8e98a8; --sw-accent: #6f98f8; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.tile { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.tile b { display: block; font: 600 22px/1.1 var(--serif); font-variant-numeric: tabular-nums lining-nums; }
.tile span { font-size: 12px; color: var(--ink-2); }
.stats-wrap { margin-top: 10px; overflow-x: auto; }
.stats { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.stats th { padding: 6px 8px; font-weight: 600; color: var(--ink-2); text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stats td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats td.empty { text-align: left; color: var(--ink-3); border: 0; }
.stats-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }

/* Win */
.win { padding-top: 26px; text-align: center; }
.win-hero { width: 132px; margin: 0 auto 16px; }
.win-hero svg { width: 100%; height: auto; filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.14)); animation: hero-in 520ms var(--ease); }
@keyframes hero-in { from { opacity: 0; transform: scale(0.9) rotate(-3deg); } }
.win-hero .h-bg { fill: var(--paper); stroke: var(--grid-thick); stroke-width: 1.2; }
.win-hero text { font: 7px var(--digits); text-anchor: middle; }
.win-hero .h-given { fill: var(--given); font-weight: 650; }
.win-hero .h-entry { fill: var(--entry); }
.win-hero .h-line { stroke: var(--grid-thick); stroke-width: 0.8; fill: none; }
.win .eyebrow { margin-bottom: 6px; color: var(--gold); }
.win-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
  margin: 18px 0 6px;
}
.win-stats div { padding: 10px 6px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.win-stats dd { margin: 0; font: 600 22px/1.15 var(--serif); font-variant-numeric: tabular-nums lining-nums; }
.win-stats dt { font-size: 12px; color: var(--ink-2); }
.win-notes { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13.5px; color: var(--ink-2); }
.win-notes li { margin: 4px 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms, transform 220ms var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- narrow screens ---------------------------------------------------------------------------------------------- */

.narrow-only { display: none !important; }
@media (max-width: 699px) {
  .wide-only { display: none !important; }
  .narrow-only { display: flex !important; }
  .bar { height: 52px; padding: 0 8px 0 4px; gap: 6px; }
  .title { font-size: 18px; }
  .brand svg { width: 26px; height: 26px; }
  .chev { display: none; }
  .play { padding: 2px 12px 12px; gap: 12px; }
  .dialog-head { padding: 16px 12px 4px 18px; }
  .dialog-body { padding: 6px 18px 18px; }
  .daily { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .daily-main { flex-wrap: nowrap; gap: 12px; }
  .daily-badge { width: 50px; }
  .daily-badge b { font-size: 22px; }
  .daily-text { min-width: 0; }
  .daily-text h3 { font-size: 15px; }
  .daily-text .fine { font-size: 12.5px; margin: 2px 0 0; }
  .calendar { width: 100%; max-width: 252px; justify-self: center; }
  dialog .day { height: 22px; line-height: 22px; font-size: 11px; }
  .dow { line-height: 16px; }
  .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
  dialog .level { padding: 10px 11px; grid-template-areas: "name" "bars" "note" "stats"; grid-template-columns: 1fr; gap: 3px; }
  .bars { margin: 1px 0 2px; }
  .bars i { height: 10px; width: 4px; }
  .level-name { font-size: 16px; }
  .level-note { font-size: 12px; line-height: 1.3; }
  .level-stats { font-size: 11.5px; margin-top: 2px; }
  .row:has(.seg) { flex-wrap: wrap; }
  .row .seg { margin-left: auto; }
  .keys td { padding-right: 8px; }
}
@media (max-height: 480px) {
  .bar { height: 46px; }
  .play { padding-top: 0; padding-bottom: 8px; }
}
