:root {
  --bg: #060912;
  --bg-panel: #0b0f1c;
  --line: #182238;
  --cyan: #29f2ff;
  --magenta: #ff2d8c;
  --amber: #ffb020;
  --text: #d7e4f5;
  --text-dim: #5c7089;
  --ambient: #2c3b52;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Consolas", "SFMono-Regular", Menlo, monospace;
  overflow: hidden;
}
html.stats-page,
body.stats-page {
  overflow: auto;
  height: auto;
  min-height: 100%;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015),
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px
  );
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 14px 24px;
  background: linear-gradient(180deg, #0c1120, #070b15);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 12px var(--magenta);
  animation: blink 1.6s ease-in-out infinite;
}
.brand-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 3px;
}
.brand-accent { color: var(--cyan); text-shadow: 0 0 10px rgba(41,242,255,.6); }

.topstats {
  display: flex;
  gap: 28px;
  margin-left: auto;
}
.stat { text-align: center; min-width: 90px; }
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(41,242,255,.5);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.randomize-btn {
  position: relative;
  background: linear-gradient(180deg, #ff3d94, #c21867);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 22px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(255, 45, 140, 0.5);
  transition: transform .1s ease;
}
.randomize-btn:hover { transform: translateY(-1px); }
.randomize-btn:active { transform: translateY(1px); }
.randomize-btn:disabled { opacity: .6; cursor: default; }
.pulse-ring {
  position: absolute; inset: -4px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.5);
  opacity: 0;
}
.randomize-btn.firing .pulse-ring {
  animation: ring 0.6s ease-out;
}

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #17d1a0, #0e9c78);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  padding: 12px 22px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 13px;
  box-shadow: 0 0 18px rgba(23, 209, 160, 0.45);
  transition: transform .1s ease;
}
.help-btn:hover { transform: translateY(-1px); }
.help-btn:active { transform: translateY(1px); }

.controlbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px;
  background: #080c17;
  border-bottom: 1px solid var(--line);
  font-size: 11.5px;
}
.control-label {
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-size: 10px;
}
.name-input {
  background: #0e1526;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11.5px;
  width: 150px;
}
.name-input::placeholder { color: var(--text-dim); }
.name-input:focus { outline: 1px solid var(--cyan); }
.dice-btn {
  background: #0e1526;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.dice-btn:hover { border-color: var(--cyan); }
.dice-btn:active { transform: scale(0.92); }
.stats-link {
  margin-left: auto;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11.5px;
  letter-spacing: .5px;
  white-space: nowrap;
}
.stats-link:hover { color: var(--cyan); }
.site-select {
  background: #0e1526;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11.5px;
}
.pick-btn {
  background: transparent;
  color: var(--cyan);
  border: 1px solid var(--cyan);
  border-radius: 4px;
  padding: 5px 12px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 11px;
  cursor: pointer;
}
.pick-btn:hover { background: rgba(41,242,255,0.08); }
a.pick-btn { display: inline-flex; align-items: center; text-decoration: none; margin-left: auto; }
.pick-btn.active {
  background: var(--cyan);
  color: #06111a;
  box-shadow: 0 0 12px rgba(41,242,255,0.6);
}
.pick-hint {
  color: var(--text-dim);
  font-style: italic;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.map-panel {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(41,242,255,0.05), transparent 60%),
    var(--bg);
  border-right: 1px solid var(--line);
}
#globeViz { width: 100%; height: 100%; }
.map-caption {
  position: absolute;
  bottom: 10px; left: 16px;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  pointer-events: none;
}

.side-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  min-height: 0;
  height: 100%;
}
.panel-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}
.panel-block h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.ticker {
  list-style: none;
  margin: 0; padding: 0;
  padding-right: 10px;
  scrollbar-gutter: stable;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ticker li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 7px;
  font-size: 11.5px;
  border-left: 2px solid var(--cyan);
  padding: 4px 8px;
  background: rgba(41,242,255,0.04);
  animation: fadeIn .25s ease;
  line-height: 1.5;
}
.ticker li.you { border-left-color: var(--magenta); background: rgba(255,45,140,0.07); }
.ticker li.ambient {
  border-left-color: var(--ambient);
  background: rgba(90, 112, 137, 0.04);
  opacity: 0.6;
}
.ticker li.ambient .nick { font-weight: 400; }
.ticker time { color: var(--text-dim); margin-right: 2px; }
.ticker .nick-icon { font-size: 11px; }
.ticker .nick { color: var(--text); font-weight: 700; }
.ticker .verb { color: var(--text-dim); }
.ticker .site { color: var(--cyan); font-weight: 700; }
.ticker .country { color: var(--text-dim); }
.site-logo {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #0e1526;
  flex: none;
  object-fit: contain;
}

