/* =========================================================
   Scrolldle — styles
   Dark by default, light via prefers-color-scheme,
   high-contrast tile palette via [data-contrast="high"].
   ========================================================= */

:root {
  color-scheme: dark;

  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --bg: #0d0d10;
  --surface: #17171c;
  --surface-2: #222229;
  --text: #f5f5f7;
  --muted: #a1a1aa;
  --line: #2a2a31;

  --tile-border: #3a3a44;
  --tile-border-filled: #75757f;
  --tile-text: #f5f5f7;

  --key-bg: #3b3b44;
  --key-bg-hover: #4a4a54;
  --key-text: #f5f5f7;

  --correct: #2fbf71;
  --on-correct: #06120b;
  --present: #ffd23f;
  --on-present: #1a1400;
  --absent: #3a3a3c;
  --on-absent: #ffffff;
  --key-absent: #232327;
  --on-key-absent: #8e8e98;

  --accent-a: rgba(47, 191, 113, 0.22);
  --accent-b: rgba(255, 210, 63, 0.16);
  --accent-c: rgba(130, 110, 255, 0.14);

  --focus: #8ab4ff;
  --danger: #ff6b6b;
  --backdrop: rgba(5, 5, 8, 0.66);
  --shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.6);

  --radius-tile: 10px;
  --radius-key: 9px;
  --gap: 6px;
  --tile: 56px;
  --key-h: 56px;
  --board-max: 420px;

  --flip-ms: 520ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #efeff2;
    --text: #121214;
    --muted: #5c5c66;
    --line: #e2e2e7;

    --tile-border: #d4d4d8;
    --tile-border-filled: #7c7c86;
    --tile-text: #121214;

    --key-bg: #dedee3;
    --key-bg-hover: #cfcfd6;
    --key-text: #121214;

    --correct: #2fbf71;
    --on-correct: #06120b;
    --present: #ffd23f;
    --on-present: #1a1400;
    --absent: #6b6f72;
    --on-absent: #ffffff;
    --key-absent: #6b6f72;
    --on-key-absent: #ffffff;

    --accent-a: rgba(47, 191, 113, 0.20);
    --accent-b: rgba(255, 196, 0, 0.20);
    --accent-c: rgba(120, 100, 255, 0.10);

    --focus: #1d4ed8;
    --danger: #c62828;
    --backdrop: rgba(20, 20, 28, 0.42);
    --shadow: 0 24px 60px -18px rgba(20, 20, 40, 0.35);
  }
}

/* Colorblind-friendly: orange = right spot, blue = wrong spot. */
:root[data-contrast='high'] {
  --correct: #ff8a3d;
  --on-correct: #160800;
  --present: #6cb6ff;
  --on-present: #04121f;
}

