/* ══════════════════════════════════════════════════════════════════════════════
   GNADENLOS™ — UI-Basis
   Gemeinsames Bedien-Design für ALLE Oberflächen (Panel, Anmeldung,
   Registrierung, Feedback, Turniere, Login).

   Grundregel: Es darf nirgends ein natives, hell hinterlegtes Browser-Element
   sichtbar sein — kein weißes Eingabefeld, keine graue Checkbox, kein heller
   Spinner, keine helle Scrollbar.

   Farbneutral: Alles zieht sich seine Farben aus --ui-*-Tokens. Jede Seite
   darf die Tokens überschreiben (z. B. tournament.html auf Schwarz/Amber),
   ohne dass das Verhalten neu gebaut werden muss.

   Spezifität: Die Basis steht in :where() (Spezifität 0) — jede Seitenregel
   gewinnt. Nur Checkbox/Radio brauchen echte Spezifität, weil sonst
   `appearance:none` nicht greift.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Die Anwendung besitzt bewusst nur dieses eine dunkle Farbschema. `only`
     verhindert, dass Samsung Internet/Chromium den fertigen Dark-UI-Look bei
     aktivem System-Darkmode ein zweites Mal automatisch abdunkelt. */
  color-scheme: only dark;

  /* Tokens mit Rückfallwerten: greift auf die Panel-Palette zu, wenn vorhanden */
  --ui-field-bg:      var(--bg4, #0f1a38);
  --ui-field-bg-alt:  var(--bg2, #060b1a);
  --ui-field-border:  var(--border2, rgba(255,255,255,.08));
  --ui-field-text:    var(--text, #f1f5ff);
  --ui-field-muted:   var(--text3, #4a5a80);
  --ui-accent:        var(--accent, #7c3aed);
  --ui-accent-soft:   var(--accent-soft, rgba(124,58,237,.14));
  --ui-accent-line:   rgba(124,58,237,.45);
  --ui-danger:        var(--danger, #ef4444);
  --ui-radius:        var(--radius, 10px);
  --ui-track:         var(--bg5, #162045);

  /* Pfeil-Grafiken: als Token, weil eine data-URI keine CSS-Variable lesen
     kann. Wer eine andere Akzentfarbe hat, überschreibt diese zwei Zeilen
     (Farbe im SVG als %23RRGGBB einsetzen). */
  --ui-select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%23a78bfa' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --ui-number-arrows: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 18'%3E%3Cpath d='M2 7l4-4 4 4M2 11l4 4 4-4' fill='none' stroke='%236d7fae' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* ── Text-artige Eingaben + Textarea ──────────────────────────────────────── */
:where(
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]):not([type=submit]):not([type=button]),
  textarea
) {
  background: var(--ui-field-bg);
  border: 1px solid var(--ui-field-border);
  border-radius: var(--ui-radius);
  padding: 9px 13px;
  color: var(--ui-field-text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s, background-color .15s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
}
:where(input, textarea)::placeholder { color: var(--ui-field-muted); opacity: 1; }
:where(input, textarea):hover:not(:disabled):not(:focus) { border-color: var(--ui-accent-line); }
:where(input, textarea):focus {
  outline: none;
  border-color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-accent-soft);
}
:where(input, textarea, select):disabled {
  opacity: .5; cursor: not-allowed; background: var(--ui-field-bg-alt);
}
:where(textarea) { resize: vertical; line-height: 1.5; }

/* Chrome/Edge färben automatisch ausgefüllte Felder sonst weiß bis gelb */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--ui-field-text);
  -webkit-box-shadow: 0 0 0 60px var(--ui-field-bg) inset;
  box-shadow: 0 0 0 60px var(--ui-field-bg) inset;
  caret-color: var(--ui-field-text);
  border-color: var(--ui-field-border);
}

/* ── Auswahlfelder ────────────────────────────────────────────────────────── */
:where(select) {
  appearance: none; -webkit-appearance: none;
  background-color: var(--ui-field-bg);
  background-image: var(--ui-select-arrow);
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px 8px;
  border: 1px solid var(--ui-field-border);
  border-radius: 9px;
  color: var(--ui-field-text);
  padding: 9px 32px 9px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, background-color .15s;
}
:where(select):focus { outline: none; border-color: var(--ui-accent); box-shadow: 0 0 0 3px var(--ui-accent-soft); }
:where(select option)   { background: var(--ui-field-bg-alt); color: var(--ui-field-text); }
:where(select optgroup) { background: var(--ui-field-bg-alt); color: var(--ui-accent); font-weight: 700; }

/* ── Zahlenfelder: eigener Stepper statt heller Browser-Pfeile ───────────── */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
:where(input[type=number]) {
  background-image: var(--ui-number-arrows);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 15px;
  padding-right: 28px;
}

/* ── Checkbox & Radio ─────────────────────────────────────────────────────────
   Häkchenfarbe kommt aus --cb-color; je Element überschreibbar
   (z. B. style="--cb-color:#f59e0b"). */
input[type=checkbox],
input[type=radio] {
  appearance: none; -webkit-appearance: none;
  --cb-color: var(--ui-accent);
  width: 16px; height: 16px; min-width: 16px;
  flex: none;
  justify-self: start;
  /* padding muss explizit weg: Formular-Regeln vererben sonst Innenabstand und
     blähen das Kästchen mit box-sizing:border-box auf. */
  margin: 0; padding: 0;
  border: 1.5px solid var(--ui-accent-line);
  background: var(--ui-field-bg);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  vertical-align: -2px;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
input[type=checkbox] { border-radius: 5px; }
input[type=radio]    { border-radius: 50%; }
input[type=checkbox]:hover:not(:disabled),
input[type=radio]:hover:not(:disabled) { border-color: var(--cb-color); }
input[type=checkbox]:focus-visible,
input[type=radio]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ui-accent-soft); }
input[type=checkbox]:checked,
input[type=radio]:checked { background: var(--cb-color); border-color: var(--cb-color); }
input[type=checkbox]::before {
  content: ''; width: 9px; height: 9px; transform: scale(0);
  transition: transform .12s ease-out; background: #fff;
  clip-path: polygon(14% 44%, 0 65%, 38% 100%, 100% 22%, 82% 4%, 36% 62%);
}
input[type=checkbox]:checked::before { transform: scale(1); }
input[type=radio]::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: #fff; transform: scale(0); transition: transform .12s ease-out;
}
input[type=radio]:checked::before { transform: scale(1); }
input[type=checkbox]:disabled,
input[type=radio]:disabled { opacity: .45; cursor: not-allowed; }

/* ── Farbwähler ───────────────────────────────────────────────────────────── */
:where(input[type=color]) {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--ui-field-border); border-radius: 8px;
  background: var(--ui-field-bg); padding: 3px; cursor: pointer;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type=color]::-moz-color-swatch { border: none; border-radius: 5px; }