.leaderboard {
  list-style: none;
  margin: 0; padding: 0;
  padding-right: 10px;
  scrollbar-gutter: stable;
  overflow-y: auto;
  flex: 1;
}
.leaderboard li {
  display: grid;
  grid-template-columns: 18px 78px 1fr 48px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  padding: 5px 0;
}
.leaderboard .name { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaderboard .bar-track { background: #101a2c; height: 8px; border-radius: 4px; overflow: hidden; }
.leaderboard .bar-fill { height: 100%; }
.leaderboard .count { text-align: right; color: var(--text-dim); white-space: nowrap; }

.footer {
  padding: 8px 24px;
  font-size: 10.5px;
  color: var(--text-dim);
  border-top: 1px solid var(--line);
  background: #070b15;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}
@keyframes ring {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(1.15); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-impact {
  position: relative;
  width: 30px;
  height: 30px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.logo-impact .badge {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(6, 9, 18, 0.9);
  border: 2px solid var(--brand, var(--cyan));
  box-shadow: 0 0 10px var(--brand, var(--cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.2);
  animation: logoPop 1.8s ease forwards;
}
.logo-impact .badge img {
  width: 18px;
  height: 18px;
  border-radius: 4px;
}
.logo-impact .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--brand, var(--cyan));
  opacity: 0.9;
  animation: logoRing 1.8s ease-out forwards;
}
@keyframes logoPop {
  0%   { opacity: 0; transform: scale(0.2); }
  15%  { opacity: 1; transform: scale(1.15); }
  25%  { opacity: 1; transform: scale(1); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9); }
}
@keyframes logoRing {
  0%   { opacity: 0.9; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(3); }
}

.milestone-banner {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  z-index: 40;
  background: linear-gradient(180deg, #ffb020, #d17f00);
  color: #1a0f00;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 10px 22px;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(255, 176, 32, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.milestone-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.country-popup {
  position: fixed;
  z-index: 60;
  min-width: 190px;
  max-width: 240px;
  background: rgba(8, 12, 23, 0.97);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 0 26px rgba(41, 242, 255, 0.35);
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.96);
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.country-popup.show {
  opacity: 1;
  transform: translate(-50%, -12px) scale(1);
  pointer-events: auto;
}
.country-popup h3 {
  margin: 0 18px 4px 0;
  font-size: 13px;
  color: var(--text);
}
.country-popup-loading {
  font-size: 11.5px;
  color: var(--text-dim);
}
.cp-total {
  font-size: 11px;
  color: var(--cyan);
  margin-bottom: 8px;
}
.cp-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.cp-close:hover { color: var(--text); }
.cp-sites {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.cp-sites li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.cp-count { margin-left: auto; color: var(--text-dim); }
.cp-empty { color: var(--text-dim); font-style: italic; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side-panel { display: none; }
}

.stats-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.stats-panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  min-width: 0;
}
.stats-panel.wide { grid-column: 1 / -1; }
.stats-panel h2 {
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--magenta);
  box-shadow: 0 0 8px var(--magenta);
  animation: blink 1.6s ease-in-out infinite;
}
.chart-box {
  position: relative;
  height: 220px;
  margin-bottom: 14px;
}
.chart-box-wide { height: 260px; }
.ticker-tall { max-height: 480px; }
.full-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.full-list li {
  display: grid;
  grid-template-columns: 22px 18px 110px 1fr 60px 48px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.full-rank { color: var(--text-dim); text-align: right; }
.full-name { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.full-flag { font-size: 14px; text-align: center; }
.full-flag-img {
  width: 18px;
  height: 13px;
  object-fit: cover;
  border-radius: 2px;
  flex: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08);
}
.full-bar-track { background: #101a2c; height: 8px; border-radius: 4px; overflow: hidden; }
.full-bar-fill { height: 100%; }
.full-count { text-align: right; color: var(--text); white-space: nowrap; }
.full-share { text-align: right; color: var(--text-dim); white-space: nowrap; }

@media (max-width: 720px) {
  .stats-main { grid-template-columns: 1fr; }
}
