/* =====================================================================
   G!RP – Erscheinungsbild nach Designvorgaben (05_design.md)
   Ruhige Weiß-/Grautöne, Schwarz für Text und Kontrast,
   genau EINE Neonfarbe (IU Blue) als Akzent – nie als Text auf Weiß.
   ===================================================================== */

:root {
  /* Primär */
  --iu-white: #FFFFFF;
  --iu-grey: #E1E1E1;          /* Linien, Rahmen, Trenner */
  --iu-light-grey: #F6F6F6;    /* Flächen, Seitenhintergrund */
  --iu-black: #1D1D1F;         /* Text, Headlines, primäre Buttons, Kopfleiste */
  --text-muted: #5A5A5E;       /* Labels, Nebentexte */

  /* Akzent */
  --iu-accent: #00F9FF;
  --iu-accent-light: #D2FAFB;

  /* Funktionsfarben (nur Status) */
  --status-error: #B3261E;
  --status-error-bg: #FBEAEA;
  --status-warning: #8A5A00;
  --status-warning-bg: #FFF4D6;
  --status-ok: #1E6B3A;
  --status-ok-bg: #E0FAD2;

  --radius: 12px;
  --radius-btn: 8px;
}

/* ---------- Grundlagen ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Source Sans 3', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--iu-light-grey);
  color: var(--iu-black);
  min-height: 100vh;
  overflow-x: hidden;
}

h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 18px; font-weight: 600; }

:focus-visible {
  outline: 2px solid var(--iu-black);
  outline-offset: 0;
  box-shadow: 0 0 0 6px var(--iu-accent);
}

.hidden { display: none !important; }

/* ---------- Icons (SVG-Sprite in index.html, ersetzt Emoji) ---------- */
.ic {
  width: 1.15em; height: 1.15em;
  flex: none;
  vertical-align: -0.2em;
  margin-right: .4em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn .ic, .ranking-filter-btn .ic { margin-right: 0; }
.pair-del-btn .ic { width: 18px; height: 18px; }
.nav-btn .ic { width: 18px; height: 18px; vertical-align: -0.22em; margin-right: 6px; }
.nav-btn.active .ic { stroke-width: 2; }
.race-date .ic { width: 15px; height: 15px; vertical-align: -0.15em; margin-right: 4px; }
.toast { display: flex; align-items: center; gap: 10px; width: max-content; }
.toast .ic { width: 20px; height: 20px; margin: 0; }

/* ---------- Kopfleiste ---------- */
.topbar {
  background: var(--iu-black);
  color: var(--iu-white);
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 500;
}
.topbar-inner {
  max-width: 860px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--iu-white);
  object-fit: cover;
}
.topbar-title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .short { display: none; }

.auth-btn {
  margin-left: auto;
  background: transparent;
  color: var(--iu-white);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: var(--radius-btn);
  padding: 6px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.auth-btn:hover { border-color: var(--iu-white); }

/* ---------- Seitenrahmen ---------- */
.container { max-width: 860px; margin: 0 auto; padding: 24px 16px; }

.header { margin-bottom: 20px; }
.header h1 {
  display: inline-block;
  background: var(--iu-black);
  color: var(--iu-white);
  font-size: 28px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  line-height: 1.1;
  padding: .35em .5em;
}
/* „The Line“ – kurz, 4° geneigt, nur dekorativ */
.header .the-line {
  width: 96px; height: 3px;
  background: var(--iu-grey);
  transform: rotate(-4deg);
  margin: 14px 0 10px 4px;
}
.header #tagline { color: var(--text-muted); font-size: 16px; }

/* ---------- Saison-Auswahl ---------- */
.season-bar { margin-top: 12px; }
.season-select {
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 8px 36px 8px 14px; border-radius: 999px;
  border: 1px solid var(--iu-black); background-color: var(--iu-white); color: var(--iu-black);
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--iu-black) 50%), linear-gradient(135deg, var(--iu-black) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
  max-width: 100%;
}
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--iu-accent-light); color: var(--iu-black); vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Navigation ---------- */
.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--iu-grey);
  margin-bottom: 20px;
}
.nav::-webkit-scrollbar { display: none; }

