@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ───── Reset & Base ───── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --card: #16213e;
  --accent: #e94560;
  --secondary: #0f3460;
  --text: #f0f0f0;
  --text-muted: #8892a4;
  --success: #2ecc71;
  --gold: #f1c40f;
  --silver: #bdc3c7;
  --bronze: #e67e22;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
}

/* ── #14: Light Theme ── */
body.light-theme {
  --bg: #f0f2f5;
  --card: #ffffff;
  --accent: #d63851;
  --secondary: #e0e4ea;
  --text: #1a1a2e;
  --text-muted: #5a6577;
  --shadow: 0 4px 20px rgba(0,0,0,.1);
}

body.light-theme .leaflet-container {
  background: #f0f2f5;
}

html, body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input {
  font-family: inherit;
  outline: none;
  border: none;
}

a { color: var(--accent); text-decoration: none; }

/* ───── Utility ───── */
.hidden { display: none !important; }

/* ───── Layout ───── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

/* ───── Header ───── */
.app-header {
  background: var(--card);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
  position: relative;
  z-index: 100;
}

.app-header .logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.app-header .logo span { color: var(--accent); }

.app-header .round-badge {
  background: var(--secondary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* ───── Landing / Create ───── */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  gap: 24px;
}

.landing h1 {
  font-size: 2.8rem;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -1px;
}

.landing h1 span { color: var(--accent); }

.landing p {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 440px;
}

/* ───── Buttons ───── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(233,69,96,.4);
}

.btn-primary:hover { box-shadow: 0 6px 24px rgba(233,69,96,.55); }

.btn-primary:disabled {
  opacity: .45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text);
}

.btn-lg {
  padding: 18px 48px;
  font-size: 1.2rem;
  border-radius: 16px;
}

.btn-sm {
  padding: 8px 18px;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* ───── Cards ───── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}



/* ───── Lobby (Host) ───── */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 20px;
}

.qr-section {
  text-align: center;
}

.qr-section img {
  width: 240px;
  height: 240px;
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}

.game-code {
  margin-top: 16px;
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--accent);
}

.join-url {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
  word-break: break-all;
}

/* #3: Copy link button */
.btn-copy {
  margin-top: 12px;
  padding: 8px 24px;
  font-size: 0.85rem;
}

/* #10: Spectator URL */
.spectator-url {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.spectator-url a {
  color: var(--accent);
  word-break: break-all;
}

.teams-list {
  width: 100%;
  max-width: 500px;
}

.teams-list h3 {
  margin-bottom: 12px;
  font-weight: 700;
}

.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--secondary);
  padding: 8px 16px;
  border-radius: 24px;
  margin: 4px;
  font-weight: 600;
  font-size: 0.9rem;
  animation: chipIn .3s ease;
}

.team-chip .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
}

/* #6: Kick button */
.kick-btn {
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0 4px;
  margin-left: 4px;
  line-height: 1;
  border-radius: 50%;
  transition: color .2s, background .2s;
}

.kick-btn:hover {
  color: var(--accent);
  background: rgba(233,69,96,.15);
}

@keyframes chipIn {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

/* ───── Host Game View ───── */
.host-game {
  padding: 20px;
}

.round-header {
  text-align: center;
  margin-bottom: 20px;
}

.round-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
}

.round-header .pl-team-name {
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent);
  margin-top: 4px;
}

/* #8: Hint display */
.hint-display {
  margin-top: 8px;
  padding: 6px 16px;
  background: var(--secondary);
  border-radius: 20px;
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gold);
}

/* #8: Player hint badge */
.hint-badge {
  margin-top: 4px;
  padding: 4px 12px;
  background: var(--secondary);
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold);
}

/* Host controls row */
.host-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ───── Rounds Picker ───── */
.rounds-picker {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.rounds-picker label {
  font-weight: 700;
  font-size: 1rem;
}

.rounds-control {
  display: flex;
  align-items: center;
  gap: 16px;
}

.rounds-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}

.rounds-btn:hover { background: var(--accent); }

.rounds-value {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent);
  min-width: 48px;
  text-align: center;
}

