/* Hidden Verse — mobile-first styles */

:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #2a251f;
  --muted: #776b5d;
  --line: #e2d8c5;
  --accent: #7c2d2d;
  --accent-ink: #fff;
  --accent-soft: #f3e3dc;
  --good: #2e6a3e;
  --good-soft: #e1efe2;
  --bad: #9a3b2a;
  --bad-soft: #f6e2dc;
  --warn: #8a5a0b;
  --reveal: #fbeab3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 6px 20px rgb(60 40 20 / 7%);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171513;
    --card: #221f1b;
    --ink: #eee7da;
    --muted: #a89b89;
    --line: #3a332b;
    --accent: #d88466;
    --accent-ink: #1d1310;
    --accent-soft: #3a2620;
    --good: #84c595;
    --good-soft: #1f3324;
    --bad: #e7957f;
    --bad-soft: #3b231d;
    --warn: #e2b55c;
    --reveal: #5a4a1c;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding: 0 max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

main { max-width: 640px; margin: 0 auto; }

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

/* ---------- Top bar ---------- */

.topbar {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 1.05rem/1 var(--serif);
  color: var(--ink); background: none; border: 0; padding: 6px 0; cursor: pointer;
}
.brand:disabled { cursor: default; opacity: 1; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  background-image:
    linear-gradient(var(--accent-ink), var(--accent-ink)),
    linear-gradient(var(--accent-ink), var(--accent-ink)),
    linear-gradient(var(--accent-ink), var(--accent-ink));
  background-size: 6px 2px, 9px 2px, 7px 2px;
  background-position: 5px 8px, 5px 12px, 12px 8px;
  background-repeat: no-repeat;
}

