:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a64;
  --line: #d9d6cc;
  --brand: #2a7ae2;
  --brand-soft: #e5effb;
  --gold: #f2b705;
  --red: #e0433a;
  --green: #1f9d55;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --map-land: #efece3; --map-water: #9cc6e6; --map-park: #bcd9a8; --map-road: #ffffff; --map-label: #3b3a35; --map-district: #8a7f6a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --card: #1f1f1d; --ink: #f1efe8; --muted: #a3a197; --line: #3a3934;
    --brand: #5b9cf0; --brand-soft: #1d2b3f;
    --map-land: #24262a; --map-water: #2d4f6e; --map-park: #2f4a2a; --map-road: #3d4047; --map-label: #d9d6cc; --map-district: #9c9583;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #141413; --card: #1f1f1d; --ink: #f1efe8; --muted: #a3a197; --line: #3a3934;
    --brand: #5b9cf0; --brand-soft: #1d2b3f;
    --map-land: #24262a; --map-water: #2d4f6e; --map-park: #2f4a2a; --map-road: #3d4047; --map-label: #d9d6cc; --map-district: #9c9583;
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { scroll-padding-bottom: 96px; } /* keep focused/scrolled items clear of the tab bar */
body {
  font-family: 'Noto Sans Thai', 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

#app { max-width: 520px; margin: 0 auto; min-height: 100%; padding: 12px 16px 96px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 12px; }
.logo { font-weight: 800; font-size: 1.35rem; letter-spacing: -.01em; text-decoration: none; color: var(--ink); }
.logo span { color: var(--brand); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .8rem; font-weight: 600; }
.chip.gold { background: #fff4cc; color: #8a6400; }
.chip.red { background: #fde4e2; color: var(--red); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin: 0 0 8px; }
.card h2 { font-size: 1.15rem; }
.card h3 { font-size: 1rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 16px; font-weight: 600; min-height: 44px; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; border-radius: 14px; }
.btn.confirm { background: var(--brand-soft); border: 2px solid var(--brand); color: var(--ink); }
.btn.confirm:not(:disabled) { background: var(--brand); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #3b2c00; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; }
.btn.danger { color: var(--red); }

input[type=text], input[type=number], select, textarea { font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-height: 44px; }
label { display: block; font-size: .875rem; color: var(--muted); margin: 8px 0 4px; }

/* countdown */
.countdown { font-variant-numeric: tabular-nums; font-size: 3rem; font-weight: 800; letter-spacing: .02em; text-align: center; line-height: 1.1; }
.countdown small { display: block; font-size: .9rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.prize { font-size: 1.6rem; font-weight: 800; color: #8a6400; }

/* play */
.play-head { display: flex; justify-content: space-between; align-items: baseline; }
.play-head h1 { font-size: 1.3rem; margin: 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--brand); font-size: 1.6rem; }
.timer.hurry { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.photo { width: 100%; aspect-ratio: 4 / 3; border-radius: var(--radius); border: 1px solid var(--line); background: #ecebe6 center / cover no-repeat; display: block; position: relative; overflow: hidden; }
.photo .zoomhint { position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 55%); color: #fff; font-size: .75rem; padding: 2px 8px; border-radius: 999px; }
.hints { display: grid; gap: 6px; margin: 10px 0; }
.hint { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; }
.hint.locked { color: var(--muted); border-style: dashed; }
.map { height: 42vh; min-height: 260px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; z-index: 0; }
.map.tall { height: 52vh; }
.status-line { display: flex; justify-content: space-between; font-size: .875rem; color: var(--muted); margin: 8px 2px; }
.sticky-confirm { position: sticky; bottom: 12px; margin-top: 10px; z-index: 5; }

/* zoom viewer */
.viewer { position: fixed; inset: 0; background: #000; z-index: 1000; touch-action: none; overflow: hidden; }
.viewer img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; max-width: none; }
.viewer .close { position: absolute; top: 12px; right: 12px; z-index: 2; background: rgb(255 255 255 / 85%); border: 0; border-radius: 999px; width: 44px; height: 44px; font-size: 1.3rem; }

/* result */
.result-hero { text-align: center; padding: 20px 16px; background: linear-gradient(160deg, var(--brand-soft), var(--card)); }
.result-hero .big { font-size: 2.4rem; font-weight: 800; line-height: 1.1; }
.rank-list { list-style: none; padding: 0; margin: 0; counter-reset: r; }
.rank-list li { display: flex; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.rank-list li:last-child { border-bottom: 0; }
.rank-list .n { width: 28px; text-align: center; font-weight: 700; color: var(--muted); }
.rank-list li.me { background: var(--brand-soft); border-radius: 8px; }
.rank-list .pts { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { text-align: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px 4px; font-size: .8rem; }
.badge .i { font-size: 1.6rem; display: block; }
.badge.off { opacity: .35; filter: grayscale(1); }

/* nav */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabbar a { flex: 1; max-width: 104px; text-align: center; padding: 8px 0 10px; text-decoration: none; color: var(--muted); font-size: .75rem; }
.tabbar a .i { display: block; font-size: 1.25rem; }
.tabbar a.on { color: var(--brand); font-weight: 700; }

.demo-bar { background: #fff4cc; color: #5a4300; border: 1px solid #f2d675; border-radius: 12px; padding: 8px 12px; font-size: .85rem; margin-bottom: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.demo-bar .btn { min-height: 32px; padding: 4px 10px; font-size: .8rem; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 2000; max-width: 90vw; font-size: .9rem; box-shadow: var(--shadow); }
.mini-card { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.mini-card .i { font-size: 2rem; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.options .btn:disabled { opacity: 1; color: var(--muted); }
.options .btn.right { background: #dff5e8; border-color: var(--green); color: #14532d; }
.options .btn.wrong { background: #fde4e2; border-color: var(--red); color: #7f1d1d; }
.item-img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.sched li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sched { list-style: none; padding: 0; margin: 0; }
.sched .d { width: 64px; text-align: center; font-weight: 700; }
.sched .d small { display: block; font-weight: 400; color: var(--muted); }
.fire { color: #f05a24; }
.prose h1 { font-size: 1.4rem; } .prose h2 { font-size: 1.1rem; margin-top: 1.4em; }
.prose li { margin: 4px 0; }
.leaflet-container { font: inherit; }
.pin-answer { font-size: 28px; line-height: 28px; text-align: center; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 40%)); }