/* ── Datei-Auswahl ────────────────────────────────────────────────────────── */
:where(input[type=file]) {
  background: var(--ui-field-bg); border: 1px dashed var(--ui-accent-line);
  border-radius: var(--ui-radius); padding: 8px 12px; color: var(--ui-field-muted);
  font-size: 12px; cursor: pointer; width: 100%;
}
input[type=file]::file-selector-button {
  background: var(--ui-accent); color: #fff; border: none;
  border-radius: 7px; padding: 6px 12px; margin-right: 10px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
input[type=file]::file-selector-button:hover { filter: brightness(1.15); }

/* ── Schieberegler ────────────────────────────────────────────────────────── */
:where(input[type=range]) {
  appearance: none; -webkit-appearance: none;
  background: transparent; height: 18px; cursor: pointer; padding: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 99px; background: var(--ui-track); }
input[type=range]::-moz-range-track            { height: 5px; border-radius: 99px; background: var(--ui-track); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -4.5px;
  border-radius: 50%; background: var(--ui-accent); border: 2px solid #fff2;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border: 2px solid #fff2;
  border-radius: 50%; background: var(--ui-accent);
}

/* ── Suchfeld: natives Löschkreuz ist hell ───────────────────────────────── */
input[type=search]::-webkit-search-cancel-button {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; cursor: pointer; background: var(--ui-field-muted);
  clip-path: polygon(20% 0,50% 30%,80% 0,100% 20%,70% 50%,100% 80%,80% 100%,50% 70%,20% 100%,0 80%,30% 50%,0 20%);
}
input[type=search]::-webkit-search-cancel-button:hover { background: var(--ui-danger); }

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
* { scrollbar-color: var(--ui-track) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ui-track); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--ui-accent); }

/* ── Fortschritt ──────────────────────────────────────────────────────────── */
:where(progress) { accent-color: var(--ui-accent); }