.streak {
  display: flex; align-items: baseline; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: .9rem;
}
.streak strong { font-size: 1.1rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.streak-label { color: var(--muted); }
.best { color: var(--muted); font-size: .8rem; padding-left: 6px; border-left: 1px solid var(--line); }

/* ---------- Start screen ---------- */

.intro { text-align: center; padding: 12px 4px 20px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
h1 { font: 600 clamp(2.1rem, 9vw, 2.8rem)/1.1 var(--serif); margin: 0 0 10px; letter-spacing: -.01em; }
.lede { margin: 0 auto; max-width: 30em; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

#start-form { display: grid; gap: 4px; }

.field { border: 0; margin: 0; padding: 12px 0; }
.field + .field { border-top: 1px solid var(--line); }
.field legend, .field > label:first-child { font-weight: 600; }
.field legend { padding: 0; margin-bottom: 10px; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block; text-align: center; padding: 10px 0; border-radius: 9px;
  font-weight: 600; letter-spacing: .03em; cursor: pointer; color: var(--muted);
  transition: background .15s, color .15s;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex-shrink: 0; }
.stepper button {
  width: 44px; min-height: 44px; border: 0; background: var(--bg); color: var(--ink);
  font-size: 1.3rem; cursor: pointer;
}
.stepper button:active { background: var(--accent-soft); }
.stepper input {
  width: 52px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  text-align: center; font: 600 1.05rem var(--sans); color: var(--ink); background: var(--card);
  -moz-appearance: textfield; appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.toggle { cursor: pointer; }
.toggle-title { display: block; font-weight: 600; }
.toggle-sub { display: block; color: var(--muted); font-size: .85rem; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex-shrink: 0; position: relative; width: 50px; height: 30px; border-radius: 999px;
  background: var(--line); transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform .2s;
}
.toggle input:checked + .switch { background: var(--accent); }
.toggle input:checked + .switch::after { transform: translateX(20px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.load-error {
  background: var(--bad-soft); color: var(--ink); border-radius: 12px; padding: 12px 14px; margin: 4px 0 8px;
  font-size: .92rem;
}
.load-error p { margin: 0 0 10px; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

.how { margin-top: 16px; padding: 4px 18px; }
.how summary { cursor: pointer; font-weight: 600; padding: 12px 0; min-height: 44px; }
.how ol { margin: 0 0 14px; padding-left: 1.2em; color: var(--muted); }
.how li { margin-bottom: 8px; }
.how strong { color: var(--ink); }

/* ---------- Buttons ---------- */

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 1rem var(--sans); min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
a.btn { text-decoration: none; }
/* Link between single-player (/solo/) and multiplayer (/) */
.mode-switch {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px;
  margin: 14px 0 0; color: var(--muted); font-size: .95rem;
}
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { min-height: 52px; font-size: 1.1rem; margin-top: 8px; }
.btn.small { min-height: 40px; font-size: .92rem; padding: 0 12px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.wide { width: 100%; }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--line); margin-top: 20px; }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: var(--card); }
.btn:disabled { opacity: .6; cursor: progress; }

/* ---------- Game ---------- */

.round-meta { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 10px; }
.pill {
  font-size: .78rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.pill.subtle { background: transparent; color: var(--muted); border: 1px solid var(--line); }

.verse-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 18px 22px;
}

.verse {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.2rem, 5vw, 1.45rem);
  line-height: 2.1;
  overflow-wrap: anywhere;
}
.chunk { white-space: nowrap; }
.punct { color: var(--muted); }

.blank {
  display: inline-block;
  vertical-align: -0.12em;
  width: calc(var(--len, 4) * .5em + .7em);
  height: 1.05em;
  margin: 0 .06em;
  border-bottom: 2px solid var(--muted);
  border-radius: 2px;
  opacity: .8;
}

.word { border-radius: 4px; padding: 0 .05em; }
.word.new { animation: reveal 1.4s ease-out; }
.word.missed {
  color: var(--bad);
  text-decoration: underline dotted var(--bad);
  text-underline-offset: .2em;
}
@keyframes reveal {
  0% { background: var(--reveal); box-shadow: 0 0 0 3px var(--reveal); }
  70% { background: var(--reveal); box-shadow: 0 0 0 3px var(--reveal); }
  100% { background: transparent; box-shadow: 0 0 0 3px transparent; }
}

.reference {
  margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line);
  font: 600 1.05rem var(--serif); color: var(--accent); text-align: right;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats > div {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; text-align: center;
  transition: border-color .2s, background .2s;
}
.stats dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; line-height: 1.2; }
.stats dd { margin: 2px 0 0; font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.score-stat { border-color: var(--accent) !important; background: var(--accent-soft) !important; }
.score-stat dd { color: var(--accent); }
.score-stat.bump { animation: bump .45s ease-out; }
@keyframes bump { 30% { transform: scale(1.08); } }

.play { display: grid; gap: 12px; }
.panel.card { padding: 14px 16px; box-shadow: none; }
.panel-title {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.cost {
  font-size: .78rem; font-weight: 700; letter-spacing: .02em; text-transform: none;
  color: var(--bad); background: var(--bad-soft); padding: 2px 8px; border-radius: 999px;
}
#reveal-btn .cost { margin-left: 4px; }
.panel .msg { margin: 8px 2px; }
.panel .msg:empty { margin: 0; min-height: 8px; }
.guess-row input:disabled { opacity: .55; }
.btn:disabled { cursor: not-allowed; }

.guess-row { display: flex; gap: 8px; }
.guess-row input {
  flex: 1; min-width: 0; min-height: 48px; padding: 0 14px;
  font: 1.05rem var(--sans); /* >=16px prevents iOS zoom on focus */
  color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
}
.guess-row input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.guess-row .btn { min-height: 48px; padding: 0 20px; }

.spell {
  margin-top: 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--line);
  animation: slide .18s ease-out;
}
.spell p { margin: 0 0 10px; }
.spell-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@keyframes slide { from { opacity: 0; transform: translateY(-4px); } }

.msg { min-height: 1.5em; margin: 10px 2px; font-weight: 500; }
.msg.good { color: var(--good); }
.msg.bad { color: var(--bad); }
.msg.warn { color: var(--warn); }

.ref-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.book { font: 600 1.15rem var(--serif); }
.colon { font-weight: 700; font-size: 1.2rem; }
.ref-row select {
  min-height: 48px; min-width: 72px; padding: 0 30px 0 12px;
  font: 600 1.05rem var(--sans); color: var(--ink); background-color: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.ref-row .btn { min-height: 48px; margin-left: auto; padding: 0 22px; }

.ref-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ref-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.ref-list .ref { font-weight: 700; font-variant-numeric: tabular-nums; }
.ref-list .wrong .note { color: var(--bad); font-weight: 600; }
.ref-list .right { border-color: var(--good); background: var(--good-soft); }
.ref-list .right .note { color: var(--good); font-weight: 600; }

.result { margin-top: 14px; padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); }
.result.won { border-color: var(--good); background: var(--good-soft); }
.result.lost { background: var(--bad-soft); }
.result h2 { margin: 0 0 4px; font: 600 1.4rem var(--serif); }
.result p { margin: 0 0 14px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.breakdown, .scoring table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: .95rem; }
.breakdown td, .scoring td { padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); vertical-align: top; }
.breakdown .pts, .scoring .pts { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }
.breakdown .total td { border-bottom: 0; border-top: 2px solid var(--line); font-weight: 700; }
.common { margin-top: 16px; }
.common-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.common h2 {
  display: flex; align-items: center; gap: 8px; margin: 0;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.common h2 .pill { font-size: .7rem; padding: 2px 8px; }
.mini-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); cursor: pointer; min-height: 36px; }
.mini-toggle input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.common-note { margin: 0 0 10px; color: var(--muted); font-size: .85rem; }
.common-list { counter-reset: none; }
.common-chip { background: var(--bg); border-color: var(--line); color: var(--ink); }
.common-chip.filler { color: var(--muted); }
.common-chip .count {
  font-variant-numeric: tabular-nums; font-weight: 700; opacity: 1; color: var(--accent);
}
.common .btn.ghost { margin-top: 8px; padding: 0 4px; }

.scoring { margin-top: 16px; }
.scoring h2 { margin: 0 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.scoring table { margin: 0; }
.scoring tr:last-child td { border-bottom: 0; }
.scoring small { display: block; color: var(--muted); font-size: .82rem; }
.scoring .pts { color: var(--bad); }
.scoring .pts.zero { color: var(--good); }

.history { margin-top: 18px; }
.history h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.empty { color: var(--muted); margin: 0; font-size: .92rem; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: .95rem; border: 1px solid transparent;
}
.chip.hit { background: var(--good-soft); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); font-weight: 600; }
.chip.miss { background: transparent; color: var(--muted); border-color: var(--line); }
.chip.miss > span:first-child { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.chip.revealed { background: var(--accent-soft); color: var(--accent); border-style: dashed; border-color: var(--accent); }
.chip .count { font-size: .78rem; opacity: .8; }
.chip.nudge { animation: nudge .5s; }
@keyframes nudge {
  0%, 100% { transform: none; }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

.noscript { text-align: center; padding: 40px; }

@media (min-width: 560px) {
  body { padding-top: 8px; }
  .verse-card { padding: 26px 28px 28px; }
  .card { padding: 22px 26px; }
}

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