:root {
  --bg: #090e17;
  --panel: #0f1623;
  --panel-2: #121c2d;
  --accent: #5ba8f5;
  --success: #22c55e;
  --warn: #e8a822;
  --danger: #e84848;
  --fg: #c8d8ec;
  --muted: #6b7a8c;
}

* { box-sizing: border-box; }

/* ─── Global scrollbar ────────────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 2px; }
*::-webkit-scrollbar-thumb:hover { background: #7cc0ff; }

.paused-badge,
.admin-badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 11px;
  letter-spacing: 0.2em;
  font-weight: 700;
  border: 1px solid currentColor;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
}
.paused-badge { color: #e8a822; background: rgba(232, 168, 34, 0.08); animation: paused-pulse 1.2s infinite; margin-right: 8px; }
.admin-badge { color: var(--accent); background: rgba(26, 127, 232, 0.08); margin-right: 8px; }
.paused-badge.hidden,
.admin-badge.hidden { display: none; }
@keyframes paused-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ─── Layout ──────────────────────────────────────────────────────────────── */

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Roboto', sans-serif;
  overflow: hidden;
}

#app {
  width: 688px;
  height: 1032px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 56px;
  padding: 0 16px;
  background: linear-gradient(180deg, #0d1420 0%, #0a1019 100%);
  border-bottom: 1px solid #1e2a3c;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-tag {
  font-family: 'Roboto', sans-serif;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.15em;
}

.status-dot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.15em;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 10px currentColor;
}
.dot.online  { background: var(--success); }
.dot.offline { background: var(--danger); animation: blink 1.2s ease infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

/* ─── Crisis banner ───────────────────────────────────────────────────────── */

.crisis-banner {
  flex-shrink: 0;
  background: var(--panel);
  border-bottom: 1px solid #1e2a3c;
  padding: 10px 16px 8px;
  overflow: hidden;
}

.crisis-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.crisis-info {
  display: flex;
  flex-direction: column;
  border-left: 3px solid var(--danger);
  padding: 4px 12px;
  flex: 1;
  min-width: 0;
}
.crisis-info .label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.crisis-info strong {
  font-family: 'Roboto', sans-serif;
  font-size: 20px;
  color: var(--fg);
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
  height: calc(20px * 1.25 * 2);
}

.crisis-stats {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.stat-box {
  display: flex;
  flex-direction: column;
  border-left: 2px solid var(--accent);
  padding: 4px 10px;
  background: rgba(26, 127, 232, 0.04);
}
.stat-box .label {
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.stat-box strong {
  font-family: 'Roboto', sans-serif;
  font-size: 20px;
  color: var(--fg);
}

/* ─── QR + city top row ───────────────────────────────────────────────────── */

.content-grid {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  height: 295px;
  gap: 8px;
  padding: 8px 8px 0;
}

.sidebar {
  width: 234px;
  flex-shrink: 0;
  background: var(--panel);
  padding: 12px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.qr-panel { text-align: center; }
.qr-panel h2 {
  font-size: 16px;
  color: var(--muted);
  margin: 0 0 6px;
  letter-spacing: 0.2em;
}
#qr-img {
  width: 190px;
  height: 190px;
  padding: 5px;
  background: #fff;
}
.qr-caption {
  font-size: 10px;
  color: var(--muted);
  margin-top: 5px;
  letter-spacing: 0.15em;
}

/* ─── 3D city strip (right side of top row) ───────────────────────────────── */

.city-strip {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid #1e2a3c;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.city-strip .city-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.city-strip .city-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Scanline + vignette overlay */
.city-strip::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 3px,
      rgba(0, 0, 0, 0.08) 3px,
      rgba(0, 0, 0, 0.08) 4px
    ),
    radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
  z-index: 2;
}

/* HUD overlay (labels + corners) */
.city-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.city-hud-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 8px 10px 0;
}

.city-hud-label {
  font-family: 'Roboto', sans-serif;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.25em;
  color: rgba(91, 168, 245, 0.7);
  text-transform: uppercase;
}

.city-hud-live {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: 'Roboto', sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--danger);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
  animation: blink 1.2s ease infinite;
}

/* Corner bracket decorations */
.city-corner {
  position: absolute;
  width: 14px;
  height: 14px;
}
.city-corner.tl { top: 6px;    left: 6px;    border-top: 1px solid var(--accent); border-left: 1px solid var(--accent); }
.city-corner.tr { top: 6px;    right: 6px;   border-top: 1px solid var(--accent); border-right: 1px solid var(--accent); }
.city-corner.bl { bottom: 6px; left: 6px;    border-bottom: 1px solid var(--accent); border-left: 1px solid var(--accent); }
.city-corner.br { bottom: 6px; right: 6px;   border-bottom: 1px solid var(--accent); border-right: 1px solid var(--accent); }

