:root {
  --bg: #F7F5F0;
  --card: #FFFFFF;
  --ink: #1C1F1A;
  --ink-2: #3E433B;
  --muted: #5A5F55;
  --line: #E6E2D8;
  --line-2: #C9C5BA;
  --magenta: #B0177A;
  --magenta-ink: #8C0F60;
  --blue: #1F5F8B;
  --orange: #E8590C;
  --amber-bg: #FFE9A8;
  --amber-ink: #5A4A00;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: calc(64px + var(--safe-b));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, a.btn { font: inherit; }
h1, h2 { margin: 0; letter-spacing: -0.3px; }
h2 { font-size: 22px; }

/* no page pinch-zoom outside the map (iOS ignores user-scalable=no) */
.view, .sheet { touch-action: pan-y; }

/* ---------- Map ---------- */
#map-view { position: fixed; inset: 0 0 var(--tabs-h) 0; }
#map { position: absolute; inset: 0; background: #fff; touch-action: none; }
#btn-help { position: absolute; left: 12px; top: calc(12px + var(--safe-t)); background: #FBEAF4; border-color: #E9B8D6; color: var(--magenta-ink); }
#compass {
  position: absolute; right: 12px; top: calc(12px + var(--safe-t));
  width: 88px; height: 88px; pointer-events: none; padding: 0; border: 0; background: none;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.25));
}
/* no reading yet: greyed out and tappable to ask for permission again */
#compass.off, #compass.unsure { pointer-events: auto; }
#compass.off .rose { opacity: .45; filter: grayscale(1); }
.compass-off-label {
  display: none; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 4px;
  white-space: nowrap; font: 700 12px system-ui, sans-serif; color: var(--ink);
  background: rgba(255,255,255,.95); padding: 3px 8px; border-radius: 999px;
}
#compass.off .compass-off-label { display: block; }
#compass .rose { width: 100%; height: 100%; will-change: transform; }
#compass .bezel { fill: rgba(255,255,255,.92); stroke: var(--line-2); stroke-width: 1.5; }
#compass text { font: 700 12px system-ui, sans-serif; text-anchor: middle; fill: var(--muted); }
#compass text.n { fill: #C2410C; }
#compass .north { fill: #C2410C; }
#compass .south { fill: #9AA096; }
#compass .hub { fill: var(--ink); }
#compass-warn {
  position: absolute; right: -2px; bottom: -2px; width: 24px; height: 24px; border-radius: 50%;
  background: #F9A825; color: #000; font-weight: 700; text-align: center; line-height: 24px;
}
#map-bottom {
  position: absolute; left: 0; right: 0; bottom: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.pill {
  pointer-events: auto; min-height: 48px; padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--line-2); background: rgba(255,255,255,.96); color: var(--ink);
  font-weight: 700; font-size: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.15);
  display: inline-flex; align-items: center; text-decoration: none;
}
#locate-status {
  background: var(--magenta); color: #fff; font-weight: 700;
  padding: 8px 16px; border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.2);
  max-width: calc(100vw - 32px); text-align: center;
}
body.panel-open #map-bottom { display: none; }

/* ---------- Full-screen views over the map ---------- */
.view {
  position: fixed; inset: 0 0 var(--tabs-h) 0; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-top: var(--safe-t);
}
.view[hidden] { display: none; }
#start { inset: 0; z-index: 40; }

