:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ece9e2;
  --ink: #1b1d21;
  --muted: #6b6f78;
  --line: #dedad1;
  --accent: #e2551f;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --knapp: #b7791f;
  --nein: #c23b3b;
  --radius: 16px;
  --tabbar: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --surface-2: #262a32;
    --ink: #f1efe9;
    --muted: #9aa0ab;
    --line: #2e333c;
    --accent: #ff6a33;
    --ok: #3cc178;
    --knapp: #e0a33c;
    --nein: #ef6161;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
a { color: inherit; }
button { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---- Rahmen ------------------------------------------------------------ */

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}
.topbar h1 { font-size: 1.7rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1.15rem;
  text-decoration: none;
  cursor: pointer;
}

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}
.tabbar a.active { color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 1.25rem; line-height: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card > h2 { margin-bottom: 8px; }

/* ---- Knoepfe ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--surface-2);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; border-color: var(--nein); color: var(--nein); }
.btn.small { min-height: 40px; font-size: 0.9rem; font-weight: 500; }
.btn.wide { width: 100%; }
.btn:active { transform: scale(0.98); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 auto; }

.linkish {
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

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

.hero { display: flex; flex-direction: column; gap: 14px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  min-width: 0;
}
.stat b { font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }

.start { min-height: 60px; font-size: 1.15rem; }
.done-note { margin: 0; color: var(--ok); font-weight: 600; }

.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }

.ex-list { list-style: none; margin: 0; padding: 0; }
.ex-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.ex-list li:first-child { border-top: 0; }
.ex-list li > span:last-child { flex-shrink: 0; text-align: right; }

.tag { font-size: 0.8rem; font-weight: 600; }
.tag.ok { color: var(--ok); }
.tag.knapp { color: var(--knapp); }
.tag.nein { color: var(--nein); }
.tag.skip { color: var(--muted); }

/* ---- Einstufung -------------------------------------------------------- */

.onboarding { padding-top: calc(32px + env(safe-area-inset-top)); }
.onboarding h1 { font-size: 2.2rem; }
.lead { margin: 0; color: var(--muted); }

.level-row { margin: 0; padding: 0; border: 0; }
.level-row legend { font-weight: 700; margin-bottom: 6px; }
.level-row legend small { margin-left: 8px; font-weight: 400; color: var(--muted); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button {
  min-height: 44px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.85rem;
  cursor: pointer;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---- Training ---------------------------------------------------------- */

body.running .tabbar { display: none; }

.run-head {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px;
}
.run-block { text-align: center; font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.run-progress {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.run-progress span, .bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: transform 0.2s linear;
}

.run {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.run h1 { font-size: 1.8rem; }
.phase { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.stufe { color: var(--muted); font-size: 0.9rem; margin-top: -8px; }
.side { font-size: 1.1rem; font-weight: 700; }

.clock {
  font-size: 5.5rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clock.big { font-size: 7rem; }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }

.reps { display: flex; flex-direction: column; align-items: center; }
.reps-n { font-size: 7rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.reps-unit { color: var(--muted); }

.up-next {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.up-next h2 { font-size: 1.3rem; margin-top: 4px; }
.up-next .ziel { font-weight: 700; color: var(--accent); margin-top: 2px; }
.up-next .desc { margin: 8px 0 0; color: var(--muted); }

.guide {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.guide summary { font-weight: 600; cursor: pointer; }
.guide p { margin: 8px 0 0; }
.guide ul { margin: 6px 0 0; padding-left: 20px; }
.fehler-titel { font-weight: 600; color: var(--nein); }

.rate-label { color: var(--muted); font-size: 0.9rem; margin-bottom: -6px; }
.rate { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.rate .btn { padding: 0 8px; min-height: 64px; font-size: 0.95rem; }
.rate-ok { background: var(--ok); color: #fff; }
.rate-knapp { background: transparent; border-color: var(--knapp); color: var(--knapp); }
.rate-nein { background: transparent; border-color: var(--nein); color: var(--nein); }

/* ---- Fertig ------------------------------------------------------------ */

.fertig { padding-top: calc(32px + env(safe-area-inset-top)); text-align: center; }
.fertig .card { text-align: left; }
.big-check {
  width: 84px;
  height: 84px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  font-size: 2.6rem;
}
.suggest.hoch { border-color: var(--ok); }
.suggest.runter { border-color: var(--knapp); }
.suggest p { margin: 6px 0 12px; }

/* ---- Verlauf ----------------------------------------------------------- */

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; text-align: center; }
.cal th { font-size: 0.75rem; font-weight: 500; color: var(--muted); padding-bottom: 4px; }
.cal td { padding: 3px 0; }
.cal td span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.cal td.trained span { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal td.today span { box-shadow: inset 0 0 0 2px var(--ink); }

/* ---- Uebungen ---------------------------------------------------------- */

.ex-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
}
.ex-card summary::-webkit-details-marker { display: none; }
.ex-card[open] summary { margin-bottom: 10px; }
.ex-card p { margin: 8px 0 0; }

.ladder { margin: 0; padding-left: 22px; }
.ladder li { padding: 5px 0; }
.ladder li .linkish { display: block; }
.ladder li.past { color: var(--muted); }
.ladder li.current { font-weight: 700; color: var(--accent); }
.ladder li.current::marker { color: var(--accent); }
.history { margin-top: 10px; }
.ex-card .tips { margin: 6px 0 0; padding-left: 20px; }
.list-title { margin: 18px 4px 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.list-title:first-child { margin-top: 4px; }

/* ---- Einstellungen ----------------------------------------------------- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.switch-row:first-child { border-top: 0; }
.switch-row small { display: block; color: var(--muted); }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }
