/* Schnarch-Trainer: dark, high contrast, mobile first.
   No fixed bottom elements (Vivaldi's address bar sits at the bottom):
   navigation is a sticky top bar, actions sit in the content flow. */

:root {
  --bg: #0b0e14;
  --surface: #151a23;
  --surface2: #1e2531;
  --line: #2c3544;
  --text: #e9edf3;
  --muted: #a3adbb;
  --dim: #7d8796;
  --accent: #6cb8ff;
  --accent-ink: #06121f;
  --ok: #4cc38a;
  --part: #e0b050;
  --danger: #ff7a70;
  --radius: 14px;
  --tap: 48px;
  --sk-line: #9fb0c8;
  --sk-dim: #5d6a7e;
  --sk-tongue: #c9686e;
  --sk-arrow: #6cb8ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px 0; font-weight: 700; font-size: 1rem; color: var(--muted);
}
.tabs { display: flex; max-width: 720px; margin: 0 auto; }
.tabs a {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 4px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-height: 480px) and (orientation: landscape) {
  .brand { display: none; }
  .tabs a { min-height: 44px; }
}

/* ---------- layout ---------- */
.main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  outline: none;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}
.card > :last-child { margin-bottom: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-title { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--text);
  font: inherit; font-weight: 650; font-size: 1.05rem;
  cursor: pointer; touch-action: manipulation; text-decoration: none;
  width: 100%;
}
.btn:active { transform: translateY(1px); filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-big { min-height: 64px; font-size: 1.25rem; border-radius: 16px; }
.btn-danger { background: #3a1715; border-color: #6b2b27; color: #ffd6d2; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 44px; font-size: .95rem; padding: 6px 12px; width: auto; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; padding: 12px 0; min-height: 44px; cursor: pointer; text-decoration: underline; }

.confirm { margin-top: 10px; }
.confirm-q { font-weight: 600; }

/* ---------- Heute ---------- */
.status-line { display: flex; align-items: center; gap: 12px; }
.status-mark {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 1.3rem;
  border: 3px solid var(--dim); color: var(--dim);
}
.status-mark.complete { background: var(--ok); border-color: var(--ok); color: #05150d; }
.status-mark.partial { border-color: var(--part); color: var(--part); }
.status-text strong { display: block; font-size: 1.15rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 0 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.stat b { display: block; font-size: 1.7rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }
.weekdots { display: flex; gap: 6px; margin-top: 8px; }
.weekdots span { flex: 1; height: 8px; border-radius: 4px; background: var(--surface2); }
.weekdots span.on { background: var(--ok); }
.insight { border-left: 3px solid var(--accent); }
.insight p { margin-bottom: 6px; }
.src { display: inline-flex; align-items: center; font-size: .8rem; color: var(--muted); min-height: 44px; }
.ref { color: var(--muted); font-size: .7rem; margin-left: 1px; }
a.src { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.plan-list { list-style: none; margin: 0; padding: 0; }
.plan-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.plan-list li:first-child { border-top: 0; }
.plan-list .ok { color: var(--ok); font-weight: 700; }

/* ---------- Training ---------- */
.tr-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--muted); font-size: .9rem; margin-bottom: 6px; }
.tr-progress { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; margin-bottom: 14px; }
.tr-progress > div { height: 100%; background: var(--accent); }
.tr-name { font-size: 1.45rem; margin: 0 0 2px; }
.tr-area { color: var(--muted); margin-bottom: 10px; }
.sketch-box { background: #0f141c; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.sketch { display: block; width: 100%; height: auto; max-height: 34vh; }
.sk-cap { margin: 2px 0 4px; text-align: center; color: var(--muted); font-size: .85rem; font-weight: 600; letter-spacing: .03em; }
body[data-screen="training"] .sketch { max-height: 24vh; }
.tr-cue { font-size: 1.1rem; font-weight: 600; margin: 12px 0; }
.steps { margin: 0 0 12px; padding-left: 1.3em; }
.steps li { margin: 4px 0; }
.counter { text-align: center; padding: 8px 0 4px; }
.counter .big { font-size: 3.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.counter .of { color: var(--muted); font-size: 1.1rem; }
.counter .phase { font-size: 1.2rem; font-weight: 700; min-height: 1.6em; margin-top: 6px; }
.phase.hold { color: var(--accent); }
.phase.rest { color: var(--muted); }
.pacer { height: 18px; background: var(--surface2); border-radius: 9px; overflow: hidden; margin: 10px 0 14px; }
.pacer > div { height: 100%; width: 0; background: var(--accent); border-radius: 9px; }
.pacer.rest > div { background: var(--dim); }
.tr-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tr-controls .btn-big { grid-column: 1 / -1; }
.summary-list { list-style: none; padding: 0; margin: 0 0 12px; }
.summary-list li { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.summary-list li:first-child { border-top: 0; }
.tag-ok { color: var(--ok); font-weight: 700; }
.tag-part { color: var(--part); font-weight: 700; }
.tag-skip { color: var(--dim); }

/* ---------- Verlauf ---------- */
.cal-nav { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; margin-bottom: 8px; }
.cal-nav h2 { text-align: center; margin: 0; }
.cal-nav .btn { width: 52px; padding: 0; font-size: 1.4rem; }
.cal { width: 100%; border-collapse: separate; border-spacing: 3px; table-layout: fixed; }
.cal th { color: var(--muted); font-size: .8rem; font-weight: 600; padding: 2px 0; }
.cal td { padding: 0; }
.day {
  position: relative; display: grid; place-items: center;
  aspect-ratio: 1 / 1; min-height: 40px; border-radius: 10px;
  font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--muted);
}
.day.complete { background: var(--ok); color: #05150d; font-weight: 700; }
.day.complete::after { content: "\2713"; position: absolute; right: 4px; top: 1px; font-size: .7rem; }
.day.partial { border: 2px dashed var(--part); color: var(--text); }
.day.partial::after { content: ""; position: absolute; left: 50%; bottom: 5px; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--part); }
.day.today { outline: 2px solid var(--text); outline-offset: -2px; }
.day.future { color: var(--dim); opacity: .6; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: -3px; margin-right: 6px; }
.legend .l-complete { background: var(--ok); }
.legend .l-partial { border: 2px dashed var(--part); }
.weeks { list-style: none; padding: 0; margin: 0; }
.weeks li { display: grid; grid-template-columns: 7.5em 1fr 3.2em; align-items: center; gap: 10px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.weeks .bar { height: 10px; border-radius: 5px; background: var(--surface2); overflow: hidden; }
.weeks .bar > div { height: 100%; background: var(--ok); }
.weeks .reached { color: var(--ok); font-weight: 700; }

/* charts */
.chart { display: block; width: 100%; height: auto; }
.chart .axis { stroke: #3a4454; stroke-width: 1; }
.chart .grid { stroke: #232b37; stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--accent); }
.chart .bar-alt { fill: #9fb0c8; }
.chart .train { fill: var(--ok); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-readout { min-height: 1.5em; font-size: .9rem; color: var(--text); margin: 4px 0 0; font-variant-numeric: tabular-nums; }
details.table-view summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }

/* ---------- Nacht ---------- */
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; display: flex; gap: 10px; }
.checks .yes { color: var(--ok); font-weight: 700; }
.checks .no { color: var(--danger); font-weight: 700; }
.howto { margin: 0; padding-left: 1.3em; }
.howto li { margin: 4px 0; }
.night {
  min-height: calc(100svh - 32px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: #4a5260; gap: 18px; padding: 24px 0;
  user-select: none; -webkit-user-select: none;
}
body.night-mode { background: #000; }
body.night-mode .topbar { display: none; }
body.night-mode .main { padding-top: 16px; }
.night .n-time { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.night .n-row { display: flex; gap: 22px; font-size: 1rem; font-variant-numeric: tabular-nums; }
.night .n-row b { display: block; font-size: 1.5rem; }
.night .btn { max-width: 320px; background: #0c0d10; border-color: #23262d; color: #6b7280; }
.night .btn-big { min-height: 88px; font-size: 1.4rem; }
.night.awake { color: var(--muted); }
.night.awake .btn { color: var(--text); border-color: var(--line); background: var(--surface2); }
.night.awake .btn-danger { background: #3a1715; border-color: #6b2b27; color: #ffd6d2; }
.level { width: 220px; height: 6px; background: #111318; border-radius: 3px; overflow: hidden; }
.level > div { height: 100%; background: #2d4c6d; }
.night.awake .level > div { background: var(--accent); }
.night-list { list-style: none; padding: 0; margin: 0; }
.night-list > li { border-top: 1px solid var(--line); padding: 10px 0; }
.night-list > li:first-child { border-top: 0; }
.night-list .meta { color: var(--muted); font-size: .9rem; }
.clips { list-style: none; padding: 0; margin: 0; }
.clips li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.clips li:first-child { border-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.notice { color: var(--muted); font-size: .9rem; }
.warn { color: var(--part); }

/* ---------- Wissen ---------- */
.ex-card .sketch-box { margin: 10px 0; }
.ex-card h3 { margin-bottom: 2px; }
.ex-meta { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.refs { padding-left: 1.4em; margin: 0; }
.refs li { margin: 6px 0; font-size: .9rem; }
.refs a { word-break: break-word; display: inline-block; padding: 12px 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 600; }
input[type="time"], input[type="number"] {
  font: inherit; font-size: 1.1rem; color: var(--text); background: var(--surface2);
  border: 1px solid var(--line); border-radius: 10px; min-height: 48px; padding: 6px 10px;
  width: 100%; color-scheme: dark;
}
.state-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-weight: 700; font-size: .9rem; border: 1px solid var(--line); }
.state-pill.on { color: var(--ok); border-color: var(--ok); }
.state-pill.blocked { color: var(--danger); border-color: var(--danger); }

/* ---------- Admin ---------- */
.adm-bar {
  position: sticky; top: var(--topbar-h, 88px); z-index: 5;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center;
}
.adm-bar span { flex: 1; font-weight: 600; }
.adm-bar .btn { width: auto; min-width: 130px; }
details.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.group > summary { min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; cursor: pointer; font-weight: 700; list-style: none; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::after { content: "+"; color: var(--muted); font-size: 1.3rem; }
details.group[open] > summary::after { content: "\2212"; }
details.group > .group-body { padding: 0 16px 6px; }
.setting { border-top: 1px solid var(--line); padding: 12px 0; }
.setting-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.setting-head label { font-weight: 650; }
.setting .help { color: var(--muted); font-size: .85rem; margin: 2px 0 8px; }
.setting .ctl { display: grid; grid-template-columns: 1fr 6.5em; gap: 12px; align-items: center; }
.setting .ctl.time { grid-template-columns: 1fr; }
.setting .num-unit { display: flex; align-items: center; gap: 6px; }
.setting .num-unit span { color: var(--muted); font-size: .9rem; }
.setting .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; margin-top: 6px; flex-wrap: wrap; }
.setting .err { color: var(--danger); font-weight: 600; font-size: .9rem; margin-top: 4px; }
.setting.changed { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
.badge { font-size: .75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); font-weight: 700; }
input[type="range"] { width: 100%; height: 44px; margin: 0; accent-color: var(--accent); background: transparent; }
.saved { color: var(--ok); font-weight: 600; }
.error-box { color: var(--danger); font-weight: 600; }

/* ---------- sketches ---------- */
.sk-line { fill: none; stroke: var(--sk-line); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sk-dim { stroke: var(--sk-dim); }
.sk-face { stroke: var(--sk-line); stroke-width: 2.5; }
.sk-wall { stroke: var(--sk-dim); stroke-width: 3; }
.sk-palate { stroke: #c9d3e0; stroke-width: 4; }
.sk-velum { fill: none; stroke: #b98a90; stroke-width: 7; stroke-linecap: round; }
.sk-velum.sk-focus { stroke: var(--accent); }
.sk-tongue { fill: var(--sk-tongue); stroke: #e79a9e; stroke-width: 1.5; }
.sk-tongue.sk-focus { fill: #d9737a; stroke: var(--accent); stroke-width: 2.5; }
.sk-tooth { fill: #e9edf3; stroke: none; }
.sk-arrow { fill: none; stroke: var(--sk-arrow); stroke-width: 3; stroke-linecap: round; }
.sk-focus-line { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; opacity: .8; }
.sk-focus-fill { fill: rgba(108, 184, 255, .25); stroke: var(--accent); stroke-width: 1.5; }
.sk-lips { stroke: #e79a9e; stroke-width: 3; }
.sk-lipfill { fill: #b9636a; stroke: #e79a9e; stroke-width: 1.5; }
.sk-lipfill.sk-focus { stroke: var(--accent); stroke-width: 2.5; }
.sk-mouth-in { fill: #2a0f14; }
.sk-tool { fill: none; stroke: #d8c39a; stroke-width: 6; stroke-linecap: round; }
.sk-tool-thin { fill: none; stroke: #d8c39a; stroke-width: 1.5; }
.sk-balloon { fill: rgba(108, 184, 255, .18); stroke: var(--accent); stroke-width: 2; }
.sk-wave { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; opacity: .8; }
.sk-label { fill: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; }

/* Training: keep the controls above the fold on small phones (360x780). */
body[data-screen="training"] .brand { display: none; }
body[data-screen="training"] .sketch { max-height: 22vh; }
body[data-screen="training"] .tr-cue { margin: 8px 0 4px; }
body[data-screen="training"] .counter { padding-top: 2px; }
body[data-screen="training"] .pacer { margin: 6px 0 12px; }

/* Admin: a 0/1 value as a two-button switch */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented .seg { width: 100%; }
.segmented .seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sk-focus-lips { stroke: var(--accent); }
