:root {
  /* Die App ist bewusst nur hell gestaltet. Ohne diese Deklaration dunkeln
     iOS-/Safari-Dark-Mode und Dark-Mode-Erweiterungen helle Flaechen (z. B.
     die Zaehltafel-Bodenleiste) mit den dunklen Markenfarben ein — dann
     wirkte die Leiste bordeaux, obwohl das CSS Weiss vorgibt. */
  color-scheme: light;

  --c-midnight: #320a28;
  --c-crimson: #511730;
  --c-reddish: #8e443d;
  --c-almond: #cb9173;
  --c-silk: #f5d0c5;

  /* Akzent für die MVP-Wahl — warmes Orange, das sich in die Bordeaux-Palette
     einfügt, aber klar heraussticht. */
  --c-mvp: #dd7a2b;
  --c-mvp-dark: #c1651c;

  --c-bg: #faeae3;
  --c-surface: #ffffff;
  --c-surface-2: #fff6f1;
  --c-text: #2a0a1f;
  --c-muted: #7a5a5a;
  --c-border: #ead2c8;

  --shadow-sm: 0 1px 2px rgba(50, 10, 40, 0.06);
  --shadow-md: 0 6px 24px rgba(50, 10, 40, 0.10);
  --shadow-lg: 0 16px 40px rgba(50, 10, 40, 0.14);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font-sans: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* ── Custom-Scrollbars im Farbschema (überall, wo gescrollt wird) ──
   Firefox: scrollbar-width/-color. WebKit/Blink (Chrome/Edge/Opera/Safari):
   ::-webkit-scrollbar. Thumb = Almond, beim Hover kräftiger (Reddish). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--c-almond) transparent;
}
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--c-almond);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--c-reddish); }
*::-webkit-scrollbar-corner { background: transparent; }

/* Material Symbols (Google Fonts) — einfarbige Icons, nehmen die
   Schriftgröße + Farbe (color) ihres Containers an. */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  vertical-align: middle;
  user-select: none;
}
/* Inline-Icon vor/neben Text (z.B. in Buttons): an die Textgröße
   angepasst, mit kleinem Abstand. */
.micon {
  font-size: 1.15em;
  vertical-align: -0.16em;
}
.micon + * , * + .micon { /* kleiner Abstand zum Text */ }
.btn .micon, button .micon { margin-right: 0.3em; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  /* Kein Gummiband-Overscroll am Handy — sonst blitzt an oberem/unterem Rand
     beim Weiterscrollen der andersfarbige Hintergrund als Streifen auf. */
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1200px 600px at 100% 0%, rgba(203,145,115,0.25), transparent 70%),
    radial-gradient(900px 500px at 0% 100%, rgba(81,23,48,0.10), transparent 70%),
    var(--c-bg);
  /* dvh statt vh: am Handy ist 100vh die GROSSE Viewport-Höhe (ohne Toolbar),
     dadurch war der Body höher als sichtbar und unten blitzte der Hintergrund
     als Streifen auf. 100dvh folgt der tatsächlich sichtbaren Höhe. */
  min-height: 100vh;
  min-height: 100dvh;
}

h1, h2, h3, h4 {
  color: var(--c-midnight);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

a {
  color: var(--c-reddish);
  text-decoration: none;
}
a:hover { color: var(--c-crimson); }

button, .btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  /* Alle Buttons sind vollstaendig selbst gestylt — die native Darstellung ist
     nie erwuenscht. Ohne diesen Reset benutzt iOS Safari sie trotzdem, und im
     DUNKELMODUS ist sie dunkel: bei Buttons mit transparentem Hintergrund
     (Ghost-Buttons, "Trennen", die Zaehltafel-Peek-Leiste) schlaegt sie durch
     und faerbt die Flaeche dunkel, obwohl das CSS hell vorgibt. */
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.05s ease, background 0.15s ease, color 0.15s ease, border 0.15s ease, box-shadow 0.15s ease;
  background: var(--c-midnight);
  color: var(--c-silk);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
/* Der generische Hover-Fill NUR auf Geraeten mit echtem Zeiger. Auf Touch
   bleibt :hover nach einem Tipp haengen (iOS), und weil button:hover (0,1,1)
   spezifischer ist als eine Klasse wie .drawer-peek oder .team-panel (0,1,0),
   uebermalt er deren eigenen Hintergrund dauerhaft dunkelrot — genau das liess
   die Zaehltafel-Leiste nach einem Tipp dunkel haengen. */
@media (hover: hover) and (pointer: fine) {
  button:hover, .btn:hover {
    background: var(--c-crimson);
  }
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--c-almond);
  color: var(--c-midnight);
}
.btn-primary:hover {
  background: var(--c-reddish);
  color: var(--c-silk);
}
.btn-ghost {
  background: transparent;
  color: var(--c-midnight);
  border: 1px solid var(--c-border);
}
.btn-ghost:hover {
  background: var(--c-silk);
  border-color: var(--c-almond);
}
.btn-danger {
  background: var(--c-reddish);
  color: var(--c-silk);
}
.btn-danger:hover { background: var(--c-crimson); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  outline: none;
  width: 100%;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--c-almond);
  box-shadow: 0 0 0 3px rgba(203, 145, 115, 0.25);
}

