:root {
  --bg: #0e1016;
  --panel: #161a23;
  --panel-2: #1d2230;
  --tile: #1e2431;
  --tile-hi: #2a3245;
  --ink: #e9edf4;
  --muted: #8d97ac;
  --line: #2a3143;
  --accent: #58e0a4;
  --accent-ink: #06251a;
  --warn: #ff7a7a;
  --gold: #ffcf5c;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --panel-2: #eef1f7;
    --tile: #ffffff;
    --tile-hi: #e8edf7;
    --ink: #131722;
    --muted: #66708a;
    --line: #d8dee9;
    --accent: #12a06a;
    --accent-ink: #ffffff;
    --warn: #d13b3b;
    --gold: #b8860b;
    --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem 4rem;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

main {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ---------- masthead ---------- */
.masthead { text-align: center; margin-bottom: 1.5rem; }
.masthead h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 2.75rem);
  letter-spacing: -0.03em;
  font-weight: 800;
}
.masthead h1 span { color: var(--accent); }
.tagline { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.95rem; }

/* ---------- hud ---------- */
.hud {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 0.75rem;
  box-shadow: var(--shadow);
}
.hud-cell { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; min-width: 0; }
.hud-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.hud-value { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.pips { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; max-width: 90px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.pip.on { background: var(--accent); }

/* ---------- combo slots ---------- */
.combo-area { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.slots { display: flex; gap: 0.6rem; }
.slot {
  width: 62px; height: 62px;
  border-radius: 12px;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.slot.filled { border-style: solid; border-color: var(--accent); background: var(--panel-2); }
.slot .slot-letter { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.slots.shake { animation: shake 0.3s ease; }
.slots.good .slot.filled { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, transparent); }
.slots.bad .slot.filled { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 18%, transparent); }

.prompt .paren { color: var(--gold); }
.prompt .res { color: var(--ink); font-weight: 700; }

/* ---------- board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}
.tile {
  aspect-ratio: 1 / 1;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.15rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.08s, border-color 0.15s;
}
.tile:hover:not(:disabled) { background: var(--tile-hi); transform: translateY(-2px); }
.tile:active:not(:disabled) { transform: translateY(1px); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile .key { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }
.tile .op { font-size: clamp(1.05rem, 5vw, 1.4rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.tile.used { border-color: var(--accent); background: var(--tile-hi); }
.tile.used .op { color: var(--accent); }
.tile.first .op { opacity: 0.55; }
.tile.first .op .sym { text-decoration: line-through; opacity: 0.5; }
.tile.hinted { border-color: var(--gold); box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 40%, transparent); }
.tile:disabled { opacity: 0.5; cursor: default; }


/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: center; }
.field { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
select, .btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-quiet { color: var(--muted); }
.badge {
  display: inline-block; min-width: 1.3em;
  padding: 0 0.35em; margin-left: 0.25rem;
  border-radius: 999px; background: var(--panel-2);
  font-size: 0.75rem; text-align: center;
}

/* ---------- found + log ---------- */
.section-title {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); margin: 0 0 0.45rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.empty { color: var(--muted); font-size: 0.85rem; }
.chip {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.chip.missed { background: var(--panel-2); border-color: var(--line); color: var(--muted); }

.log {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  font-size: 0.88rem;
  max-height: 190px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.log:empty::after { content: "Your guesses show up here."; color: var(--muted); }
.log .row { display: flex; gap: 0.5rem; align-items: baseline; }
.log .row .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.log .ok { color: var(--accent); }
.log .no { color: var(--warn); }
.log .note { color: var(--muted); }
.log .big { color: var(--gold); font-weight: 700; }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.75rem;
}
.stats div { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; text-align: center; }
.stats strong { font-variant-numeric: tabular-nums; }

.rules { color: var(--muted); font-size: 0.85rem; }
.rules summary { cursor: pointer; color: var(--ink); }
.rules ul { padding-left: 1.1rem; line-height: 1.6; }
.rules kbd {
  font-family: ui-monospace, Menlo, monospace; font-size: 0.78em;
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 0 0.3em; background: var(--panel-2); color: var(--ink);
}

/* ---------- motion ---------- */
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
/*
 * Reduced motion, done right.
 *
 * This used to be a blanket `animation: none; transition: none`, which is the
 * intuitive mistake: it deleted channels without substituting anything. A
 * rejected tile was signalled by the shake and nothing else, so with the setting
 * on it produced no feedback at all.
 *
 * Two rules instead. Keep the identical total duration and drop only the
 * trajectory — without the arc drawing the eye, the player needs at least as
 * long to register the change, not less. And opacity and colour are exempt from
 * WCAG 2.3.3, so they are what carries the signal once travel is gone.
 */
@media (prefers-reduced-motion: reduce) {
  .tile:hover:not(:disabled),
  .tile:active:not(:disabled),
  .slot,
  .prompt .step { transform: none !important; }

  .box:active { animation: none !important; }

  /* Same 0.3s as the shake, carried by opacity instead of travel. */
  .slots.shake { animation: reject-fade 0.3s ease both !important; }

  /* Hold the pulse at full strength rather than letting it fade back —
     with the movement gone, colour is all that is left to carry it. */
  .hud-big.pulse .hud-value { animation: pulse-hold 0.4s steps(1) both !important; }
}

@keyframes reject-fade {
  0%, 100% { opacity: 1; }
  35%, 65% { opacity: 0.3; }
}

@keyframes pulse-hold {
  0%, 99% { color: var(--gold); }
  100% { color: var(--accent); }
}

/* Rejection is never carried by motion alone, at any motion setting: the slots
   also take a warning border for the duration of the shake. */
.slots.shake .slot { border-color: var(--warn); }

/* ---------- value-change feedback ---------- */
.prompt .step.latest { animation: step-in 0.28s ease; }
@keyframes step-in {
  0% { transform: translateY(-4px) scale(0.94); opacity: 0.4; }
  100% { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .prompt .step.latest { animation: fade-in 0.28s ease; }
}
@keyframes fade-in { 0% { opacity: 0.3; } 100% { opacity: 1; } }

.btn.nudge { animation: nudge 0.5s ease; }
@keyframes nudge {
  0%, 100% { transform: none; }
  30% { transform: translateY(-3px); }
  60% { transform: translateY(1px); }
}
@media (prefers-reduced-motion: reduce) {
  .btn.nudge { animation: fade-in 0.5s ease; }
}

@media (max-width: 420px) {
  .tab { font-size: 0.72rem; padding: 0.5rem 0.1rem; }
  body { padding: 1.25rem 0.75rem 3rem; }
  .hud { grid-template-columns: 1.3fr 1fr 1fr 1fr; padding: 0.7rem 0.4rem; }
  .hud-value { font-size: 1.05rem; }
  .hud-target .hud-value { font-size: 1.6rem; }
  .slot { width: 54px; height: 54px; }
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 0.75rem; }
}

/* ---------- mode tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.25rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.3rem;
}
.tab {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 0.2rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.tab:first-child { color: var(--gold); }
.tab:first-child.on { color: var(--gold); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.blurb { margin: -0.5rem 0 0; text-align: center; color: var(--muted); font-size: 0.9rem; }
.blurb em { color: var(--ink); font-style: normal; }

/* ---------- hud extras ---------- */
.hud-sub { font-size: 0.65rem; color: var(--muted); }
.hud-big .hud-value { font-size: 2rem; color: var(--accent); line-height: 1.05; }
.hud-big.pulse .hud-value { animation: pop 0.4s ease; }
.hud-warn .hud-value { color: var(--warn); }

/* ---------- stage ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.prompt {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.05rem;
  min-height: 1.6em;
  text-align: center;
  line-height: 1.8;
}
.prompt .muted { color: var(--muted); }
.slots[hidden] { display: none; }

/* ladder trail */
.prompt .step {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 700;
}
.prompt .step.start { color: var(--muted); }
.prompt .step.hit { border-color: var(--accent); color: var(--accent); }
.prompt .op-step { color: var(--gold); padding: 0 0.15rem; }
.prompt .arrow { color: var(--muted); padding: 0 0.15rem; }

/* ---------- board states ---------- */
.tile.spent { opacity: 0.35; }
.tile.winning { border-color: var(--gold); box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 45%, transparent); }
.tile.dead { opacity: 0.32; }
.tile.dead .op { text-decoration: line-through; }
.tile.known { border-color: var(--gold); }
.tile-note {
  font-size: 0.62rem; color: var(--muted);
  font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}
.board-note { margin: -0.4rem 0 0; text-align: center; font-size: 0.82rem; color: var(--muted); }
.board-note em { color: var(--ink); font-style: normal; }

/* ---------- controls row ---------- */
.controls-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: center; }
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.field[hidden] { display: none; }

/* ---------- panel ---------- */
.panel:empty { display: none; }
.panel .pips { display: inline-flex; gap: 3px; margin-left: 0.5rem; vertical-align: middle; }

/* deduce guess grid */
.grid { display: flex; flex-direction: column; gap: 0.35rem; }
.grow { display: flex; align-items: center; gap: 0.3rem; }
.gcell {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--panel-2);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.gcell em { font-style: normal; font-weight: 700; font-size: 0.9rem; }
.gcell small { font-size: 0.62rem; opacity: 0.75; }
.gcell.hit { background: color-mix(in srgb, var(--accent) 30%, transparent); border-color: var(--accent); }
.gcell.moved { background: color-mix(in srgb, var(--gold) 28%, transparent); border-color: var(--gold); }
.gcell.off { opacity: 0.55; }
.gval {
  margin-left: 0.4rem; font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.garrow { color: var(--gold); font-size: 1rem; }

.section-title .pips { vertical-align: middle; }

/* ---------- daily + share ---------- */
.share:empty { display: none; }
.daily-note {
  margin: 0; padding: 0.7rem 0.9rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--muted); font-size: 0.86rem; text-align: center;
}
.daily-note strong { color: var(--accent); }
.share-card {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 1rem; text-align: center;
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.share-head { font-weight: 700; letter-spacing: -0.01em; }
.share-grid {
  margin: 0; font-size: 1.15rem; line-height: 1.35;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
}
.share-detail { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* ---------- deduce: glyphs so colour is never the only signal ---------- */
.gmark { font-style: normal; font-size: 0.7rem; line-height: 1; opacity: 0.85; }
.gcell.hit .gmark { color: var(--accent); }
.gcell.moved .gmark { color: var(--gold); }
.gcell.off .gmark { color: var(--muted); }

.share-streak {
  font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--gold); font-weight: 700;
}
.daily-note strong { color: var(--accent); }

/* ---------- restore codes ---------- */
.transfer { color: var(--muted); font-size: 0.85rem; }
.transfer summary { cursor: pointer; color: var(--ink); }
.transfer-note { margin: 0.5rem 0; line-height: 1.5; }
.transfer-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.transfer-field {
  width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.72rem; padding: 0.5rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  resize: vertical; word-break: break-all;
}
.transfer-status { margin: 0.5rem 0 0; min-height: 1.2em; color: var(--accent); }

.btn-icon { font-size: 0.82rem; padding: 0.5rem 0.7rem; }

/*
 * The first tile of a combo contributes its number and nothing else, so while
 * that slot is the one being filled, the operators on the board mean nothing.
 * Dim the signs until a first tile is down, then bring them back for slots 2
 * and 3 where they decide the answer. Ladder never gets this: there the
 * operator applies to the running total on every single step.
 */
.tile .op .sym { transition: opacity 0.18s ease; }
.tile.op-muted .op .sym { opacity: 0.28; }
