:root {
  --olive: #3d4a2c;
  --olive-2: #56643f;
  --paper: #f3ecd8;
  --paper-2: #e8dfc4;
  --ink: #1f1d17;
  --muted: #6b6553;
  --red: #b3261e;
  --amber: #c98a12;
  --green: #2e7d32;
  --blue: #2b5fa8;
  --line: #cfc4a3;
  --close: #4f7a3a;
  --middle: #2b6ca8;
  --far: #8a4fa8;
  --deep: #b3261e;
  --radius: 14px;
  --hud-h: 58px;
  --tabs-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
body { font-size: 17px; line-height: 1.4; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.stencil { font-family: "Courier New", Courier, monospace; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }

/* HUD */
#hud {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  height: calc(var(--hud-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 6px;
  background: var(--olive); color: var(--paper);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.hud-cell { display: flex; flex-direction: column; justify-content: center; align-items: center; background: none; border: 0; padding: 0; min-width: 0; }
.hud-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hud-val { font-family: "Courier New", Courier, monospace; font-weight: 700; font-size: 22px; white-space: nowrap; }
#hud-fuel.warn { background: var(--amber); border-radius: 10px; color: #1b1300; }
#hud-fuel.danger { background: var(--red); border-radius: 10px; color: #fff; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .7; } }
#sync { font-size: 15px; }

/* Layout */
#app { position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
body.in-game #app { top: calc(var(--hud-h) + env(safe-area-inset-top)); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.page { padding: 16px 16px 32px; max-width: 640px; margin: 0 auto; }
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 1000;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper-2); border-top: 1px solid var(--line);
}
#tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 13px; font-weight: 600; color: var(--muted); }
#tabs button span { font-size: 22px; }
#tabs button.on { color: var(--olive); background: var(--paper); box-shadow: inset 0 3px 0 var(--olive); }