/* Passwort-Feld mit Anzeigen/Verbergen-Umschalter rechts im Feld. */
.pw-field {
  position: relative;
  width: 100%;
}
.pw-field input {
  padding-right: 46px;
}
.pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--c-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* Wichtig: den generischen button:hover (crimson-Fill) hier zuruecknehmen —
   sonst sitzt das dunkle Auge-Icon auf dunklem crimson und verschwindet. Der
   Umschalter liegt im Feld, ein Farbblock waere ohnehin falsch. Feedback nur
   ueber das Abdunkeln des Icons. */
.pw-toggle:hover { background: transparent; color: var(--c-midnight); }
.pw-toggle .material-symbols-outlined { font-size: 1.35rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--c-crimson);
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  margin: 0 0 6px;
  font-weight: 700;
}

.stat {
  font-size: 2rem;
  font-weight: 700;
  color: var(--c-midnight);
  letter-spacing: -0.02em;
}

.tag {
  display: inline-block;
  background: var(--c-silk);
  color: var(--c-crimson);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.tag-dark {
  background: var(--c-midnight);
  color: var(--c-silk);
}
.tag-accent {
  background: var(--c-almond);
  color: var(--c-midnight);
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-almond);
  box-shadow: 0 0 0 0 rgba(203, 145, 115, 0.7);
  animation: pulse 1.6s infinite;
  vertical-align: middle;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(203, 145, 115, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(203, 145, 115, 0); }
  100% { box-shadow: 0 0 0 0 rgba(203, 145, 115, 0); }
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--c-silk);
  border-top-color: var(--c-reddish);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: rgba(142, 68, 61, 0.10);
  color: var(--c-crimson);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(142, 68, 61, 0.2);
  font-size: 0.92rem;
}
.success {
  background: rgba(203, 145, 115, 0.15);
  color: var(--c-crimson);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(203, 145, 115, 0.3);
  font-size: 0.92rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
}
th {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-muted);
}
tbody tr:hover { background: var(--c-surface-2); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--c-muted);
}

/* ── Code-Eingabe: ein Kästchen je Ziffer ────────────────────────────────
   Gemeinsam für Turnierseite, Zähltafel und Streaming. Die Kästchen dürfen
   schrumpfen (min-width: 0 + flexibler Anteil), sonst laufen sechs Stück auf
   einem 320-px-Handy aus dem Feld. */
.code-input {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
}
/* Zwei Klassen (0,2,0), damit diese Regeln seitenspezifische Input-Regeln
   schlagen. Konkret setzt score.css für „.score-pair input" ein einseitiges
   padding-left: 0.5em samt letter-spacing: 0.5em — beides Ausgleich für das
   frühere EINE Feld mit sechs Zeichen. In einem Kästchen mit genau einer
   Ziffer schiebt es den Inhalt und damit den Schreibzeiger aus der Mitte. */
.code-input .code-digit {
  padding: 0;
  letter-spacing: normal;
  text-align: center;
}
.code-digit {
  flex: 1 1 0;
  min-width: 0;
  max-width: 56px;
  aspect-ratio: 3 / 4;
  padding: 0;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  /* Dieselbe Farbe wie die Umrandung des Kästchens, in dem man gerade steht
     (.code-digit:focus weiter unten) — Ziffern und Rahmen gehören zusammen. */
  color: var(--c-reddish);
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: 10px;
  /* Der Zeiger sitzt sonst je nach Browser oben statt mittig. */
  line-height: 1;
  /* Schreibzeiger in der Randfarbe statt Schwarz — er gehört zum Kästchen,
     nicht zum Text. Mittig steht er von allein, solange kein Placeholder
     dagegenhält (siehe klassenSetzen in api.js). */
  caret-color: var(--c-almond);
}
.code-digit:focus {
  outline: none;
  border-color: var(--c-reddish);
  box-shadow: 0 0 0 3px rgba(142, 68, 61, 0.18);
}
/* Ein gefülltes Kästchen hebt sich ab, damit man den Fortschritt sieht. */
.code-digit.gefuellt { border-color: var(--c-almond); }
@media (max-width: 360px) {
  .code-input { gap: 5px; }
  .code-digit { font-size: 1.3rem; }
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-midnight);
  color: var(--c-silk);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

