:root {
  color-scheme: dark;
  --bg: #0e0f12;
  --surface: #17191e;
  --surface-2: #1f2228;
  --surface-3: #2a2e36;
  --line: #2c3038;
  --text: #f2f3f5;
  --text-2: #b4b8c2;
  --muted: #7d828e;
  --accent: #c6f432;
  --accent-ink: #12160a;
  --danger: #ff6b6b;
  --good: #2ee6a6;
  /* Chart-Serien (validiert gegen --surface) */
  --c-train: #199e70;
  --c-kcal: #d95926;
  --c-protein: #3987e5;
  --c-weight: #9085e9;
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

#app {
  max-width: 720px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}
.boot { display: grid; place-items: center; height: 70vh; }
.logo-mark { width: 44px; height: 44px; border-radius: 12px; background: url(/icon.svg) center/cover; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .6; } }

/* ---------- Layout-Bausteine ---------- */
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid-3.collapse { grid-template-columns: 1fr; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head .hint { color: var(--muted); font-size: 13px; }
.card.link { display: block; text-decoration: none; transition: border-color .15s, transform .15s; }
.card.link.row { display: flex; }
.card.link:hover { border-color: var(--surface-3); }
.card.link:active { transform: scale(.99); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 2px 10px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 10px 16px; font-weight: 650; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  transition: background .15s, transform .1s, border-color .15s; white-space: nowrap; min-height: 42px;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: #4a2a2e; }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.icon { width: 42px; padding: 0; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Formulare ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; outline: none; min-height: 44px; transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; min-height: 70px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(198, 244, 50, .15); }
.input::placeholder { color: var(--muted); }
.input-unit { position: relative; }
.input-unit .input { padding-right: 44px; }
.input-unit em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 650; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface-3); color: var(--text); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--surface-3); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); background: var(--accent-ink); }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- Auth ---------- */
.auth { min-height: 80vh; display: grid; place-items: center; }
.auth-box { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand .logo-mark { animation: none; }
.brand b { font-size: 26px; font-weight: 850; letter-spacing: -0.02em; }
.hero-line { font-size: 15px; color: var(--text-2); margin-bottom: 26px; }

/* ---------- Avatar ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-weight: 800; font-size: 14px; color: #111; text-transform: uppercase;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.lg { width: 56px; height: 56px; font-size: 22px; }

/* ---------- Heute ---------- */
.hello { font-size: 14px; color: var(--muted); font-weight: 600; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 650; white-space: nowrap;
}
.chip b { font-weight: 800; }
.chip.hot { border-color: #5a3a1c; background: #24190f; }
.datebar { display: flex; align-items: center; gap: 8px; }
.datebar .label { flex: 1; text-align: center; font-weight: 700; }
.datebar .label small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }

.checkoff {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  transition: background .15s, border-color .15s;
}
.checkoff:hover { border-color: var(--surface-3); }
.checkoff .tick {
  width: 44px; height: 44px; border-radius: 14px; border: 2px dashed var(--surface-3); display: grid; place-items: center; flex: none;
}
.checkoff .tick svg { width: 24px; height: 24px; fill: none; stroke: var(--accent-ink); stroke-width: 3; opacity: 0; }
.checkoff.done { background: #1b2410; border-color: #3b4d17; }
.checkoff.done .tick { background: var(--accent); border: 0; }
.checkoff.done .tick svg { opacity: 1; }

.workout-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.workout-item:first-child { border-top: 0; }
.workout-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c-train); flex: none; }