.rounds-picker input[type="range"] {
  width: 100%;
  max-width: 300px;
  accent-color: var(--accent);
  height: 6px;
}

/* ───── Timeout Picker ───── */
.timeout-picker {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.timeout-picker label {
  font-weight: 700;
  font-size: 1rem;
}

.timeout-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.timeout-btn {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--secondary);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .2s, color .2s;
}

.timeout-btn:hover { background: var(--accent); }

.timeout-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── #7: Scoring Picker ── */
.scoring-picker {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.scoring-picker label {
  font-weight: 700;
  font-size: 1rem;
}

.scoring-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.scoring-btn {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--secondary);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .2s, color .2s;
}

.scoring-btn:hover { background: var(--accent); }

.scoring-btn.active {
  background: var(--accent);
  color: #fff;
}

.scoring-desc {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ───── Countdown ───── */
.countdown {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 8px;
}

.countdown.urgent {
  color: var(--accent);
  animation: countdownPulse 0.5s ease-in-out infinite;
}

@keyframes countdownPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

/* ───── Submissions Counter ───── */
.submissions-counter {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 12px;
  transition: color .3s, transform .3s;
}

.submissions-counter.all-in {
  color: var(--success);
  transform: scale(1.05);
}

.submissions-tracker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.sub-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  transition: background .3s, transform .3s;
}

.sub-dot.submitted {
  background: var(--success);
  transform: scale(1.1);
}

/* Host map */
#host-map, #spec-map {
  width: 100%;
  height: 450px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.round-panels {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.round-panel {
  flex: 1;
  min-width: 0;
}

.round-panel h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* #4: Reveal badge */
.reveal-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--secondary);
  border-radius: var(--radius);
}