/* ---------- base ---------- */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
button:not(:disabled) { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px; top: -60px;
  z-index: 50;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.skip-link:focus { top: calc(8px + var(--safe-t)); }

[hidden] { display: none !important; }

/* ---------- app shell ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  position: relative;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 56px;
  isolation: isolate;
}

/* Soft gradient glow + film grain behind the header. */
.topbar::before {
  content: '';
  position: absolute;
  inset: calc(-1 * var(--safe-t) - 40px) 0 0;
  z-index: -1;
  background:
    radial-gradient(40% 120% at 18% 0%, var(--accent-a), transparent 70%),
    radial-gradient(38% 110% at 82% 0%, var(--accent-b), transparent 70%),
    radial-gradient(30% 90% at 50% -10%, var(--accent-c), transparent 70%);
  pointer-events: none;
}
.topbar::after {
  content: '';
  position: absolute;
  inset: calc(-1 * var(--safe-t) - 40px) 0 0;
  z-index: -1;
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
  mask-image: linear-gradient(to bottom, #000 30%, transparent);
  pointer-events: none;
}

.topbar-side { display: flex; gap: 2px; }
.topbar-side--end { justify-content: flex-end; }

.logo {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 7.2vw, 2.1rem);
  font-variation-settings: 'opsz' 96;
  letter-spacing: -0.045em;
  line-height: 1;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.logo::after {
  content: '';
  display: inline-block;
  width: 0.26em;
  height: 0.26em;
  margin-left: 0.07em;
  border-radius: 0.07em;
  background: var(--correct);
  box-shadow: 0.32em 0 0 var(--present);
  vertical-align: 0.02em;
  margin-right: 0.34em;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  transition: background-color 160ms ease, transform 160ms var(--ease-out);
}
.icon-btn svg {
  width: 24px; height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn svg .dot { fill: currentColor; stroke: none; }
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:disabled:hover { background: transparent; }
.icon-btn[aria-pressed='true'],
.icon-btn.is-on { color: var(--present); }
:root[data-contrast='high'] .icon-btn.is-on { color: var(--present); }
@media (prefers-color-scheme: light) {
  .icon-btn.is-on { color: #8a6a00; }
  :root[data-contrast='high'] .icon-btn.is-on { color: #0b5cad; }
}

/* ---------- meta chips, banner, hint ---------- */

.meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 12px 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.chip--accent { color: var(--text); }

.banner,
.hint-strip {
  margin: 0 12px 8px;
  padding: 9px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  text-align: center;
}
.banner {
  text-wrap: balance;
  background: color-mix(in srgb, var(--present) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--present) 40%, transparent);
}
.banner--archive {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  font-size: 0.82rem;
  line-height: 1.3;
  text-align: left;
  background: color-mix(in srgb, var(--accent-c) 60%, var(--surface));
  border-color: color-mix(in srgb, var(--text) 16%, transparent);
}
#archive-banner-text { min-width: 0; text-wrap: balance; }
.banner-btn {
  flex: none;
  min-height: 32px;
  white-space: nowrap;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--text) 22%, transparent);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  transition: transform 120ms var(--ease-out), background-color 160ms ease;
}
.banner-btn:hover { background: var(--surface-2); }
.banner-btn:active { transform: scale(0.96); }
.hint-strip {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  background: var(--surface);
  border: 1px dashed var(--tile-border-filled);
  animation: rise 280ms var(--ease-out);
}
.hint-label {
  flex: none;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ---------- board ---------- */

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 4px 12px;
  position: relative;
  /* Never let tiles spill over (and steal taps from) the keyboard. */
  overflow: hidden;
}

.board {
  display: grid;
  gap: var(--gap);
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), var(--tile));
  gap: var(--gap);
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border: 2px solid var(--tile-border);
  border-radius: var(--radius-tile);
  background: transparent;
  color: var(--tile-text);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: calc(var(--tile) * 0.52);
  line-height: 1;
  text-transform: uppercase;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: border-color 120ms ease;
}
.tile[data-filled] { border-color: var(--tile-border-filled); }

.tile[data-state] { border-color: transparent; }
.tile[data-state='correct'] { background: var(--correct); color: var(--on-correct); }
.tile[data-state='present'] { background: var(--present); color: var(--on-present); }
.tile[data-state='absent'] { background: var(--absent); color: var(--on-absent); }

.tile.pop { animation: pop 110ms var(--ease-out); }
.tile.flip { animation: flip var(--flip-ms) ease-in-out both; }
.tile.win { animation: bounce 620ms var(--ease-out) both; }
.row.shake { animation: shake 480ms ease-in-out; }

@keyframes pop {
  0% { transform: scale(0.86); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-34%); }
  55% { transform: translateY(4%); }
  70% { transform: translateY(-10%); }
  85% { transform: translateY(1%); }
  100% { transform: translateY(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- empty / error state ---------- */

.state-card {
  max-width: 320px;
  padding: 26px 22px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise 300ms var(--ease-out);
}
.state-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.state-body { margin: 0 0 18px; color: var(--muted); }

/* ---------- new puzzle pill ---------- */

.new-puzzle {
  align-self: center;
  margin: 0 12px 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: rise 300ms var(--ease-out);
}

/* ---------- keyboard ---------- */

.keyboard {
  flex: none;
  position: relative;
  z-index: 1; /* keys always paint above (and receive taps before) the board */
  padding: 6px 6px calc(8px + max(0px, 6px - var(--safe-b)));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 7px;
}
.kb-row:last-child { margin-bottom: 0; }

.key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 46px;
  height: var(--key-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius-key);
  background: var(--key-bg);
  color: var(--key-text);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  display: grid;
  place-items: center;
  transition: background-color 180ms ease, color 180ms ease, transform 90ms ease;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.key:hover { background: var(--key-bg-hover); }
.key:active,
.key.is-pressed { transform: scale(0.93); }
.key--wide {
  flex: 1.55 1 0;
  max-width: 72px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.key svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.key[data-state='correct'] { background: var(--correct); color: var(--on-correct); }
.key[data-state='present'] { background: var(--present); color: var(--on-present); }
.key[data-state='absent'] { background: var(--key-absent); color: var(--on-key-absent); }
.keyboard[aria-disabled='true'] .key { opacity: 0.55; }

.kb-spacer { flex: 0.5 1 0; max-width: 23px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  top: calc(var(--safe-t) + 100px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  box-shadow: var(--shadow);
  animation: toast-in 220ms var(--ease-out-quint);
}
.toast.out { animation: toast-out 220ms ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

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

.sheet {
  width: min(440px, calc(100vw - 24px));
  max-height: min(88dvh, 760px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
  overscroll-behavior: contain;
}
.sheet--small { width: min(360px, calc(100vw - 32px)); }
.sheet::backdrop {
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.sheet[open] { animation: sheet-in 260ms var(--ease-out); }
.sheet[open]::backdrop { animation: fade-in 200ms ease; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
@keyframes fade-in { from { opacity: 0; } }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 6px 22px;
  background: var(--surface);
}
.sheet h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.025em;
}
.sheet-body { padding: 6px 22px 22px; }
.sheet--small .sheet-body { padding: 22px; }
.sheet--small h2 { margin-bottom: 6px; }
.sheet--small p { margin: 0 0 20px; color: var(--muted); }

.lede { margin: 0 0 10px; }
.rules { margin: 0 0 18px; padding-left: 1.15em; color: var(--muted); }
.rules li { margin: 4px 0; }
.rules strong { color: var(--text); }
.fine { margin: 18px 0; color: var(--muted); font-size: 0.875rem; }

.eyebrow {
  margin: 18px 0 10px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.example { margin: 0 0 12px; }
.example p { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.example strong { color: var(--text); }
.mini-row { display: flex; gap: 5px; }
.mini {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 2px solid var(--tile-border-filled);
  border-radius: 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
}
.mini[data-state] { border-color: transparent; }
.mini[data-state='correct'] { background: var(--correct); color: var(--on-correct); }
.mini[data-state='present'] { background: var(--present); color: var(--on-present); }
.mini[data-state='absent'] { background: var(--absent); color: var(--on-absent); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  transition: transform 120ms var(--ease-out), filter 160ms ease, background-color 160ms ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn--primary {
  border-color: transparent;
  background: var(--correct);
  color: var(--on-correct);
}
.btn--block { width: 100%; }
.btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.btn-row { display: flex; gap: 10px; justify-content: flex-end; }
.btn-row .btn { flex: 1; }

/* ---------- result ---------- */

.result {
  margin: 0 0 6px;
  padding: 16px;
  border-radius: 18px;
  background: var(--surface-2);
  text-align: center;
}
.result .eyebrow { margin: 0 0 10px; }
.answer {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.answer .mini {
  flex: 0 1 36px;
  min-width: 0;
  width: auto;
  height: auto;
  aspect-ratio: 1;
}
.result-category {
  display: inline-block;
  margin: 12px 0 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}
.blurb { margin: 12px 0 10px; font-size: 0.95rem; text-align: left; }
.source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--correct);
  text-underline-offset: 3px;
}
.source::after { content: '\2197'; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 16px 0 0;
  text-align: center;
}
.stat-grid div { display: flex; flex-direction: column-reverse; }
.stat-grid dt { font-size: 0.72rem; color: var(--muted); line-height: 1.2; }
.stat-grid dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.85rem;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.dist li {
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dist .bar {
  width: var(--w, 8%);
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  text-align: right;
}
.dist li.is-today .bar { background: var(--correct); color: var(--on-correct); }

.result-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.countdown { display: grid; }
.countdown .eyebrow { margin: 0 0 2px; }
.countdown-time {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.3rem, 6vw, 1.7rem);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.btn--share { flex: 0 0 auto; min-width: 132px; font-size: 1.05rem; }

.share-fallback { margin-top: 14px; }
.share-fallback label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); }
.share-fallback textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: 0.95rem/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: none;
}

.stats-note {
  margin: 14px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- archive ---------- */

.archive-desc { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.archive-empty { margin: 8px 0 0; color: var(--muted); text-align: center; }
.archive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.archive-row {
  display: grid;
  grid-template-columns: 2.4em minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  transition: background-color 160ms ease, border-color 160ms ease, transform 120ms var(--ease-out);
}
.archive-row:hover { background: color-mix(in srgb, var(--text) 6%, var(--surface-2)); }
.archive-row:active { transform: scale(0.985); }
.archive-row[aria-current='true'] { border-color: var(--tile-border-filled); }
.ar-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.ar-main { display: grid; gap: 1px; min-width: 0; overflow: hidden; }
.ar-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ar-date { font-weight: 700; }
.ar-tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--correct);
  color: var(--on-correct);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
/* Each item carries a leading "·"; the row is shifted left by one separator
   width so the dot at the start of any (wrapped) line is clipped by .ar-main. */
.ar-sub { display: flex; flex-wrap: wrap; margin-left: -1em; font-size: 0.8rem; color: var(--muted); }
.ar-sub > span::before { content: '·'; display: inline-block; width: 1em; text-align: center; }
.archive-row[data-status='won'] .ar-status { color: var(--text); font-weight: 700; }
.ar-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 6px);
  gap: 1.5px;
}
.ar-cell { width: 6px; height: 6px; border-radius: 1.5px; background: color-mix(in srgb, var(--absent) 78%, var(--text)); }
.ar-cell[data-state='correct'] { background: var(--correct); }
.ar-cell[data-state='present'] { background: var(--present); }

/* ---------- settings ---------- */

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.setting-name { font-weight: 700; }
.setting-desc { margin: 2px 0 0; font-size: 0.85rem; color: var(--muted); }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--key-bg);
  border: 1px solid var(--tile-border-filled);
  cursor: pointer;
  transition: background-color 180ms ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 220ms var(--ease-out-quint);
}
.switch:checked { background: var(--correct); border-color: transparent; }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { border-radius: 999px; }

/* ---------- responsive ---------- */

@media (max-height: 640px) {
  :root { --key-h: 48px; }
  .topbar { min-height: 48px; padding-block: 4px; }
  .meta { padding-bottom: 6px; }
  .kb-row { margin-bottom: 6px; }
}
@media (max-height: 560px) {
  :root { --key-h: 42px; }
}
/* Landscape phones: give the board more of the little height there is. */
@media (max-height: 420px) {
  :root { --key-h: 36px; }
  .topbar { min-height: 40px; padding-block: 2px; }
  .meta { padding-bottom: 4px; }
  .kb-row { margin-bottom: 4px; }
  .banner, .hint-strip { margin-bottom: 4px; padding-block: 5px; }
}
@media (max-width: 360px) {
  .kb-row { gap: 4px; }
  .keyboard { padding-inline: 4px; }
  .key { font-size: 1rem; }
  .key--wide { font-size: 0.68rem; letter-spacing: 0.02em; }
  .icon-btn { width: 38px; }
  .stat-grid dd { font-size: 1.55rem; }
  /* If the countdown and Share can't share a line, Share wraps and fills it. */
  .btn--share { flex: 1 1 auto; }
}
/* Five header icons + the logo: tighten the header before it can overflow. */
@media (max-width: 440px) {
  .topbar { gap: 6px; padding-inline: 8px; }
  .topbar-side { gap: 0; }
  .icon-btn { width: 38px; }
}
@media (max-width: 380px) {
  .topbar { gap: 4px; padding-inline: 6px; }
  .topbar .icon-btn { width: 34px; }
  .logo { font-size: 1.4rem; }
}
@media (min-width: 600px) {
  .key { max-width: 50px; }
  .key--wide { max-width: 78px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .tile.flip,
  .tile.win,
  .tile.pop,
  .row.shake { animation: none !important; }
}
