/* Deduce — a daily logic grid. Carries its own copy of the palette and chrome,
   like the other games, so moving between them feels like one place. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --tile: #ffffff;
  --tile-border: #d9dee5;
  --ink: #131720;
  --ink-soft: #5c6673;
  --ink-faint: #97a1ae;
  --accent: #2f6df6;
  --correct: #2f9e5f;
  --correct-bg: #e6f5ec;
  --accent-bg: #e8effd;
  --wrong: #d2453c;
  --shadow: 0 1px 2px rgba(16, 22, 34, .08), 0 4px 14px rgba(16, 22, 34, .06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171c23;
    --tile: #1c222b;
    --tile-border: #2c3540;
    --ink: #eef2f7;
    --ink-soft: #9aa5b3;
    --ink-faint: #6b7684;
    --accent: #5c8dff;
    --correct: #43c17f;
    --correct-bg: #16342a;
    --accent-bg: #16233d;
    --wrong: #ef6a61;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI",
               Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           0 env(safe-area-inset-left);
}

button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ---------- top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 7px 14px;
  border-bottom: 1px solid var(--tile-border);
  flex: none;
}
.topbar-side { display: flex; align-items: center; gap: 2px; }
.topbar-side.end { justify-self: end; }

.wordmark {
  margin: 0;
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .24em;
  text-indent: .24em;
}
.mark { font-size: 17px; letter-spacing: 0; margin-right: 9px; vertical-align: -1px; }

.icon-btn {
  width: 32px; height: 32px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:active { background: var(--tile-border); transform: scale(.88); }
a.icon-btn { display: grid; place-items: center; text-decoration: none; }

/* ---------- game ---------- */
#game {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 14px 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.head { flex: none; text-align: center; }

.puzzle-no {
  margin: 0;
  font-size: 12px;
  letter-spacing: .1em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.theme {
  margin: 3px 0 10px;
  font-size: 19px;
  font-weight: 800;
}

/* ---------- clues ---------- */
.clues {
  flex: none;
  list-style: none;
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  counter-reset: clue;
}
.clue {
  position: relative;
  margin: 0 0 7px;
  padding-left: 22px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
}
.clue:last-child { margin-bottom: 0; }
.clue::before {
  counter-increment: clue;
  content: counter(clue) ".";
  position: absolute;
  left: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
}
/* Tapping a clue dims it — the player's own record of what they have used.
   It carries no logic; the grid is the only state that matters. */
.clue.used { color: var(--ink-faint); text-decoration: line-through; }

/* A clue handed over by the Hint button. Marked, because it is worth knowing
   which of these you worked for — and the count is on the results screen. */
.clue.spare { padding-left: 26px; }
.clue.spare::before {
  content: "★";
  counter-increment: none;
  color: var(--accent);
  font-size: 12px;
}
.clue.spare::after {
  content: "hint";
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.clue.spare.used::after { opacity: .5; }

/* ---------- the grid ---------- */
.grid {
  flex: none;
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
/* minmax(0, 1fr), not 1fr: a grid track sized 1fr still refuses to go below the
   intrinsic width of its content, so a long label like "croissant" pushed the
   whole row wider than the phone and shunted the last category off-screen. */
.grid-row {
  display: grid;
  grid-template-columns: minmax(0, 54px) repeat(var(--cols), minmax(0, 1fr));
  gap: 5px;
  align-items: stretch;
}

.colhead, .rowname {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.colhead { justify-content: center; text-align: center; }
.rowname {
  font-size: 12.5px;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 800;
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
}

.cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;              /* same reason as the track sizing above */
  padding: 4px 2px;
  background: var(--tile);
  border: 1.5px solid var(--tile-border);
  border-radius: 10px;
}
/* One candidate left: this row's answer for this category is settled. */
/* Blue, not green. A cell with one possibility left is DECIDED, not right — the
   player may well have decided wrongly, and green quietly tells them they have
   not. Green is reserved for the finished, checked board. */
.cell.settled { border-color: var(--accent); background: var(--accent-bg); }
.cell.empty  { border-color: var(--wrong); }

.chip {
  padding: 3px 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  min-width: 0;
  overflow-wrap: anywhere;   /* "croissant" wraps rather than widening the grid */
}
.chip:active { transform: scale(.9); }
.chip.out {
  color: var(--ink-faint);
  text-decoration: line-through;
  opacity: .55;
  font-weight: 500;
}
.cell.settled .chip:not(.out) { color: var(--accent); font-weight: 800; }
.chip:disabled { cursor: default; }

/* ---------- dock ---------- */
.dock {
  flex: none;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 6px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--tile-border);
  background: var(--bg);
}
/* Two rows rather than one: Undo, Reset and Check alongside the status text
   squeezed it to nothing on a narrow phone. */
.statusbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.statusbar .feedback { text-align: left; }

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.actions .spacer { flex: 1; }

.minor {
  padding: 6px 13px;
  border: 1.5px solid var(--tile-border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.minor:active { transform: scale(.92); }
.minor:disabled { color: var(--ink-faint); opacity: .5; cursor: default; transform: none; }
/* Reset asks before it wipes the grid — one mistap should not cost the puzzle. */
.minor.armed {
  border-color: var(--wrong);
  color: var(--wrong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wrong) 18%, transparent);
}

.feedback {
  margin: 0;
  min-height: 17px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.feedback b { color: var(--ink); }
.feedback.bad b { color: var(--wrong); }

#btn-check {
  flex: none;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
#btn-check:active { transform: scale(.92); }
#btn-check:disabled {
  background: transparent;
  border: 1.5px solid var(--tile-border);
  color: var(--ink-faint);
  cursor: default;
  transform: none;
}

/* a wrong finish shakes the grid rather than silently doing nothing */
.grid.reject { animation: rejectShake .42s ease; }
@keyframes rejectShake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-7px); }
  32%      { transform: translateX(6px); }
  50%      { transform: translateX(-5px); }
  68%      { transform: translateX(4px); }
  85%      { transform: translateX(-2px); }
}

