:root {
  --bg: #04080f;
  --bg2: #071222;
  --panel: rgba(10, 22, 38, 0.72);
  --line: #16304a;
  --line2: #1f4263;
  --ink: #dcebf7;
  --dim: #7590ab;
  --accent: #49f2c2;
  --accent-ink: #022018;
  --gold: #ffd166;
  --red: #ff6b6b;
  --radius: 14px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Space Grotesk', system-ui, -apple-system, Segoe UI, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 30% 40%, rgba(73, 242, 194, 0.06), transparent 60%),
    radial-gradient(900px 600px at 90% 10%, rgba(124, 140, 255, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
.mono { font-family: var(--mono); }
.dim { color: var(--dim); }
.gold { color: var(--gold); }
.red { color: var(--red); }

/* ---------- header ---------- */
.top {
  height: 60px;
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 8, 15, 0.7);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.word { font-weight: 500; letter-spacing: 0.22em; font-size: 15px; }
.word b { font-weight: 700; color: var(--accent); }
.logo { position: relative; width: 26px; height: 26px; }
.logo i {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--accent);
  animation: sonar 2.4s infinite ease-out;
}
.logo i:nth-child(2) { animation-delay: 0.8s; }
.logo i:nth-child(3) { animation-delay: 1.6s; }
.logo::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px;
  margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
}
@keyframes sonar { from { transform: scale(0.15); opacity: 1; } to { transform: scale(1); opacity: 0; } }

.seg {
  display: flex; padding: 3px; gap: 2px;
  border: 1px solid var(--line2); border-radius: 999px; background: rgba(7, 18, 34, 0.8);
}
.seg button {
  border: 0; background: none; padding: 6px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: var(--dim);
  transition: background 0.2s, color 0.2s;
}
.seg button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:not([aria-selected="true"]):hover { color: var(--ink); }

.actions { display: flex; justify-content: flex-end; gap: 6px; }
.icon {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 10px; background: none;
  transition: border-color 0.2s, background 0.2s;
}
.icon:hover { border-color: var(--line2); background: rgba(73, 242, 194, 0.06); }
.icon svg, .zoom svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon svg .fill { fill: currentColor; }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
.stage { position: relative; min-height: 0; overflow: hidden; }
.stage::after {
  /* faint scanlines over the globe */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
}
#globe { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#globe.grabbing { cursor: grabbing; }

.hud { position: absolute; z-index: 2; pointer-events: none; }
.hud-tl { top: 16px; left: 16px; display: flex; gap: 6px; }
.chip {
  font: 600 11px/1 var(--mono); letter-spacing: 0.14em;
  padding: 7px 10px; border-radius: 999px;
  border: 1px solid var(--line2); background: rgba(4, 8, 15, 0.75); color: var(--accent);
}
.chip.hard { color: var(--red); border-color: rgba(255, 107, 107, 0.4); }
.hud-bl {
  left: 16px; bottom: 16px; font-size: 12px; color: var(--dim);
  padding: 6px 10px; border-radius: 8px; background: rgba(4, 8, 15, 0.6);
  white-space: pre;
}

.stage:has(.pending:not([hidden])) .hud-bl { display: none; }

.zoom { position: absolute; right: 16px; top: 16px; z-index: 2; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line2); border-radius: 10px;
  background: rgba(4, 8, 15, 0.75); font-size: 20px; line-height: 1;
  transition: border-color 0.2s, color 0.2s;
}
.zoom button:hover { border-color: var(--accent); color: var(--accent); }

.pending {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 16px; border-radius: 16px;
  background: rgba(7, 18, 34, 0.92); border: 1px solid var(--line2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(73, 242, 194, 0.08);
  animation: rise 0.25s ease-out;
  max-width: calc(100% - 32px);
}
.pending[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.pending-info { display: flex; flex-direction: column; min-width: 0; margin-right: 6px; }
.pending-info small { font: 600 10px var(--mono); letter-spacing: 0.16em; color: var(--accent); }
.pending-info strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-info span { font-size: 11px; color: var(--dim); white-space: pre; }

.btn {
  border: 1px solid var(--line2); background: rgba(73, 242, 194, 0.05);
  padding: 10px 18px; border-radius: 12px; font-weight: 600; letter-spacing: 0.02em;
  transition: transform 0.1s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  box-shadow: 0 0 24px rgba(73, 242, 194, 0.35);
}
.btn.primary:hover { box-shadow: 0 0 34px rgba(73, 242, 194, 0.55); }
.btn.ghost { background: none; }
.btn.sm { padding: 8px 12px; }
.btn.wide { width: 100%; margin-top: 8px; }
#btnPing { font-family: var(--mono); letter-spacing: 0.14em; padding: 12px 20px; }

.loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 2; display: flex; align-items: center; gap: 10px;
  font: 500 13px var(--mono); color: var(--dim); text-align: center;
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute; left: 50%; top: 18px; transform: translate(-50%, -12px);
  z-index: 4; padding: 10px 16px; border-radius: 12px;
  background: rgba(7, 18, 34, 0.95); border: 1px solid var(--line2);
  font-size: 14px; white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- side panel ---------- */
.panel {
  min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(7, 18, 34, 0.6), rgba(4, 8, 15, 0.6));
}
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }
.card-head .mono { font-size: 10px; letter-spacing: 0.14em; }
.label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 8px; }

