:root {
  --bg: #0f1420;
  --panel: #18202f;
  --panel2: #212b3d;
  --border: #2d3a52;
  --text: #e8edf6;
  --muted: #8f9bb3;
  --accent: #ffcc33;
  --accent2: #4fa3ff;
  --good: #3ccf7a;
  --bad: #ff5c6c;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* Top bar */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px; background: #0b0f18; border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 1000;
}
.brand { font-weight: 800; font-size: 1.3rem; color: var(--text); letter-spacing: .5px; }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }
#nav { display: flex; gap: 18px; align-items: center; }
#nav a { color: var(--muted); font-weight: 600; }
#nav a.active, #nav a:hover { color: var(--text); text-decoration: none; }
.user-chip { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--c, #888); flex-shrink: 0; }
body.playing #topbar { display: none; }

main#app { flex: 1; overflow: auto; position: relative; }
.page { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.page.narrow { max-width: 440px; }

/* Panels / forms */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font: inherit;
}
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; width: 60px; }
textarea { min-height: 140px; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
.field + .field { margin-top: 14px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-weight: 500; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none !important; white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { filter: brightness(1.15); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); color: #1b1b1b; border-color: var(--accent); }
.blue { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.big { padding: 14px 28px; font-size: 1.1rem; }
.link { background: none; border: none; color: var(--accent2); padding: 0; }
.error { color: var(--bad); min-height: 1.4em; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; cursor: default; }
th.sortable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: rgba(255, 204, 51, .08); }

.hero { text-align: center; padding: 30px 0 20px; }
.hero h1 { font-size: 2.6rem; }
.hero h1 span { color: var(--accent); }
.join-code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 4px; text-transform: uppercase; font-size: 1.3rem; text-align: center; }
.code-badge { font-family: ui-monospace, Consolas, monospace; font-size: 1.8rem; letter-spacing: 6px; color: var(--accent); font-weight: 800; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; color: var(--accent); }
.stat span { color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.banner { background: #3a2a10; border: 1px solid #8a6420; color: #ffd98a; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); font-size: .75rem; font-weight: 600; }

/* Toasts */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 5000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--panel2); border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.4); transition: opacity .4s; }
.toast.error { border-color: var(--bad); }
.toast.success { border-color: var(--good); }
.toast.hide { opacity: 0; }

