:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --text: #17201d;
  --muted: #5d6b66;
  --border: #d5dcd9;
  --accent: #0f6b5c;
  --accent-text: #ffffff;
  --accent-soft: #d9efe9;
  --chart: #00806a;
  --ok: #1a7f37;
  --ok-soft: #dcf3e2;
  --bad: #c62828;
  --bad-soft: #fbe1e1;
  --warn: #9a6200;
  --warn-soft: #fff1d6;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.04);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --surface: #171e1c;
    --surface-2: #1f2825;
    --text: #e4ebe8;
    --muted: #93a39d;
    --border: #2d3935;
    --accent: #3fb59e;
    --accent-text: #06201b;
    --accent-soft: #163a33;
    --chart: #1fa58a;
    --ok: #4cc26b;
    --ok-soft: #173a22;
    --bad: #ff6b6b;
    --bad-soft: #3d1a1a;
    --warn: #e6b450;
    --warn-soft: #3a2d10;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1413;
  --surface: #171e1c;
  --surface-2: #1f2825;
  --text: #e4ebe8;
  --muted: #93a39d;
  --border: #2d3935;
  --accent: #3fb59e;
  --accent-text: #06201b;
  --accent-soft: #163a33;
  --chart: #1fa58a;
  --ok: #4cc26b;
  --ok-soft: #173a22;
  --bad: #ff6b6b;
  --bad-soft: #3d1a1a;
  --warn: #e6b450;
  --warn-soft: #3a2d10;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
p { margin: 0.5rem 0; }
a { color: var(--accent); }
kbd {
  font: 0.8em var(--mono);
  padding: 0.05em 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
}

/* --- Kopfzeile --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.logo { color: var(--accent); font-family: var(--mono); letter-spacing: 0.1em; }
/* Rufzeichen im Titel: Effekt aus chrome-neon.css (Kopie aus
   der-fahrtrainer.de/shared/design/, wie auf dl9bm.de und tigerserver.bpunktm.de).
   Ändert sich die Optik, dann dort. Das aria-label sitzt am Link, damit der
   Text der Effekt-Ebenen nicht mehrfach vorgelesen wird. */
@font-face {
  font-family: "Russo One";
  src: url("../fonts/RussoOne-Regular.ttf") format("truetype");
  font-display: swap;
}
.brand .chrome-neon { --cn-groesse: 1.4rem; }
.logo:empty { display: none; } /* Logo ist derzeit leer, sonst bliebe die Lücke (gap) */
.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  margin-left: auto;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 0.9rem 0.7rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 0; padding: 0; }
  .brand { padding: 0.6rem 16px 0; }
  .tabs { margin-left: 0; padding: 0 8px; }
  .tabs a { padding: 0.6rem 0.6rem; }
}

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
@media (max-width: 480px) { .card { padding: 16px; } }

/* --- Formulare --- */
.field { margin-bottom: 1rem; }
.label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; font-weight: normal; }
.center { text-align: center; justify-content: center; }
.mono { font-family: var(--mono); }

.grid2, .grid3 { display: grid; gap: 0 1.25rem; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }

select, input[type="text"], input[type="number"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
input[type="checkbox"] { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; }
.check { display: flex; align-items: center; gap: 0.5rem; min-height: 2.5rem; }
output { font-variant-numeric: tabular-nums; }

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  background: var(--surface-2);
}
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 0.5rem 0.25rem;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.segmented input:checked + span { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 2rem; padding: 0.25rem 0.7rem; font-size: 0.9rem; }
.btn.big { width: 100%; min-height: 3.2rem; font-size: 1.15rem; margin-top: 0.5rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }

.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.6rem; }
.chip {
  font-family: var(--mono);
  font-weight: 700;
  min-width: 2.1rem;
  padding: 0.2rem 0.45rem;
  text-align: center;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
}
.chip.new { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* --- Trainingslauf --- */
.run-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.run-head .status { flex: 1; text-align: center; font-weight: 600; }
.run-head .status.warn { color: var(--warn); }

.groups {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.1rem;
  justify-content: center;
  font-family: var(--mono);
  font-size: 1.6rem;
  min-height: 3rem;
}
@media (max-width: 480px) { .groups { font-size: 1.3rem; gap: 0.5rem 0.8rem; } }
.group { display: flex; gap: 2px; padding: 0.15rem 0.3rem; border-radius: 8px; border: 2px solid transparent; }
.group.active { border-color: var(--accent); }
.slot {
  min-width: 1.1em;
  text-align: center;
  border-bottom: 2px solid var(--border);
  line-height: 1.4;
}
.slot.current { border-bottom-color: var(--accent); background: var(--accent-soft); border-radius: 4px 4px 0 0; }
.slot.ok { color: var(--ok); }
.slot.retry { color: var(--warn); }
.slot.bad { color: var(--bad); }
.slot.flash { animation: flash 0.35s; }
@keyframes flash { from { background: var(--bad-soft); } to { background: transparent; } }
.prosign { text-decoration: overline; font-size: 0.75em; }

.reveal {
  text-align: center;
  font: 700 3.5rem/1.1 var(--mono);
  color: var(--warn);
  margin-bottom: 0.5rem;
}
.reveal small { display: block; font-size: 1.1rem; letter-spacing: 0.15em; }

/* --- Bildschirmtastatur --- */
.keypad { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.2rem, 1fr)); gap: 0.4rem; margin-top: 1.25rem; }
.keypad[hidden] { display: none; }
.keypad button {
  min-height: 3.2rem;
  font: 700 1.2rem var(--mono);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: manipulation;
  user-select: none;
}
.keypad button:active { background: var(--accent-soft); }
.keypad button.ctl { font: 600 0.95rem system-ui, sans-serif; color: var(--muted); }
.keypad button.wide { grid-column: span 2; }

/* Feld für die Systemtastatur (Touch-Geräte). 1.4rem > 16 px, sonst zoomt iOS beim Fokus. */
.sysinput {
  display: block;
  width: 100%;
  max-width: 16rem;
  margin: 0 auto 1rem;
  padding: 0.6rem 0.8rem;
  font: 700 1.4rem var(--mono);
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  caret-color: transparent;
}
.sysinput[hidden] { display: none; }

/* --- Morse-Baum --- */
.tree-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.5rem 0 1rem; }
.tree-head .field { min-width: 12rem; }
.tree-now { display: flex; align-items: baseline; gap: 0.9rem; flex-wrap: wrap; min-height: 3rem; }
.tree-char { font: 700 2.4rem/1 var(--mono); color: var(--accent); }
.tree-code { font: 700 1.5rem/1 var(--mono); letter-spacing: 0.15em; }
.tree-wrap { width: 100%; }
.tree { display: block; width: 100%; height: auto; }
.tree .edge { stroke: var(--border); stroke-width: 2; stroke-linecap: round; }
.tree .edge.on { stroke: var(--accent); stroke-width: 4; }
/* Punkt-Äste gepunktet: Strichlänge 0 + runde Enden = runde Punkte.
   Etwas dicker, sonst wirken die Punkte neben den Strich-Ästen zu blass. */
