:root {
  --bg: #12201c;
  --card: #1b2e29;
  --card-2: #223832;
  --line: #3a5850;
  --text: #eef2ee;
  --muted: #b3c4bd;
  --accent: #f7942d;
  --accent-ink: #1a1206;
  --green: #5cc08a;
  --yellow: #e8c547;
  --red: #f0726a;
  --focus: #ffd27a;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.no-scroll { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.error { color: var(--red); }
.m0 { margin: 0; }
.mt { margin-top: 12px; }
.block { display: block; }
.center { text-align: center; }
.quote { text-align: center; margin: 22px 8px; }
.h-plain { font-size: 1.05rem; margin: 0; }

/* ---------- Topbar & Tabbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(18, 32, 28, 0.96);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: 0.08em; white-space: nowrap; }
.brand span { font-weight: 500; letter-spacing: 0; color: var(--accent); margin-left: 4px; }
.sync-status { font-size: 0.8rem; color: var(--yellow); text-align: right; }
.sync-status.error { color: var(--red); }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px calc(100px + var(--safe-bottom));
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #0f1b18;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  background: none; border: 0; padding: 8px 0 10px;
  color: var(--muted); font-size: 0.85rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 62px; cursor: pointer;
}
.tabbar .ico { font-size: 1.25rem; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 700; }
.tabbar button[aria-current="page"]::after {
  content: ""; width: 24px; height: 3px; border-radius: 2px; background: var(--accent); margin-top: 2px;
}

/* ---------- Karten & Layout ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2, .card h3 { margin: 0 0 10px; }
.card h2 { font-size: 1.15rem; }
.card h3 { font-size: 1rem; margin-top: 14px; }
.card > :last-child { margin-bottom: 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ---------- Heute-Kopf ---------- */

.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.day-nav .nav-arrow { min-width: 52px; min-height: 52px; font-size: 1.6rem; padding: 0; }
.day-nav .date { text-align: center; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }

.hero {
  background: linear-gradient(160deg, #213a33, #182a25);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
}
.hero-top { display: flex; gap: 14px; align-items: center; }
.code-badge {
  flex: 0 0 auto;
  width: 64px; height: 64px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 900; font-size: 1.7rem;
}
.code-badge.test { font-size: 1rem; letter-spacing: 0.05em; }
.code-badge.light { background: #3d6b5c; color: var(--text); }
.hero h1 { font-size: 1.3rem; margin: 0; }
.hero .phase { color: var(--muted); font-size: 0.9rem; margin: 3px 0 0; }
.hero .note { margin: 12px 0 0; font-size: 0.95rem; color: #dce6e0; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--card-2); border: 1px solid var(--line);
  font-size: 0.82rem; color: var(--muted);
}
.pill.ok { color: var(--green); border-color: #3b7d58; }
.pill.warn { color: var(--yellow); border-color: #7a6a2e; }
.pill.bad { color: var(--red); border-color: #7d3a35; }
.pill.neutral { color: var(--text); border-color: var(--line); }
.verdict { max-width: 58%; white-space: normal; text-align: right; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }
.btn-xl { min-height: 68px; font-size: 1.25rem; padding: 0 28px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.link-btn {
  background: none; border: 0; padding: 6px 0; color: var(--accent);
  text-decoration: underline; cursor: pointer; font-weight: 600; text-align: left; min-height: 40px;
}

.start-buttons { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
.start-buttons .btn-primary { min-height: 64px; font-size: 1.15rem; }

/* ---------- Formularelemente ---------- */

.field { display: block; }
.field > span { display: block; font-size: 0.88rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #13241f;
}
.field textarea { min-height: 80px; resize: vertical; }
[aria-invalid="true"] { border-color: var(--red) !important; box-shadow: 0 0 0 1px var(--red); }

.check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: 0 0 auto; }

fieldset.plain { border: 0; margin: 0; padding: 0; }
fieldset.plain legend { padding: 0; margin-bottom: 4px; }

.scale-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.scale-label .val { font-weight: 700; white-space: nowrap; }
.scale { display: grid; gap: 6px; }
.scale.eleven { grid-template-columns: repeat(11, 1fr); }
.scale.five { grid-template-columns: repeat(5, 1fr); }
.scale button {
  min-height: 48px; border-radius: 10px;
  border: 1px solid var(--line); background: #13241f;
  font-weight: 700; font-size: 1rem; cursor: pointer; padding: 0;
}
.scale button.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale.pain button.sel.g { background: var(--green); border-color: var(--green); color: #07140d; }
.scale.pain button.sel.y { background: var(--yellow); border-color: var(--yellow); color: #1b1603; }
.scale.pain button.sel.r { background: var(--red); border-color: var(--red); color: #1e0605; }
.scale button.sel { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35); text-decoration: underline; text-underline-offset: 3px; }

/* Auf schmalen Displays 0–5 und 6–10 in zwei Reihen, damit jede Taste groß genug bleibt */
@media (max-width: 520px) {
  .scale.eleven { grid-template-columns: repeat(6, 1fr); }
}

.yn-block { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-width: 180px; }
.yn button {
  min-height: 48px; border-radius: 10px; border: 1px solid var(--line);
  background: #13241f; font-weight: 700; cursor: pointer;
}
.yn button.sel { background: var(--card-2); border-color: var(--text); }
.yn button.sel.bad { background: var(--red); border-color: var(--red); color: #1e0605; }

.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.segmented button {
  min-height: 52px; border-radius: 10px; border: 1px solid var(--line);
  background: #13241f; font-weight: 700; font-size: 0.95rem; cursor: pointer; padding: 0 6px;
}
.segmented button.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (min-width: 560px) { .segmented { grid-template-columns: repeat(4, 1fr); } }

details.fold { border-top: 1px solid var(--line); padding-top: 6px; }
details.fold > summary {
  cursor: pointer; list-style: none; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center; min-height: 48px;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "+"; color: var(--accent); font-size: 1.5rem; }
details.fold[open] > summary::after { content: "–"; }
.fold-body { margin-top: 10px; }

/* ---------- Übungen ---------- */

.ex-list { list-style: none; margin: 0; padding: 0; counter-reset: ex; }
.ex-list li {
  display: grid; grid-template-columns: 32px 1fr; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.ex-list li:last-child { border-bottom: 0; }
.ex-list li::before {
  counter-increment: ex; content: counter(ex);
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--card-2); display: grid; place-items: center;
  font-weight: 700; font-size: 0.9rem; color: var(--accent);
}
.ex-list .name { font-weight: 700; }
.ex-list .tech { font-size: 0.92rem; color: var(--muted); margin-top: 2px; }

fieldset.ex-log { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 12px; margin: 10px 0 0; background: #172925; }
fieldset.ex-log legend { font-weight: 700; padding: 0 6px; }
fieldset.ex-log .grid-2 { margin-top: 6px; }

/* ---------- Hinweise ---------- */

.warnbox {
  border: 2px solid #7a6a2e; background: #2a2715;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
}
.warnbox strong { color: var(--yellow); }
.warnbox ul { margin: 6px 0 6px 18px; padding: 0; font-size: 0.95rem; }
.warnbox .advice { font-size: 0.92rem; margin: 6px 0 0; }

.infobox {
  border: 1px solid var(--line); background: #172925;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 0.95rem;
}
.infobox p { margin: 4px 0 10px; }

/* ---------- Tabellen & Listen ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th, table.data td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
table.data tbody th { font-weight: 600; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.week-list { padding: 4px 12px; }
.week-day {
  width: 100%;
  display: grid; grid-template-columns: 52px 40px 1fr auto;
  gap: 10px; align-items: center; text-align: left;
  padding: 12px 4px; min-height: 60px;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.week-day:last-child { border-bottom: 0; }
.week-day .wd { font-weight: 700; }
.week-day .wd small { display: block; font-weight: 400; color: var(--muted); font-size: 0.82rem; }
.week-day .mini-badge {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--card-2); font-weight: 800;
}
.week-day.today .mini-badge { background: var(--accent); color: var(--accent-ink); }
.week-day .status { text-align: right; }

.score { font-size: 2rem; font-weight: 800; }
.kpis > div { padding: 4px 0; }

ol.ladder { list-style: none; margin: 0; padding: 0; }
.ladder-step {
  display: grid; grid-template-columns: 42px 1fr; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.ladder-step:last-child { border-bottom: 0; }
.ladder-step .num {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800;
  background: var(--card-2); border: 2px solid var(--line);
}
.ladder-step.done .num { background: #3b7d58; border-color: #3b7d58; }
.ladder-step.current .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ladder-step .t { font-weight: 700; }
.ladder-step .d { font-size: 0.92rem; color: var(--muted); }

.check-list { list-style: none; margin: 4px 0 0; padding: 0; }
.check-list .check { min-height: 44px; }
.prep-card { border-color: var(--accent); }
.flow { white-space: pre-wrap; font: inherit; font-size: 0.95rem; margin: 0; }

.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 4px 0; }

.prose p, .prose li { font-size: 0.97rem; }
.prose ul { padding-left: 20px; margin: 8px 0; }

.export-list .btn {
  flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px;
  text-align: left; margin-bottom: 8px; min-height: 60px; padding: 8px 16px;
}
.export-list .btn small { display: block; font-weight: 400; color: var(--muted); font-size: 0.82rem; }
.export-list .btn-primary small { color: #4a2c05; }

.spark { width: 100%; height: 90px; display: block; }
.spark-raw { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.spark-avg { fill: none; stroke: var(--accent); stroke-width: 3; }
.legend-avg { color: var(--accent); }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; max-width: none; }
.login-card { width: 100%; max-width: 380px; }
.login-card form { margin-top: 24px; display: grid; gap: 14px; }
.brand-big { font-size: 2.6rem; font-weight: 900; letter-spacing: 0.06em; line-height: 1; margin: 0; }
.brand-big span { display: block; font-size: 1.1rem; font-weight: 500; letter-spacing: 0; color: var(--accent); margin-top: 6px; }

/* ---------- Timer ---------- */

.timer {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 20px calc(var(--safe-bottom) + 20px);
}
.timer.work { background: #1d3a2a; }
.timer.rest { background: #14211d; }
.timer-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.timer-phase { color: var(--muted); font-size: 0.95rem; }
.timer-body { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 8px; }
.timer-kind { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.9rem; color: var(--accent); font-weight: 700; }
.timer-label { font-size: 1.8rem; font-weight: 800; margin: 0; }
.timer-sub { color: #dce6e0; font-size: 1.05rem; max-width: 30em; margin: 0 auto; }
.timer-count { font-size: clamp(5rem, 28vw, 9rem); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; margin: 10px 0; }
.timer-next { color: var(--muted); font-size: 1rem; margin: 0; }
.timer-progress { height: 10px; background: var(--card-2); border-radius: 8px; overflow: hidden; }
.timer-progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s linear; }
.timer-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; margin: 6px 0 16px; font-variant-numeric: tabular-nums; }
.timer-controls { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }

/* ---------- Dialog-Sheets ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 10, 8, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(var(--safe-bottom) + 16px);
}
.sheet-title { font-size: 1.5rem; margin: 0 0 4px; }
.sheet-actions { display: grid; gap: 8px; margin-top: 18px; }
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 80; background: #0b1512; border: 1px solid var(--line);
  padding: 12px 16px; border-radius: 12px; font-size: 0.95rem;
  width: max-content; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* ---------- Bericht (Druck) ---------- */

.report {
  position: fixed; inset: 0; z-index: 70; overflow: auto;
  background: #fff; color: #1a1a1a;
  padding: 20px 16px 40px;
}
.report .report-inner { max-width: 800px; margin: 0 auto; }
.report h1 { font-size: 1.5rem; margin: 0 0 4px; }
.report h2 { font-size: 1.1rem; margin: 22px 0 8px; border-bottom: 2px solid #f7942d; padding-bottom: 4px; }
.report table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.report th, .report td { border-bottom: 1px solid #ddd; padding: 5px 6px; text-align: left; }
.report th { background: #f4f4f0; }
.report .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.report .kpi { border: 1px solid #ccc; border-radius: 10px; padding: 10px; }
.report .kpi b { display: block; font-size: 1.4rem; }
.report .report-actions { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.report .report-actions .btn { background: #eee; color: #111; border-color: #999; }
.report .report-actions .btn-primary { background: var(--accent); border-color: #b86412; }
.report :focus-visible { outline-color: #1a4dd6; }
.report .disclaimer { font-size: 0.85rem; color: #444; margin-top: 20px; }

@media print {
  body > *:not(#report) { display: none !important; }
  .report { position: static; padding: 0; }
  .report .report-actions { display: none; }
}

@media (min-width: 700px) {
  .start-buttons { grid-template-columns: 2fr 1fr; }
}
