:root {
  --bg: #0d0d1a;
  --surface: #13132a;
  --surface2: #1a1a35;
  --surface3: #22223f;
  --border: #2e2e55;
  --accent: #00d4ff;
  --accent2: #7c3aed;
  --accent-dim: rgba(0, 212, 255, 0.15);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --gold: #fbbf24;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Typography ── */
h1 { font-size: 2.5rem; font-weight: 800; letter-spacing: -0.5px; }
h2 { font-size: 1.6rem; font-weight: 700; }
h3 { font-size: 1.2rem; font-weight: 600; }
p  { line-height: 1.6; }

.brand {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagme-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--text);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.tagme-mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.35em;
  height: 1.35em;
  border-radius: 0.38em;
  color: #06101f;
  background: linear-gradient(135deg, var(--accent), #35f0b4 58%, var(--gold));
  box-shadow: 0 0.28em 1em rgba(0, 212, 255, 0.24);
  font-weight: 1000;
  transform: rotate(-7deg);
}

.tagme-mark::after {
  content: "";
  position: absolute;
  width: 0.26em;
  height: 0.26em;
  margin-top: -0.82em;
  margin-left: 0.82em;
  border-radius: 50%;
  background: var(--accent2);
}

.tagme-word {
  background: linear-gradient(135deg, var(--text), var(--accent) 48%, #35f0b4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand.tagme-logo {
  font-size: 3rem;
  background: none;
  -webkit-text-fill-color: currentColor;
}

.brand-sm.tagme-logo {
  background: none;
  -webkit-text-fill-color: currentColor;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }

/* ── Layout helpers ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.w-full { width: 100%; }
.text-center { text-align: center; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0099cc);
  color: #000;
}
.btn-primary:not(:disabled):hover { filter: brightness(1.15); transform: translateY(-1px); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:not(:disabled):hover { background: var(--surface3); border-color: var(--accent); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:not(:disabled):hover { filter: brightness(1.15); }

.btn-success {
  background: var(--success);
  color: #000;
  font-weight: 700;
}
.btn-success:not(:disabled):hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #d97706);
  color: #000;
  font-weight: 700;
}
.btn-gold:not(:disabled):hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.85rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1.1rem; }
.btn-xl { padding: 1.25rem 2.5rem; font-size: 1.2rem; font-weight: 700; border-radius: 12px; }

/* ── Inputs ── */
input[type="text"], input[type="number"], select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder { color: var(--text-muted); }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group { margin-bottom: 1rem; }

/* ── Badge / pill ── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.badge-accent { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ── Room code display ── */
.room-code {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(0,212,255,0.4);
  font-family: 'Courier New', monospace;
}

/* ── Timer ── */
.timer-display {
  font-size: 5rem;
  font-weight: 900;
  font-family: 'Courier New', monospace;
  line-height: 1;
}
.timer-display.urgent { color: var(--danger); animation: pulse 0.5s ease infinite alternate; }
.timer-display.normal { color: var(--accent); }

@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: 0.5; }
}