.city-marker {
  position: absolute;
  top: 0;
  left: 0;
}

.city-marker .glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger), 0 0 14px rgba(232, 72, 72, 0.5);
  color: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  animation: marker-pulse 1.2s ease infinite;
}

@keyframes marker-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 6px var(--danger), 0 0 14px rgba(232, 72, 72, 0.5); }
  50%       { transform: scale(1.25); box-shadow: 0 0 10px var(--danger), 0 0 22px rgba(232, 72, 72, 0.7); }
}

.city-marker.resolved .glyph {
  background: var(--success);
  box-shadow: 0 0 6px var(--success), 0 0 14px rgba(34, 197, 94, 0.5);
  animation: none;
}

/* ─── Bottom split: log + leaderboard ────────────────────────────────────── */

.bottom-grid {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  gap: 8px;
  padding: 8px;
}

.log {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  padding: 12px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.log h2 {
  font-size: 10px;
  color: var(--muted);
  margin: 0 0 6px;
  letter-spacing: 0.2em;
  flex-shrink: 0;
}

/* ─── Leaderboard section ─────────────────────────────────────────────────── */

.leaderboard-section {
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  padding: 10px 14px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.leaderboard-header h2 {
  font-size: 10px;
  color: var(--muted);
  margin: 0;
  letter-spacing: 0.2em;
}

.tabs { display: flex; gap: 0; margin-bottom: 8px; }
.tab {
  flex: 1;
  background: #0a121e;
  color: var(--muted);
  border: 1px solid #1e2a3c;
  font-family: 'Roboto', sans-serif;
  font-size: 10px;
  letter-spacing: 0.15em;
  padding: 6px 8px;
  cursor: pointer;
}
.tab.active { background: var(--accent); color: #ffffff; border-color: var(--accent); }

#leaderboard {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
#leaderboard li {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-left: 2px solid #1e2a3c;
  margin-bottom: 4px;
  background: rgba(26, 127, 232, 0.02);
  font-size: 13px;
}
#leaderboard li.rank-1 { border-color: var(--warn); background: rgba(232, 168, 34, 0.1); }
#leaderboard li.rank-2 { border-color: #c0c0c0; background: rgba(192, 192, 192, 0.08); }
#leaderboard li.rank-3 { border-color: #cd7f32; background: rgba(205, 127, 50, 0.08); }
#leaderboard .score { color: var(--accent); font-weight: 700; }

#event-log {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  font-family: 'Roboto Mono', monospace;
}
#event-log li {
  padding: 6px 8px;
  margin-bottom: 4px;
  font-size: 12px;
  border-left: 2px solid var(--muted);
  background: rgba(107, 122, 140, 0.05);
}
#event-log li.ev-solve    { border-color: var(--success); background: rgba(34, 197, 94, 0.06); }
#event-log li.ev-first    { border-color: var(--warn); background: rgba(232, 168, 34, 0.08); color: var(--warn); }
#event-log li.ev-join     { border-color: var(--accent); background: rgba(26, 127, 232, 0.06); }
#event-log li.ev-crisis   { border-color: var(--danger); background: rgba(232, 72, 72, 0.08); color: var(--danger); }
#event-log li.ev-resolved { border-color: var(--success); background: rgba(34, 197, 94, 0.12); color: var(--success); }

.leaderboard-header .tabs { margin-bottom: 0; }

/* ─── Events bar & pills ──────────────────────────────────────────────────── */

.events-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  max-height: 58px;
  overflow: hidden;
  align-items: center;
}
.event-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid #1e2a3c;
  font-size: 12px;
  letter-spacing: 0.08em;
}
.event-pill .indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: blink 1s ease infinite;
}
.event-pill.resolved .indicator {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: none;
}
.event-pill.resolved { color: var(--success); border-color: var(--success); }

#toast-container {
  position: absolute;
  top: 90px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  background: var(--panel-2);
  border-left: 3px solid var(--warn);
  padding: 10px 14px;
  font-size: 13px;
  min-width: 240px;
  animation: slide-in 0.3s ease, fade-out 0.5s ease 2.5s forwards;
}
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
@keyframes fade-out { to { opacity: 0; transform: translateX(30px); } }
