:root {
  --bg: #f7f5f0;
  --ink: #1d1b22;
  --muted: #9a958c;
  --line: #d9d4ca;
  --accent: #1d1b22;
  --good: #2f8a55;
  --bad: #c2413b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131217;
    --ink: #eeebe4;
    --muted: #6d6974;
    --line: #34313b;
    --accent: #eeebe4;
    --good: #6fcf97;
    --bad: #f0807a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

main {
  width: 100%;
  max-width: 36rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  text-align: center;
}

.view { width: 100%; animation: fade 500ms ease-out both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.dots { display: flex; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.dots li { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--line); transition: background 300ms; }
.dots li.solved { background: var(--muted); }
.dots li.current { background: var(--ink); }

.question {
  margin: 0 0 2.5rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
  line-height: 1.35;
  text-wrap: balance;
  white-space: pre-wrap;
}

.hint {
  margin: -1.25rem 0 2.25rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--muted);
  white-space: pre-wrap;
}

form { display: flex; flex-direction: column; align-items: center; gap: 2rem; }
.field { width: 100%; position: relative; container-type: inline-size; }

/* Free-text riddles: a single underlined line. */
input {
  width: 100%;
  font: inherit;
  font-size: 1.25rem; /* ≥16px avoids iOS zoom on focus */
  text-align: center;
  padding: 0.5rem 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid var(--line);
  border-radius: 0;
  outline: none;
  transition: border-color 150ms;
}
input:focus { border-bottom-color: var(--ink); }

/* Fill-in-the-blank riddles: the real input sits invisibly over the boxes,
   so tapping them opens the keyboard. */
form.blank-mode input {
  position: absolute;
  inset: 0;
  opacity: 0;
  color: transparent;
  caret-color: transparent;
  cursor: text;
  border: 0;
}

.blanks {
  /* Box size, up to 2.6rem: the longest word must fit on one line, and the
     whole answer (--total counts a word gap as two boxes) in about three.
     Both are set from JS. */
  --longest: 6;
  --total: 6;
  --cell: min(
    2.6rem,
    calc((100cqi - (var(--longest) - 1) * 0.3rem) / var(--longest)),
    calc(300cqi / (var(--total) * 1.2))
  );
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.9rem 1.2rem; /* between rows, between words */
}
.blanks .word { display: flex; gap: 0.3rem; }
.blanks .slot, .blanks .literal {
  display: grid;
  place-items: end center;
  height: calc(var(--cell) * 1.25);
  padding-bottom: 0.3rem;
  font-size: calc(var(--cell) * 0.6);
  font-weight: 600;
  text-transform: uppercase;
}
.blanks .slot {
  width: var(--cell);
  border-bottom: 2px solid var(--line);
  transition: border-color 150ms, color 150ms;
}
.blanks .slot.filled { border-bottom-color: var(--muted); }
.blanks .slot.active { border-bottom-color: var(--ink); }
.blanks .literal { color: var(--muted); }

.wrong .blanks .slot, .wrong input { border-bottom-color: var(--bad); color: var(--bad); }
.right .blanks .slot, .right input { border-bottom-color: var(--good); color: var(--good); }
.wrong .field { animation: shake 380ms; }
@keyframes shake {
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

button {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--bg);
  background: var(--ink);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: opacity 150ms, transform 100ms, background 200ms, width 200ms;
}
button svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button:active { transform: scale(0.96); }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
button:disabled { cursor: default; opacity: 0.35; }
/* Cooldown: the button shows the time left instead of the arrow. */
button.waiting svg { display: none; }
button.waiting { width: 4.25rem; border-radius: 1.625rem; opacity: 1; color: var(--muted); background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }

.clue {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.3rem, 5vw, 1.75rem);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.clue + .reward { margin-top: 2rem; }
.reward { display: block; width: 100%; max-height: 75dvh; object-fit: contain; border-radius: 0.75rem; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
