:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #14171c; --muted: #6b7280; --line: #e3e6eb;
  --accent: #12996b; --accent-soft: #dff5ec; --danger: #d43c3c; --warm: #b7791f; --field: #eef0f3;
  --tab-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #191c22; --text: #eceef2; --muted: #9098a6; --line: #2a2e37;
    --accent: #2fc28d; --accent-soft: #173a2e; --danger: #f06a6a; --warm: #e0a84a; --field: #242831;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
main {
  max-width: 720px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 90px);
}
h1 { font-size: 26px; margin: 4px 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 22px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; font-weight: 600;
  background: var(--field); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:active { opacity: 0.7; }

input[type=text], input[type=date], input[type=password], input[type=search], select {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid transparent; background: var(--field); outline: none;
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.card { background: var(--card); border-radius: 16px; padding: 14px; margin: 10px 0; border: 1px solid var(--line); }
.card.tap { display: block; width: 100%; text-align: left; }
.card.tap:active { opacity: 0.75; }
.card-title { font-weight: 650; font-size: 17px; }
.list { background: var(--card); border-radius: 16px; border: 1px solid var(--line); overflow: hidden; margin: 10px 0; }
.list > * { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 48px; }
.list > *:last-child { border-bottom: 0; }
.list > button:active { background: var(--field); }

.seg { display: flex; background: var(--field); border-radius: 10px; padding: 3px; margin: 8px 0 12px; }
.seg button { flex: 1; min-height: 34px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

/* Trainingseditor */
.ed-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 8px) 0 8px; margin-top: calc(-1 * env(safe-area-inset-top) - 8px); }
.ex-name { font-weight: 650; font-size: 17px; color: var(--accent); text-align: left; }
.notes { margin: 8px 0 4px; min-height: 36px !important; font-size: 14px; }
.sets { width: 100%; }
.set, .set-head { display: grid; grid-template-columns: 30px minmax(0, 1fr) 58px 44px 44px 38px; gap: 5px; align-items: center; padding: 3px 0; }
.set.noc, .set-head.noc { grid-template-columns: 30px minmax(0, 1fr) 64px 50px 50px; }
.set-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; text-align: center; }
.set input { text-align: center; padding: 0 4px; min-height: 40px; font-variant-numeric: tabular-nums; }
.set .badge { min-height: 40px; border-radius: 10px; background: var(--field); font-weight: 700; }
.set .badge.warm { color: var(--warm); }
.set .prev { font-size: 12px; letter-spacing: -0.01em; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.set .chk { min-height: 40px; border-radius: 10px; background: var(--field); font-weight: 700; color: var(--muted); }
.set.done { background: var(--accent-soft); border-radius: 10px; }
.set.done .chk { background: var(--accent); color: #fff; }
.set.done input { background: transparent; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; height: var(--tab-h); font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tabs button.on { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; }

.rest {
  position: fixed; left: 12px; right: 12px; z-index: 19; max-width: 696px; margin: 0 auto;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 10px);
  background: var(--accent); color: #fff; border-radius: 14px; padding: 8px 8px 8px 16px;
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.rest[hidden] { display: none; }
.rest.over { background: var(--warm); }
.rest button { min-height: 38px; padding: 0 12px; border-radius: 10px; background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }

.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 720px; background: var(--card); border-radius: 18px 18px 0 0; padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px); max-height: 90vh; overflow: auto; }
.sheet-title { text-align: center; font-weight: 650; padding: 8px 0 10px; }
.sheet-btn { display: block; width: 100%; min-height: 50px; border-radius: 12px; background: var(--field); margin: 6px 0; font-weight: 600; }
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { background: transparent; color: var(--muted); }
.picker { height: 90vh; display: flex; flex-direction: column; }
.picker .list { flex: 1; overflow: auto; margin-bottom: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60; max-width: 90vw;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 70px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; text-align: center;
}
.toast[hidden] { display: none; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Kalorientracker */
.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--field); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.bar.over i { background: var(--danger); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macros .bar { height: 6px; margin-top: 4px; }
.daybtn { text-align: center; min-height: 44px; }
.btn[disabled] { opacity: 0.35; }
.entries { margin-top: 8px; border-top: 1px solid var(--line); }
.entry { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.entry:last-child { border-bottom: 0; padding-bottom: 2px; }
.entry:active { opacity: 0.6; }
.list > .list-head { min-height: 0; padding: 8px 14px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--field); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { min-height: 38px; padding: 0 14px; border-radius: 19px; background: var(--field); font-weight: 600; font-size: 14px; }
.goal-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 90px; gap: 8px; align-items: center; margin: 6px 0; }
.goal-row input { text-align: center; }
.goal-row.small span { text-align: center; }
.overlay.scan { align-items: center; background: rgba(0,0,0,.9); }
.scan-box { width: 100%; max-width: 520px; padding: 16px; position: relative; }
.scan-video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 16px; background: #000; display: block; }
.scan-line { position: absolute; left: 32px; right: 32px; top: calc(16px + (100% - 32px) * 0.28); height: 2px; background: var(--danger); opacity: 0.8; pointer-events: none; }
