:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #1f2a2a;
  --muted: #6b726f;
  --line: #e3dccd;
  --primary: #1f4e45;
  --primary-ink: #ffffff;
  --accent: #c8742c;
  --success: #2f7d4f;
  --success-bg: #e5f3ea;
  --danger: #b4412f;
  --danger-bg: #fbe9e5;
  --warn-bg: #fff4d6;
  --test: #6b4bb8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 42, 42, .06), 0 4px 16px rgba(31, 42, 42, .06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Fraunces', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a19; --paper: #1d2523; --ink: #ece8df; --muted: #a2a9a5; --line: #2f3936;
    --primary: #4fa08f; --primary-ink: #0d1413; --accent: #e0995a;
    --success-bg: #1b3326; --danger-bg: #3a1f1a; --warn-bg: #3a321b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font);
  min-height: 100vh; overscroll-behavior-y: contain;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 2rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 600; }
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
code { background: var(--line); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.screen { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--primary); color: var(--primary-ink);
}
.bar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-stats { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.05rem; }
.penalty { background: var(--danger); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: .8rem; font-weight: 600; }
.badge { background: var(--test); color: #fff; border-radius: 6px; padding: 0 6px; font-size: .7rem; vertical-align: middle; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 1.5rem; line-height: 1; padding: 4px 8px; cursor: pointer; }

/* Blocks */
.hero { padding: 8px 2px 0; }
.hero p { color: var(--muted); margin: 0; font-size: 1.05rem; }
.hero.small h1 { font-size: 1.6rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--accent); margin: 0 0 .3em; }
.cover { width: calc(100% + 32px); margin: -16px -16px 0; max-height: 260px; object-fit: cover; display: block; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card.success { background: var(--success-bg); border-color: transparent; }
.card.warn { background: var(--warn-bg); border-color: transparent; }
.card.hint { background: var(--warn-bg); border-color: transparent; }
.card.place { font-size: 1.1rem; }
.test-banner { background: #efe9fb; border-color: #d8ccf3; color: #3a2a6b; }
@media (prefers-color-scheme: dark) { .test-banner { background: #2a2340; border-color: #3d3360; color: #ddd3fa; } }

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md img { display: block; border-radius: 12px; margin: 12px auto; }
.md blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.content { font-size: 1.05rem; }

.list { display: flex; flex-direction: column; gap: 12px; }
.game-card { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.game-card img { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; flex-shrink: 0; }
.game-card p { margin: 0; color: var(--muted); }
.choice { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; font: inherit; color: inherit; cursor: pointer; width: 100%; }
.choice:active { transform: scale(.99); }
.choice p { margin: 0; color: var(--muted); }
.choice-dist { font-weight: 600; color: var(--accent); white-space: nowrap; }

.rules { margin: 0; padding-left: 1.2em; }
.rules li + li { margin-top: 6px; }

/* Forms & buttons */
label { display: block; font-weight: 600; margin-bottom: 6px; }
input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink); margin-bottom: 12px;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 12px 18px; border-radius: 12px; border: 0; background: var(--primary); color: var(--primary-ink);
  cursor: pointer; text-decoration: none; min-height: 48px;
}
.btn:disabled { opacity: .6; }
.btn.big { width: 100%; font-size: 1.1rem; }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.test { background: var(--test); color: #fff; }
.link-btn { background: none; border: 0; color: var(--primary); font: inherit; text-decoration: underline; padding: 0; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 140px; }

.answer-row { display: flex; gap: 8px; }
.answer-row input { margin: 0; }
.feedback { margin: 8px 0 0; min-height: 1.4em; font-weight: 600; }
.feedback.error { color: var(--danger); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* Navigation */
.nav-panel { display: flex; align-items: center; gap: 20px; }
.nav-panel.solo { justify-content: center; text-align: center; }
.distance { font-family: var(--display); font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.direction { color: var(--muted); margin: 4px 0 6px; }
.compass {
  width: 120px; height: 120px; border-radius: 50%; flex-shrink: 0; background: var(--paper);
  border: 2px solid var(--line); box-shadow: var(--shadow); position: relative;
}
.compass.live { border-color: var(--primary); }
.dial { position: absolute; inset: 0; transition: transform .3s ease-out; }
.north { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); font-weight: 700; font-size: .8rem; color: var(--danger); }
.needle { position: absolute; inset: 14px; transition: transform .3s ease-out; }
.needle::before {
  content: ''; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border-left: 14px solid transparent; border-right: 14px solid transparent; border-bottom: 46px solid var(--accent);
}
.needle::after { content: ''; position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px; border-radius: 50%; background: var(--ink); }
.map { height: 280px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); z-index: 0; }
.map-label { font-weight: 600; }
.gps-status:empty { display: none; }

/* End */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats div { display: flex; flex-direction: column; }
.stats span { color: var(--muted); font-size: .85rem; }
.stats strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stats .final strong { color: var(--accent); }
.stats p { grid-column: 1 / -1; margin: 0; }
.board { width: 100%; border-collapse: collapse; }
.board td, .board th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.board .num { text-align: right; font-variant-numeric: tabular-nums; }
.board tr.me { background: var(--success-bg); font-weight: 600; }

/* Overlays */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; z-index: 3000; max-width: calc(100% - 32px);
  transition: all .3s; box-shadow: var(--shadow); font-weight: 500;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 2000; display: flex; align-items: flex-end; }
.sheet {
  background: var(--paper); width: 100%; max-width: 640px; margin: 0 auto; border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
}
.sheet p { margin: 0; }
.loading { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Multiple choice */
.label { font-weight: 600; margin: 0 0 8px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice-btn { justify-content: flex-start; text-align: left; color: var(--ink); background: var(--bg); }
.choice-btn.wrong { text-decoration: line-through; color: var(--danger); border-color: var(--danger); opacity: .7; }
.md audio, .md video { width: 100%; margin: 8px 0; }
.md video { border-radius: 12px; }
