/* Bierkastenrennen — shared styles */

:root {
  --bg:           #1a1410;
  --bg-card:      #231a12;
  --bg-card-hover:#2d2016;
  --text:         #f4ead5;
  --text-dim:     #b9a98a;
  --accent:       #f6c453;
  --accent-dark:  #c79932;
  --danger:       #e63946;
  --success:      #4caf50;
  --border:       #3a2c1e;
  --shadow:       0 4px 20px rgba(0,0,0,.5);
  --topbar-height: 68px;

  /* 4px spacing scale */
  --sp1: 4px; --sp2: 8px; --sp3: 12px; --sp4: 16px;
  --sp5: 20px; --sp6: 24px; --sp7: 28px; --sp8: 32px; --sp10: 40px;

  /* Typography */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(246,196,83,.08), transparent 40%),
    radial-gradient(circle at 80% 100%, rgba(230,57,70,.06), transparent 40%),
    var(--bg);
}

/* ---------- Header ---------- */
header.topbar {
  background: linear-gradient(135deg, #2a2018 0%, #1a1410 100%);
  border-bottom: 2px solid var(--accent-dark);
  padding: var(--sp3) var(--sp5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp3);
  position: sticky;
  top: 0;
  z-index: 100;
}

header.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--sp2);
}

header.topbar h1 .emoji { font-size: 24px; }
header.topbar h1 .edition {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(255,255,255,.06);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

nav.tabs { display: flex; gap: var(--sp1); flex-wrap: wrap; }

nav.tabs a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.15s;
}
nav.tabs a:hover { color: var(--text); background: rgba(255,255,255,.05); }
nav.tabs a.active { color: var(--bg); background: var(--accent); font-weight: 600; }

/* Race status pill */
.race-status {
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  gap: 6px;
}
.race-status.live    { background: var(--danger); color: white; border: none; }
.race-status.notstarted { color: var(--text-dim); }
.race-status.finished   { background: var(--success); color: white; border: none; }

/* Pulsing live dot */
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: white;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.8); }
}
@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50%       { opacity: .6; }
}

/* ---------- Layout ---------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--sp5);
}

.grid { display: grid; gap: var(--sp5); grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 3fr 2fr; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: var(--sp5);
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 var(--sp4) 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: var(--sp2);
}

.card h3 {
  margin: var(--sp3) 0 var(--sp2);
  font-size: 15px;
  color: var(--text);
}

/* ---------- Leaderboard ---------- */
table.leaderboard {
  width: 100%;
  border-collapse: collapse;
}

table.leaderboard th, table.leaderboard td {
  text-align: left;
  padding: 10px var(--sp2);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

table.leaderboard th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  font-weight: 600;
}

/* Rank badges */
table.leaderboard tr.rank-1 td:first-child { font-weight: 800; }
table.leaderboard tr.rank-2 td:first-child { font-weight: 700; }
table.leaderboard tr.rank-3 td:first-child { font-weight: 700; }

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
}
.rank-badge.gold   { background: linear-gradient(135deg,#ffd700,#b8860b); color: #1a1410; }
.rank-badge.silver { background: linear-gradient(135deg,#c0c0c0,#808080); color: #1a1410; }
.rank-badge.bronze { background: linear-gradient(135deg,#cd7f32,#8b4513); color: #fff; }
.rank-badge.other  { background: rgba(255,255,255,.08); color: var(--text-dim); }

/* Rank change animation */
table.leaderboard tr {
  transition: background 0.3s ease;
}
table.leaderboard tr.rank-moved-up {
  animation: rank-up 0.6s ease;
}
@keyframes rank-up {
  0%   { background: rgba(76,175,80,.25); }
  100% { background: transparent; }
}

.team-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp2);
}
.team-pill .swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,.06);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
  min-width: 50px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}
/* Shimmer when station is active */
.progress-bar.active > div {
  background-image: linear-gradient(90deg, var(--accent) 0%, #fff9c4 50%, var(--accent) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% center; }
  100% { background-position: -200% center; }
}

/* ---------- Station cards ---------- */
.station-list { display: grid; gap: var(--sp3); }
.station-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp4);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp4);
  align-items: start;
  transition: border-color 0.2s;
}
.station-card:hover { border-color: rgba(246,196,83,.3); }

.station-card .station-icon {
  font-size: 28px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(246,196,83,.1);
  border-radius: 50%;
  flex-shrink: 0;
}
.station-card h3 { margin: 0 0 var(--sp1); font-size: 15px; }
.station-card .meta { font-size: 12px; color: var(--text-dim); margin-bottom: var(--sp2); }
.station-card .game-name {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: var(--sp2);
}
.station-card p { margin: var(--sp2) 0; font-size: 14px; line-height: 1.5; }
.station-card details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  padding: var(--sp2) 0;
  list-style: none;
  user-select: none;
}
.station-card details summary::before { content: '▶ '; font-size: 10px; }
.station-card details[open] summary::before { content: '▼ '; }
.station-card details .rules {
  font-size: 13px;
  background: rgba(0,0,0,.3);
  padding: var(--sp2) var(--sp3);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  margin-top: var(--sp2);
}
.station-card .scoring {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: var(--sp2);
}

/* Tappable station card (team view) */
.station-card.tappable { cursor: pointer; }
.station-card.tappable:active { transform: scale(.98); }

/* ---------- Map ---------- */
#map {
  width: 100%;
  height: 360px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* ---------- Forms / Buttons ---------- */
button, .btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.05s, background 0.15s;
}
button:hover  { background: var(--accent-dark); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--bg-card-hover); color: var(--text); border: 1px solid var(--border); }
button.danger    { background: var(--danger); color: white; }
button.full      { width: 100%; }
button:disabled  { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  background: rgba(0,0,0,.3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font-body);
  width: 100%;
  min-height: 48px;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(246,196,83,.15);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: var(--sp1);
  margin-top: var(--sp3);
}

.form-row { display: grid; gap: var(--sp2); grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- Timer ---------- */
.timer {
  font-size: 52px;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  padding: var(--sp4) 0;
  font-family: var(--font-mono);
}
.timer.small     { font-size: 22px; }
.timer.countdown { color: var(--danger); }

/* ---------- Station status badges ---------- */
.station-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-pending { background: rgba(255,255,255,.08); color: var(--text-dim); }
.status-active  { background: var(--danger); color: white; animation: pulse-badge 1.4s ease-in-out infinite; }
.status-done    { background: var(--success); color: white; }

/* ---------- Team dashboard specific ---------- */
.team-stripe {
  height: 5px;
  border-radius: 14px 14px 0 0;
  margin: calc(-1 * var(--sp5)) calc(-1 * var(--sp5)) var(--sp4);
}

/* Login: team grid */
.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--sp2);
  margin-bottom: var(--sp4);
}
.team-grid button {
  text-align: left;
  background: var(--bg-card-hover);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: var(--sp4);
  color: var(--text);
  min-height: 64px;
}
.team-grid button.selected {
  border-color: var(--accent);
  background: rgba(246,196,83,.12);
}
.team-grid button .swatch {
  width: 16px; height: 16px; border-radius: 4px;
  display: inline-block; margin-right: var(--sp2);
  vertical-align: middle;
}

/* Collapsible other-teams section */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.collapsible-header::after {
  content: '▼';
  font-size: 11px;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.collapsible-header.collapsed::after { transform: rotate(-90deg); }

/* Fullscreen modal on mobile */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: var(--sp5);
  }
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: var(--sp6);
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-width: 600px) {
  .modal-box {
    max-width: 520px;
    border-radius: 14px;
    max-height: 85vh;
  }
}
.modal-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto var(--sp5);
}
@media (min-width: 600px) { .modal-handle { display: none; } }

/* ---------- Login card ---------- */
.login-card {
  max-width: 440px;
  margin: var(--sp10) auto;
}