/* Map */
#map { position: absolute; inset: 0; background: #e9e4cf; }
.map-btns { position: absolute; right: 12px; bottom: 16px; z-index: 600; display: flex; flex-direction: column; gap: 10px; }
.map-btn { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--paper); box-shadow: 0 2px 8px rgba(0,0,0,.3); font-size: 22px; }
.gps-chip { position: absolute; left: 12px; bottom: 16px; z-index: 600; background: rgba(243,236,216,.95); border-radius: 999px; padding: 6px 12px; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.25); max-width: calc(100% - 90px); }
.pin { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.pin.done { background: #9a9480 !important; }
.pin.base { background: var(--olive); width: 40px; height: 40px; font-size: 18px; }
.leaflet-container { font: inherit; }
.leaflet-tooltip.lbl { background: rgba(243,236,216,.92); border: 0; box-shadow: none; font-size: 11px; font-weight: 700; padding: 1px 5px; color: var(--ink); }
.leaflet-tooltip.lbl::before { display: none; }

/* Cards & lists */
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
.card { background: #fffaf0; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap; }
.chip.close { background: var(--close); } .chip.middle { background: var(--middle); } .chip.far { background: var(--far); } .chip.deep { background: var(--deep); }
.target { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; background: #fffaf0; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; min-height: 64px; }
.target.done { opacity: .6; }
.target .name { font-weight: 700; }
.ticks { font-size: 18px; letter-spacing: 2px; white-space: nowrap; }
.dist { font-family: "Courier New", Courier, monospace; font-weight: 700; white-space: nowrap; }

/* Buttons */
.btn { display: block; width: 100%; min-height: 56px; border-radius: 12px; border: 0; padding: 12px 16px; font-size: 18px; font-weight: 700; background: var(--olive); color: var(--paper); margin: 10px 0; }
.btn.secondary { background: var(--paper-2); color: var(--ink); border: 1px solid var(--line); }
.btn.red { background: var(--red); color: #fff; }
.btn:disabled { opacity: .45; }
.opt { display: block; width: 100%; min-height: 54px; text-align: left; border-radius: 12px; border: 2px solid var(--line); background: #fffaf0; padding: 12px 14px; margin: 8px 0; font-size: 17px; font-weight: 600; }
.opt.sel { border-color: var(--olive); background: #eef0e2; }
input[type=text], input[type=number], input[type=tel] { width: 100%; font-size: 20px; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: #fffaf0; }

/* Sheet (target detail) */
#sheet { position: fixed; inset: 0; z-index: 1500; background: var(--paper); overflow-y: auto; padding-top: env(safe-area-inset-top); }
.sheet-top { position: sticky; top: 0; background: var(--olive); color: var(--paper); display: flex; align-items: center; gap: 8px; padding: 10px 12px; z-index: 2; }
.sheet-top button { background: none; border: 0; color: var(--paper); font-size: 17px; font-weight: 700; padding: 8px; min-height: 44px; }
.step { border-left: 4px solid var(--line); padding-left: 12px; margin: 18px 0; }
.step.ok { border-color: var(--green); }
.result { font-size: 20px; font-weight: 800; }
.result.hit { color: var(--green); } .result.miss { color: var(--red); }
.thumb { width: 100%; border-radius: 10px; display: block; margin-top: 8px; }

#toast { position: fixed; left: 50%; top: calc(var(--hud-h) + env(safe-area-inset-top) + 10px); transform: translateX(-50%) translateY(-20px); opacity: 0; transition: .25s; z-index: 2000; background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 700; max-width: 90vw; text-align: center; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hero { background: var(--olive); color: var(--paper); padding: calc(28px + env(safe-area-inset-top)) 20px 24px; text-align: center; }
.hero .badge { font-size: 54px; }
.big-clock { font-family: "Courier New", Courier, monospace; font-size: 48px; font-weight: 800; text-align: center; }
ol.rules { padding-left: 22px; } ol.rules li { margin: 6px 0; }
.warnbox { background: #fdecea; border: 1px solid #f2b8b5; border-radius: 12px; padding: 12px 14px; }

.beacon { position: fixed; inset: 0; z-index: 3000; background: rgba(20,24,12,.85); display: grid; place-items: center; padding: 20px; animation: flash .6s 3; }
.beacon-box { background: var(--paper); border-radius: 18px; padding: 22px; max-width: 420px; text-align: center; box-shadow: 0 0 0 6px var(--amber); }
@keyframes flash { 50% { background: rgba(201,138,18,.7); } }

.legend { position: absolute; left: 12px; top: 12px; z-index: 600; background: rgba(243,236,216,.96); border-radius: 12px; padding: 6px 12px; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.25); max-width: calc(100% - 24px); }
.legend summary { font-weight: 700; cursor: pointer; min-height: 28px; line-height: 28px; }
.legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 3px 0 6px; vertical-align: -1px; }
.legend .ln { display: inline-block; width: 26px; margin-right: 6px; vertical-align: middle; }

/* Netlify injects a "Powered by Netlify" badge that covers the tab bar on phones */
#nl-badge-frame { display: none !important; }

.lb { display: grid; grid-template-columns: 30px 84px 1fr auto; gap: 8px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.lb.me { background: #eef0e2; border-radius: 10px; }
.lb .rk { font-family: "Courier New", monospace; font-weight: 800; font-size: 22px; text-align: center; }
.lb .pt { font-family: "Courier New", monospace; font-weight: 800; font-size: 26px; }
.lb .pl { background: #eef3e3; border-radius: 6px; }

/* the hidden attribute must win over display:grid on #hud/#tabs */
[hidden] { display: none !important; }

/* question countdown */
.qclock { position: relative; height: 26px; border-radius: 13px; background: #e4dcc0; overflow: hidden; margin: 6px 0 10px; }
.qbar { position: absolute; inset: 0 auto 0 0; background: #4f7a3a; transition: width .5s linear; }
.qclock span { position: relative; display: block; text-align: center; line-height: 26px; font-weight: 700; font-size: 14px; color: #1d2414; }
/* compass arrow on the "me" dot */
.me-arrow { width: 34px; height: 34px; transition: transform .2s linear; }

/* two-part games */
.pin.burned { filter: grayscale(.85); opacity: .65; }
.codecell { width: 46px; height: 58px; border-radius: 8px; background: #1f1d17; color: #ff7a33; font: 700 26px "Courier New", monospace; display: grid; place-items: center; position: relative; }
.codecell small { position: absolute; bottom: 2px; right: 5px; font-size: 10px; color: #bbb; }
.swap { border-top: 1px solid var(--line); padding: 8px 0; }
.swap select, .card select { width: 100%; font-size: 16px; padding: 8px; margin: 4px 0; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.btn.inline { display: inline-block; width: auto; padding: 8px 14px; margin: 4px 4px 0 0; }

/* ---------- spy theme (game.json "theme": "spy"): dark, Freemans orange, decode type ---------- */
html[data-theme=spy] {
  --olive: #0b0c11; --olive-2: #1b1e27; --paper: #12141a; --paper-2: #181b23; --card: #1b1e27;
  --ink: #e5e1e7; --muted: #8b8f9c; --line: #2c303b; --accent: #ff5000; --accent-ink: #120700;
  --red: #ff4d4d; --amber: #ffb000; --green: #3fcf8e; --blue: #4d9bff;
  --mono: Menlo, "SF Mono", SFMono-Regular, "Roboto Mono", Consolas, monospace;
  --cond: "DIN Condensed", "Barlow Condensed", "Roboto Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;
  color-scheme: dark;
}
[data-theme=spy] body { background: var(--paper); }
[data-theme=spy] .stencil { font-family: var(--cond); letter-spacing: .06em; font-weight: 700; }
[data-theme=spy] h1, [data-theme=spy] h2 { font-family: var(--cond); letter-spacing: .03em; text-transform: uppercase; font-weight: 700; }
[data-theme=spy] h1 { font-size: 34px; } [data-theme=spy] h2 { font-size: 26px; }
[data-theme=spy] a { color: var(--accent); }
[data-theme=spy] #hud { background: var(--olive); color: var(--ink); border-bottom: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0,0,0,.6); }
[data-theme=spy] .hud-label { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; color: var(--muted); opacity: 1; }
[data-theme=spy] .hud-val, [data-theme=spy] .dist, [data-theme=spy] .big-clock, [data-theme=spy] .lb .rk, [data-theme=spy] .lb .pt { font-family: var(--mono); }
[data-theme=spy] #hud-fuel .hud-val { color: var(--accent); }
[data-theme=spy] #hud-fuel.warn { background: var(--amber); color: #1b1300; } [data-theme=spy] #hud-fuel.warn .hud-val, [data-theme=spy] #hud-fuel.warn .hud-label { color: #1b1300; }
[data-theme=spy] #hud-fuel.danger { background: var(--red); } [data-theme=spy] #hud-fuel.danger .hud-val, [data-theme=spy] #hud-fuel.danger .hud-label { color: #fff; }
[data-theme=spy] #tabs { background: var(--olive); border-top: 1px solid var(--line); }
[data-theme=spy] #tabs button { color: var(--muted); font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
[data-theme=spy] #tabs button.on { color: var(--accent); background: var(--paper-2); box-shadow: inset 0 3px 0 var(--accent); }
[data-theme=spy] .card, [data-theme=spy] .target, [data-theme=spy] .opt { background: var(--card); border-color: var(--line); color: var(--ink); }
[data-theme=spy] .card { position: relative; border-radius: 6px; }
[data-theme=spy] .card::before { content: ""; position: absolute; left: -1px; top: -1px; width: 14px; height: 14px; border-left: 2px solid var(--accent); border-top: 2px solid var(--accent); border-top-left-radius: 6px; pointer-events: none; }
[data-theme=spy] .target { border-radius: 6px; }
[data-theme=spy] .opt { border-radius: 6px; }
[data-theme=spy] .opt.sel { border-color: var(--accent); background: #2a1a10; }
[data-theme=spy] .btn { background: var(--accent); color: var(--accent-ink); border-radius: 6px; font-family: var(--cond); font-size: 22px; letter-spacing: .05em; text-transform: uppercase; }
[data-theme=spy] .btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); font-family: inherit; font-size: 17px; text-transform: none; letter-spacing: 0; }
[data-theme=spy] .btn.red { background: var(--red); color: #fff; }
[data-theme=spy] input:not([type]), [data-theme=spy] input[type=text], [data-theme=spy] input[type=number], [data-theme=spy] input[type=tel], [data-theme=spy] input[type=password] { width: 100%; font-size: 20px; padding: 12px; border: 2px solid; margin-top: 6px; background: #0d0f14; color: var(--ink); border-color: var(--line); border-radius: 6px; font-family: var(--mono); letter-spacing: .08em; }
[data-theme=spy] input:focus { outline: none; border-color: var(--accent); }
[data-theme=spy] .swap select, [data-theme=spy] .card select { background: #0d0f14; color: var(--ink); border-color: var(--line); }
[data-theme=spy] #sheet { background: var(--paper); }
[data-theme=spy] .sheet-top { background: var(--olive); color: var(--ink); border-bottom: 1px solid var(--line); }
[data-theme=spy] .sheet-top button { color: var(--accent); }
[data-theme=spy] .step { border-left-color: var(--line); }
[data-theme=spy] .step.ok { border-left-color: var(--green); }
[data-theme=spy] #toast { background: var(--accent); color: var(--accent-ink); border-radius: 6px; font-family: var(--mono); font-size: 15px; }
[data-theme=spy] .hero { background: radial-gradient(120% 90% at 50% 0%, #1d2030 0%, var(--olive) 70%); color: var(--ink); border-bottom: 1px solid var(--line); }
[data-theme=spy] .hero .badge { font-family: var(--mono); font-size: 12px; letter-spacing: .3em; color: var(--accent); margin-bottom: 10px; }
[data-theme=spy] .hero h1 { font-size: 46px; margin-bottom: 4px; }
[data-theme=spy] .warnbox { background: #2a1214; border-color: #6b2a2e; color: var(--ink); }
[data-theme=spy] .beacon { background: rgba(5,6,9,.9); animation: spyflash .5s 3; }
[data-theme=spy] .beacon-box { background: var(--card); color: var(--ink); border-radius: 6px; box-shadow: 0 0 0 2px var(--accent), 0 0 40px rgba(255,80,0,.35); }
@keyframes spyflash { 50% { background: rgba(255,80,0,.35); } }
[data-theme=spy] .lb { border-bottom-color: var(--line); }
[data-theme=spy] .lb.me { background: #2a1a10; }
[data-theme=spy] .lb .pl { background: var(--paper-2); }
[data-theme=spy] .qclock { background: #0d0f14; border: 1px solid var(--line); }
[data-theme=spy] .qbar { background: var(--accent); }
[data-theme=spy] .qclock span { color: var(--ink); font-family: var(--mono); }
[data-theme=spy] .result.hit { color: var(--green); } [data-theme=spy] .result.miss { color: var(--red); }
[data-theme=spy] .codecell { background: #07080b; border: 1px solid var(--line); color: var(--accent); }
[data-theme=spy] .codecell small { color: var(--muted); }
[data-theme=spy] .chip { color: #0b0c11; }
/* map furniture */
[data-theme=spy] #map { background: #101318; }
[data-theme=spy] .map-btn { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
[data-theme=spy] .gps-chip, [data-theme=spy] .legend { background: rgba(18,20,26,.94); color: var(--ink); border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; }
[data-theme=spy] .leaflet-tooltip { background: #1b1e27; color: var(--ink); border-color: var(--line); }
[data-theme=spy] .leaflet-tooltip.lbl { background: rgba(18,20,26,.9); color: var(--ink); }
[data-theme=spy] .leaflet-tooltip-top::before { border-top-color: #1b1e27; }
[data-theme=spy] .leaflet-control-attribution { background: rgba(18,20,26,.8) !important; color: var(--muted); }
[data-theme=spy] .pin { border-color: #0b0c11; box-shadow: 0 0 0 2px rgba(255,255,255,.75), 0 1px 6px rgba(0,0,0,.6); color: #0b0c11; }
[data-theme=spy] .pin.done { background: #3a3e48 !important; color: #8b8f9c; }
[data-theme=spy] .pin.base { background: var(--accent); color: #0b0c11; }
/* scanlines on the hero and overlays, very faint */
[data-theme=spy] .hero { background: repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px), radial-gradient(120% 90% at 50% 0%, #1d2030 0%, var(--olive) 70%); }
/* Mission Control + board under the spy theme */
[data-theme=spy] .tabs2 button { background: var(--card); color: var(--ink); }
[data-theme=spy] .tabs2 button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
[data-theme=spy] .panel { border: 1px solid var(--line); border-radius: 8px !important; }
[data-theme=spy] .clock { font-family: var(--mono) !important; color: var(--accent); }
[data-theme=spy] .pts, [data-theme=spy] .rank { font-family: var(--mono) !important; }
[data-theme=spy] .tname { font-family: var(--cond); text-transform: uppercase; letter-spacing: .03em; font-weight: 700 !important; }
[data-theme=spy] .status { color: #0b0c11 !important; font-family: var(--mono); letter-spacing: .06em; }
[data-theme=spy] #bmap { background: #101318 !important; }
[data-theme=spy] #snd { background: var(--card) !important; color: var(--ink); }
/* title decode effect */
.decoding { color: var(--accent); }
