:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eceff4;
  --text: #15171c;
  --muted: #5c6372;
  --border: #dde1e8;
  --accent: #2b63e0;
  --accent-text: #ffffff;
  --ok: #1d8a4c;
  --warn: #a8670f;
  --bad: #cc3b3b;
  --pod-off: #d3d7df;
  --pod-ring: #c3c8d2;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 6px 20px rgb(0 0 0 / 0.06);
  --radius: 14px;
  --tabbar-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242d;
    --text: #eceef3;
    --muted: #9aa2b1;
    --border: #2a2f3a;
    --accent: #5d8dff;
    --accent-text: #0b1020;
    --ok: #45c47c;
    --warn: #e0a647;
    --bad: #ff6b6b;
    --pod-off: #262a33;
    --pod-ring: #363c48;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; letter-spacing: -0.01em; }
h2, h3 { margin: 0; }
.subhead { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 1.5rem 0 0.5rem; font-weight: 600; }
code { font: 0.85em ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Kopf & Navigation */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { border-radius: 7px; }

main { max-width: 720px; margin: 0 auto; padding: 8px 16px 24px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font: inherit; font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }

/* Bedienelemente */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 0.7rem 1rem; border-radius: 11px; cursor: pointer;
  min-height: 44px; transition: transform 0.06s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 0.45rem 0.8rem; min-height: 36px; font-size: 0.875rem; }
.btn.huge { width: 100%; font-size: 1.25rem; padding: 1rem; margin-top: 16px; border-radius: 16px; }
.btn.huge.stop { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:focus-visible, .tabbar button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .pod:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
.link { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0 0.25rem; }
.icon { border: 0; background: var(--surface-2); color: var(--text); width: 34px; height: 34px; border-radius: 9px; font-size: 1rem; cursor: pointer; }
.icon.danger { color: var(--bad); }

.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 0.3rem 0.75rem; font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }

.segmented { display: inline-grid; grid-auto-flow: column; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 0.45rem 0.9rem; border-radius: 9px; cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented.small button { padding: 0.3rem 0.7rem; font-size: 0.85rem; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.msg { min-height: 1.4em; margin: 10px 0 0; font-size: 0.9rem; color: var(--muted); }
.msg.bad { color: var(--bad); }
.msg.ok { color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 0.9rem; }

.banner {
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--border));
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 0.92rem;
}
.banner ol { margin: 8px 0 4px; padding-left: 1.2rem; }
.banner li { margin: 4px 0; }
.banner p { margin: 6px 0 0; }

/* Pods */
.pod-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 16px; }
.pod-grid.compact { gap: 10px; margin-top: 14px; }
.pod {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 6px 10px; box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit;
}
.pod .light {
  width: min(64px, 18vw); aspect-ratio: 1; border-radius: 50%;
  background: var(--pod-off); border: 4px solid var(--pod-ring);
  display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; color: var(--muted);
  transition: background 0.08s, box-shadow 0.08s;
}
.pod.lit .light { background: var(--c); border-color: color-mix(in srgb, var(--c) 70%, white); color: rgb(0 0 0 / 0.65); box-shadow: 0 0 22px 4px color-mix(in srgb, var(--c) 70%, transparent); }
.pod .state { font-size: 0.75rem; color: var(--muted); text-align: center; line-height: 1.2; }
.pod .state.ok { color: var(--ok); }
.pod .state.bad { color: var(--bad); }
.pod .batt { position: absolute; top: 6px; right: 8px; font-size: 0.7rem; color: var(--muted); }
.pod.flash { animation: flash 0.35s; }
@keyframes flash { 50% { transform: scale(0.94); } }
.pod-grid.compact .pod { padding: 8px 4px; }
.pod-grid.compact .light { width: min(52px, 15vw); font-size: 1rem; }