/* ---------- Loading spinner ---------- */
.loading-spinner {
  text-align: center;
  font-size: 32px;
  padding: var(--sp8);
  animation: spin 1.2s linear infinite;
  display: inline-block;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ---------- Info banner ---------- */
.info-banner {
  background: rgba(246,196,83,.1);
  border: 1px solid rgba(246,196,83,.25);
  border-radius: 10px;
  padding: var(--sp3) var(--sp4);
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: var(--sp4);
  display: flex;
  gap: var(--sp2);
  align-items: center;
}

/* ---------- TV Mode ---------- */
body.tv-mode {
  overflow: hidden;
  height: 100vh;
}
body.tv-mode header.topbar {
  padding: var(--sp4) var(--sp8);
}
body.tv-mode header.topbar h1 { font-size: 26px; }
body.tv-mode header.topbar h1 .emoji { font-size: 34px; }
body.tv-mode nav.tabs { display: none; }
body.tv-mode main {
  max-width: 100%;
  padding: var(--sp5) var(--sp8);
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
}
body.tv-mode .grid.two {
  grid-template-columns: 3fr 2fr;
  height: 100%;
}
body.tv-mode .card { height: 100%; overflow: hidden; }
body.tv-mode #map { height: calc(100% - 60px); }
body.tv-mode table.leaderboard th,
body.tv-mode table.leaderboard td { font-size: 18px; padding: 14px var(--sp3); }
body.tv-mode table.leaderboard th { font-size: 13px; }
body.tv-mode .rank-badge { width: 36px; height: 36px; font-size: 16px; }
body.tv-mode .team-pill { font-size: 18px; gap: var(--sp2); }
body.tv-mode .team-pill .swatch { width: 16px; height: 16px; }
body.tv-mode .progress-bar { min-width: 80px; height: 8px; }
body.tv-mode footer.foot { display: none; }
body.tv-mode #station-progress { display: none; }

/* TV last-updated ticker */
#tv-ticker {
  display: none;
  position: fixed;
  bottom: var(--sp3);
  right: var(--sp4);
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0,0,0,.4);
  padding: 4px 10px;
  border-radius: 999px;
}
body.tv-mode #tv-ticker { display: block; }

/* ---------- Error message ---------- */
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: var(--sp2);
  min-height: 18px;
}

/* ---------- Utilities ---------- */
.muted   { color: var(--text-dim); }
.right   { text-align: right; }
.center  { text-align: center; }
.spaced > * + * { margin-top: var(--sp3); }
.tiny    { font-size: 12px; }
.bold    { font-weight: 700; }
.hidden  { display: none !important; }
.flex    { display: flex; }
.flex.between { justify-content: space-between; align-items: center; }
.flex.gap { gap: var(--sp2); }

footer.foot {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: var(--sp8) var(--sp3) var(--sp10);
}