.reveal-badge img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.reveal-badge span {
  font-weight: 700;
  font-size: 0.95rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.results-table th,
.results-table td {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.9rem;
}

.results-table th {
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.results-table td {
  border-bottom: 1px solid rgba(255,255,255,.04);
}

.results-table .distance { color: var(--accent); font-weight: 700; }
.results-table .score    { color: var(--success); font-weight: 700; }

/* ───── Leaderboard ───── */
.leaderboard {
  padding: 32px 20px;
  text-align: center;
}

.leaderboard h2 {
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 32px;
}

.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 32px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.podium-bar {
  width: 100px;
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 16px 8px;
  font-weight: 800;
  font-size: 1.5rem;
  color: #fff;
}

.podium-bar.first  { height: 180px; background: linear-gradient(180deg, #f1c40f 0%, #c7960c 100%); }
.podium-bar.second { height: 130px; background: linear-gradient(180deg, #bdc3c7 0%, #8e9497 100%); }
.podium-bar.third  { height: 100px; background: linear-gradient(180deg, #e67e22 0%, #b8631a 100%); }

.podium-name {
  font-weight: 700;
  font-size: 0.9rem;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-score {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rank-list {
  list-style: none;
  max-width: 500px;
  margin: 0 auto;
}

.rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.rank-item .rank {
  font-weight: 800;
  font-size: 1.1rem;
  width: 32px;
  color: var(--text-muted);
}

.rank-item.top-1 { border-left: 4px solid var(--gold); }
.rank-item.top-2 { border-left: 4px solid var(--silver); }
.rank-item.top-3 { border-left: 4px solid var(--bronze); }

.rank-item .name { flex: 1; font-weight: 600; text-align: left; }
.rank-item .total-score { font-weight: 800; color: var(--accent); font-size: 1.1rem; }

/* #18: Final actions */
.final-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* #15: Crown icon */
.crown-icon {
  font-size: 2rem;
}

/* ───── Player Join ───── */
.join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
  gap: 20px;
}

.join-screen h1 {
  font-size: 2rem;
  font-weight: 900;
}

.join-screen h1 span { color: var(--accent); }

.join-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 340px;
}

.join-form input {
  background: var(--card);
  color: var(--text);
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 1rem;
  border: 2px solid transparent;
  transition: border-color .2s;
}

.join-form input:focus {
  border-color: var(--accent);
}

.join-form input::placeholder { color: var(--text-muted); }

/* ───── Player Game View ───── */
.player-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.player-header {
  background: var(--card);
  padding: 16px 16px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
  z-index: 1000;
  flex-shrink: 0;
}

.player-header .prompt {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-muted);
}

.player-header .prompt .team-target {
  display: block;
  color: var(--accent);
  font-weight: 900;
  font-size: 1.6rem;
  line-height: 1.2;
  text-align: center;
  margin-top: 2px;
}

.player-header .round-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

#player-map {
  flex: 1;
  z-index: 1;
}

.player-footer {
  background: var(--card);
  padding: 12px 16px;
  display: flex;
  justify-content: center;
  box-shadow: 0 -2px 12px rgba(0,0,0,.3);
  z-index: 1000;
  flex-shrink: 0;
}

.player-footer .btn { width: 100%; max-width: 400px; }

/* ───── Waiting Overlay ───── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,26,46,.92);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 16px;
}

body.light-theme .overlay {
  background: rgba(240,242,245,.92);
}

.overlay h2 { font-size: 1.6rem; font-weight: 800; }
.overlay p  { color: var(--text-muted); font-size: 1rem; }

.pulse-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.6); opacity: .4; }
}

/* ───── Results Overlay (Player) ───── */
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 360px;
  width: 100%;
}

/* #4: Result badge */
.result-badge {
  width: 48px;
  height: 48px;
  object-fit: contain;
  margin: 0 auto 12px;
  display: block;
}

.result-card .correct-label {
  color: var(--success);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.result-card .pl-team {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 16px;
}

.result-stat {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.result-stat:last-child { border-bottom: none; }

.result-stat .label { color: var(--text-muted); }
.result-stat .value { font-weight: 700; }
.result-stat .value.dist { color: var(--accent); }
.result-stat .value.pts  { color: var(--success); }

/* ── #13: Distance Feedback ── */
.distance-feedback {
  text-align: center;
  font-weight: 800;
  font-size: 1rem;
  padding: 8px 0;
  animation: feedbackPop .4s ease;
}

.feedback-great { color: #2ecc71; }
.feedback-good  { color: #27ae60; }
.feedback-ok    { color: #f39c12; }
.feedback-far   { color: #e74c3c; }

@keyframes feedbackPop {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* ───── Player Final Scores ───── */
.player-final {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  gap: 20px;
  text-align: center;
}

.player-final h2 {
  font-size: 2rem;
  font-weight: 900;
}

.your-rank {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
}

.your-score {
  font-size: 1.2rem;
  color: var(--text-muted);
}

/* ───── Leaflet Overrides ───── */
.leaflet-container {
  background: #1a1a2e;
}

.correct-marker {
  background: var(--success);
  border: 3px solid #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  box-shadow: 0 0 10px rgba(46,204,113,.6);
}

.guess-marker {
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  box-shadow: 0 0 8px rgba(233,69,96,.5);
}

/* ───── Buy Me a Coffee ───── */
.bmc-link {
  display: inline-block;
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .2s;
}

.bmc-link:hover {
  color: #ffdd00;
}

.bmc-link.bmc-flash {
  animation: bmcFlash 0.6s ease-in-out 5;
}

.player-final .bmc-link {
  font-size: 1.7rem;
}

.bmc-link.bmc-flash-forever {
  animation: bmcFlash 0.6s ease-in-out infinite;
}

@keyframes bmcFlash {
  0%, 100% { color: var(--text-muted); }
  50%      { color: #ffdd00; }
}

/* ───── Responsive ───── */
@media (max-width: 600px) {
  .landing h1 { font-size: 2rem; }
  .game-code { font-size: 1.8rem; letter-spacing: 4px; }
  .qr-section img { width: 200px; height: 200px; }
  .podium-bar { width: 80px; }
  .podium-bar.first  { height: 140px; }
  .podium-bar.second { height: 100px; }
  .podium-bar.third  { height: 80px; }
  #host-map, #spec-map { height: 300px; }
  .round-panels { flex-direction: column; }
  .container { padding: 12px; }
  .btn-lg { padding: 16px 32px; font-size: 1.05rem; }
  .host-controls { gap: 8px; }
  .host-controls .btn { padding: 10px 16px; font-size: 0.9rem; }
}
