:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f172a;
  --primary-text: #ffffff;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .08);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, .12);
  --warn-bg: #fff7e6;
  --warn-text: #92400e;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17;
    --surface: #141a24;
    --surface-2: #1c2431;
    --text: #e6eaf0;
    --muted: #8b97a8;
    --border: #243041;
    --primary: #e6eaf0;
    --primary-text: #0b0f17;
    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, .16);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, .1);
    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, .14);
    --warn-bg: #2a2110;
    --warn-text: #fbbf24;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #141a24;
  --surface-2: #1c2431;
  --text: #e6eaf0;
  --muted: #8b97a8;
  --border: #243041;
  --primary: #e6eaf0;
  --primary-text: #0b0f17;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, .16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .1);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, .14);
  --warn-bg: #2a2110;
  --warn-text: #fbbf24;
  --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.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.ic { width: 20px; height: 20px; flex: none; }
.ic.big { width: 44px; height: 44px; color: var(--muted); }

/* ---------- Kopfzeile ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.bar-in {
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 0 8px 0 8px;
}
.bar h1 {
  flex: 1; min-width: 0;
  font-size: 18px; font-weight: 650;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap; overflow: hidden;
}
.bar h1 span { overflow: hidden; text-overflow: ellipsis; }
.bar h1.brand { padding-left: 8px; }
.brand-ic { width: 24px; height: 24px; }
.bar-actions { display: flex; gap: 4px; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 560px; margin: 0 auto;
  padding: 8px 16px calc(40px + env(safe-area-inset-bottom));
}
.section-title {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 24px 4px 10px;
}
.ex-title { font-size: 26px; font-weight: 700; margin: 18px 4px 14px; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 0 0 10px; }
.small { font-size: 14px; }
.center { text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Listen ---------- */
.list, .history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.row { display: flex; align-items: center; padding: 4px 6px 4px 0; }
.row-main { flex: 1; min-width: 0; padding: 12px 8px 12px 16px; display: grid; gap: 2px; }
.row-title { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.row-sub { color: var(--muted); font-size: 14px; }
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: var(--ok); background: var(--ok-soft);
  padding: 2px 8px 2px 6px; border-radius: 99px;
}
.badge .ic { width: 13px; height: 13px; }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 12px; cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.sm .ic { width: 18px; height: 18px; }
.bar .icon-btn { color: var(--text); }

.add-card {
  width: 100%; margin-top: 12px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 64px; padding: 14px;
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.add-card:hover { border-color: var(--muted); color: var(--text); background: var(--surface); }
.add-card.slim { min-height: 52px; }

.empty { text-align: center; padding: 36px 16px 20px; }
.empty h3 { font-size: 18px; margin: 12px 0 6px; }
.empty p { color: var(--muted); margin: 0; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn-text); font-size: 14px;
}
.notice .ic { margin-top: 1px; }

/* ---------- Training ---------- */
.prev {
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 12px 14px;
}
.prev-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--accent); }
.prev .chips { margin-top: 8px; }
.link {
  display: inline-flex; align-items: center; gap: 4px;
  border: 0; background: transparent; color: var(--accent);
  font-weight: 600; font-size: 14px; cursor: pointer; padding: 6px 0 6px 8px;
}
.link .ic { width: 16px; height: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 14px; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 99px; white-space: nowrap;
}
.hist .chip { background: var(--surface-2); border-color: transparent; }

.sets { display: grid; gap: 10px; }
.set { padding: 10px 12px 12px 14px; }
.set-head { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.set-no { font-weight: 650; }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.set-grid label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.field {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field::placeholder { color: var(--muted); opacity: .55; }
.field.num { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
textarea.field { resize: vertical; min-height: 64px; }

details { margin-top: 8px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0; list-style-position: inside; }
details textarea { margin-top: 6px; }

/* ---------- Fortschritt ---------- */
.chart-card { padding: 14px 12px 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; text-align: center; }
.stat-v { display: block; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-v.up { color: var(--ok); }
.stat-l { display: block; font-size: 12px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); }
.chart .pt { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart .pt.last { fill: var(--accent); }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 700; }
.chart-card .muted { margin: 8px 4px 10px; }

.hist { padding: 8px 6px 12px 14px; }
.hist-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.hist-head strong { font-size: 15px; }
.hist-note { margin: 8px 0 0; font-size: 14px; color: var(--muted); font-style: italic; }

/* ---------- Einstellungen ---------- */
.block { padding: 16px; margin-top: 14px; }
.block h2 { font-size: 17px; margin-bottom: 10px; }
.block p { margin: 0 0 10px; }
.block p:last-child { margin-bottom: 0; }
.block .muted .ic { width: 16px; height: 16px; vertical-align: -3px; color: var(--ok); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg-btn { border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; cursor: pointer; font-weight: 550; font-size: 15px; color: var(--muted); }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
:root[data-theme="dark"] .seg-btn.on { background: var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg-btn.on { background: var(--border); } }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 11px;
  border: 1px solid transparent; font-weight: 600; cursor: pointer;
}
.btn .ic { width: 18px; height: 18px; }
.btn.full { width: 100%; margin-bottom: 10px; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-ghost { background: var(--danger-soft); color: var(--danger); }

/* ---------- Dialoge ---------- */
.modal {
  border: 0; padding: 0; border-radius: 18px;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(10, 14, 22, .5); backdrop-filter: blur(2px); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100dvh - 48px); }
.modal-body h2 { font-size: 19px; }
.modal-body .muted { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: -6px; }

.picker { height: min(640px, calc(100dvh - 48px)); }
.search { position: relative; display: block; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search .field { padding-left: 38px; }
.picker-list { flex: 1; overflow-y: auto; margin: 0 -8px; padding: 0 8px; overscroll-behavior: contain; }
.pick-group { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 4px 4px; }
.pick-group:first-child { margin-top: 4px; }
.pick {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  min-height: 46px; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; text-align: left; cursor: pointer; font-size: 16px;
}
.pick:hover:not([disabled]) { background: var(--surface-2); }
.pick[disabled] { color: var(--muted); cursor: default; }
.pick small { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; }
.pick small .ic { width: 14px; height: 14px; color: var(--ok); }
.pick.custom { background: var(--accent-soft); color: var(--accent); font-weight: 600; justify-content: flex-start; margin-top: 4px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--primary); color: var(--primary-text);
  padding: 10px 18px; border-radius: 99px; font-size: 15px; font-weight: 550;
  transition: opacity .2s, transform .2s; z-index: 50;
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