.nav-btn {
  background: transparent;
  border: none;
  border-bottom: 4px solid transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 15px;
  padding: 10px 12px 8px;
  white-space: nowrap;
  cursor: pointer;
}
.nav-btn:hover { color: var(--iu-black); }
.nav-btn.active { color: var(--iu-black); font-weight: 700; border-bottom-color: var(--iu-accent); }

.sub-nav { display: flex; gap: 8px; margin: 0 0 20px; }
.sub-tab {
  background: var(--iu-white);
  border: 1px solid var(--iu-grey);
  border-radius: 999px;
  color: var(--iu-black);
  font: inherit;
  font-size: 14px;
  padding: 6px 14px;
  cursor: pointer;
}
.sub-tab:hover { background: var(--iu-light-grey); }
.sub-tab.active { background: var(--iu-accent-light); border-color: var(--iu-black); font-weight: 600; }

/* ---------- Bereiche ---------- */
.section {
  display: none;
  background: var(--iu-white);
  border: 1px solid var(--iu-grey);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}
.section.active { display: block; }
.section > h2 { margin-bottom: 16px; }

.ranking-header {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--iu-grey);
}

.card {
  background: var(--iu-light-grey);
  border-radius: var(--radius);
  padding: 16px;
}

/* ---------- Formulare ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }

.form-group input,
.form-group select,
.modal-input,
.record-table select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--iu-grey);
  border-radius: var(--radius-btn);
  background: var(--iu-white);
  color: var(--iu-black);
  font: inherit;
  font-size: 16px;
}
.form-group input:focus,
.form-group select:focus,
.modal-input:focus { outline: 2px solid var(--iu-black); box-shadow: 0 0 0 6px var(--iu-accent-light); border-color: var(--iu-black); }
.modal-input { margin-bottom: 10px; }

input[type=range] { width: 100%; accent-color: var(--iu-black); }
input[type=checkbox] { accent-color: var(--iu-black); width: 16px; height: 16px; }

.input-button-group { display: flex; gap: 10px; align-items: stretch; }
.input-button-group input { flex: 1; }
.input-button-group .btn { margin: 0; }

/* ---------- Buttons ---------- */
/* Standard = sekundär: weiß mit grauem Rand */
.btn, .ranking-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  margin: 6px 4px;
  background: var(--iu-white);
  color: var(--iu-black);
  border: 1px solid var(--iu-grey);
  border-radius: var(--radius-btn);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover, .ranking-filter-btn:hover { background: var(--iu-light-grey); border-color: #C8C8C8; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* Primär: schwarz – nur einer je Ansicht */
.btn-primary { background: var(--iu-black); color: var(--iu-white); border-color: var(--iu-black); }
.btn-primary:hover { background: #000; border-color: #000; }

/* Destruktiv: sekundär mit Fehlerfarbe */
.btn-danger { color: var(--status-error); }
.btn-danger:hover { background: var(--status-error-bg); border-color: var(--status-error); }

.btn-small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-modal { min-height: 40px; }

/* ---------- Listen / Ranglisten ---------- */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--iu-grey);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--iu-white);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.list-item:hover { background: var(--iu-light-grey); }
.list-item .meta, .list-item div > div { color: var(--text-muted); font-size: 14px; }
.list-item.archived { opacity: .6; }

.elo-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--iu-light-grey);
  color: var(--iu-black);
  border-radius: 999px;
  padding: 2px 12px;
  white-space: nowrap;
}

.status-inactive { color: var(--text-muted); font-size: 13px; }