/* Lobby */
.lobby { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; }
@media (max-width: 800px) { .lobby { grid-template-columns: 1fr; } }
.player-list { list-style: none; padding: 0; margin: 0; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.player-list li.offline { opacity: .45; }
.player-list .actions { margin-left: auto; display: flex; gap: 6px; }
.player-list .actions button { padding: 3px 8px; font-size: .75rem; }
.crown { color: var(--accent); }

/* Game */
.game { position: absolute; inset: 0; background: #000; overflow: hidden; }
#pano { position: absolute; inset: 0; }
.pano-blocker { position: absolute; inset: 0; z-index: 5; }
.pano-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); z-index: 1; text-align: center; padding: 20px; }
.hud-top {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; gap: 2px; background: rgba(10, 14, 24, .85); border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
}
.hud-top > div { padding: 6px 18px; text-align: center; }
.hud-top small { display: block; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .5px; }
.hud-top b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.timer.low b { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.hud-left { position: absolute; top: 12px; left: 12px; z-index: 20; display: flex; flex-direction: column; gap: 8px; }
.hud-box { background: rgba(10, 14, 24, .85); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.hud-players { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.hud-players li { display: flex; gap: 8px; align-items: center; padding: 2px 0; }
.hud-players li.offline { opacity: .45; }
.hud-players .tick { margin-left: auto; color: var(--good); font-weight: 800; min-width: 14px; }
.hud-buttons { display: flex; gap: 6px; }
.hud-buttons button { padding: 6px 10px; background: rgba(10, 14, 24, .85); }
.compass {
  position: absolute; top: 84px; left: 50%; transform: translateX(-50%); z-index: 20;
  width: 54px; height: 54px; border-radius: 50%; background: rgba(10, 14, 24, .85); border: 2px solid var(--border);
}
.compass .needle { position: absolute; inset: 0; transition: transform .1s linear; }
.compass .needle::before { content: ''; position: absolute; left: 50%; top: 5px; border: 7px solid transparent; border-bottom: 20px solid var(--bad); transform: translateX(-50%); }
.compass .needle::after { content: ''; position: absolute; left: 50%; bottom: 5px; border: 7px solid transparent; border-top: 20px solid #ddd; transform: translateX(-50%); }
.compass .n { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-weight: 800; font-size: .75rem; }

.guess-wrap {
  position: absolute; right: 16px; bottom: 30px; z-index: 30;
  width: 320px; display: flex; flex-direction: column; gap: 6px;
  transition: width .2s ease;
  opacity: .75;
}
.guess-wrap:hover, .guess-wrap.pinned, .guess-wrap.expanded { width: min(720px, 60vw); opacity: 1; }
.guess-wrap .guess-map { height: 200px; border-radius: 10px; border: 2px solid var(--border); transition: height .2s ease; cursor: crosshair; }
.guess-wrap:hover .guess-map, .guess-wrap.pinned .guess-map, .guess-wrap.expanded .guess-map { height: min(480px, 55vh); }
.guess-wrap .bar { display: flex; gap: 6px; }
.guess-wrap .bar button.primary { flex: 1; }
.guess-wrap .bar button.size { padding: 6px 10px; }
.leaflet-container { background: #aad3df; font: inherit; }
.leaflet-container.crosshair { cursor: crosshair; }

.overlay {
  position: absolute; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column;
}
.overlay .result-map { flex: 1; min-height: 240px; }
.overlay .result-panel { max-height: 48vh; overflow: auto; padding: 16px 24px; background: var(--panel); border-top: 1px solid var(--border); }
.overlay.final .result-panel { max-height: 58vh; }
.result-head { text-align: center; }
.result-head .big-score { font-size: 2.2rem; font-weight: 800; color: var(--accent); }
.score-bar { height: 8px; border-radius: 4px; background: var(--panel2); overflow: hidden; margin: 6px auto 12px; max-width: 460px; }
.score-bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #ffe58a); }
.waiting { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; z-index: 50; background: rgba(15, 20, 32, .92); }
.spinner { width: 38px; height: 38px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 10px 0 20px; }
.podium .step { text-align: center; width: 140px; }
.podium .block { background: var(--panel2); border-radius: 8px 8px 0 0; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 800; }
.podium .p1 .block { height: 110px; background: linear-gradient(#ffcc33, #b8901e); color: #1b1b1b; }
.podium .p2 .block { height: 80px; background: linear-gradient(#d4d9e3, #8d96a8); color: #1b1b1b; }
.podium .p3 .block { height: 60px; background: linear-gradient(#e0995a, #94592a); color: #1b1b1b; }
.podium .name { font-weight: 700; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Map pins */
.pin-icon { background: none; border: none; }
.pin { width: 26px; height: 26px; border-radius: 50%; background: var(--c); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.pin span { font-size: 11px; font-weight: 800; color: #000; mix-blend-mode: luminosity; }
.flag { font-size: 26px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); position: relative; }
.flag b { position: absolute; top: -6px; right: -10px; background: #000; color: #fff; font-size: 11px; border-radius: 99px; padding: 0 5px; }

/* Maps / editor */
.map-card h3 { margin-bottom: 4px; }
.map-card .meta { color: var(--muted); font-size: .85rem; }
.map-card .row { margin-top: 12px; }
.editor { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 420px; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; grid-template-rows: 50vh auto; position: static; } }
.editor-map { position: relative; min-height: 300px; }
.editor-map #emap { position: absolute; inset: 0; }
.editor-side { overflow: auto; padding: 16px; background: var(--panel); border-left: 1px solid var(--border); }
.editor-side section { border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.editor-pano { height: 260px; border-radius: 8px; overflow: hidden; background: #000; position: relative; }
.editor-pano #epano { position: absolute; inset: 0; }