.metric { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.metric .k { font-size: 12px; color: var(--text-2); font-weight: 650; display: flex; align-items: center; gap: 6px; }
.metric .k i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.metric .input { margin-top: 8px; background: var(--surface); font-size: 18px; font-weight: 750; padding: 8px 10px; min-height: 42px; }
.bar { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .3s; }
.metric .goal { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; gap: 4px; }
.metric .goal b { color: var(--text-2); font-weight: 650; }
.hit-badge { color: var(--good); font-weight: 700; }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart text.axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .goal-line { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .goal-label { fill: var(--text-2); font-size: 11px; font-weight: 650; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart-empty { color: var(--muted); font-size: 14px; padding: 26px 0; text-align: center; }
.big-num { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.big-num small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.delta { font-size: 13px; font-weight: 700; color: var(--text-2); }

.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 4px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--surface-3); display: block; }
.heat i.on { background: var(--c-train); }
.heat i.today { outline: 2px solid var(--text-2); outline-offset: 1px; }
.heat i.future { background: transparent; }
.heat-wrap { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: stretch; }
.heat-days { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; font-size: 10px; color: var(--muted); }
.heat-days span { display: flex; align-items: center; }

.tip {
  position: fixed; z-index: 50; pointer-events: none; background: #0b0c0f; border: 1px solid var(--surface-3);
  color: var(--text); padding: 8px 10px; border-radius: 10px; font-size: 12.5px; line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); max-width: 220px; white-space: nowrap;
}
.tip b { font-weight: 750; }
.tip .tk { display: flex; align-items: center; gap: 6px; }
.tip .tk i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- Pläne ---------- */
.plan-card .days { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tag { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-weight: 600; }
.ex-table { width: 100%; border-collapse: collapse; }
.ex-table td { padding: 10px 0; border-top: 1px solid var(--line); vertical-align: top; }
.ex-table tr:first-child td { border-top: 0; }
.ex-table .sr { text-align: right; white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; font-weight: 650; padding-left: 10px; }
.ex-edit { display: grid; grid-template-columns: 1fr 64px 84px auto; gap: 6px; align-items: center; margin-top: 6px; }
.ex-edit .input { min-height: 40px; padding: 8px 10px; }
.ex-edit .note { grid-column: 1 / -2; }
@media (max-width: 480px) {
  .ex-edit { grid-template-columns: 1fr 56px 70px auto; }
}
.day-edit { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-2); }
.day-edit .input { background: var(--surface); }
.day-edit + .day-edit { margin-top: 10px; }
.ex-sep { height: 1px; background: var(--line); margin: 10px 0 4px; }

/* ---------- Workout-Editor ---------- */
.ex-check {
  display: grid; grid-template-columns: auto 1fr 92px; gap: 12px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
}
.ex-check + .ex-check { margin-top: 8px; }
.ex-check.done { border-color: #2c4a3b; background: #142019; }
.ex-check .cb {
  width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--surface-3); background: transparent;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.ex-check.done .cb { background: var(--c-train); border-color: var(--c-train); }
.ex-check .cb svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 3; opacity: 0; }
.ex-check.done .cb svg { opacity: 1; }
.ex-check .nm { font-weight: 650; }
.ex-check.done .nm { color: var(--text-2); }
.ex-check .input { min-height: 38px; padding: 6px 10px; background: var(--surface); }
.progress-ring { display: flex; align-items: center; gap: 10px; }

/* ---------- Crew ---------- */
.ch-card .meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; color: var(--text-2); font-size: 13px; }
.rank-badge { font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; }
.period { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.period > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.invite { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px dashed var(--surface-3); border-radius: var(--radius-sm); padding: 10px 12px; }
.invite code { font-size: 18px; font-weight: 800; letter-spacing: .12em; color: var(--accent); }

.lb-row { display: grid; grid-template-columns: 28px auto 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.lb-row:first-child { border-top: 0; }
.lb-row .pos { font-weight: 800; font-size: 17px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-row.first .pos { color: var(--accent); }
.lb-row .pts { text-align: right; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.lb-row .pts small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.lb-row .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.lb-row.me { background: linear-gradient(90deg, rgba(198, 244, 50, .06), transparent); border-radius: 10px; }

.week-grid { display: grid; grid-template-columns: minmax(0, 120px) repeat(7, minmax(0, 1fr)); gap: 6px 4px; align-items: center; }
@media (max-width: 480px) {
  .week-grid { grid-template-columns: 30px repeat(7, minmax(0, 1fr)); }
  .week-grid .nm > span:last-child { display: none; }
}
.week-grid .h { font-size: 11px; color: var(--muted); text-align: center; font-weight: 650; }
.week-grid .h.today { color: var(--text); }
.week-grid .nm { font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.wg-cell { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 7px 0; border-radius: 8px; cursor: default; }
.wg-cell:hover { background: var(--surface-2); }
.wg-cell i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--surface-3); display: block; }
.wg-cell i.t.on { background: var(--c-train); border-color: var(--c-train); }
.wg-cell i.k.on { background: var(--c-kcal); border-color: var(--c-kcal); }
.wg-cell i.p.on { background: var(--c-protein); border-color: var(--c-protein); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.feed-item { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); align-items: center; }
.feed-item:first-child { border-top: 0; }
.rules { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 14px; }
.rules b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Verlauf ---------- */
.hist-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: center; }
.hist-item:first-child { border-top: 0; }
.date-box { width: 46px; text-align: center; flex: none; background: var(--surface-2); border-radius: 10px; padding: 5px 0; }
.date-box b { display: block; font-size: 17px; font-weight: 800; line-height: 1.1; }
.date-box small { font-size: 10.5px; color: var(--muted); text-transform: uppercase; font-weight: 700; }

/* ---------- Profil ---------- */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatches button.on { border-color: var(--text); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; gap: 2px;
  background: rgba(14, 15, 18, .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 650; padding: 6px 0; border-radius: 12px;
}
.tabbar a svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.on { color: var(--accent); }
.tabbar[hidden] { display: none; }

/* ---------- Toast & Modal ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: #111; padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--danger); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 40; display: grid; align-items: end; justify-items: center; }
.modal {
  width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 85dvh; overflow: auto;
}
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 22px; border-bottom: 1px solid var(--line); } }
.empty { text-align: center; padding: 26px 12px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 6px 4px; text-align: right; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }
details.tbl summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }
