/* Farben und Maße an einer Stelle: zum Umgestalten reicht es meist, hier Werte zu ändern. */
:root {
  --bg: #0f1115; --panel: #181b22; --panel-2: #20242d; --line: #2c313c;
  --text: #ecebe8; --muted: #9aa0ab; --accent: #2f9e6a; --accent-2: #d64545; --warn: #e0a43a;
  --active: #2f9e6a; --on-accent: #fff;
  --radius: 14px; --gap: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --num: "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f2ef; --panel: #ffffff; --panel-2: #ecebe7; --line: #d9d7d1;
  --text: #17191d; --muted: #646a74; --accent: #1f8a59; --accent-2: #c23b3b; --warn: #b07a12; --active: #1f8a59;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f3f2ef; --panel: #ffffff; --panel-2: #ecebe7; --line: #d9d7d1;
    --text: #17191d; --muted: #646a74; --accent: #1f8a59; --accent-2: #c23b3b; --warn: #b07a12; --active: #1f8a59;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; color: var(--muted); font-weight: 600; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px; flex: 1; display: flex; flex-direction: column; gap: var(--gap); }
.center { margin: auto; text-align: center; padding: 40px 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar .title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a, .topbar button.link { color: var(--text); text-decoration: none; background: none; border: 0; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.topbar a:hover, .topbar button.link:hover { background: var(--panel-2); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.click { cursor: pointer; } .card.click:hover { border-color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text); user-select: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.danger { color: var(--accent-2); }
.btn.on { background: var(--active); border-color: var(--active); color: var(--on-accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--panel-2); padding: 0 12px; min-height: 40px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--active); color: var(--on-accent); }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 0 12px; color: var(--text); width: 100%; }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; }
.chip.on { background: var(--active); border-color: var(--active); color: var(--on-accent); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(120px); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; transition: transform .25s; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--accent-2); }

/* ---------- Spiel ---------- */
.game { display: grid; gap: 10px; grid-template-columns: 1fr; grid-template-areas: "scores" "visit" "input" "hist"; width: 100%; }
.g-scores { grid-area: scores; } .g-visit { grid-area: visit; } .g-input { grid-area: input; } .g-hist { grid-area: hist; }
@media (min-width: 900px) {
  .game { grid-template-columns: 1.1fr 1fr; grid-template-areas: "scores input" "visit input" "hist input"; grid-template-rows: auto auto 1fr; align-items: start; }
}
/* Spielseite auf dem Handy: Kopfzeile nicht mitscrollen lassen, damit der Spielstand oben bleibt */
.page:has(.game) { padding: 10px; max-width: 1400px; }
.scores { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.pcard { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px; position: relative; }
.pcard.turn { border-color: var(--active); box-shadow: 0 0 0 3px color-mix(in srgb, var(--active) 25%, transparent); }
.pcard .name { font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .rest { font: 700 clamp(2.6rem, 9vw, 4.2rem)/1 var(--num); letter-spacing: -.02em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.pcard .meta { display: flex; gap: 10px; color: var(--muted); font-size: .85rem; flex-wrap: wrap; }
.pcard .legs { position: absolute; top: 10px; right: 12px; font: 700 1.1rem var(--num); }
.pcard .co { color: var(--warn); font-weight: 600; font-size: .95rem; min-height: 1.3em; }
.visit { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 8px; align-items: center; }
.visit .slot { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; min-height: 48px; display: grid; place-items: center; font: 700 1.2rem var(--num); }
.visit .slot.empty { color: var(--muted); font-weight: 400; }
.visit .sum { font: 700 1.6rem var(--num); min-width: 64px; text-align: right; }

.inputbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.pad { display: grid; gap: 6px; grid-template-columns: repeat(7, 1fr); }
.pad button { min-height: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font: 600 1.15rem var(--num); cursor: pointer; touch-action: manipulation; }
.pad button:active { background: var(--line); }
.pad button.mod.on { background: var(--warn); color: #111; border-color: var(--warn); }
.pad button.wide { grid-column: span 2; }
.numpad { display: grid; gap: 6px; grid-template-columns: repeat(3, 1fr); }
.numpad button { min-height: 58px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); font: 600 1.4rem var(--num); cursor: pointer; touch-action: manipulation; }
.numpad .display { grid-column: span 3; font: 700 2rem var(--num); text-align: center; padding: 6px; min-height: 52px; }
.board-wrap { max-width: 520px; margin: 0 auto; width: 100%; }
.board-wrap svg { width: 100%; height: auto; display: block; touch-action: manipulation; }
.board-wrap path, .board-wrap circle.hit { cursor: pointer; }
.board-wrap path:hover, .board-wrap circle.hit:hover { filter: brightness(1.35); }

.history { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow: auto; font-size: .9rem; }
.history .h { display: flex; gap: 8px; color: var(--muted); }
.history .h b { color: var(--text); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

.banner { background: var(--accent); color: var(--on-accent); border-radius: var(--radius); padding: 16px; text-align: center; font-weight: 700; font-size: 1.3rem; }

/* ---------- TV ---------- */
.tv { padding: 3vh 3vw; flex: 1; display: flex; flex-direction: column; gap: 2vh; }
.tv .scores { grid-template-columns: repeat(auto-fit, minmax(min(30vw, 160px), 1fr)); gap: 2vw; }
/* Zahlengröße an die Kartenbreite koppeln (cqi), damit es auf Handy hoch, MacBook und TV passt */
.tv .pcard { padding: 2vh 2vw; border-width: 4px; container-type: inline-size; min-width: 0; }
.tv .pcard .name { font-size: min(4vh, 11cqi); }
.tv .pcard .rest { font-size: min(22vh, 46cqi); margin: 1vh 0; }
.tv .pcard .meta { font-size: min(2.6vh, 7.5cqi); gap: 2vw; }
.tv .pcard .legs { font-size: 5vh; top: 2vh; right: 2vw; }
.tv .pcard .co { font-size: min(3.6vh, 9cqi); }
.tv .visit .slot { min-height: 9vh; font-size: 5vh; }
.tv .visit .sum { font-size: 7vh; }
.tv .info { font-size: 2.4vh; color: var(--muted); display: flex; justify-content: space-between; }
.tv .tvhist .history { max-height: none; font-size: min(2.4vh, 4vw); }
@media (orientation: landscape) and (max-height: 700px) { .tv .tvhist { display: none; } }

/* ---------- Kamera ---------- */
.cam { padding: 10px; }
.cam-view { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.cam-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-view canvas { position: absolute; inset: 0; pointer-events: none; }
.cam-status { margin-top: 8px; min-height: 1.3em; }
.cam-view { cursor: crosshair; }
.cam.off .cam-view { display: none; }
.cam.off .cam-status { margin-top: 0; }
.cam-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cam-align { margin-top: 8px; padding: 8px 10px; border-radius: 8px; font-weight: 600; font-size: .92rem; }
.cam-align.ok { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--text); }
.cam-align.warn { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--text); }
.cam-align.bad { background: color-mix(in srgb, var(--accent-2) 25%, transparent); color: var(--text); }
details > summary { cursor: pointer; }

/* ---------- Statistik ---------- */
.stat { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; }
.stat .v { font: 700 1.5rem var(--num); font-variant-numeric: tabular-nums; }
.stat .k { color: var(--muted); font-size: .8rem; }
.spark { width: 100%; height: 120px; display: block; }
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list td, table.list th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th { color: var(--muted); font-weight: 600; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