/* ---------- LOS Overlay (team view) ---------- */
.los-overlay {
  position: fixed;
  inset: 0;
  background: var(--success);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: los-appear 0.3s ease;
}
.los-overlay .los-text {
  font-size: clamp(80px, 20vw, 160px);
  font-weight: 800;
  color: white;
  text-align: center;
  line-height: 1;
}
@keyframes los-appear {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- TV next-start ---------- */
#tv-next-start {
  display: none;
  font-size: 15px;
  font-weight: 600;
  padding: var(--sp2) var(--sp4);
  background: rgba(255,255,255,.06);
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
body.tv-mode #tv-next-start { display: inline-flex; align-items: center; gap: var(--sp2); }

/* TV LOS overlay */
.tv-los-overlay {
  position: fixed;
  inset: 0;
  background: rgba(76,175,80,.93);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(60px, 10vw, 110px);
  font-weight: 800;
  color: white;
  animation: los-appear 0.3s ease;
}

/* ---------- Podium ---------- */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--sp5);
  padding: var(--sp6) 0 var(--sp4);
  flex-wrap: wrap;
}
.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp3);
  min-width: 100px;
}
.podium-place .pedestal {
  width: 110px;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: #1a1410;
}
.podium-place.first  .pedestal { height: 150px; background: linear-gradient(135deg,#ffd700,#b8860b); }
.podium-place.second .pedestal { height: 110px; background: linear-gradient(135deg,#c0c0c0,#808080); }
.podium-place.third  .pedestal { height: 80px;  background: linear-gradient(135deg,#cd7f32,#8b4513); color: white; }
.podium-place .podium-name  { font-size: 16px; font-weight: 700; text-align: center; }
.podium-place .podium-pts   { font-size: 13px; color: var(--text-dim); }

/* ---------- Station reveal animation ---------- */
.station-card.revealed {
  animation: station-reveal 0.8s ease;
}
@keyframes station-reveal {
  0%   { background: rgba(76,175,80,.35); box-shadow: 0 0 20px rgba(76,175,80,.4); }
  100% { background: var(--bg-card); box-shadow: var(--shadow); }
}

/* ---------- Heatmap table ---------- */
.heatmap-wrap { overflow-x: auto; }
.heatmap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 500px;
}
.heatmap-table th, .heatmap-table td {
  padding: var(--sp2) 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
.heatmap-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.heatmap-table td:first-child { text-align: left; font-weight: 600; }
.heatmap-table td.heat-best  { background: rgba(76,175,80,.25); color: #4caf50; font-weight: 700; }
.heatmap-table td.heat-worst { background: rgba(230,57,70,.2);  color: #e63946; }
.heatmap-table td.heat-mid   { background: rgba(246,196,83,.08); }

/* ---------- Stats summary ---------- */
.stats-badges { display: flex; flex-wrap: wrap; gap: var(--sp3); margin-top: var(--sp4); }
.stats-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp2);
  padding: var(--sp3) var(--sp4);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.stats-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-top: var(--sp3);
}
.stats-summary-table th, .stats-summary-table td {
  padding: var(--sp2) var(--sp3);
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.stats-summary-table th { font-size: 11px; text-transform: uppercase; color: var(--text-dim); font-weight: 600; }
.stats-summary-table td:first-child { text-align: left; }

/* ---------- Zieleinlauf admin ---------- */
.zieleinlauf-row {
  display: grid;
  grid-template-columns: auto 1fr 90px auto 90px auto;
  align-items: center;
  gap: var(--sp3);
  padding: var(--sp3) 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.zieleinlauf-row:last-child { border-bottom: none; }
.zieleinlauf-row input[type="number"] { min-height: 40px; }
.zieleinlauf-row .penalty-preview { font-size: 13px; color: var(--danger); font-weight: 600; }
.zieleinlauf-row .arrival-bonus  { font-size: 13px; color: var(--success); font-weight: 600; }
.zieleinlauf-row .confirmed { color: var(--success); font-weight: 700; font-size: 14px; }
@media (max-width: 700px) {
  .zieleinlauf-row { grid-template-columns: auto 1fr; }
}

/* ---------- Dynamic scoring form ---------- */
.scoring-form { margin-top: var(--sp3); }
.scoring-form .player-row {
  display: flex;
  align-items: center;
  gap: var(--sp3);
  padding: var(--sp2) 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.scoring-form .player-row:last-child { border-bottom: none; }
.scoring-form .player-name { font-weight: 600; min-width: 80px; }
.scoring-form .player-pts-preview { font-size: 13px; color: var(--accent); font-weight: 700; min-width: 60px; text-align: right; }
.scoring-form .task-row { display: flex; align-items: center; gap: var(--sp3); padding: var(--sp2) 0; }
.scoring-form .task-row label { cursor: pointer; flex: 1; }
#modal-points-preview {
  margin-top: var(--sp3);
  padding: var(--sp3) var(--sp4);
  background: rgba(246,196,83,.12);
  border: 1px solid rgba(246,196,83,.3);
  border-radius: 10px;
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
}
#modal-points-preview .breakdown { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-top: 4px; }
