:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eceff0;
  --text: #15201b;
  --muted: #5d6b64;
  --line: #dde3df;
  --accent: #1f9d6b;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ea;
  --warn: #b7791f;
  --warn-soft: #fbf0dc;
  --danger: #c2413b;
  --g: #2f9e5b; --y: #d4a017; --r: #d04a3f;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1714; --surface: #18221e; --surface-2: #222e29; --text: #e8efeb; --muted: #93a39b;
    --line: #2b3833; --accent: #3ccf8e; --accent-ink: #062016; --accent-soft: #173a2b;
    --warn: #e9b44c; --warn-soft: #3a2f17; --danger: #f07167; --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1714; --surface: #18221e; --surface-2: #222e29; --text: #e8efeb; --muted: #93a39b;
  --line: #2b3833; --accent: #3ccf8e; --accent-ink: #062016; --accent-soft: #173a2b;
  --warn: #e9b44c; --warn-soft: #3a2f17; --danger: #f07167; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
main { max-width: 640px; margin: 0 auto; padding: calc(12px + env(safe-area-inset-top)) 16px 24px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.01em; }
h3 { font-size: 17px; margin: 0 0 4px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.top { padding: 12px 2px 16px; }
.top .muted { margin-top: 2px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 700; margin: 0 0 4px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; gap: 12px; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.center { justify-content: center; }
.grow { flex: 1; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 99px; font-size: 13px; font-weight: 600; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card.accent { border-color: var(--accent); }
.hero h2 { font-size: 26px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; margin-top: 12px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 8px; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); font-size: 16px; cursor: pointer; }

.mini-list { display: flex; gap: 6px; margin: 12px 0 0; overflow: hidden; }
.mini-list .thumb { width: 48px; height: 48px; }

.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; background: var(--surface-2); flex-shrink: 0; }
.ex-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 0; background: none; border: 0; border-top: 1px solid var(--line); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.card .ex-row:first-of-type, #lib-results .ex-row:first-of-type { border-top: 0; }
.ex-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ex-row-text small { color: var(--muted); font-size: 14px; }
.chev { color: var(--muted); font-size: 22px; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 14px 0 0; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 12px 0; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.day i { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); border: 2px solid transparent; }
.day.on i { background: var(--accent); }
.day.today i { border-color: var(--accent); }
.day.today span { color: var(--text); font-weight: 700; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress.thin { height: 4px; margin: 0; border-radius: 0; }

.notice { border-radius: 12px; padding: 12px; margin: 10px 0 0; font-size: 15px; }
.notice.ok { background: var(--accent-soft); }
.notice.warn { background: var(--warn-soft); }
.traffic { list-style: none; padding: 0; margin: 8px 0; }
.traffic li { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.dot.g { background: var(--g); } .dot.y { background: var(--y); } .dot.r { background: var(--r); }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0; font-size: 15px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.steps { padding-left: 20px; margin: 8px 0 0; }
.steps li { margin-bottom: 6px; }

/* Bildpaar: Start- und Endposition im Wechsel */
.pair { position: relative; aspect-ratio: 4 / 3; background: #fff; border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.pair img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pair.anim img:last-child { animation: swap 2.4s infinite steps(1); }
.pair.paused img:last-child { animation-play-state: paused; }
@keyframes swap { 0% { opacity: 0; } 50% { opacity: 1; } }

/* Bibliothek */
.filters { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 4px 0 12px; display: grid; gap: 8px; }
input[type=search], select, textarea, .num input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.filters .row select { min-width: 0; flex: 1; font-size: 14px; padding: 8px; }
textarea { margin: 12px 0 0; resize: vertical; }

/* Training */
body[data-route="workout"] .tabs { display: none; }
body[data-route="workout"] { padding-bottom: 0; }
body[data-route="workout"] main { padding-top: env(safe-area-inset-top); }
.wk-top { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.wk-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wk-title small { color: var(--accent); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.wk-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.wk .pair { margin: 12px 0; }
.wk-body { padding-bottom: 100px; }
.target { font-size: 20px; font-weight: 700; color: var(--accent); margin: 2px 0 4px; }
.note { color: var(--muted); }
.last { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.tip { margin: 6px 0 0; font-size: 15px; }
.sets { display: grid; gap: 8px; margin: 14px 0; }
.set { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 8px 8px 14px; }
.set.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.set.done { opacity: .6; }
.set-n { font-weight: 700; width: 56px; flex-shrink: 0; }
.set-val { flex: 1; color: var(--muted); }
.num { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.num input { width: 100%; min-width: 0; text-align: center; padding: 8px 4px; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.num span { color: var(--muted); font-size: 13px; }
.check { width: 48px; height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 22px; cursor: pointer; flex-shrink: 0; margin-left: auto; }
.set.current .check { border-color: var(--accent); color: var(--accent); }
.set.done .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.set .check.play { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 18px; }
.cues { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.cues summary, details summary { font-weight: 700; cursor: pointer; }
.cues ol, .sheet ol { padding-left: 20px; margin: 8px 0 0; }
.cues li, .sheet li { margin-bottom: 6px; }
.en { color: var(--muted); font-size: 15px; }
.wk-nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); max-width: 640px; margin: 0 auto;
}
.wk-nav .btn { min-height: 52px; }

/* Pausen-Overlay */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: grid; place-items: center; padding: 24px 16px; }
.ov-inner { text-align: center; width: 100%; max-width: 360px; display: grid; gap: 14px; justify-items: center; }
.overlay .eyebrow { font-size: 15px; }
.overlay[data-kind="ready"] .eyebrow { color: var(--warn); }
.ring { position: relative; width: min(70vw, 260px); aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 339.3; transition: stroke-dashoffset .25s linear; }
.overlay[data-kind="ready"] .fg { stroke: var(--warn); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ov-sub { color: var(--muted); font-size: 17px; }

/* Abschluss */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.stats strong { font-size: 26px; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 14px; }
.pain-scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; margin: 10px 0 16px; }
.pain { border: 0; border-radius: 8px; min-height: 40px; font: inherit; font-weight: 700; color: #fff; cursor: pointer; opacity: .55; display: inline-grid; place-items: center; }
.pain.pg { background: var(--g); } .pain.py { background: var(--y); } .pain.pr { background: var(--r); }
.pain.sel { opacity: 1; outline: 3px solid var(--text); outline-offset: 1px; }
.session summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none; }
.session summary::-webkit-details-marker { display: none; }
.session summary div { display: flex; flex-direction: column; }
.session .pain { opacity: 1; width: 34px; min-height: 34px; }
.log { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.log td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.log td:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; padding-left: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row select { width: auto; }
.switch-row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.card > .row.gap.wrap { margin-top: 8px; }

/* Detail-Sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { position: relative; background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .close { position: absolute; top: 24px; right: 24px; z-index: 2; background: rgba(0,0,0,.55); color: #fff; }
.sheet-body { padding-top: 14px; }
.sheet h3 { margin-top: 16px; }
.sheet details { margin-top: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: var(--surface-2); border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.chip.strong { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Tab-Leiste */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; padding: 8px 0 6px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.tabs a span { font-size: 22px; line-height: 1.1; }
.tabs a.on { color: var(--accent); }
.session summary small { font-weight: 400; }

/* Anmeldung & Profil */
body[data-route="login"] .tabs { display: none; }
body[data-route="login"] { padding-bottom: 0; }
.login { min-height: 90vh; display: flex; flex-direction: column; justify-content: center; gap: 8px; max-width: 400px; margin: 0 auto; }
.login h1 { text-align: center; }
.login > .muted { text-align: center; margin-bottom: 8px; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.field input:not([type=checkbox]) { font: inherit; font-weight: 400; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%; }
.field textarea { margin: 0; font-weight: 400; }
.field .row input { flex: 1; min-width: 0; }
.field-val { font-size: 18px; color: var(--text); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; }
.pw-form { margin: 4px 0 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 8px; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 24px; font-weight: 700; flex-shrink: 0; }
.sync-ok { color: var(--accent); }
.sync-saving { color: var(--muted); }
.sync-offline, .sync-auth { color: var(--warn); }
.reminder { background: var(--warn-soft); border-color: transparent; }
.reminder .eyebrow { color: var(--warn); }
.reminder p:last-child { margin: 0; white-space: pre-line; }
.tabs a { font-size: 11px; }