/* ---------- Controls list ---------- */
.list-head { padding: 18px 16px 4px; display: flex; flex-direction: column; gap: 6px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.list-head h1 { font-size: 24px; }
.countdown {
  font-size: 14px; font-weight: 700; color: var(--amber-ink); background: var(--amber-bg);
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}
.list-meta { display: flex; justify-content: space-between; align-items: center; font-size: 15px; font-weight: 700; color: #2E7D32; }

#sections { padding: 0 16px 24px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 18px 2px 8px; padding-bottom: 6px; border-bottom: 3px solid var(--grade);
}
.section-head h2 { font-size: 18px; color: var(--grade); }
.section-head .rule { font-size: 14px; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.ctl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ctl-list button {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 10px 12px; background: var(--card); border-radius: 14px; border: 1px solid var(--line); color: var(--ink);
}
.ring {
  width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--grade, var(--magenta)); flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: var(--grade, var(--magenta-ink)); background: #fff;
}
.ring.big { width: 76px; height: 76px; border-width: 5px; font-size: 30px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-desc { font-size: 16px; font-weight: 600; }
.row-sub { font-size: 13px; color: var(--muted); }
.chev { color: var(--line-2); flex: none; }
.ctl-list button.done { background: #F1F7EE; border-color: #CFE3C6; }
.ctl-list button.done .ring { background: #2E7D32; border-color: #2E7D32; color: #fff; font-size: 22px; }
.row-num { color: var(--muted); font-weight: 700; }
.perk-chip { white-space: nowrap; font-size: 13px; font-weight: 800; color: #7A4E00; background: #FFF4D6; padding: 2px 8px; border-radius: 999px; vertical-align: 2px; }

/* ---------- Bottom sheets ---------- */
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: var(--tabs-h); z-index: 30;
  max-height: 70vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 20px 20px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.18);
  padding: 18px 16px 16px;
  animation: up .18s ease-out;
}
.sheet.modal { bottom: 0; padding-bottom: calc(16px + var(--safe-b)); }
.sheet[hidden] { display: none; }
@keyframes up { from { transform: translateY(30%); opacity: .4; } to { transform: none; opacity: 1; } }
.close {
  position: absolute; right: 10px; top: 10px; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: #F0EEE8; color: var(--ink); font-size: 26px; line-height: 1;
}
.sheet h2 { padding-right: 48px; margin-bottom: 8px; }
.panel-hero { display: flex; gap: 14px; align-items: center; padding-right: 48px; }
.back {
  width: 44px; height: 44px; margin-right: -6px; border-radius: 50%; flex: none;
  border: 0; background: #F0EEE8; color: var(--ink); font-size: 30px; line-height: 1; padding: 0 0 4px;
}
.perk { margin: 8px 0 0; font-weight: 800; color: #7A4E00; }
.grade { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--grade); }
.ladder { font-size: 15px; color: var(--ink-2); margin-top: 2px; }
.desc { font-size: 19px; font-weight: 600; margin: 12px 0 6px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #EEF3E6; color: #2F4A1E; }
.card { background: var(--bg); border-radius: 12px; padding: 10px 14px; margin: 10px 0 0; }
.card p { margin: 2px 0 0; font-size: 16px; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.btn.snap { margin-top: 14px; background: var(--card); color: var(--ink); border: 2px solid var(--line-2); }
.btn.snap.on { background: #2E7D32; border-color: #2E7D32; color: #fff; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 54px; margin: 8px 0; border-radius: 14px; border: 1px solid transparent; padding: 0 14px;
  font-weight: 700; font-size: 17px; text-decoration: none; cursor: pointer; text-align: center;
}
.btn.primary { background: var(--orange); color: #fff; }
.btn.secondary { background: var(--card); color: var(--ink); border-color: var(--line-2); }
.btn.hint-btn { background: #FBEAF4; color: var(--magenta-ink); border-color: #E9B8D6; justify-content: flex-start; }
.btn.hint-btn.on { background: var(--magenta); color: #fff; border-color: var(--magenta); }
.btn:disabled { opacity: .45; }
.link { background: none; border: 0; color: var(--blue); text-decoration: underline; font-size: 15px; padding: 6px 0; }
.hint { color: var(--muted); font-size: 14px; }

/* ---------- Rules ---------- */
.rules { padding-left: 22px; margin: 8px 0; }
.rules li { margin: 8px 0; font-size: 16px; color: var(--ink-2); }
.bonus { font-weight: 700; color: #7A4E00; background: #FFF4D6; padding: 10px 12px; border-radius: 12px; }

/* ---------- Control sign ---------- */
.sign { display: flex; gap: 14px; align-items: center; margin: 14px 0; }
.sign svg { width: 92px; height: 92px; flex: none; border-radius: 4px; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.sign figcaption { font-size: 15px; color: var(--ink-2); }
.sign-slot.small .sign svg { width: 64px; height: 64px; }
.sign-slot.small .sign figcaption { font-size: 14px; color: var(--muted); }

/* ---------- Tabs ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabs-h); z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card); border-top: 1px solid #DDD8CC; padding-bottom: var(--safe-b);
}
.tab {
  border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tab.on { color: var(--ink); font-weight: 800; }

/* ---------- Welcome ---------- */
#start {
  /* confetti */
  background:
    radial-gradient(circle at 8% 6%, #E8590C 0 5px, transparent 6px),
    radial-gradient(circle at 88% 4%, #1565C0 0 4px, transparent 5px),
    radial-gradient(circle at 72% 12%, #2E7D32 0 3px, transparent 4px),
    radial-gradient(circle at 22% 15%, #B0177A 0 3px, transparent 4px),
    radial-gradient(circle at 95% 18%, #F9A825 0 5px, transparent 6px),
    radial-gradient(circle at 4% 24%, #F9A825 0 3px, transparent 4px),
    radial-gradient(circle at 60% 3%, #B0177A 0 4px, transparent 5px),
    var(--bg);
  background-attachment: local;
}
.start-body { max-width: 480px; margin: 0 auto; padding: 24px 20px 40px; text-align: left; }
.cake { font-size: 64px; line-height: 1; text-align: center; margin: 8px 0 6px; }
.kicker { text-align: center; margin: 0; font-weight: 800; color: var(--orange); text-transform: uppercase; letter-spacing: 1px; font-size: 14px; }
.start-body h1 { font-size: 30px; color: var(--magenta-ink); margin: 4px 0 8px; text-align: center; }
.lede { text-align: center; font-size: 17px; color: var(--ink-2); margin: 0 0 8px; }
.start-body .rules-slot h2 { display: none; }
.heads-up { background: #E8F1F8; color: #17435F; border-radius: 12px; padding: 12px 14px; font-size: 15px; margin: 16px 0 4px; }
#btn-go { font-size: 20px; min-height: 60px; }
.progress { height: 12px; border-radius: 6px; background: var(--line); overflow: hidden; margin-top: 16px; }
#progress-bar { height: 100%; width: 0; background: var(--orange); transition: width .3s; }
