:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --line: #d9dde3;
  --text: #171b21;
  --muted: #5d6673;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --done: #2b8a3e;
  --missed: #c92a2a;
  --planned: #1c7ed6;
  --extra: #6b7380;
  --z1: #9aa3af;
  --z2: #339af0;
  --z3: #40c057;
  --z4: #fcc419;
  --z5: #fd7e14;
  --z6: #e03131;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #14181f;
    --surface: #1d222b;
    --surface-2: #272d38;
    --line: #353c49;
    --text: #eef1f5;
    --muted: #a0a9b7;
    --accent: #ff6b2c;
    --accent-text: #14181f;
    --done: #51cf66;
    --missed: #ff6b6b;
    --planned: #4dabf7;
    --extra: #a0a9b7;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.3rem; font-weight: 700; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; font-weight: 650; }

.hint { color: var(--muted); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { align-items: flex-end; }
.grow { flex: 1 1 180px; min-width: 0; }

/* Bedienelemente */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: transparent; border-color: var(--missed); color: var(--missed); }
.btn.wide { width: 100%; }
.link {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.icon-btn {
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.field.narrow { width: 84px; }
.field.medium { width: 128px; }
.field.exercise-name { flex: 1 1 100%; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  /* 16px verhindert das automatische Hineinzoomen auf dem iPhone. */
  font: inherit;
  font-size: 16px;
}
input[type="file"] { padding: 6px; }
textarea { resize: vertical; }
.form-error { color: var(--missed); font-weight: 600; }

/* Anmeldung */
.auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 16px;
}
.auth-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(380px, 100%);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.logo { border-radius: 12px; }

/* Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.month-nav { display: flex; align-items: center; gap: 2px; min-width: 0; }
.month-nav h1 { white-space: nowrap; }

/* Kalender */
.calendar { padding: 12px 16px 32px; }
.weekdays, .week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)) 112px;
  gap: 1px;
}
.weekdays {
  padding-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.weekdays span { padding-left: 6px; }
.week { margin-bottom: 1px; }
.day {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 120px;
  padding: 6px;
  background: var(--surface);
}
.day.outside { opacity: 0.55; }
.day.drop { box-shadow: inset 0 0 0 2px var(--accent); }
.day-head { display: flex; align-items: center; justify-content: space-between; min-height: 26px; }
.day-num { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.weekday-inline { display: none; }
.day.today .day-num {
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-text);
}
.add {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.add:hover { background: var(--surface-2); color: var(--text); }

.card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--planned);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.card.done { border-left-color: var(--done); }
.card.missed { border-left-color: var(--missed); }
.card.extra { border-left-color: var(--extra); }
.card-title {
  overflow: hidden;
  font-size: 0.83rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta { color: var(--muted); font-size: 0.74rem; }
.card-note.plain { font-style: normal; }
.card-note {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.76rem;
  font-style: italic;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.card-actual { color: var(--done); font-size: 0.76rem; font-weight: 700; }

/* Vergleich: Training und Aktivität nebeneinander */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pair .card { justify-content: flex-start; padding: 10px; }
.pair .card-title { white-space: normal; }
.pair-label { color: var(--muted); font-size: 0.74rem; font-weight: 700; }
.pair-action { margin-top: auto; padding-top: 6px; color: var(--accent); font-size: 0.82rem; font-weight: 600; }
@media (max-width: 480px) { .pair { grid-template-columns: minmax(0, 1fr); } }

.week-sum {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.74rem;
}
.sum-label { color: var(--text); font-weight: 700; }

/* Intensitätsprofil */
.profile { display: block; width: 100%; }
.profile.mini { height: 24px; }
.profile.large { height: 110px; border-radius: 8px; background: var(--surface-2); }
.z1 { fill: var(--z1); }
.z2 { fill: var(--z2); }
.z3 { fill: var(--z3); }
.z4 { fill: var(--z4); }
.z5 { fill: var(--z5); }
.z6 { fill: var(--z6); }
.zfree { fill: var(--line); }
.zpace { fill: var(--planned); }

.stats { display: flex; gap: 24px; margin: 10px 0 0; }
.stats div { margin: 0; }
.stats dt { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.stats dd { margin: 0; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Dialog */
.sheet {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.5); }
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sheet-body { padding: 16px; }
.sheet-actions { padding-top: 6px; }

/* Editor */
.steps { display: flex; flex-direction: column; gap: 8px; }
.step {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--z2);
  border-radius: 8px;
  background: var(--surface);
}
.step.kind-work { border-left-color: var(--z5); }
.step.kind-recovery { border-left-color: var(--z1); }
.step.kind-warmup, .step.kind-cooldown { border-left-color: var(--z3); }
.step-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; min-width: 0; flex: 1; }
.step-fields .field:first-child { width: 124px; }
.step-actions { display: flex; flex: none; }
.step-actions .icon-btn { width: 30px; }
.watts { width: 100%; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.watts:empty { display: none; }

.repeat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.repeat-head { display: flex; align-items: center; justify-content: space-between; }
.repeat-count { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.repeat-count input { width: 72px; }

.export {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
}
.small-links { gap: 16px; font-size: 0.9rem; }

.compare { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.compare th, .compare td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.compare thead th, .compare tbody th { color: var(--muted); font-weight: 600; }
.settings section + section { padding-top: 16px; border-top: 1px solid var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  transform: translateX(-50%);
}
.toast.error { background: var(--missed); color: #fff; }

/* Handy: Der Kalender wird zur Liste */
@media (max-width: 760px) {
  .topbar { padding-left: 8px; padding-right: 8px; }
  .month-nav h1 { font-size: 1.05rem; }
  .topbar .btn { padding: 6px 10px; }
  .weekdays { display: none; }
  .calendar { padding: 0 0 32px; }
  .week { display: block; margin-bottom: 10px; }
  .day {
    min-height: 0;
    padding: 8px 16px;
    border-bottom: 1px solid var(--line);
    scroll-margin-top: 70px;
  }
  .day.outside { display: none; }
  .day-head { min-height: 36px; }
  .add { width: 36px; height: 36px; }
  .day-num { font-size: 0.95rem; }
  .weekday-inline { display: inline; }
  .card { padding: 10px; }
  .card-title { font-size: 0.95rem; white-space: normal; }
  .card-meta { font-size: 0.82rem; }
  .profile.mini { height: 34px; }
  .week-sum { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; padding: 8px 16px; }

  .step { flex-direction: column-reverse; align-items: stretch; }
  .step-actions { justify-content: flex-end; }
  .step-fields .field:first-child { flex: 1 1 100%; width: auto; }
  .step-fields .field.narrow { flex: 1 1 60px; width: auto; }

  .sheet {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .sheet-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .sheet-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