/* ---------- Podium ---------- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 12px; margin-bottom: 24px; }
.podium-item {
  flex: 1 1 0;
  max-width: 200px;
  text-align: center;
  padding: 16px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--iu-grey);
  background: var(--iu-light-grey);
  color: var(--iu-black);
  cursor: pointer;
}
.podium-item.first {
  background: var(--iu-black);
  color: var(--iu-white);
  border-color: var(--iu-black);
  border-top: 4px solid var(--iu-accent);
  padding-top: 24px;
}
.podium-position {
  width: 36px; height: 36px; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--iu-black);
  background: var(--iu-white);
  font-size: 18px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.podium-item.first .podium-position { background: var(--iu-accent); width: 42px; height: 42px; font-size: 21px; }
.podium-name { font-weight: 600; word-wrap: break-word; }
.podium-elo { font-weight: 700; font-variant-numeric: tabular-nums; }

@media (min-width: 601px) {
  .podium-item.first  { order: 2; }
  .podium-item.second { order: 1; }
  .podium-item.third  { order: 3; }
}

#driversRanking, #carsRanking { margin-top: 8px; }

/* ---------- Rennen erfassen ---------- */
.race-meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.race-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.race-actions .btn { margin: 0; }

.race-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
  padding: 12px;
  background: var(--iu-light-grey);
  border-radius: var(--radius);
}
.race-entry select { min-width: 120px; }

.pred { font-size: 12px; margin-top: 4px; white-space: nowrap; color: var(--text-muted); line-height: 1.2; }
.pred.posChange { color: var(--status-ok); }
.pred.negChange { color: var(--status-error); }

.pair-del-btn {
  background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 4px;
  margin-left: auto; align-self: center; order: 99;
}

/* ---------- Historie ---------- */
.race-history-item {
  border: 1px solid var(--iu-grey);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: var(--iu-white);
}
.race-date { font-size: 14px; color: var(--text-muted); font-weight: 600; }
.race-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 15px; font-variant-numeric: tabular-nums; }
.race-table td { padding: 2px 6px; vertical-align: top; }
/* Fahrer + Fahrzeug = ein Paar; Trennlinie nur zwischen den Paaren */
.race-table tbody.pair + tbody.pair tr.pair-driver td,
.race-table tbody.pair + tbody.pair td.pos { border-top: 1px solid var(--iu-grey); }
.race-table tr.pair-driver td { padding-top: 8px; }
.race-table tr.pair-car td { padding-bottom: 8px; color: var(--text-muted); font-size: 14px; }
.race-table td.pos { font-size: 20px; vertical-align: top; padding-top: 6px; }
.race-table td.pts { text-align: right; white-space: nowrap; }

.pos { width: 40px; text-align: right; font-weight: 700; }
.elo-up   { color: var(--status-ok); }
.elo-down { color: var(--status-error); }

/* ---------- Tabellen (Rekorde, Statistik, Paarungen) ---------- */
.record-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 15px; font-variant-numeric: tabular-nums; }
.record-table th, .record-table td { padding: 8px 10px; border-bottom: 1px solid var(--iu-grey); text-align: left; }
.record-table th { background: var(--iu-light-grey); font-weight: 600; font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.record-table tbody tr { cursor: pointer; }
.record-table tbody tr:hover { background: var(--iu-light-grey); }
#statsTableWrap { overflow-x: auto; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(29,29,31,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-content {
  background: var(--iu-white);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.modal-content h3 { margin-bottom: 12px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: -24px -24px 16px; padding: 12px 24px;
  background: var(--iu-black); color: var(--iu-white);
  border-radius: var(--radius) var(--radius) 0 0;
}
.mode-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  color: var(--iu-white); opacity: .75;
  font: inherit; font-size: 14px; padding: 4px 8px; cursor: pointer;
}
.mode-tab:hover { opacity: 1; }
.mode-tab.active { opacity: 1; font-weight: 700; border-bottom-color: var(--iu-accent); }

.stats-img { max-width: 200px; max-height: 200px; object-fit: contain; }

/* ---------- Glücksrad ---------- */
#wheelCanvas { border-radius: 50%; border: 4px solid var(--iu-black); display: block; margin: 24px auto 0; }
#wheelModal .modal-content { position: relative; }
#wheelModal .modal-content::after {
  content: ""; position: absolute; top: 70px; left: 50%;
  border-left: 12px solid transparent; border-right: 12px solid transparent; border-top: 24px solid var(--iu-black);
  transform: translateX(-50%); z-index: 10;
}
#powerBarWrap.power-wrap { background: var(--iu-grey); height: 8px; border-radius: 4px; margin: 12px 0; width: 100%; }
#powerBar.power-bar { background: var(--iu-black); height: 100%; width: 0; border-radius: 4px; transition: width .05s; box-shadow: 0 0 0 2px var(--iu-accent) inset; }
#spinBtn { user-select: none; -webkit-user-select: none; touch-action: none; }

