:root {
  --bg: #101418;
  --bg2: #1a2027;
  --bg3: #232b34;
  --border: #2f3a45;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #34c759;
  --accent-dark: #248a3d;
  --danger: #e5484d;
  --gold: #f5c518;
}
* { box-sizing: border-box; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.err { color: var(--danger); min-height: 1.2em; font-size: .9rem; margin: .4rem 0; }
.hidden { display: none !important; }

/* Header / Layout */
header {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem;
  padding: .8rem 1.2rem; background: var(--bg2); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
nav { display: flex; gap: 1.1rem; flex-wrap: wrap; align-items: center; }
nav a { color: var(--muted); } nav a:hover { color: var(--text); }
main { width: 100%; margin: 0; padding: 1.2rem 2rem; }
footer { text-align: center; padding: 1.5rem; }
footer a { color: var(--muted); font-size: .85rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* Buttons & Forms */
button {
  background: var(--accent-dark); color: #fff; border: 0; border-radius: 8px;
  padding: .55rem 1.1rem; font-size: .95rem; cursor: pointer;
  /* Long-Press darf keine Textauswahl / kein Kontextmenü auslösen (Touch) */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--accent); color: #06280f; }
button:disabled { background: var(--bg3); color: var(--muted); cursor: not-allowed; }
button.secondary { background: var(--bg3); color: var(--text); }
button.secondary:hover { background: var(--border); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
.small-btn { padding: .3rem .6rem; font-size: .8rem; }
label { display: block; margin: .6rem 0; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dark); border-color: transparent; }
.row { display: flex; gap: 1rem; } .row > label { flex: 1; }
.row.wrap { flex-wrap: wrap; align-items: flex-end; }
.row-end { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }
label.check { display: flex; align-items: center; gap: .4rem; }
label.check input { width: auto; margin: 0; }

/* Login */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 1rem; }
.login-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 2rem; width: 100%; max-width: 380px;
}
.login-box h1 { text-align: center; margin-bottom: 1rem; }
.login-box button { width: 100%; margin-top: .5rem; }
.login-box p { text-align: center; margin-top: 1rem; }

/* Cards / Tags */
.card {
  display: block; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: .8rem; color: var(--text);
}
.t-card:hover { border-color: var(--accent-dark); }
.t-name { font-weight: 600; font-size: 1.05rem; }
.t-meta { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.tag { background: var(--bg3); border-radius: 20px; padding: .1rem .6rem; font-size: .75rem; }
.tag.done { background: var(--accent-dark); color: #fff; }
.tag.fun-tag { background: transparent; border: 1px solid var(--gold); color: var(--gold); vertical-align: middle; }
.champion {
  background: linear-gradient(90deg, #2a2413, var(--bg2)); border: 1px solid var(--gold);
  border-radius: 12px; padding: .8rem 1.2rem; margin-bottom: 1rem; font-size: 1.05rem;
}
.live-badge { color: var(--danger); font-size: .7rem; font-weight: 700; margin-left: .4rem; }
.match.live { border-color: var(--danger); }
.mrow.mturn { background: rgba(52, 199, 89, .12); }
.mlegs {
  display: inline-block; background: var(--accent-dark); color: #fff;
  border-radius: 6px; padding: 0 .4rem; margin-right: .4rem;
  font-weight: 700; font-variant-numeric: tabular-nums; min-width: 1.5em; text-align: center;
}
.live-note {
  background: var(--bg); border: 1px solid var(--danger); border-radius: 10px;
  padding: .8rem 1rem; margin-bottom: .8rem;
}
.live-note-score {
  display: flex; justify-content: center; align-items: baseline; gap: .8rem;
  margin: .5rem 0 .3rem; font-size: 1.1rem;
}
.live-note-score strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stats-badge {
  background: var(--bg3); color: var(--muted); border-radius: 8px;
  padding: 0 .4rem; font-size: .65rem; margin-left: .4rem; vertical-align: middle;
}
.modal-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.scorer-btn { background: var(--accent-dark); }
.chip-row { display: flex; gap: .6rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.chip {
  min-width: 64px; min-height: 56px; font-size: 1.3rem;
  background: var(--bg3); color: var(--text); border-radius: 10px;
}
.chip:hover, .chip.sel { background: var(--accent-dark); color: #fff; }
.chip[disabled] { opacity: .4; cursor: not-allowed; }

/* Bracket */
.bracket { display: flex; gap: 1.2rem; overflow-x: auto; padding: .5rem 0 1rem; }
.round-col { min-width: 210px; display: flex; flex-direction: column; }
.round-title {
  color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: .5rem; display: flex; align-items: center; gap: .3rem;
}
.bo-edit {
  background: var(--bg3); color: var(--muted); border: 1px solid var(--border);
  border-radius: 12px; padding: .05rem .5rem; font-size: .72rem; min-height: 0;
  text-transform: none; letter-spacing: 0;
}
.bo-edit:hover { color: var(--accent); border-color: var(--accent); background: var(--bg3); }
.bo-label { font-size: .72rem; text-transform: none; letter-spacing: 0; }
.round-matches { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: .7rem; }
.match {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; font-size: .92rem;
}
.match.editable { cursor: pointer; }
.match.editable:hover { border-color: var(--accent); }
.match.bye { opacity: .55; }
.mrow { display: flex; justify-content: space-between; padding: .4rem .7rem; }
.mrow + .mrow { border-top: 1px solid var(--border); }
.mrow.win { background: rgba(52, 199, 89, .12); }
.mrow.win .mname { color: var(--accent); font-weight: 600; }
.mscore { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 1.2em; text-align: right; }

/* Round Robin / Gruppen / Tabellen */
.rr-round { margin-bottom: 1rem; }
.rr-matches { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.standings { border-collapse: collapse; width: 100%; max-width: 560px; margin: .3rem 0 1rem; }
.standings th, .standings td { padding: .4rem .6rem; text-align: center; border-bottom: 1px solid var(--border); font-size: .9rem; }
.standings th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
.standings .left { text-align: left; } .standings .right { text-align: right; }
.standings tr.adv td { color: var(--accent); font-weight: 600; }
.standings tr.adv td:first-child { border-left: 3px solid var(--accent); }
.users-table { max-width: 720px; }
.role-select { width: auto; min-width: 150px; margin: 0; padding: .25rem .4rem; font-size: .85rem; }
details.group { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: .6rem 1rem; margin-bottom: .8rem; }
details.group summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.advance-box { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.stat-table td, .stat-wide td { font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.stat-wide { max-width: none; }
.stats-controls { display: flex; gap: .8rem; align-items: center; margin-bottom: 1.2rem; flex-wrap: wrap; }
.stats-controls select { width: auto; min-width: 220px; margin: 0; min-height: 44px; }
.lf-btn.sel { background: var(--accent-dark); color: #fff; }

/* Leg-Details in der Match-Statistik */
.leg-detail { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .4rem .8rem; margin: .4rem 0; }
.leg-detail summary { cursor: pointer; font-size: .95rem; padding: .2rem 0; }
.leg-visits { max-width: none; margin-top: .4rem; }
.leg-visits td, .leg-visits th { font-size: .95rem; padding: .3rem .5rem; }
.leg-visits .hd-cell { background: var(--bg3); color: var(--muted); }
.bust-cell { color: var(--danger); text-decoration: line-through; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
  display: flex; justify-content: center; align-items: center; padding: 1rem; z-index: 10;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 1.5rem; width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto;
}
.modal-box.wide { max-width: 96vw; width: 96vw; min-height: 80vh; }
.modal-box.wide .stat-table { max-width: 640px; font-size: 1.05rem; }
.modal-box.wide .stat-table th, .modal-box.wide .stat-table td { font-size: 1rem; padding: .45rem .7rem; }
.modal-box h2 { margin: 0 0 .8rem; }
.modal-box p { margin: .5rem 0; font-size: .9rem; }
.res-form .res-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .6rem 0; }
.res-form .res-row span { flex: 1; font-weight: 600; }
.res-form .res-row input { width: 90px; margin: 0; text-align: center; font-size: 1.2rem; }

/* Live-Ansicht: Kacheln, moderat vergrößert; Turnierfilter mit "Alle" */
.live-head-row { align-items: center; margin-bottom: .5rem; }
.live-head-row .stats-controls { margin: 0; }
.live-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr));
}
.live-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  padding: 1rem 1.2rem; max-width: 640px;
}
.live-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap; }
.live-board { font-weight: 700; color: var(--accent); font-size: 1.15rem; }
.live-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: .8rem;
  align-items: center; padding: .45rem .6rem; border-radius: 10px;
}
.live-row.turn { background: rgba(52, 199, 89, .1); }
.live-legsbox {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--accent-dark); color: #fff; border-radius: 10px;
  padding: .2rem .55rem; line-height: 1.1; min-width: 2.4em;
}
.live-legs-num { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.live-legs-label { font-size: .6rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.live-name {
  font-weight: 700; font-size: 1.25rem; min-width: 0;
  overflow-wrap: anywhere; word-break: break-word; hyphens: auto;
}
.live-row.turn .live-name::before { content: '🎯 '; }
.live-last { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 1.15rem; }
.live-rem {
  font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums;
  min-width: 2em; text-align: right; line-height: 1.05; white-space: nowrap;
}
.live-foot { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .85rem; margin-top: .6rem; flex-wrap: wrap; }

/* ============ Scorer (Layout nach Darts-Scorer-Vorlage) ============ */
.scorer {
  display: flex; flex-direction: column; min-height: 100vh;
  max-width: 760px; margin: 0 auto; padding: .6rem; position: relative;
  /* Im Scorer wird nichts markiert – verhindert Auswahl-Popups beim Long-Press */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.sc-top { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.sc-top button { min-height: 48px; }
#sc-full { min-width: 52px; font-size: 1.3rem; }
.sc-info { color: var(--muted); font-size: .85rem; text-align: center; }
.sc-switch {
  width: 100%; min-height: 54px; margin-top: .6rem; font-size: 1.15rem; font-weight: 700;
  background: var(--accent-dark); color: #fff; border-radius: 12px;
}
.sc-switch:hover { background: var(--accent); color: #06280f; }

/* Namensleiste */
.sc-namebar { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin-top: .6rem; }
.sc-ncell {
  background: var(--bg2); padding: .5rem .8rem; font-size: 1.25rem; font-weight: 700;
  border: 2px solid transparent; border-radius: 10px 10px 0 0; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-ncell.active { border-color: var(--accent); }

/* Score-Zeile: Rest | Legs | Rest */
.sc-scorerow { display: grid; grid-template-columns: 1fr auto 1fr; gap: 2px; align-items: stretch; }
.sc-remcell {
  background: var(--bg2); font-size: clamp(3.2rem, 12vw, 5.5rem); font-weight: 800;
  font-variant-numeric: tabular-nums; text-align: center; line-height: 1.1;
  border: 2px solid transparent; border-radius: 0 0 10px 10px; padding: .1rem .4rem;
}
.sc-remcell.active { border-color: var(--accent); }
.sc-legscell {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 .8rem; background: var(--bg2);
}
.sc-legscell span { color: var(--muted); font-size: .95rem; }
.sc-legscell strong { font-size: 1.7rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Ø-Zeile: Spiel / Leg / Best pro Spieler */
.sc-statsrow { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; margin-top: 2px; }
.sc-statgrp { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.sc-stat {
  background: var(--bg3); border-radius: 6px; text-align: center; padding: .25rem .2rem;
  line-height: 1.2;
}
.sc-stat span { display: block; color: var(--muted); font-size: .72rem; }
.sc-stat strong { font-size: .95rem; font-variant-numeric: tabular-nums; }

/* Aufnahmen-Verlauf: Score | Rest | Darts | Score | Rest, 501-Zeile zuerst.
   Bis zu 9 Zeilen im DOM; die Containerhöhe bestimmt die sichtbaren (min. 3+Start). */
.sc-history {
  display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
  gap: .15rem; margin: .5rem 0 .2rem; width: 100%;
  max-height: 9.6rem; flex: 1;
}
.sc-hrow {
  display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; gap: .8rem;
  align-items: center; font-size: 1.3rem; font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.sc-hrow span { text-align: right; }
.sc-hdarts {
  background: var(--bg3); color: var(--muted); border-radius: 6px;
  padding: 0 .55rem; min-width: 2.3em; text-align: center !important; font-size: 1.05rem;
}
.sc-hscore { color: var(--muted); }
.sc-hscore.bust { text-decoration: line-through; color: var(--danger); }
.sc-hrem { font-weight: 700; }

.sc-msg { min-height: 1.4em; text-align: center; font-size: 1.05rem; margin: .1rem 0; color: var(--gold); }
.sc-msg.err { color: var(--danger); font-weight: 600; }
.sc-msg.ok { color: var(--accent); font-weight: 600; }

/* Eingabe */
.sc-entry { margin-top: auto; }
.sc-disprow { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: stretch; }
.sc-display {
  flex: 1; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  font-size: 1.7rem; font-weight: 700; text-align: left; padding: .3rem .8rem;
  font-variant-numeric: tabular-nums; min-height: 1.6em; display: flex; align-items: center;
}
.sc-ph { color: var(--muted); font-weight: 400; font-size: 1.2rem; }
.sc-undobtn, .sc-restbtn {
  font-size: .8rem; background: var(--bg3); border-radius: 10px; padding: .3rem .7rem;
}
.sc-undobtn { color: var(--text); border: 1px solid var(--border); }
.sc-undobtn:hover { background: var(--border); color: var(--text); }
.sc-restbtn { color: var(--gold); border: 1px solid var(--gold); }
.sc-restbtn:hover { background: var(--gold); color: #1a1a1a; }

/* Unten: Schnellauswahl links (3 Spalten), Ziffernblock rechts */
.sc-bottom { display: grid; grid-template-columns: 1fr 1.15fr; gap: .6rem; }
.sc-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.sc-q {
  min-height: 56px; font-size: 1.15rem;
  background: var(--bg3); color: var(--text); border-radius: 10px;
}
.sc-q:hover { background: var(--accent-dark); color: #fff; }
.sc-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.sc-k { min-height: 56px; font-size: 1.5rem; background: var(--bg3); color: var(--text); border-radius: 10px; }
.sc-k:hover { background: var(--border); color: var(--text); }
.sc-back { background: #4a2a2a; font-size: 1.7rem; }
.sc-ok { background: var(--accent-dark); color: #fff; font-size: 1.7rem; }
.sc-ok:hover { background: var(--accent); color: #06280f; }
/* Ohne Eingabe: rote 0 – trägt direkt 0 Punkte ein (z. B. nach Überwerfen) */
.sc-ok.zero { background: var(--danger); color: #fff; font-weight: 800; }
.sc-ok.zero:hover { background: #c93b3f; color: #fff; }
.sc-k.finish-key {
  background: rgba(245, 197, 24, .18); border: 2px solid var(--gold); color: var(--gold);
  animation: fk-pulse 1.2s infinite;
}
@keyframes fk-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 197, 24, .4); }
  50% { box-shadow: 0 0 0 6px rgba(245, 197, 24, 0); }
}

/* Match-Ende-Overlay */
.sc-overlay {
  position: absolute; inset: 0; background: rgba(16, 20, 24, .92);
  display: flex; justify-content: center; align-items: center; border-radius: 14px; z-index: 5;
}
.sc-overlay-box { text-align: center; padding: 2rem; }
.sc-final { font-size: 3rem; font-weight: 800; margin: .5rem 0 1.5rem; }
.sc-overlay-btns { display: flex; flex-direction: column; gap: .8rem; }
.sc-overlay-btns button { min-height: 56px; font-size: 1.1rem; }

/* Große Displays: mehr Verlauf */
@media (min-height: 900px) { .sc-history { max-height: 16rem; } }
@media (min-width: 900px) { .scorer { max-width: 860px; } .sc-history { max-height: 13rem; } }

/* Kleine/flache Displays: kompakter, Verlauf mindestens 3 Zeilen + Start */
@media (max-width: 560px) {
  .sc-remcell { font-size: 15vw; }
  .sc-ncell { font-size: 1.05rem; padding: .35rem .5rem; }
  .sc-stat span { font-size: .62rem; }
  .sc-stat strong { font-size: .8rem; }
  .sc-hrow { font-size: 1.05rem; gap: .5rem; }
  .sc-history { max-height: 7.4rem; }
  .sc-q { min-height: 48px; font-size: 1rem; }
  .sc-k { min-height: 50px; font-size: 1.3rem; }
  .sc-display { font-size: 1.4rem; }
  .sc-top button { min-height: 44px; padding: .4rem .7rem; }
  .sc-switch { min-height: 48px; }
}
@media (max-height: 640px) {
  .sc-remcell { font-size: 2.8rem; }
  .sc-legscell strong { font-size: 1.2rem; }
  .sc-history { max-height: 6.4rem; }
  .sc-hrow { font-size: 1rem; }
  .sc-msg { min-height: 1.1em; font-size: .9rem; }
  .sc-k, .sc-q { min-height: 44px; }
  .sc-info { font-size: .72rem; }
}
@media (max-width: 380px) {
  .sc-quick { display: none; }
  .sc-bottom { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  main { padding: .8rem; }
  .row { flex-direction: column; gap: 0; }
  .live-grid { min-height: 0; grid-auto-rows: auto; }
}