.status { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pips { display: flex; gap: 6px; }
.pip {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px dashed var(--line2); position: relative;
}
.pip.next { border-style: solid; border-color: var(--accent); animation: glow 1.6s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 12px rgba(73, 242, 194, 0.6); } }
.pip.used { border: 0; background: var(--c); box-shadow: 0 0 10px color-mix(in srgb, var(--c) 60%, transparent); animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(0.3); } 60% { transform: scale(1.2); } }
.status-text { font-size: 14px; color: var(--dim); }
.status-text b { color: var(--ink); }
.status-text b.gold { color: var(--gold); }
.status-text b.red { color: var(--red); }

.search-wrap { position: relative; }
#cityInput {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--line2); background: var(--bg2); color: var(--ink);
  font: inherit; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
#cityInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(73, 242, 194, 0.15); }
#cityInput:disabled { opacity: 0.5; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 10;
  list-style: none; margin: 0; padding: 4px;
  background: #0a1830; border: 1px solid var(--line2); border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}
.suggest[hidden] { display: none; }
.suggest li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: rgba(73, 242, 194, 0.1); }
.suggest .dim { margin-left: auto; font-size: 12px; }
.suggest .fe { width: 22px; text-align: center; }

.dossier { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dossier li { display: flex; gap: 10px; align-items: flex-start; }
.dossier .tag {
  flex: none; width: 46px; text-align: center; padding: 4px 0; margin-top: 2px;
  font: 700 10px var(--mono); letter-spacing: 0.1em;
  color: var(--accent); border: 1px solid rgba(73, 242, 194, 0.35); border-radius: 6px;
}
.dossier small { display: block; font-size: 11px; color: var(--dim); }
.dossier .val { font-size: 14px; }
.dossier .locked .tag { color: var(--dim); border-color: var(--line2); }
.redact {
  display: inline-block; font: 500 11px var(--mono); color: #4d6782;
  background: repeating-linear-gradient(-45deg, #0c1c30 0 6px, #0a1728 6px 12px);
  padding: 2px 8px; border-radius: 4px;
}
.dossier .fresh { animation: declass 0.9s ease-out; }
@keyframes declass {
  0% { opacity: 0; transform: translateX(-8px); filter: blur(3px); }
  60% { opacity: 1; filter: blur(0); }
}
.dossier .fresh .tag { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 30% { background: var(--accent); color: var(--accent-ink); } }
.flag { height: 30px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12); vertical-align: middle; margin-top: 3px; }
.flag.lg { height: 46px; }
.tiles { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.tiles i {
  font-style: normal; width: 22px; height: 26px; display: grid; place-items: center;
  font: 700 13px var(--mono);
}
.tiles .tile { border: 1px solid var(--line2); border-radius: 5px; background: var(--bg2); }
.tiles .tile.on { border-color: var(--gold); color: var(--gold); }
.tiles .gap { width: 10px; }
.tiles .punct { width: 10px; color: var(--dim); }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.log li[data-i] {
  display: flex; gap: 10px; padding: 10px; border-radius: 10px;
  background: rgba(4, 8, 15, 0.55); border: 1px solid var(--line);
  border-left: 3px solid var(--c); cursor: pointer;
  animation: declass 0.6s ease-out;
}
.log li[data-i]:hover { border-color: var(--line2); border-left-color: var(--c); }
.log .n { font: 700 12px var(--mono); color: var(--c); width: 16px; padding-top: 1px; }
.log .main { flex: 1; min-width: 0; }
.log .row { display: flex; justify-content: space-between; gap: 8px; }
.log .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log .km { font: 700 13px var(--mono); color: var(--c); white-space: nowrap; }
.log .bar { height: 4px; border-radius: 4px; background: var(--line); margin: 7px 0 5px; overflow: hidden; }
.log .bar i { display: block; height: 100%; background: var(--c); border-radius: 4px; box-shadow: 0 0 8px var(--c); }
.log .sub { font-size: 12px; color: var(--dim); }
.log .warm { color: var(--accent); }
.log .cold { color: #8fa5ff; }
.log .empty { font-size: 13px; color: var(--dim); padding: 6px 2px; }

/* ---------- dialogs ---------- */
.modal {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 26px; border-radius: 20px; border: 1px solid var(--line2);
  background: linear-gradient(180deg, #0b1a2e, #060e1a); color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal[open] { animation: modalIn 0.28s ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.modal::backdrop { background: rgba(2, 5, 10, 0.7); backdrop-filter: blur(3px); }
.modal h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: 0.02em; }
.modal .x {
  position: absolute; right: 14px; top: 14px; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid var(--line2); background: none; color: var(--dim);
}
.modal .x:hover { color: var(--ink); border-color: var(--accent); }
.lede { color: var(--dim); margin: 0 0 16px; }
.lede b { color: var(--ink); }
.steps { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; gap: 12px; font-size: 14px; }
.steps li > span {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font: 700 12px var(--mono); color: var(--accent-ink); background: var(--accent);
}
.steps em { color: var(--accent); font-style: normal; }
kbd { font: 600 11px var(--mono); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line2); background: var(--bg2); }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-bottom: 16px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.legend .mono { margin-left: auto; color: var(--dim); font-size: 11px; }
.fine { font-size: 12px; color: var(--dim); margin: 12px 0 0; }
.fine b { color: var(--ink); }

.switch { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { flex: none; width: 40px; height: 22px; border-radius: 999px; background: var(--line2); position: relative; transition: background 0.2s; margin-top: 2px; }
.switch .track i { position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.switch input:checked + .track { background: var(--red); }
.switch input:checked + .track i { transform: translateX(18px); }
.switch input:disabled ~ * { opacity: 0.55; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch small { display: block; color: var(--dim); font-size: 12px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.stat-row div { text-align: center; padding: 10px 4px; border-radius: 12px; background: rgba(4, 8, 15, 0.6); border: 1px solid var(--line); }
.stat-row b { display: block; font: 700 22px var(--mono); }
.stat-row b.sm { font-size: 12px; padding: 6px 0; white-space: pre; }
.stat-row span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
#statsBody h4 { margin: 18px 0 8px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.dist { display: flex; flex-direction: column; gap: 5px; }
.drow { display: flex; align-items: center; gap: 8px; font: 600 12px var(--mono); }
.drow > span { width: 12px; color: var(--dim); }
.dbar { background: var(--line2); padding: 3px 8px; border-radius: 4px; text-align: right; min-width: 24px; }
.dbar.cur { background: var(--accent); color: var(--accent-ink); }

.end-status {
  display: inline-block; font: 700 11px var(--mono); letter-spacing: 0.2em; text-transform: uppercase;
  padding: 6px 10px; border-radius: 999px; margin-bottom: 14px;
}
.end-status.win { color: var(--gold); background: rgba(255, 209, 102, 0.1); border: 1px solid rgba(255, 209, 102, 0.4); }
.end-status.lose { color: var(--red); background: rgba(255, 107, 107, 0.1); border: 1px solid rgba(255, 107, 107, 0.4); }
.end-city { display: flex; align-items: center; gap: 14px; }
.end-city h2 { font-size: 30px; margin: 0; line-height: 1.1; }
.end-city p { margin: 2px 0 0; color: var(--dim); }
.end-fact { font-size: 14px; color: var(--ink); opacity: 0.9; border-left: 2px solid var(--accent); padding-left: 12px; margin: 16px 0; }
.end-grid { font-size: 26px; letter-spacing: 4px; text-align: center; }
.end-actions { display: flex; gap: 8px; }
.end-actions .btn { flex: 1; }
.end-next { text-align: center; color: var(--dim); font-size: 13px; margin: 14px 0 0; }
.end-next b { color: var(--ink); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  body { height: auto; min-height: 100dvh; overflow-y: auto; }
  .layout { grid-template-columns: 1fr; }
  .stage { height: 62dvh; min-height: 360px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}
@media (max-width: 560px) {
  .top { grid-template-columns: auto 1fr auto; padding: 0 12px; gap: 8px; }
  .word { font-size: 13px; letter-spacing: 0.14em; }
  .brand .word { display: none; }
  .seg { justify-self: center; }
  .seg button { padding: 6px 12px; }
  .hud-bl { font-size: 11px; left: 12px; bottom: 12px; }
  .hud-tl { left: 12px; top: 12px; }
  .zoom { right: 12px; top: 12px; }
  .pending { bottom: 12px; width: calc(100% - 24px); }
  .pending-info { flex: 1; }
  .end-city h2 { font-size: 24px; }
  .modal { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
