:root {
  --bg: #140a20;
  --panel: #23143a;
  --panel-2: #2f1d4b;
  --ink: #f6eeff;
  --muted: #b9a6d3;
  --orange: #ff8a1f;
  --orange-deep: #e8640c;
  --green: #7dff4f;
  --radius: 18px;
  --font-display: 'Creepster', 'Chalkduster', fantasy;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: radial-gradient(ellipse at top, #2a1446 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .05em; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}
.brand { display: flex; flex-direction: column; line-height: 1.05; }
.brand-small { font-size: .75rem; text-transform: uppercase; letter-spacing: .2em; color: var(--muted); }
.brand-title { font-family: var(--font-display); font-size: 1.45rem; color: var(--orange); letter-spacing: .03em; }

.icon-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--orange); background: transparent; color: var(--orange);
  font: 800 1.15rem/1 var(--font-body); cursor: pointer;
  display: grid; place-items: center;
  transition: background .2s, color .2s, transform .1s;
}
.icon-btn:hover { background: var(--orange); color: var(--bg); }
.icon-btn:active { transform: scale(.94); }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

/* ---------- Status ---------- */
.status { padding: 4px 16px 8px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.progress { flex: 1 1 180px; }
.progress-label { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.progress-label strong { color: var(--ink); font-size: 1rem; }
.progress-bar { height: 10px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.progress-bar span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--orange-deep), var(--orange), #ffd84a);
  border-radius: inherit; transition: width .8s cubic-bezier(.2,.8,.2,1);
}
.raffle {
  font-size: .75rem; color: var(--muted); background: var(--panel);
  padding: 6px 10px; border-radius: 99px; border: 1px solid var(--panel-2);
}
.raffle code { color: var(--orange); font-weight: 700; font-size: .85rem; }

.complete-banner {
  margin: 4px 16px 8px; padding: 12px 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, #ff8a1f, #c2410c); color: #1a0b2e;
  display: flex; gap: 12px; align-items: center;
  box-shadow: 0 0 30px rgba(255, 138, 31, .45);
}
.complete-banner p { margin: 2px 0 0; font-size: .85rem; }
.complete-banner code { font-weight: 800; }
.complete-emoji { font-size: 2rem; animation: bob 2s ease-in-out infinite; }

/* ---------- Map ---------- */
.map-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0 12px 16px; }
.map {
  width: 100%; max-width: 520px; height: auto; display: block;
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.5), inset 0 0 0 1px #2c1d3d;
}
.map-hint { color: var(--muted); font-size: .8rem; text-align: center; margin: 10px 0 0; max-width: 40ch; }

