/* Reverse Oracle. Mobile-first, no framework, no external requests.
   The hero is the bot's card: the question, the split it expects, and why.
   The board underneath shrinks as you answer, so the reasoning is seen, not read. */

:root {
  color-scheme: light dark;
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #eaeaf0;
  --ink: #17181c;
  --ink-soft: #5d6068;
  --line: #d9d9e1;
  --accent: #4a3f9a;
  --accent-soft: #e3dff5;
  --warm: #b4571f;
  --cool: #1f6f9a;
  --dim: #a8a4a0;
  --radius: 10px;
  --gap: 10px;
  --maxw: 720px;
  font-synthesis-weight: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131420;
    --surface: #1c1d2b;
    --surface-2: #262838;
    --ink: #eceef2;
    --ink-soft: #a2a7b3;
    --line: #343749;
    --accent: #a99cf0;
    --accent-soft: #2d2850;
    --warm: #e08c4e;
    --cool: #5fb3e0;
    --dim: #5c616e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--ink-soft); font-size: 13px; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

button { font: inherit; cursor: pointer; border-radius: var(--radius); }
button:disabled { cursor: default; }
button:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 3px;
}
.round-label, .instruction { margin: 0; color: var(--ink-soft); font-size: 12px; }
.instruction { font-size: 14px; color: var(--ink); }
.round-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.round-actions:not(:has(> :not([hidden]))) { display: none; }
.notice { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); }
#stat-cap { font-size: 12px; color: var(--ink-soft); }

.ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 13px;
}
.ghost:hover { border-color: var(--accent); }
.ghost[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }

.primary {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 8px 14px;
  font-weight: 600;
}
@media (prefers-color-scheme: dark) { .primary { color: #14122a; } }

.link {
  background: none; border: 0; color: var(--ink-soft);
  text-decoration: underline; padding: 0; font-size: 13px;
}

/* ---------- status ---------- */

.status {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.stat { display: flex; flex-direction: column; align-items: center; min-width: 42px; }
.stat-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { font-size: 11px; color: var(--ink-soft); text-transform: lowercase; white-space: nowrap; }

.meter { position: relative; flex: 1; height: 26px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.meter-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  transition: width 420ms cubic-bezier(.22,.61,.36,1);
}
.meter-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 11px; color: var(--ink); mix-blend-mode: luminosity;
}

/* ---------- the bot's card ---------- */

.oracle {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.08);
}
.oracle-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-soft); }
.oracle-text { margin: 6px 0 10px; font-size: 21px; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
.oracle.done .oracle-text { font-size: 18px; }

.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); margin-bottom: 10px; }
.split span { display: block; height: 100%; transition: width 380ms cubic-bezier(.22,.61,.36,1); }
.split span:nth-child(odd) { background: var(--accent); }
.split span:nth-child(even) { background: var(--cool); }
.split span:nth-child(n+3) { opacity: 0.7; }

.answers { display: flex; flex-wrap: wrap; gap: 8px; }
.answers button {
  flex: 1 1 120px;
  min-height: 48px;
  padding: 8px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.answers button small { font-size: 11px; font-weight: 400; opacity: 0.85; }
.answers .primary small { color: inherit; }

.why { margin-top: 10px; font-size: 13px; color: var(--ink-soft); }
.why summary { cursor: pointer; color: var(--ink); font-weight: 600; font-size: 13px; }
.why p { margin: 6px 0; }
.alts { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.alts li { display: flex; gap: 8px; align-items: baseline; }
.alts li span:first-child { flex: 1; }
.alts .num { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-soft); }
.alts .chosen { color: var(--ink); font-weight: 600; }
.oracle-foot { margin-top: 8px; display: flex; justify-content: flex-end; }

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

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  gap: var(--gap);
}

.card {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  font-size: 13px;
  line-height: 1.25;
  min-height: 54px;
  display: grid;
  place-items: center;
  transition: opacity 380ms ease, transform 380ms cubic-bezier(.22,.61,.36,1), border-color 160ms;
}
.card:disabled:not(.out):not(.mark) { cursor: default; }
.board.picking .card:not(:disabled):hover { border-color: var(--accent); }
.card.mark { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.card.out {
  opacity: 0.22;
  transform: scale(0.9);
  pointer-events: none;
  text-decoration: line-through;
  text-decoration-color: var(--dim);
}
.card.named { opacity: 0.3; border-style: dashed; }
.card.found { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; transform: scale(1.04); }

@media (prefers-reduced-motion: reduce) {
  .card, .meter-fill, .split span { transition: none; }
}

/* ---------- log ---------- */

.log { display: flex; flex-direction: column; gap: 4px; }
.log-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; font-size: 13px;
}
.log-step { color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 18px; }
.log-text { flex: 1; }
.log-answer { font-weight: 700; }
.log-answer.yes, .log-answer.right { color: var(--accent); }
.log-answer.no, .log-answer.wrong { color: var(--warm); }
.log-count { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12px; }

/* ---------- sheet ---------- */

.sheet {
  position: fixed; inset: 0; z-index: 20;
  margin: 0; border: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  color: var(--ink);
  background: rgb(0 0 0 / 0.45);
  display: grid; place-items: end center;
  padding: 0;
}
.sheet-open { overflow: hidden; }
.sheet::backdrop { background: transparent; }
.sheet-inner {
  position: relative;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  width: min(100%, var(--maxw));
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 18px 30px;
}
.sheet-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: 0; font-size: 26px; line-height: 1; color: var(--ink-soft);
}
.sheet h2 { margin: 0 30px 4px 0; font-size: 20px; }
.sheet h3 { margin: 18px 0 6px; font-size: 14px; }
.sheet p, .sheet li { color: var(--ink); font-size: 14px; }
.sheet ul { padding-left: 18px; margin: 6px 0; }
.sheet .muted { color: var(--ink-soft); font-size: 13px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; vertical-align: middle;
}
@media (prefers-color-scheme: dark) { .badge { color: #14122a; } }

.result-strip { font-size: 22px; letter-spacing: 2px; margin: 10px 0; word-break: break-all; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; margin: 12px 0; }
.result-cell { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.result-cell b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.result-cell span { font-size: 11px; color: var(--ink-soft); }

table.moves { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.moves th, table.moves td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.moves th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
table.moves td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.moves tr.mismatch td { color: var(--warm); font-weight: 600; }

.share {
  width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin-top: 8px; resize: vertical; color: var(--ink);
}
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

@media (max-width: 420px) {
  .status { gap: 8px; padding: 10px; flex-wrap: wrap; }
  .meter { flex-basis: 100%; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 150px; }
  .oracle-text { font-size: 18px; }
  .sheet-inner { padding-inline: 12px; }
  table.moves { font-size: 11px; }
  table.moves th, table.moves td { padding: 5px 3px; overflow-wrap: anywhere; }
}
