/* Whittle. Mobile-first, no framework, no external requests.
   The one animation that matters is candidates leaving the board: that is this
   game's equivalent of tiles merging. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eeece7;
  --ink: #17181c;
  --ink-soft: #5d6068;
  --line: #dcd9d2;
  --accent: #1f6f5c;
  --accent-soft: #d7e9e3;
  --warm: #b4571f;
  --dim: #a8a49c;
  --radius: 10px;
  --gap: 10px;
  --maxw: 720px;
  font-synthesis-weight: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --surface: #1d1f26;
    --surface-2: #262932;
    --ink: #eceef2;
    --ink-soft: #a2a7b3;
    --line: #333743;
    --accent: #58c3a5;
    --accent-soft: #1f3b35;
    --warm: #e08c4e;
    --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, input:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 3px;
}
.round-label, .round-note { margin: 0; color: var(--ink-soft); font-size: 12px; }
.round-note { margin-top: -8px; }
.round-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.round-actions:has(> :not([hidden])) { margin-bottom: 2px; }
.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); }

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

.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; }

.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;
}

/* ---------- tiers ---------- */

.tiers { display: flex; gap: 6px; flex-wrap: wrap; }
.tiers button {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft);
  padding: 5px 11px; font-size: 12px;
}
.tiers button[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600;
}
.tiers button:disabled:not([aria-pressed="true"]) { opacity: 0.5; }

/* ---------- 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:hover:not(.out) { border-color: var(--accent); }
.card[aria-pressed="true"] { 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; }

.board-hidden {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 18px; text-align: center; color: var(--ink-soft); font-size: 14px;
}

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

/* ---------- action bar ---------- */

.actionbar {
  position: sticky; bottom: 10px; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 10px 12px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
.actionbar span { flex: 1; font-size: 14px; }

/* ---------- deck ---------- */

.deck { display: flex; flex-direction: column; gap: 12px; }
.cat h2 {
  margin: 0 0 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-soft);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  padding: 7px 11px; font-size: 13px; text-align: left;
}
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip .hint { color: var(--ink-soft); font-size: 11px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.chip.good .hint { color: var(--accent); font-weight: 600; }

/* ---------- 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 { color: var(--accent); }
.log-answer.no { color: var(--warm); }

/* ---------- 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; }

.result-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.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; }

.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; }
input.share { min-width: 0; font: inherit; }
@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: 115px; }
  .sheet-inner { padding-inline: 12px; }
  table.moves { font-size: 11px; }
  table.moves th, table.moves td { padding: 5px 3px; overflow-wrap: anywhere; }
}
