:root {
  --bg: #0e1116;
  --bg-2: #151b24;
  --card: #1b232e;
  --card-2: #222c39;
  --line: #2b3645;
  --txt: #eef3f9;
  --muted: #8c9bb0;
  --accent: #ff5a3c;
  --accent-2: #ffb43c;
  --green: #34d399;
  --blue: #4aa8ff;
  --danger: #ff4d6d;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box; -webkit-tap-highlight-color: transparent;
  /* Doppeltipp-Zoom & 300ms-Delay aus -> schnelles Tippen ohne Verrutschen */
  touch-action: manipulation;
}
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg);
  background-image: radial-gradient(1200px 800px at 50% -10%, #1a2230 0%, var(--bg) 60%);
  color: var(--txt);
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* Kein Selektieren/Callout beim schnellen Mehrfach-Tippen */
body {
  position: fixed; inset: 0; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* #app ist der einzige Scroll-Container -> kein Document-Bounce / weiße Bänder */
#app {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; display: flex; flex-direction: column;
}

button { font-family: inherit; cursor: pointer; border: none; color: inherit; }
/* Texteingaben dürfen selektierbar sein */
input { font-family: inherit; -webkit-user-select: text; user-select: text; }

.screen {
  flex: 1; display: flex; flex-direction: column;
  max-width: 760px; width: 100%; margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}

/* ---------- Header / Brand ---------- */
.brand { text-align: center; margin: 8px 0 22px; }
.brand .logo {
  font-size: 13px; letter-spacing: .42em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin-bottom: 6px;
}
.brand h1 {
  margin: 0; font-size: 40px; font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(100deg, #fff 10%, var(--accent-2) 55%, var(--accent) 90%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.section-title {
  font-size: 12px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin: 0 4px 10px;
}

.card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 18px;
}

/* ---------- Game mode chooser ---------- */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode {
  position: relative; padding: 18px 16px; border-radius: var(--radius-sm);
  background: var(--card-2); border: 2px solid transparent; text-align: left;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.mode:active { transform: scale(.97); }
.mode.active { border-color: var(--accent); background: rgba(255,90,60,.10); }
.mode .m-title { font-size: 19px; font-weight: 700; }
.mode .m-desc { font-size: 13px; color: var(--muted); margin-top: 3px; }
.mode .m-ico { font-size: 24px; margin-bottom: 8px; display: block; }

.x01-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.chip {
  padding: 14px 0; border-radius: var(--radius-sm); background: var(--card-2);
  border: 2px solid transparent; font-size: 18px; font-weight: 700; text-align: center;
  transition: transform .1s ease, border-color .1s ease, background .1s;
}
.chip:active { transform: scale(.95); }
.chip.active { border-color: var(--accent-2); background: rgba(255,180,60,.12); color: var(--accent-2); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.toggle-row .t-label { font-weight: 600; }
.toggle-row .t-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch { width: 56px; height: 32px; border-radius: 20px; background: var(--line); position: relative; transition: background .15s; flex: 0 0 auto; }
.switch.on { background: var(--green); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on::after { transform: translateX(24px); }

/* ---------- Players ---------- */
.player-add { display: flex; gap: 10px; }
.player-add input {
  flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  border-radius: var(--radius-sm); padding: 14px 14px; font-size: 16px; outline: none;
}
.player-add input:focus { border-color: var(--accent); }
.player-add button {
  background: var(--accent); color: #fff; font-weight: 700; font-size: 22px;
  width: 54px; border-radius: var(--radius-sm); flex: 0 0 auto;
}
.player-add button:disabled { opacity: .4; }

.player-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 12px; background: var(--card-2);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.player-list .pnum {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #0e1116; flex: 0 0 auto;
}
.player-list .pname { flex: 1; font-size: 16px; font-weight: 600; }
.player-list .premove { background: transparent; color: var(--muted); font-size: 22px; width: 34px; height: 34px; border-radius: 8px; }
.player-list .premove:active { background: rgba(255,77,109,.15); color: var(--danger); }
.player-hint { color: var(--muted); font-size: 13px; margin: 10px 4px 0; text-align: center; }

.btn-primary {
  width: 100%; padding: 18px; border-radius: var(--radius); font-size: 19px; font-weight: 800;
  background: linear-gradient(100deg, var(--accent) 0%, var(--accent-2) 100%); color: #14100c;
  box-shadow: 0 8px 22px rgba(255,90,60,.35); letter-spacing: .01em;
  transition: transform .1s ease, opacity .1s; margin-top: 6px;
}
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; box-shadow: none; }

/* ---------- Game top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 18px; flex: 0 0 auto;
}
.icon-btn:active { background: var(--card-2); }
.topbar .game-label { flex: 1; text-align: center; font-weight: 700; font-size: 18px; }
.topbar .game-label small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }

/* ---------- X01 player tiles (Raster – alle sichtbar) ---------- */
.players-grid { display: grid; gap: 8px; margin-bottom: 14px; }
.ptile {
  background: var(--card); border: 2px solid var(--line); position: relative; overflow: hidden;
  border-radius: var(--radius-sm); padding: 10px 12px; transition: border-color .15s, background .15s, transform .15s;
}
.ptile.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(255,90,60,.16), var(--card));
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(255,90,60,.22);
}
.ptile.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.ptile .pt-name { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ptile.active .pt-name { color: var(--txt); }
.ptile .pt-score { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin-top: 1px; }
.ptile .pt-meta { display: flex; gap: 6px; align-items: baseline; margin-top: 3px; }
.ptile .pt-avg { font-size: 13px; font-weight: 700; color: var(--accent-2); }
.ptile .pt-avg-lbl { font-size: 10px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.ptile .pt-darts { font-size: 10px; color: var(--muted); margin-left: auto; }
.ptile .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; flex: 0 0 auto; }

/* ---------- Eingabemodus-Umschalter (segmented) ---------- */
.io-toggle { display: flex; gap: 4px; width: fit-content; max-width: 100%; margin: 0 auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.io-toggle button { padding: 8px 16px; border-radius: 8px; font-weight: 700; font-size: 13px; color: var(--muted); background: transparent; white-space: nowrap; }
.io-toggle button.active { background: var(--accent); color: #14100c; }
.td-rest { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 1px; min-height: 16px; }
.td-rest.bust { color: var(--danger); }

/* ---------- Gesamt-Eingabe ---------- */
.total-display {
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px;
  text-align: center; padding: 8px; margin-bottom: 8px; font-size: 30px; font-weight: 800; letter-spacing: .02em;
}
.total-display.empty { color: var(--muted); }
.total-quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 8px; }
.total-quick button { padding: 12px 0; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); font-weight: 700; font-size: 15px; }
.total-quick button:active { transform: scale(.95); }
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.numpad .key { height: clamp(44px, 9.5vw, 58px); font-size: 20px; }

/* ---------- Turn display ---------- */
.turnbox {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.turnbox .turn-top { display: flex; justify-content: space-between; align-items: baseline; }
.turnbox .turn-who { font-weight: 700; font-size: 17px; }
.turnbox .turn-who span { color: var(--accent-2); }
.turnbox .turn-total { font-weight: 800; font-size: 22px; }
.darts { display: flex; gap: 8px; margin-top: 12px; }
.dart {
  flex: 1; height: 52px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line);
  display: grid; place-items: center; font-size: 18px; font-weight: 700; color: var(--muted);
}
.dart.filled { border-style: solid; border-color: var(--accent); color: var(--txt); background: var(--card-2); }

/* ---------- Keypad ---------- */
.mults { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.mult { padding: 12px 0; border-radius: 12px; background: var(--card-2); font-weight: 700; font-size: 16px; border: 2px solid transparent; }
.mult.active { border-color: var(--blue); color: var(--blue); background: rgba(74,168,255,.12); }
.mult:active { transform: scale(.96); }

.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.key {
  height: clamp(40px, 10.5vw, 54px); border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-size: 18px; font-weight: 700; display: grid; place-items: center;
  transition: transform .08s ease, background .08s;
}
.key:active { transform: scale(.94); background: var(--card-2); }
.key.zero { color: var(--muted); }
.key.bull { color: var(--accent-2); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.act { padding: 16px; border-radius: 14px; font-weight: 700; font-size: 16px; background: var(--card-2); border: 1px solid var(--line); }
.act.undo { color: var(--muted); }
.act.next { background: linear-gradient(100deg, var(--accent), var(--accent-2)); color: #14100c; border: none; }
.act:active { transform: scale(.98); }
.act:disabled { opacity: .4; }

/* ---------- Cricket ---------- */
.cricket-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; margin-bottom: 14px; }
table.cricket { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.cricket th, table.cricket td { text-align: center; padding: 8px 4px; }
table.cricket col.numcol { width: 52px; }
table.cricket thead th { font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 10px; }
table.cricket thead th.active { color: var(--accent); }
table.cricket thead th .ch-name { display: block; max-width: 100%; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.cricket thead th .ch-score { display: block; font-size: 18px; font-weight: 800; color: var(--txt); margin-top: 2px; }
table.cricket thead th.active .ch-score { color: var(--accent-2); }
table.cricket .numcell { font-size: 18px; font-weight: 800; color: var(--accent-2); width: 56px; }
table.cricket tr + tr td { border-top: 1px solid rgba(43,54,69,.6); }
.marks { display: inline-flex; gap: 3px; align-items: center; justify-content: center; min-height: 26px; }
.mark { font-size: 20px; font-weight: 800; line-height: 1; }
.mark.m1 { color: var(--blue); }
.mark.m2 { color: var(--blue); }
.mark.m3 { color: var(--green); }
.closed-cell { color: var(--green); }

.hint-mult { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* antippbare Zellen (Spalte des aktiven Spielers) */
table.cricket td.markcell { transition: background .1s; }
table.cricket td.markcell.tap {
  cursor: pointer; background: rgba(255,90,60,.10);
  box-shadow: inset 0 0 0 1px rgba(255,90,60,.35); border-radius: 8px;
}
table.cricket td.markcell.tap:active { background: rgba(255,90,60,.28); }
.actions-3 { grid-template-columns: 1.3fr .7fr 1.3fr; }

/* ---------- Winner overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,10,14,.86); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.winner-card {
  background: linear-gradient(180deg, var(--card), var(--bg-2)); border: 1px solid var(--line);
  border-radius: 24px; padding: 32px 26px; text-align: center; max-width: 380px; width: 100%;
  box-shadow: var(--shadow); animation: pop .3s cubic-bezier(.2,1.3,.5,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.winner-card .trophy { font-size: 64px; }
.winner-card h2 { margin: 6px 0 2px; font-size: 14px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.winner-card .wname {
  font-size: 34px; font-weight: 800; margin-bottom: 18px;
  background: linear-gradient(100deg, var(--accent-2), var(--accent)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.winner-card .w-actions { display: grid; gap: 10px; }
.winner-card .w-actions button { padding: 15px; border-radius: 14px; font-weight: 700; font-size: 16px; }
.w-rematch { background: linear-gradient(100deg, var(--accent), var(--accent-2)); color: #14100c; }
.w-home { background: var(--card-2); border: 1px solid var(--line); color: var(--txt); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: var(--danger); color: #fff; font-weight: 700; padding: 12px 20px; border-radius: 999px;
  z-index: 60; box-shadow: var(--shadow); animation: toastIn .3s ease;
}
@keyframes toastIn { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 20px; }

/* ---------- Auth / Account ---------- */
.field-input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--txt);
  border-radius: var(--radius-sm); padding: 14px; font-size: 16px; outline: none;
}
.field-input:focus { border-color: var(--accent); }
select.field-input { appearance: none; -webkit-appearance: none; }

.acct-bar { display: flex; align-items: center; gap: 8px; }
.acct-name { flex: 1; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-btn { background: var(--card); border: 1px solid var(--line); color: var(--txt); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 600; }
.acct-btn:active { background: var(--card-2); }

/* ---------- Gespeicherte Spieler ---------- */
.saved-players { margin-top: 14px; }
.saved-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.saved-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip { background: var(--card-2); border: 1px solid var(--line); color: var(--txt); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.pchip:active { transform: scale(.95); border-color: var(--accent); }

/* ---------- Verlauf ---------- */
.game-log { display: flex; flex-direction: column; gap: 10px; }
.game-row { background: var(--card-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.gr-head { display: flex; justify-content: space-between; align-items: baseline; }
.gr-mode { font-weight: 800; color: var(--accent-2); font-size: 15px; }
.gr-date { font-size: 12px; color: var(--muted); }
.gr-winner { font-weight: 700; margin-top: 4px; }
.gr-detail { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.4; }

/* ---------- Pro-Spieler-Statistik ---------- */
.player-list li.clickable { cursor: pointer; }
.player-list li.clickable:active { background: var(--card); }
.winrate { text-align: right; line-height: 1.1; }
.winrate b { font-size: 17px; color: var(--accent-2); }
.winrate small { display: block; font-size: 11px; color: var(--muted); }
.chev { color: var(--muted); font-size: 22px; margin-left: 4px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat-box { background: linear-gradient(180deg, var(--card), var(--bg-2)); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 14px; text-align: center; }
.sb-val { font-size: 30px; font-weight: 800; letter-spacing: -.02em; color: var(--accent-2); }
.sb-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; }
svg.spark { display: block; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