.tree .edge.dit { stroke-width: 3.5; stroke-dasharray: 0 7; }
.tree .edge.dit.on { stroke-width: 5.5; stroke-dasharray: 0 9; }
.tree .node circle { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.tree .node.empty circle, .tree .node.start circle { fill: var(--border); stroke: none; }
.tree .node.start.on circle { fill: var(--accent); }
.tree .node[data-char] { cursor: pointer; }
.tree .node text { font: 700 12px var(--mono); fill: var(--text); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.tree .node text.small { font-size: 8px; }
.tree .node.on circle { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); }
.tree .node.hit circle { animation: tree-hit 0.9s ease-out both; }
.tree .node.hit text { fill: var(--accent-text); }
@keyframes tree-hit {
  0%, 30%, 60% { fill: var(--accent); stroke: var(--accent); r: 15px; }
  15%, 45% { fill: var(--accent-soft); r: 13px; }
  100% { fill: var(--accent); stroke: var(--accent); r: 11px; }
}

/* --- Ergebnis --- */
.score {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.score .big-number { font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score.pass .big-number { color: var(--ok); }
.score.fail .big-number { color: var(--bad); }
.banner { border-radius: 10px; padding: 0.8rem 1rem; margin: 1rem 0; }
.banner.pass { background: var(--ok-soft); }
.banner.fail { background: var(--surface-2); }
.compare { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; font-family: var(--mono); font-size: 1.15rem; margin: 1rem 0; }
.compare .pair { display: grid; gap: 0; }
.compare .line { display: flex; gap: 1px; }
.compare .line span { min-width: 1.05em; text-align: center; }
.compare .exp { color: var(--muted); font-size: 0.85em; }
.c-ok { color: var(--ok); }
.c-sub { color: var(--bad); background: var(--bad-soft); border-radius: 3px; }
.c-miss { color: var(--bad); }
.c-extra { color: var(--bad); text-decoration: line-through; }
.legend { font-size: 0.85rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.pct-good { color: var(--ok); font-weight: 600; }
.pct-mid { color: var(--warn); font-weight: 600; }
.pct-bad { color: var(--bad); font-weight: 600; }

/* --- Rufzeichen --- */
.rz-form { margin: 0.5rem 0; }
.rz-input {
  font: 700 2rem var(--mono) !important;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.6rem !important;
}
.rz-log { list-style: none; padding: 0; margin: 1rem 0 0; font-family: var(--mono); }
.rz-log li { display: flex; gap: 0.75rem; justify-content: space-between; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.rz-log .pts { color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- Gebetrainer --- */
.task { background: var(--surface-2); border-radius: 10px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; }
.task-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.task-head .label { margin: 0; }
.task-head .row { margin: 0; }
.target, .output { font-size: 1.5rem; min-height: 2.2rem; word-break: break-all; letter-spacing: 0.05em; margin-top: 0.4rem; }
.output .pending { color: var(--muted); }
.timeline { display: flex; align-items: center; gap: 3px; height: 14px; margin-top: 0.5rem; overflow: hidden; justify-content: flex-end; }
.timeline .m { height: 10px; background: var(--accent); border-radius: 2px; flex: none; }
.timeline .g { height: 10px; flex: none; }
.timeline .sep { width: 1px; height: 14px; background: var(--muted); flex: none; }
.paddles { display: grid; gap: 0.75rem; grid-template-columns: 1fr; margin: 1rem 0 0.5rem; }
.paddles.two { grid-template-columns: 1fr 1fr; }
.paddle {
  min-height: 9rem;
  font: 700 1.3rem system-ui, sans-serif;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 14px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}
.paddle.down { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* --- Hilfe: Zeichentabelle --- */
.code-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.4rem; }
.code-cell {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.code-cell b { font-family: var(--mono); font-size: 1.1rem; }
.code-cell span { font-family: var(--mono); color: var(--accent); letter-spacing: 0.1em; }
.prose li { margin: 0.3rem 0; }
.prose dt { font-weight: 700; margin-top: 0.75rem; }
.prose dd { margin: 0.2rem 0 0; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

[hidden] { display: none !important; }

/* --- Tagestraining --- */
.daily { display: grid; gap: 0.75rem; }
.daily-info { display: grid; gap: 0.5rem; }
.daily-text { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; align-items: baseline; }
.meter { height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.compare .pair[data-group] { cursor: pointer; border-radius: 6px; padding: 0 0.2rem; }
.compare .pair[data-group]:hover { background: var(--surface-2); }

/* --- Übungen --- */
.pair-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 1rem 0; }
.pair-btn {
  min-height: 8rem;
  font: 700 3rem var(--mono);
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.pair-btn small { display: block; font: 600 0.95rem var(--mono); color: var(--muted); margin-top: 0.4rem; }
.pair-btn.right { background: var(--ok-soft); border-color: var(--ok); }
.pair-btn.wrong { background: var(--bad-soft); border-color: var(--bad); }
textarea.copy-area {
  width: 100%;
  font: 1.15rem/1.6 var(--mono);
  text-transform: uppercase;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem;
  resize: vertical;
}
.text-block { font-size: 1.05rem; line-height: 1.8; word-break: break-word; }
.text-block u { text-decoration-thickness: 2px; }
details { margin: 1rem 0; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.contest-fields { display: grid; grid-template-columns: 2fr 1fr; gap: 0.75rem; }
.contest-fields .rz-input { font-size: 1.6rem !important; }
.transcript { max-height: 320px; overflow-y: auto; margin: 0.5rem 0; }
.transcript .msg { margin: 0.35rem 0; font-family: var(--mono); word-break: break-word; }
.transcript .msg.dx { cursor: pointer; }
.transcript .msg.me strong { color: var(--accent); }
.qso-options { margin-top: 0.75rem; }
#qso-typed input { flex: 1; font-family: var(--mono); text-transform: uppercase; }
.segmented + h1, #rz-rufz-setup h1, #rz-contest-setup h1 { margin-top: 1.25rem; }

/* --- Diagramme --- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 640px) { .charts { grid-template-columns: minmax(0, 1fr); } }
.chart { position: relative; }
.chart h3 { margin: 0 0 0.25rem; font-size: 0.95rem; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; touch-action: pan-y; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart); opacity: 0.1; }
.chart .dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
  transform: translate(-50%, -110%);
}
.chart-tip strong { display: block; font-size: 1rem; }
.chart-tip span { color: var(--muted); }

/* --- Drucken (Prüfungsergebnis) --- */
@media print {
  .topbar, .no-print, details, #ex-mode, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; box-shadow: none; }
  .view:not(#view-uebungen) { display: none !important; }
  .certificate { border: 2px solid #000; padding: 2rem; border-radius: 12px; }
}
.code-cell span small { display: block; color: var(--muted); font-size: 0.75rem; letter-spacing: 0; text-align: right; }
.chart .bar { fill: var(--chart); }