/* ---------- sheets ---------- */
.sheet-wrap[hidden] { display: none; }
.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 11, 16, .55);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 26px 20px calc(26px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  animation: rise .26s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { transform: translateY(24px); } }

@media (min-width: 560px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 20px; }
}

.sheet h2 { margin: 0 0 6px; font-size: 22px; text-align: center; }

/* Sits above the other sheets: it can appear while help or stats is open, and it
   is the one that must be answered first. */
.sheet-wrap.pause { z-index: 60; background: rgba(8, 11, 16, .78); }
.pause-clock {
  margin: 6px 0 20px;
  text-align: center;
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.close {
  position: absolute;
  top: 12px; right: 12px;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.result-sub {
  margin: 0 0 20px;      /* carries the gap the answer table used to leave */
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
}

.primary, .secondary {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
.primary {
  padding: 13px 30px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
}
.secondary {
  padding: 11px 26px;
  margin-top: 10px;
  border: 1.5px solid var(--tile-border);
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 600;
}
.primary:active, .secondary:active { transform: scale(.94); }
.primary.press, .secondary.press, #btn-check.press {
  animation: press .26s cubic-bezier(.2, .8, .3, 1);
}
@keyframes press {
  0%   { transform: scale(.94); }
  55%  { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.statrow {
  display: flex;
  justify-content: center;
  align-items: start;
  gap: 18px;
  margin: 20px 0 0;
}
.stat { text-align: center; }
.stat b { display: block; font-size: 26px; font-weight: 800; }
.stat span {
  display: block;
  max-width: 74px;
  margin-inline: auto;
  font-size: 11px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .06em;
  line-height: 1.25;
}

.countdown {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.dist-title {
  margin: 22px 0 10px;
  font-size: 13px;
  text-align: center;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .09em;
}
.dist { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dist-row .track { flex: 1; min-width: 0; display: flex; }
.dist-row .lab {
  width: 76px;
  flex: none;
  font-weight: 700;
  font-size: 12px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.dist-row .bar {
  background: var(--accent);
  color: #fff;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12px;
  min-width: 26px;
  text-align: right;
}

.help-list { margin: 16px 0; padding-left: 20px; line-height: 1.65; font-size: 15px; }
.help-list li { margin-bottom: 8px; }
.help-foot {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--tile-border);
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  font-style: italic;
}

/* short screens */
@media (max-height: 740px) {
  .topbar { padding: 5px 12px; }
  #game { padding: 8px 12px 0; }
  .theme { font-size: 17px; margin-bottom: 8px; }
  .clues { padding: 10px 12px; margin-bottom: 10px; }
  .clue { font-size: 13px; margin-bottom: 5px; }
  .chip { font-size: 11px; padding: 2px 3px; }
  #btn-check { padding: 6px 14px; font-size: 12px; }
  .minor { padding: 5px 11px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
