:root {
  --bg: #eef3f9;
  --surface: #ffffff;
  --text: #0e1a2b;
  --muted: #5d6b80;
  --line: #d9e2ee;
  --accent: #1f7ae0;
  --accent-2: #19b8c9;
  --accent-text: #ffffff;
  --good: #1fa36b;
  --bad: #d9473b;
  --gold: #e8a317;
  --shadow: 0 2px 10px rgba(14, 26, 43, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1422;
    --surface: #142236;
    --text: #e8eef7;
    --muted: #8e9db3;
    --line: #22344d;
    --accent: #4c9dff;
    --accent-2: #34d1e0;
    --accent-text: #06111f;
    --good: #3ccf8e;
    --bad: #ff6b5e;
    --gold: #ffc23d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Kopf und Tabs ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(120deg, #0e2a4d, #1f7ae0 60%, #19b8c9);
  color: #fff;
}
.top h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.who { font-size: 13px; opacity: .85; }

main { max-width: 640px; margin: 0 auto; padding: 14px 12px 0; }
.tab { display: flex; flex-direction: column; gap: 12px; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0 9px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
}
.tabs button span { font-size: 21px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active span { filter: none; opacity: 1; }

/* ---------- Bausteine ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.list { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; margin: 18px 0; }
.sub { margin: 10px 2px 0; font-size: 14px; color: var(--muted); }
h2 { margin: 0; font-size: 16px; }
.note { margin: 6px 0 0; color: var(--muted); white-space: pre-line; font-size: 14px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }
.btn.primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  border-color: transparent;
}
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 13px; font-size: 16px; }
.icon {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  min-width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.icon:active { background: var(--bg); }
.icon.del { font-size: 20px; }
.icon.del:hover { color: var(--bad); }

.pill {
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}
.tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--accent);
}
.error { color: var(--bad); margin: 0; font-size: 14px; }
.ok { color: var(--good); margin: 0; font-size: 14px; }

.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: none; border-radius: 8px; padding: 7px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--bg); color: var(--text); font-weight: 600; }

/* ---------- Formulare ---------- */
.form { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > input, .row > select { flex: 1; min-width: 0; }
.row.end { align-items: center; }
.grow { flex: 1; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 16px; /* verhindert Zoom auf iOS */
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.mini { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); flex: 1; min-width: 0; }
label.mini input { width: 100%; }

/* ---------- Training ---------- */
.workout.mine { cursor: pointer; }
.workout.mine:active { border-color: var(--accent); }
.w-head { display: flex; align-items: center; gap: 10px; }
.w-icon {
  width: 38px; height: 38px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 20px;
}
.w-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.w-title .muted { font-size: 13px; }
.sets { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.sets li { display: flex; justify-content: space-between; gap: 10px; border-top: 1px dashed var(--line); padding-top: 3px; }

dialog {
  border: none;
  border-radius: 18px;
  padding: 16px;
  background: var(--surface);
  color: var(--text);
  width: min(560px, calc(100vw - 20px));
  max-height: calc(100vh - 30px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(5, 12, 24, .55); }
.sets-head, .set-row { display: grid; grid-template-columns: 1fr 52px 58px 64px 30px; gap: 5px; align-items: center; }
.sets-head { font-size: 12px; color: var(--muted); padding: 0 2px; }
#w-sets { display: flex; flex-direction: column; gap: 6px; }
.set-row input { padding: 8px 6px; width: 100%; }
.set-row .icon { min-width: 30px; }

/* ---------- Ernährung ---------- */
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav input { flex: 1; text-align: center; font-weight: 600; }
.bar + .bar { margin-top: 12px; }
.bar-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; gap: 10px; }
.track { height: 10px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.track.big { height: 14px; }
.fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }
.fill.over { background: linear-gradient(90deg, var(--gold), var(--bad)); }
.meal { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 6px 8px 14px; }
.meal-right { display: flex; align-items: center; gap: 2px; font-size: 13px; white-space: nowrap; }
.other { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; flex-wrap: wrap; }

/* ---------- Challenge ---------- */
.board { display: flex; flex-direction: column; gap: 10px; }
.player.me { border-color: var(--accent); }
.p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 17px; }
.crown { font-size: 18px; }
.p-head .pill { margin-left: auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 8px 4px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-size: 17px; }
.stat span { font-size: 11px; color: var(--muted); }

/* ---------- Ich ---------- */
.kg-list { display: flex; flex-direction: column; }
.kg-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.kg-row > :first-child { flex: 1; }
#a-list { gap: 0; }

/* ---------- Login ---------- */
body.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(160deg, #0e2a4d, #1f7ae0 55%, #19b8c9);
}
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.logo { font-size: 46px; line-height: 1; }
.login-card h1 { margin: 6px 0 18px; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card .btn { padding: 12px; margin-top: 4px; }

@media (min-width: 700px) {
  .tabs { justify-content: center; }
  .tabs button { flex: 0 0 140px; }
}