/* ---------- Slotmachine ---------- */
.reel-wrap { display: flex; flex-direction: column; align-items: center; }
.reel { width: 120px; height: 360px; overflow: hidden; position: relative; border: 2px solid var(--iu-black); border-radius: var(--radius-btn); background: var(--iu-black); color: var(--iu-white); font-size: 14px; text-align: center; }
.reel-track { position: absolute; top: 0; left: 0; width: 100%; }
.reel-item { display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--iu-grey); font-size: 12px; padding: 6px 4px; text-align: center; }
.reel-item:nth-child(odd)  { background: var(--iu-black); color: var(--iu-white); }
.reel-item:nth-child(even) { background: var(--iu-white); color: var(--iu-black); }
.reel-start-btn, .reel-stop-btn { margin: 4px 0; }
/* gezogenes Fahrzeug je Walze – bleibt stehen, solange das Fenster offen ist */
.reel-result {
  width: 120px; min-height: 40px; margin: 4px 0;
  padding: 6px 8px; border-radius: var(--radius-btn);
  background: var(--iu-accent-light); border: 1px solid var(--iu-black);
  color: var(--iu-black); font-size: 13px; font-weight: 600; line-height: 1.25;
  text-align: center; display: flex; align-items: center; justify-content: center;
  overflow-wrap: anywhere;
}
.reel-item.reel-item-chosen { box-shadow: inset 0 0 0 3px var(--iu-accent); }
.reel-img { max-width: 90%; max-height: 90%; object-fit: contain; }
#slotReels { position: relative; }
#slotSelectLine { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); height: 3px; background: var(--iu-accent); box-shadow: 0 0 0 1px var(--iu-black); z-index: 20; pointer-events: none; }

/* ---------- Toasts ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--iu-black); color: var(--iu-white);
  padding: 12px 18px; border-radius: var(--radius-btn);
  font-size: 15px; white-space: pre-line; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 9999;
}
.toast.show { opacity: 1; }

/* ---------- Footer ---------- */
.site-footer { text-align: center; font-size: 13px; color: var(--text-muted); margin: 32px 16px 24px; line-height: 1.5; }

/* ---------- Utilities ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.muted { color: var(--text-muted); }
.empty-state { text-align: center; color: var(--text-muted); padding: 16px 0; }

/* aktiver Filter */
.ranking-filter-btn.filter-active { background: var(--iu-accent-light); border-color: var(--iu-black); }

/* ---------- Mobil ---------- */
@media (max-width: 600px) {
  .topbar-title .long { display: none; }
  .topbar-title .short { display: inline; }
  .header h1 { font-size: 22px; }
  .section { padding: 16px; }
  .race-entry { flex-direction: column; gap: 8px; }
  .race-entry .form-group { width: 100%; }
  .race-meta-grid { grid-template-columns: 1fr; }
  .input-button-group { flex-direction: column; }
  .podium { gap: 8px; }
  .podium-item { padding: 12px 6px; }
  .podium-item.first { order: 2; }
  .podium-item.second { order: 1; }
  .podium-item.third { order: 3; }
  .podium-position { width: 30px; height: 30px; font-size: 16px; }
  .podium-item.first .podium-position { width: 36px; height: 36px; font-size: 18px; }
  .podium-name { font-size: 14px; }
  .race-history-item > div:first-child { gap: 8px !important; }
  /* Historie: auf dem Handy nur neuer Wert + Änderung, mehr Platz für Namen */
  .race-table .old { display: none; }
  .race-table td.pos { width: 28px; font-size: 18px; padding-left: 0; }
  .race-history-item { padding: 12px; }
}
