:root {
  --ink: #060912;
  --panel: rgba(10, 16, 30, 0.9);
  --panel-solid: #0c1426;
  --line: rgba(148, 178, 220, 0.14);
  --line-strong: rgba(148, 178, 220, 0.28);
  --text: #e9eff9;
  --muted: #8392ab;
  --heat: #ff7a1a;
  --heat-deep: #d7301f;
  --found: #34d399;
  --danger: #ff5d6c;
  --radius: 18px;
  --display: 'Unbounded', 'Arial Black', system-ui, sans-serif;
  --body: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(1200px 800px at 70% 45%, #0f2446 0%, transparent 60%),
    radial-gradient(900px 600px at 10% 100%, #2a0f16 0%, transparent 55%),
    var(--ink);
  color: var(--text);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.globe { position: fixed; inset: 0; z-index: 0; cursor: grab; }
.globe:active { cursor: grabbing; }
.globe canvas { display: block; touch-action: none; }
.globe-tooltip { position: fixed; top: 0; left: 0; z-index: 30; pointer-events: none; }
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(3, 5, 10, 0.75) 100%);
}

.loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  font-family: var(--display); letter-spacing: 0.04em; color: var(--muted); background: var(--ink);
}

/* ---------- primitives ---------- */

.logo {
  margin: 0; font: 900 clamp(3rem, 2rem + 4vw, 5.2rem)/0.9 var(--display);
  letter-spacing: -0.04em; color: var(--text); text-decoration: none;
}
.logo span {
  background: linear-gradient(95deg, #fee090 0%, var(--heat) 45%, var(--heat-deep) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-sm { font-size: 1.15rem; letter-spacing: -0.02em; }

.eyebrow {
  margin: 0 0 0.6rem; font: 600 0.72rem/1 var(--body); letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--heat);
}
.muted { color: var(--muted); margin: 0.4rem 0; }
.small { font-size: 0.82rem; }

.btn {
  border: 1px solid transparent; border-radius: 12px; padding: 0.78rem 1.2rem;
  font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: transform 160ms var(--ease), background 160ms, border-color 160ms, box-shadow 200ms;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:focus-visible, .seg:focus-visible, input:focus-visible { outline: 2px solid #fee090; outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(135deg, #ff9a3c, var(--heat-deep)); color: #1a0703;
  box-shadow: 0 8px 28px -10px rgba(255, 110, 30, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 12px 36px -8px rgba(255, 110, 30, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.btn-ghost { background: rgba(255, 255, 255, 0.04); border-color: var(--line-strong); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.09); }
.btn-quiet { background: transparent; color: var(--muted); padding-inline: 0.8rem; }
.btn-quiet:hover { color: var(--danger); }
.btn-wide { width: 100%; margin-top: 1.2rem; padding-block: 0.95rem; font-size: 1.02rem; }

input {
  width: 100%; background: rgba(4, 8, 18, 0.7); border: 1px solid var(--line-strong);
  border-radius: 12px; padding: 0.78rem 1rem; transition: border-color 160ms, background 160ms;
}
input::placeholder { color: #5b6a82; }
input:focus { border-color: var(--heat); background: rgba(4, 8, 18, 0.9); outline: none; }

.chip {
  border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.04); border-radius: 999px;
  padding: 0.3rem 0.8rem; cursor: pointer; font: 700 0.85rem var(--display); letter-spacing: 0.12em;
}
.chip:hover { border-color: var(--heat); }

.swatch {
  width: 12px; height: 12px; flex: none; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

/* ---------- home ---------- */

.home {
  position: fixed; inset: 0; z-index: 5; display: flex; align-items: center;
  padding: 2rem clamp(1rem, 5vw, 5rem); pointer-events: none; overflow-y: auto;
}
.home-card {
  pointer-events: auto; width: min(480px, 100%); padding: 2.2rem;
  background: linear-gradient(160deg, rgba(12, 20, 38, 0.94), rgba(8, 12, 24, 0.86));
  border: 1px solid var(--line); border-radius: 26px;
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.8);
  animation: rise 700ms var(--ease) both;
}
.lede { color: #b7c3d6; margin: 1.1rem 0 1.6rem; max-width: 40ch; }
.home-form { display: grid; gap: 1rem; }
.field { display: grid; gap: 0.4rem; }
.field span { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.code-input { text-transform: uppercase; font: 700 1rem var(--display); letter-spacing: 0.2em; text-align: center; padding-inline: 0.4rem; }
.join-hint {
  border-left: 3px solid var(--heat); padding: 0.55rem 0.8rem; background: rgba(255, 122, 26, 0.08);
  border-radius: 0 10px 10px 0; font-weight: 600;
}
.form-error { min-height: 1.2em; margin: 0; color: var(--danger); font-weight: 600; }
.rules { margin: 1.4rem 0 0; padding: 1.2rem 0 0; border-top: 1px dashed var(--line-strong); list-style: none; display: grid; gap: 0.5rem; counter-reset: r; color: var(--muted); font-size: 0.9rem; }
.rules li { counter-increment: r; display: flex; gap: 0.7rem; }
.rules li::before { content: counter(r, decimal-leading-zero); font: 700 0.75rem/1.9 var(--display); color: var(--heat); }
.rules b { color: var(--text); font-weight: 700; }

/* ---------- room layout ---------- */

.room { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.room > * { pointer-events: auto; }

.topbar {
  position: absolute; top: 1rem; left: 1rem; right: 1rem; display: flex; align-items: center; gap: 0.9rem;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.round-info { font-weight: 700; color: var(--muted); }
.timer {
  margin-left: auto; font: 700 1.5rem/1 var(--display); letter-spacing: 0.02em; padding: 0.45rem 0.9rem;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.timer.urgent { color: var(--danger); border-color: rgba(255, 93, 108, 0.5); animation: pulse 1s ease-in-out infinite; }
.conn-status { margin-left: auto; color: #fee090; font-weight: 700; animation: pulse 1.2s infinite; }
.timer:not([hidden]) + .conn-status { margin-left: 0; }

.panel {
  position: absolute; top: 4.4rem; max-height: calc(100vh - 10.5rem); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.3rem; scrollbar-width: thin;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.9);
}
.panel-left { left: 1rem; width: 350px; animation: slideL 500ms var(--ease) both; }
.panel-right { right: 1rem; width: 300px; animation: slideR 500ms var(--ease) both; }
.panel-title {
  display: flex; align-items: center; justify-content: space-between; margin: 0 0 0.8rem;
  font: 700 0.78rem var(--body); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
}
.count { font-family: var(--display); color: var(--text); }
.panel-heading { margin: 0 0 0.8rem; font: 700 1.35rem/1.2 var(--display); letter-spacing: -0.01em; }

/* ---------- lobby ---------- */

.big-code {
  display: flex; align-items: baseline; justify-content: space-between; width: 100%; gap: 1rem;
  background: none; border: 0; border-bottom: 1px dashed var(--line-strong); padding: 0 0 0.6rem; cursor: pointer;
  font: 900 3.2rem/1 var(--display); letter-spacing: 0.12em; text-align: left;
}
.big-code span { font: 600 0.75rem var(--body); letter-spacing: 0; color: var(--muted); transition: color 160ms; }
.big-code:hover span { color: var(--heat); }
.settings { margin-top: 1.2rem; display: grid; gap: 0.9rem; }
.setting { border: 0; margin: 0; padding: 0; min-width: 0; }
.setting legend { font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 0.35rem; padding: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: rgba(0, 0, 0, 0.3); border-radius: 12px; border: 1px solid var(--line); }
.seg {
  flex: 1 1 auto; border: 0; background: transparent; border-radius: 9px; padding: 0.45rem 0.6rem; cursor: pointer;
  font-weight: 700; font-size: 0.86rem; color: var(--muted); transition: background 160ms, color 160ms;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--text); color: var(--ink); }
.setting:disabled .seg { cursor: default; }
.setting:disabled .seg:not(.active):hover { color: var(--muted); }
.waiting { margin: 1.3rem 0 0; padding: 0.8rem; text-align: center; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); }

/* ---------- scoreboard ---------- */

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.player { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.6rem; border-radius: 10px; transition: background 200ms; }
.player.me { background: rgba(255, 255, 255, 0.05); }
.player.offline { opacity: 0.45; }
.player.found .player-status { color: var(--found); }
.player-main { flex: 1; min-width: 0; }
.player-name { font-weight: 700; display: flex; align-items: center; gap: 0.35rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.player-status { font-size: 0.8rem; color: var(--muted); }
.tag { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; padding: 0.08rem 0.35rem; border-radius: 5px; background: rgba(255, 122, 26, 0.16); color: var(--heat); }
.tag-me { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.player-score { text-align: right; display: grid; font-variant-numeric: tabular-nums; }
.player-score b { font: 700 1rem var(--display); }
.gain { color: var(--found); font-size: 0.75rem; font-weight: 800; }

/* ---------- play ---------- */

.closest { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 0.6rem; margin-bottom: 1rem; }
.closest span { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; }
.closest b { font: 900 2.1rem/1.1 var(--display); letter-spacing: -0.02em; }
.closest em { font-style: normal; color: var(--muted); font-weight: 600; }
.guess-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.guess-list li { display: flex; align-items: center; gap: 0.6rem; padding: 0.42rem 0.2rem; border-bottom: 1px solid var(--line); animation: pop 400ms var(--ease) both; }
.guess-name { flex: 1; font-weight: 600; }
.guess-country { margin-left: 0.4rem; color: var(--muted); font-weight: 500; font-size: 0.78rem; }
.secret-country { margin: -0.9rem 0 1.2rem; color: var(--muted); font-weight: 700; }
.banner .banner-country { color: var(--muted); font-weight: 600; }
.guess-km { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.88rem; }

.banner { display: grid; gap: 0.15rem; padding: 1rem 1.1rem; border-radius: 14px; margin-bottom: 1rem; animation: pop 500ms var(--ease) both; }
.banner span { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.banner b { font: 900 1.7rem/1.15 var(--display); }
.banner em { font-style: normal; font-weight: 700; }
.banner small { color: var(--muted); margin-top: 0.3rem; }
.banner-win { background: linear-gradient(135deg, rgba(52, 211, 153, 0.2), rgba(52, 211, 153, 0.04)); border: 1px solid rgba(52, 211, 153, 0.4); }
.banner-win span, .banner-win em { color: var(--found); }
.banner-lose { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line-strong); }
.banner-lose span { color: var(--muted); }

.guess {
  position: absolute; left: 50%; bottom: 1.4rem; transform: translateX(-50%); width: min(620px, calc(100vw - 2rem));
  display: flex; gap: 0.5rem; padding: 0.5rem; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 16px; box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.9);
  animation: riseCenter 500ms var(--ease) both;
}
.guess-box { position: relative; flex: 1; }
.guess-box input { border-color: transparent; background: rgba(0, 0, 0, 0.35); font-size: 1.05rem; font-weight: 600; }
.suggestions {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 0.7rem); margin: 0; padding: 0.35rem; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, 0.9);
}
.suggestions li { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: 0.55rem 0.75rem; border-radius: 9px; cursor: pointer; font-weight: 600; }
.suggestions li small { color: var(--muted); font-weight: 500; }
.suggestions li.active { background: linear-gradient(90deg, rgba(255, 122, 26, 0.22), rgba(255, 122, 26, 0.05)); }

.globe-label {
  padding: 0.35rem 0.6rem; border-radius: 8px; background: rgba(6, 9, 18, 0.9); border: 1px solid var(--line-strong);
  font: 600 13px var(--body); color: var(--text); display: grid;
}
.globe-label span { color: var(--muted); font-size: 12px; }
.globe-label .found { color: var(--found); font-weight: 800; }

/* ---------- results & final ---------- */

.secret { margin: 0 0 1.2rem; font: 900 2.2rem/1.05 var(--display); letter-spacing: -0.02em; color: var(--found); }
.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.standings details { border-radius: 12px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.standings summary { display: grid; grid-template-columns: 2rem 1fr auto; grid-template-rows: auto auto; column-gap: 0.4rem; align-items: center; padding: 0.55rem 0.7rem; cursor: pointer; list-style: none; }
.standings summary::-webkit-details-marker { display: none; }
.place { grid-row: 1 / 3; font-size: 1.3rem; text-align: center; color: var(--muted); }
.standing-name { font-weight: 800; }
.standing-meta { grid-column: 2; font-size: 0.8rem; color: var(--muted); }
.standings .gain { grid-column: 3; grid-row: 1 / 3; font: 700 1rem var(--display); }
.missed .gain { color: var(--muted); }
.path { display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0 0.7rem 0.7rem 2.8rem; }
.path-chip { font-size: 0.76rem; font-weight: 600; padding: 0.12rem 0.5rem 0.12rem 0.4rem; border-radius: 6px; background: rgba(255, 255, 255, 0.05); border-left: 4px solid var(--c); }

.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 0.4rem; margin-top: 1.4rem; }
.step { display: grid; justify-items: center; text-align: center; gap: 0.1rem; min-width: 0; }
.step b { font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step em { font-style: normal; font-size: 0.78rem; color: var(--muted); }
.step-medal { font-size: 1.8rem; }
.step-block {
  width: 100%; margin-top: 0.4rem; border-radius: 10px 10px 0 0; display: grid; place-items: center;
  font: 900 1.6rem var(--display); color: rgba(0, 0, 0, 0.45); animation: grow 900ms var(--ease) both; transform-origin: bottom;
}
.step-1 .step-block { height: 120px; background: linear-gradient(#fee090, var(--heat)); }
.step-2 .step-block { height: 84px; background: linear-gradient(#e2e8f0, #8392ab); animation-delay: 150ms; }
.step-3 .step-block { height: 60px; background: linear-gradient(#f5b98a, #b5652f); animation-delay: 300ms; }

/* ---------- loser meme ---------- */

.meme {
  position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; justify-items: center; gap: 1rem;
  padding: 1rem; background: rgba(3, 5, 10, 0.78); cursor: pointer; animation: memeFade 200ms ease-out both;
}
.meme img {
  width: min(420px, 80vw); height: auto; border-radius: 22px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9), 0 0 0 4px rgba(255, 122, 26, 0.6);
  animation: memeIn 550ms cubic-bezier(0.34, 1.56, 0.64, 1) both, memeShake 420ms 550ms ease-in-out 3;
}
.meme p { margin: 0; font: 900 clamp(1.3rem, 1rem + 2vw, 2rem)/1.1 var(--display); color: #fee090; text-align: center; animation: memeFade 300ms 400ms both; }
@keyframes memeFade { from { opacity: 0; } }
@keyframes memeIn { from { opacity: 0; transform: scale(0.3) rotate(-12deg); } }
@keyframes memeShake { 25% { transform: rotate(-4deg) scale(1.03); } 75% { transform: rotate(4deg) scale(1.03); } }

/* ---------- sound ---------- */

.sound-btn {
  position: fixed; top: 0.9rem; right: 1rem; z-index: 45; width: 2.4rem; height: 2.4rem; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; font-size: 1.05rem;
  transition: border-color 160ms, transform 160ms var(--ease);
}
.sound-btn:hover { border-color: var(--heat); transform: scale(1.06); }
.topbar { right: 4.2rem; }
.sound-panel { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 1rem; background: rgba(3, 5, 10, 0.6); animation: memeFade 160ms ease-out both; }
.sound-card {
  width: min(360px, 100%); padding: 1.3rem 1.4rem; border-radius: var(--radius); background: var(--panel-solid);
  border: 1px solid var(--line-strong); box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.9); animation: pop 260ms var(--ease) both;
}
.sound-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; }
.sound-head h2 { margin: 0; font: 700 1.2rem var(--display); }
.sound-close { border: 0; background: none; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; }
.sound-close:hover { color: var(--text); }
.sound-row { display: grid; grid-template-columns: 5.5rem 1fr 2.8rem; align-items: center; gap: 0.7rem; margin: 0.55rem 0; font-weight: 600; }
.sound-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sound-row input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--heat); width: 100%; }
.sound-track { margin: 0.9rem 0 0.6rem; color: #fee090; font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.sound-actions .btn { padding: 0.6rem 0.5rem; }

/* ---------- toasts ---------- */

.toasts { position: fixed; top: 4.6rem; left: 50%; transform: translateX(-50%); z-index: 40; display: grid; gap: 0.4rem; justify-items: center; pointer-events: none; width: min(420px, calc(100vw - 2rem)); }
.toast {
  padding: 0.6rem 1rem; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--line-strong);
  font-weight: 700; box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.9); animation: drop 400ms var(--ease) both;
  transition: opacity 400ms, transform 400ms;
}
.toast-error { border-color: rgba(255, 93, 108, 0.6); color: #ffc2c8; }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ---------- motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
@keyframes riseCenter { from { opacity: 0; transform: translate(-50%, 18px); } }
@keyframes slideL { from { opacity: 0; transform: translateX(-24px); } }
@keyframes slideR { from { opacity: 0; transform: translateX(24px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }
@keyframes grow { from { transform: scaleY(0); } }
@keyframes pulse { 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  body { overflow-y: auto; }
  .globe { position: fixed; height: 46vh; bottom: auto; }
  .vignette { display: none; }
  .home { position: relative; min-height: 100%; align-items: flex-end; padding: 38vh 1rem 1.5rem; }
  .home-card { padding: 1.5rem; }
  .home-actions { grid-template-columns: 1fr; }

  .room { position: relative; inset: auto; min-height: 100%; padding: 46vh 1rem 6.5rem; display: grid; gap: 0.8rem; align-content: start; }
  .topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 6; padding: 0.7rem 4rem 1.2rem 1rem;
    background: linear-gradient(rgba(6, 9, 18, 0.9), transparent);
  }
  .round-info { display: none; }
  .timer { font-size: 1.15rem; }
  .panel { position: static; width: auto; max-height: none; animation: rise 500ms var(--ease) both; }
  .guess { position: fixed; bottom: 0.7rem; }
  .guess .btn-quiet { padding-inline: 0.4rem; }
  .big-code { font-size: 2.4rem; }
}

@media (max-width: 480px) {
  .guess { flex-wrap: wrap; }
  .guess-box { flex-basis: 100%; }
  .guess .btn { flex: 1; }
  .room { padding-bottom: 9.5rem; }
}