.street-label { fill: #8a76a6; font: 700 9px var(--font-body); letter-spacing: .2em; }
.entrance { fill: var(--orange); opacity: .8; }
.map-title text { fill: #1a0b2e; font: 400 18px var(--font-display); letter-spacing: .08em; }
.lanterns circle { animation: flicker 3s infinite; }
.lanterns circle:nth-child(2n) { animation-delay: 1.1s; }
.lanterns circle:nth-child(3n) { animation-delay: .6s; }

/* Venue markers */
.venue { cursor: pointer; outline: none; }
.venue .venue-pin { transition: transform .25s; transform-box: fill-box; transform-origin: center; }
.venue:hover .venue-pin, .venue:focus-visible .venue-pin { transform: scale(1.12); }
.venue:focus-visible .venue-ring { stroke: var(--green); stroke-width: 4; }
.venue .venue-ring { fill: #2a2a2a; stroke: #9a9a9a; stroke-width: 2.5; }
.venue .venue-art { filter: grayscale(1) contrast(1.1) brightness(.95); transition: filter .9s ease; }
.venue .venue-num { fill: #1a0b2e; font: 800 10px var(--font-body); }
.venue .venue-num-bg { fill: #cfcfcf; }
.venue .venue-halo { fill: var(--orange); opacity: 0; }

.venue.scanned .venue-ring { fill: #3a1d05; stroke: var(--orange); }
.venue.scanned .venue-art { filter: none; }
.venue.scanned .venue-num-bg { fill: var(--green); }
.venue.scanned .venue-halo { opacity: .35; animation: pulse 2.4s ease-in-out infinite; }
.venue.just-scanned .venue-pin { animation: pop .9s cubic-bezier(.2,1.6,.4,1); }
.venue.just-scanned .venue-halo { animation: burst 1.2s ease-out, pulse 2.4s 1.2s ease-in-out infinite; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px); opacity: 0;
  width: min(92vw, 440px); padding: 14px 16px; border-radius: 14px;
  background: var(--panel); border: 2px solid var(--orange); color: var(--ink);
  box-shadow: 0 10px 30px rgba(0,0,0,.5); font-weight: 600; text-align: center;
  transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { border-color: #ffd84a; }
.toast.error { border-color: #ff4f6d; }

/* ---------- Dialogs ---------- */
dialog { color: var(--ink); border: 0; padding: 0; }
dialog::backdrop { background: rgba(8, 3, 14, .78); backdrop-filter: blur(3px); }

.modal {
  width: min(92vw, 440px); max-height: 92dvh; overflow: auto;
  background: linear-gradient(180deg, #2b1747 0%, #1b0f2c 100%);
  border: 2px solid var(--orange); border-radius: 24px;
  padding: 28px 22px 22px; text-align: center;
  box-shadow: 0 0 60px rgba(255, 138, 31, .35);
}
.modal[open] { animation: rise .35s cubic-bezier(.2,.8,.2,1); }
.modal-moon { font-size: 2.4rem; animation: bob 2.4s ease-in-out infinite; }
.modal h1 {
  font-family: var(--font-display); font-weight: 400; color: var(--orange);
  font-size: clamp(1.9rem, 8vw, 2.4rem); line-height: 1.05; margin: 6px 0 10px;
  text-shadow: 0 0 18px rgba(255, 138, 31, .5);
}
.lead { font-size: 1.05rem; margin: 0 0 18px; }
.prizes { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 10px; text-align: left; }
.prizes li {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: 14px;
  background: rgba(255,255,255,.05); border: 1px solid #3f2b5c;
}
.prizes li.grand { background: rgba(255, 138, 31, .14); border-color: var(--orange); }
.prizes span { color: var(--muted); font-size: .9rem; }
.prizes b { color: var(--orange); }
.prize-tag { font-size: .7rem !important; text-transform: uppercase; letter-spacing: .15em; color: var(--orange) !important; font-weight: 800; }

.cta {
  width: 100%; padding: 16px; border: 0; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, #ffa043, var(--orange-deep)); color: #1a0b2e;
  font: 400 1.6rem var(--font-display); letter-spacing: .08em;
  box-shadow: 0 6px 0 #9a3a06, 0 10px 24px rgba(255,138,31,.35);
  transition: transform .1s, box-shadow .1s;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 #9a3a06; }

.modal-close { position: absolute; top: 12px; right: 12px; z-index: 2; width: 34px; height: 34px; font-size: .95rem; }
.modal.mode-intro .modal-close { display: none; }
.modal.mode-info .cta { display: none; }

.sheet {
  position: fixed; margin: auto auto 0; width: 100%; max-width: 520px;
  background: var(--panel); border-radius: 24px 24px 0 0; border-top: 3px solid var(--orange);
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
}
.sheet[open] { animation: slideup .3s cubic-bezier(.2,.8,.2,1); }
.sheet-head { display: flex; gap: 14px; align-items: center; padding-right: 40px; }
.sheet-icon { width: 64px; height: 64px; flex: none; filter: grayscale(1); }
.sheet.scanned .sheet-icon { filter: none; }
.sheet h2 { margin: 0; font-size: 1.25rem; }
.venue-status { margin: 4px 0 0; font-size: .85rem; font-weight: 700; color: var(--muted); }
.sheet.scanned .venue-status { color: var(--green); }
.venue-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: .9rem; }
.venue-meta dt { color: var(--muted); }
.venue-meta dd { margin: 0; }
.venue-meta a { color: var(--orange); }

/* ---------- Animations ---------- */
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes flicker { 0%,100% { opacity: 1; } 45% { opacity: .5; } 50% { opacity: .9; } 70% { opacity: .4; } }
@keyframes pulse { 50% { opacity: .1; } }
@keyframes burst { 0% { opacity: .9; transform: scale(.6); } 100% { opacity: .35; transform: scale(1); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px) scale(.97); } }
@keyframes slideup { from { transform: translateY(100%); } }
.venue-halo { transform-box: fill-box; transform-origin: center; }

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