:root {
  --bg: #0b1020;
  --panel: #141b31;
  --panel-2: #1d2643;
  --line: #2c3760;
  --text: #f2f4fb;
  --muted: #9aa5c7;
  --accent: #ffb238;
  --accent-ink: #231600;
  --good: #58d68d;
  --mid: #ffd166;
  --bad: #ff7b6b;
  --easy: #58d68d;
  --medium: #ffd166;
  --hard: #ff7b6b;
  --hold: #3d9bff;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }

#map { position: fixed; inset: 0; background: #050814; }
.maplibregl-canvas { outline: none; }
.maplibregl-ctrl-attrib { font-size: 10px; opacity: .75; }

/* ---------- botones ---------- */
.btn { display: block; width: 100%; padding: 13px 18px; border-radius: var(--radius); background: var(--panel-2);
  border: 1px solid var(--line); font-weight: 600; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { padding: 16px 18px; font-size: 1.15rem; }
.btn:active { transform: translateY(1px); filter: brightness(.94); }
.link { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 8px 6px; font-size: .92rem; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; background: rgba(15, 21, 40, .86); border: 1px solid var(--line);
  display: grid; place-items: center; backdrop-filter: blur(6px); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: calc(var(--sat) + 8px); left: 8px; right: 8px; z-index: 5; pointer-events: none;
  max-width: 560px; margin: 0 auto; }
#hud > * { pointer-events: auto; }
#topbar { display: flex; align-items: center; gap: 10px; }
#progress { flex: 1; font-weight: 600; color: var(--muted); text-shadow: 0 1px 3px #000; font-variant-numeric: tabular-nums; }
#score { background: rgba(15, 21, 40, .86); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; height: 44px;
  display: flex; align-items: baseline; gap: 5px; line-height: 44px; backdrop-filter: blur(6px); }
#score-num { font-weight: 800; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
#score small { color: var(--muted); font-size: .75rem; }

#prompt { margin-top: 8px; background: rgba(15, 21, 40, .9); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px 12px; backdrop-filter: blur(6px); }
#p-name { font-size: 1.45rem; font-weight: 800; line-height: 1.15; margin-top: 4px; overflow-wrap: anywhere; }
#p-country { color: var(--muted); }
.chip { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 99px; color: #10131f; }
.chip.d1 { background: var(--easy); }
.chip.d2 { background: var(--medium); }
.chip.d3 { background: var(--hard); }

#mapctl { position: fixed; right: 8px; top: 50%; transform: translateY(-50%); z-index: 4; display: flex; flex-direction: column; gap: 8px; }
@media (max-height: 560px) { #mapctl { top: auto; bottom: calc(var(--sab) + 28px); transform: none; } }
@media (pointer: coarse) { #btn-zin, #btn-zout { display: none; } }

#p-hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* aro de "mantener apretado" */
#hold { position: fixed; z-index: 7; width: 84px; height: 84px; margin: -42px 0 0 -42px; pointer-events: none; }
#hold svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#hold circle { fill: none; stroke-width: 5; }
#hold .track { stroke: rgba(255, 255, 255, .35); }
#hold .fill { stroke: var(--hold); stroke-linecap: round; stroke-dasharray: 157.1; stroke-dashoffset: 157.1; animation: hold-fill var(--hold-ms, 1000ms) linear forwards; }
@keyframes hold-fill { to { stroke-dashoffset: 0; } }
#map, #map * { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

/* ---------- marcadores ---------- */
.pin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
.pin.guess { background: var(--accent); }
.pin.target { background: var(--good); }
.pin.target::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 2px solid var(--good); opacity: .7;
  animation: ping 1.4s ease-out infinite; }
@keyframes ping { from { transform: scale(.5); opacity: .9; } to { transform: scale(1.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pin.target::after { animation: none; } }

/* ---------- resultado ---------- */
.sheet { position: fixed; left: 8px; right: 8px; bottom: calc(var(--sab) + 8px); z-index: 6; max-width: 480px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 14px 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55); }
.r-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
#r-name { font-weight: 800; font-size: 1.15rem; line-height: 1.2; overflow-wrap: anywhere; }
#r-fact { color: var(--muted); font-size: .88rem; margin-top: 2px; }
#r-verdict { font-weight: 700; font-size: .85rem; white-space: nowrap; padding: 3px 10px; border-radius: 99px; color: #10131f; }
#r-verdict.v-good { background: var(--good); }
#r-verdict.v-mid { background: var(--mid); }
#r-verdict.v-bad { background: var(--bad); }
.r-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.r-nums > div { background: var(--panel-2); border-radius: 12px; padding: 8px 12px; }
.r-nums b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.r-nums span { color: var(--muted); font-size: .8rem; }
#r-bonus { font-size: .88rem; margin: -4px 2px 10px; }
#r-bonus.hit { color: var(--good); }
#r-bonus.miss { color: var(--muted); }
.r-tune { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }

#toast { position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 30; background: rgba(10, 14, 28, .95);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 86vw; text-align: center; pointer-events: none; }

/* ---------- pantallas ---------- */
#overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: calc(var(--sat) + 16px) 16px calc(var(--sab) + 16px);
  background: rgba(5, 8, 20, .5); backdrop-filter: blur(2px); overflow-y: auto; }
.panel { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 22px 20px;
  display: flex; flex-direction: column; gap: 14px; align-items: stretch; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
.panel h1 { font-size: 2.4rem; letter-spacing: -.02em; line-height: 1; }
.panel h2 { font-size: 1.5rem; }
.panel h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.panel .link { align-self: center; }
.lead, .muted { color: var(--muted); }
.field label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--panel-2); padding: 4px; border-radius: 12px; }
.seg button { padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--text); color: #10131f; }

.switch { display: flex; align-items: center; gap: 12px; padding: 4px 0; cursor: pointer; }
.switch input { appearance: none; flex: none; width: 46px; height: 28px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line);
  position: relative; transition: background .15s; margin: 0; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked { background: var(--accent); border-color: transparent; }
.switch input:checked::after { transform: translateX(18px); background: var(--accent-ink); }

.w-row { display: grid; grid-template-columns: 7.2em 1fr 3em; align-items: center; gap: 10px; padding: 3px 0; }
.w-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.w-row input[type="range"] { width: 100%; accent-color: var(--accent); }

#records { color: var(--muted); font-size: .88rem; text-align: center; }
#records b { color: var(--text); }

#end-total { font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats > div { background: var(--panel-2); border-radius: 12px; padding: 8px 12px; }
.stats b { display: block; font-size: 1.1rem; }
.stats span { color: var(--muted); font-size: .8rem; }
#end-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto; border-top: 1px solid var(--line); }
#end-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: .92rem; align-items: baseline; }
#end-list .km { color: var(--muted); font-variant-numeric: tabular-nums; }
#end-list .pt { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
#end-list .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