/* Licht: Helligkeit und Effekte */
.range-field input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.range-field b { color: var(--text); font-variant-numeric: tabular-nums; }
.effect-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.btn.effect { text-align: left; display: grid; gap: 2px; padding: 0.6rem 0.8rem; }
.btn.effect span { font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.btn.effect[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.effect[aria-pressed="true"] span { color: inherit; opacity: 0.85; }

/* Rechtliches unten auf jeder Seite */
.legal { margin: 32px 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); text-align: center; }
.legal p { margin: 4px 0; }
.legal a { color: inherit; }

/* Impressum, Datenschutz */
body.page { padding-bottom: 32px; }
.page .brand { color: inherit; text-decoration: none; }
main.text { line-height: 1.55; }
main.text h2 { font-size: 1rem; margin: 1.4rem 0 0.3rem; }
main.text p { margin: 0 0 0.6rem; }
main.text a { color: var(--accent); }
main.text .back { margin-top: 2rem; }

/* Karten */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card h3 { font-size: 1rem; margin: 0 0 2px; }
.card p { margin: 0; color: var(--muted); font-size: 0.875rem; }
.card .card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card .meta { font-size: 0.8rem; color: var(--muted); }

/* Training */
.field { display: grid; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 0; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 0.55rem 0.7rem; min-height: 44px;
}
textarea { font: 0.85rem/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; resize: vertical; }

.scoreboard { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); text-align: center; }
.scoreboard .big { font-size: clamp(3.2rem, 16vw, 5rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.scoreboard .big .idle { color: var(--muted); font-weight: 300; }
.scoreboard .big small { font-size: 0.3em; font-weight: 700; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.run-status { margin: 8px 0 14px; font-weight: 700; color: var(--muted); min-height: 1.4em; }
.run-status.go { color: var(--accent); }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat-row div { display: grid; }
.stat-row b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat-row span { font-size: 0.75rem; color: var(--muted); }

.summary { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border)); border-radius: var(--radius); padding: 14px; margin-top: 16px; }
.summary h3 { margin: 0 0 8px; font-size: 1rem; }
.summary dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 0 0 12px; }
.summary dt { font-size: 0.75rem; color: var(--muted); }
.summary dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

.log { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 4px; font-variant-numeric: tabular-nums; }
.log li { display: grid; grid-template-columns: 5.5em 4.5em 1fr auto; gap: 8px; padding: 6px 10px; border-radius: 9px; background: var(--surface); font-size: 0.9rem; }
.log li .res { font-weight: 700; }
.log li.Treffer .res { color: var(--ok); }
.log li.verpasst .res { color: var(--warn); }
.log li.Ablenker .res, .log li.Fehltipp .res { color: var(--bad); }
.log li.info { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.log li.info .res { color: var(--accent); }

/* Staffel: eine Kachel pro Bahn */
.lane-board { list-style: none; padding: 0; margin: 14px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.lane {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 0 8px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--c); border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}
.lane .nr { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.lane .taps { font-size: 0.75rem; color: var(--muted); }
.lane b { grid-column: 1 / -1; font-size: 1.7rem; line-height: 1.15; }
.lane .sub { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); }
.lane.blink b { color: var(--warn); }
.lane.pause b, .lane.wartet b { color: var(--ok); }
.lane.raus { border-left-color: var(--bad); }
.lane.raus b { color: var(--bad); }
.lane.sieger { border-left-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.lane.sieger b { color: var(--ok); }
.lane-board.duell { grid-template-columns: 1fr 1fr; }
.lane-board.duell .lane b { font-size: 2.4rem; }

.ranking { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; font-variant-numeric: tabular-nums; }
.ranking li { display: grid; grid-template-columns: 2em 1fr auto; gap: 2px 8px; padding: 6px 10px; border-radius: 9px; background: var(--surface); font-size: 0.9rem; }
.ranking li > span:last-child { grid-column: 2 / -1; font-size: 0.8rem; color: var(--muted); }
.ranking li.sieger { font-weight: 700; }
.ranking li.sieger b, .ranking li.sieger > span:last-child { color: var(--ok); }

/* Editor */
dialog#editor {
  width: min(680px, 100vw); max-width: 100vw; max-height: 100dvh; height: 100dvh;
  margin: 0 auto; padding: 0; border: 0; background: var(--bg); color: var(--text);
}
@media (min-width: 720px) { dialog#editor { height: auto; max-height: 92dvh; margin-top: 4dvh; border-radius: 18px; border: 1px solid var(--border); } }
dialog#editor::backdrop { background: rgb(0 0 0 / 0.45); }
#ed-form { display: flex; flex-direction: column; height: 100%; max-height: inherit; }
.ed-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.ed-head h2 { font-size: 1.1rem; }
.ed-body { flex: 1; overflow: auto; padding: 14px 16px; }
.ed-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.errors { margin: 0; padding: 0 16px; color: var(--bad); font-size: 0.875rem; white-space: pre-line; }
.errors:not(:empty) { padding: 8px 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.inline { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.inline .num { width: 6.5em; }
.radio { display: inline-flex; align-items: center; gap: 6px; min-width: 4.2em; }
.steps { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 10px; counter-reset: step; }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px 4px; }
.step-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.step-tools { display: flex; gap: 6px; }
.step details { margin: 0 0 8px; }
.step summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.875rem; padding: 4px 0 8px; }

@media (max-width: 380px) {
  .grid2 { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; }
}