/* ── Leaderboard ── */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}
.leaderboard-table th,
.leaderboard-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.leaderboard-table th {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.leaderboard-table tr:last-child td { border-bottom: none; }
.leaderboard-table .rank { font-weight: 800; color: var(--text-muted); width: 2rem; }
.leaderboard-table .rank-1 { color: var(--gold); }
.leaderboard-table .rank-2 { color: #94a3b8; }
.leaderboard-table .rank-3 { color: #b45309; }
.leaderboard-table .score-col { font-weight: 700; color: var(--accent); text-align: right; }
.leaderboard-table tr.highlight { background: rgba(0,212,255,0.06); }

/* ── Distance table ── */
.distance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.distance-table th,
.distance-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.distance-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.distance-table td input[type="number"] {
  width: 90px;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  text-align: center;
}
.distance-table tr:last-child td { border-bottom: none; }
.closest-row td { color: var(--success); font-weight: 600; }

/* ── Player list ── */
.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.player-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.85rem;
}
.player-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

/* ── Map container ── */
.map-container {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
#map, #player-map, #reveal-map, #host-reveal-map {
  width: 100%; height: 100%;
}

.map-chrome-host {
  position: absolute;
  inset: 0;
  z-index: 450;
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  color: rgba(226, 232, 240, 0.86);
}

.map-edge-label {
  position: absolute;
  padding: 0.16rem 0.34rem;
  border-radius: 5px;
  background: rgba(7, 10, 24, 0.58);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.map-edge-label.top,
.map-edge-label.bottom {
  left: 50%;
  transform: translateX(-50%);
}

.map-edge-label.top { top: 0.45rem; }
.map-edge-label.bottom { bottom: 0.45rem; }

.map-edge-label.left,
.map-edge-label.right {
  top: 50%;
  transform: translateY(-50%);
}

.map-edge-label.left { left: 0.45rem; }
.map-edge-label.right { right: 0.45rem; }

/* ── Question bar ── */
.question-bar {
  background: rgba(13,13,26,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  z-index: 500;
}
.question-text-display {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}
.timer-bar-display {
  font-size: 1.4rem;
  font-weight: 900;
  font-family: monospace;
  min-width: 3rem;
  text-align: right;
}

/* ── Submission counter ── */
.sub-counter {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
}

/* ── Screen management ── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* Full height screens */
.fullscreen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}

/* ── Setup screen ── */
.setup-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  height: 100%;
  overflow: hidden;
}
.setup-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.round-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}
.round-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--surface3);
  border-radius: 6px;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}
.question-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--surface3);
  border-radius: 6px;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.bank-item:hover { border-color: var(--accent); }
.bank-item.used { opacity: 0.4; cursor: default; }
.bank-item .bank-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ── Host game layout ── */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 0;
  flex: 1;
  overflow: hidden;
}
.game-sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1rem;
  overflow-y: auto;
}

/* ── Reveal layout ── */
.reveal-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 0;
  flex: 1;
  overflow: hidden;
}
.reveal-sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1rem;
  overflow-y: auto;
}

/* ── Waiting animation ── */
.waiting-dots::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%, 100% { content: ''; }
  25%       { content: '.'; }
  50%       { content: '..'; }
  75%       { content: '...'; }
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

/* ── Pin colors for Leaflet ── */
.pin-marker {
  width: 36px; height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  border: 3px solid rgba(255,255,255,0.7);
  font-weight: 800;
  font-size: 0.75rem;
  color: #000;
  box-shadow: 0 3px 12px rgba(0,0,0,0.5);
}
.pin-initials {
  transform: rotate(45deg);
}
.correct-marker {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 0 16px rgba(251,191,36,0.7), 0 3px 12px rgba(0,0,0,0.5);
}

/* ── Index page ── */
.index-hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(124,58,237,0.15) 0%, transparent 70%),
              radial-gradient(ellipse at 80% 80%, rgba(0,212,255,0.08) 0%, transparent 60%);
}
.index-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 700px;
  width: 100%;
  margin-top: 2.5rem;
}
.index-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: border-color 0.2s, transform 0.2s;
}
.index-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.index-card h2 { font-size: 1.3rem; }
.index-card .icon { font-size: 2.5rem; }

/* ── Player page specific ── */
.player-fullscreen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.player-map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.player-submit-bar {
  background: rgba(13,13,26,0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.pin-hint {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 700px) {
  .index-cards { grid-template-columns: 1fr; }
  .setup-layout { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .reveal-layout { grid-template-columns: 1fr; }
  .brand { font-size: 2rem; }
  .room-code { font-size: 2.5rem; }
}

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Lobby screen ── */
.lobby-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 2rem;
  background: radial-gradient(ellipse at 50% -10%, rgba(0,212,255,0.1) 0%, transparent 60%);
}
.lobby-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  width: 100%;
  max-width: 780px;
  align-items: start;
}

/* ── Game over ── */
.gameover-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 1.5rem;
  text-align: center;
}
.trophy { font-size: 5rem; }

/* ── Header bar ── */
.host-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-shrink: 0;
}
.host-header .brand-sm {
  font-size: 1.25rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.progress-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: auto;
}