.admin-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 360px;
  width: calc(100vw - 48px);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-almond);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  outline: none;
}
.admin-notification.show {
  opacity: 1;
  transform: translateY(0);
}
.admin-notification:hover {
  border-color: var(--c-almond);
  box-shadow: 0 12px 30px rgba(50, 10, 40, 0.20);
}
.admin-notification .notif-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-notification .notif-badge {
  background: var(--c-almond);
  color: var(--c-midnight);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.admin-notification .notif-title {
  font-weight: 800;
  color: var(--c-midnight);
  font-size: 0.95rem;
}
.admin-notification .notif-msg {
  color: var(--c-text);
  font-size: 0.92rem;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.admin-notification .notif-hint {
  margin-top: 8px;
  color: var(--c-muted);
  font-size: 0.78rem;
  font-style: italic;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(50, 10, 40, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform 0.18s ease;
  max-height: 90vh;
  overflow-y: auto;
}
/* Niedriger Viewport — Handy im Querformat, oder Hochformat mit offenem
   Datums-Picker bzw. Tastatur. Dort sind 90vh abzüglich 2×28px Innenabstand
   so wenig, dass schon ein normaler Dialog vertikal zu scrollen anfängt.
   Enger schneiden ist hier besser, als die Texte für alle zu kürzen. */
@media (max-height: 460px) {
  .modal { padding: 16px 18px; max-height: 96vh; }
  .modal .actions { margin-top: 12px; }
}
.modal-backdrop.show .modal { transform: translateY(0); }
.modal h2 { margin-top: 0; }
.modal .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}
.modal .actions button {
  min-width: 110px;
  justify-content: center;
}
/* Schmales Display: die Knöpfe teilen sich die Zeile, statt umzubrechen.
   Bei drei Möglichkeiten (z. B. Abbrechen · Behalten · Einbeziehen) bleiben
   sonst nur ~90px pro Knopf — dafür müssen Mindestbreite, Polsterung und
   Schrift zurückgenommen werden, sonst rutscht der dritte in die zweite
   Zeile und sieht aus, als gehöre er nicht dazu. */
@media (max-width: 460px) {
  /* Nur der SEITLICHE Innenabstand wird knapper — das schafft rund 20px mehr
     Breite für die Knopfreihe. Oben/unten bleibt unangetastet, sonst geriete
     die Regel mit der Höhen-Media-Query weiter oben in Konflikt. */
  .modal {
    padding-left: 18px;
    padding-right: 18px;
  }
  .modal .actions {
    flex-wrap: nowrap;
    gap: 6px;
  }
  .modal .actions button {
    min-width: 0;
    flex: 1 1 0;
    /* Hoch genug zum sicheren Treffen mit dem Daumen (~45px). */
    padding: 13px 8px;
    font-size: 0.875rem;
    /* Bewusst KEIN white-space: nowrap: auf sehr schmalen Geräten (320px)
       passt „Einbeziehen" sonst nicht und würde abgeschnitten. Trennen darf
       der Browser auch innerhalb des Wortes — aber mit break-word, NICHT mit
       anywhere: „anywhere" verändert zusätzlich die Mindestbreiten-Berechnung,
       wodurch die Flex-Knöpfe schon umbrechen, obwohl der Text noch passt
       (gemessen: 62px hohe Knöpfe statt 45px bei 375px Breite). */
    overflow-wrap: break-word;
    line-height: 1.2;
  }
}
.modal .field { margin-bottom: 14px; }
.modal .field:last-of-type { margin-bottom: 0; }

.modal-team-head {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.modal-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.modal-chip-list .player-chip {
  background: var(--c-silk);
  color: var(--c-crimson);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: default;
}
.team-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.stat-tile {
  background: var(--c-silk);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat-tile-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--c-midnight);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-tile-label {
  font-size: 0.74rem;
  color: var(--c-crimson);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.clickable-team {
  cursor: pointer;
  border-bottom: 1px dotted transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.clickable-team:hover {
  border-bottom-color: var(--c-reddish);
  color: var(--c-reddish);
}

/* Konto-Avatar (Kreis mit Initiale) — oben rechts in Dashboard und Cockpit. */
.account-avatar {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--c-crimson);
  color: var(--c-silk);
  border: none;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s ease, transform 0.05s ease;
  -webkit-tap-highlight-color: transparent;
}
.account-avatar:hover { background: var(--c-midnight); }
.account-avatar:active { transform: scale(0.96); }
