:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --text: #14161b;
  --text-2: #636a78;
  --border: #e2e5eb;
  --accent: #3d63f5;
  --accent-contrast: #ffffff;
  --accent-soft: #e8edff;
  --success: #1f9d55;
  --success-soft: #e2f5e9;
  --danger: #d93636;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 6px rgba(16, 24, 40, 0.05);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a21;
    --surface-2: #20242d;
    --text: #eef0f4;
    --text-2: #9aa2b1;
    --border: #2a2f3a;
    --accent: #6d8bff;
    --accent-contrast: #0e1014;
    --accent-soft: #1d2745;
    --success: #34c26f;
    --success-soft: #15301f;
    --danger: #ff6b6b;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--text-2);
}

.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
  font-weight: 700;
  font-size: 17px;
}
.brand-icon { color: var(--accent); }

.topbar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}

.topbar-title {
  max-width: 100%;
  margin: 0;
  padding: 2px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 17px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title:active { background: var(--surface-2); }

.save-status {
  min-height: 15px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--text-2);
}
.save-status[data-state="saved"]::before { content: "✓ "; color: var(--success); font-weight: 700; }
.save-status[data-state="error"] { color: var(--danger); font-weight: 600; }

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--text);
  text-decoration: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.25; }

/* ---------- Inhalt ---------- */

.content {
  padding: 16px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.content.with-bottom-bar { padding-bottom: calc(112px + env(safe-area-inset-bottom)); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 6px 4px 14px;
}
.section-head h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.text-btn {
  margin: -8px;
  padding: 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Liste der Trainingstage ---------- */

.day-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.day-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s ease;
}
a.day-card:active { transform: scale(0.985); }
.day-card.sorting { padding-right: 6px; }

.day-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 17px;
}

.day-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.day-name, .day-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-name { font-size: 17px; font-weight: 650; }
.day-meta { font-size: 14px; color: var(--text-2); }
.day-preview { font-size: 13px; color: var(--text-2); opacity: 0.85; margin-top: 1px; }
.day-chevron { color: var(--text-2); }
.sort-btns { display: flex; }

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-2);
}
.empty.small { padding: 20px 16px 4px; }
.empty-icon { width: 52px; height: 52px; margin-bottom: 10px; color: var(--accent); }
.empty h2 { margin: 0 0 6px; font-size: 19px; color: var(--text); }
.empty p { margin: 0 0 16px; }

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.bottom-bar .btn { max-width: 608px; margin: 0 auto; }

/* ---------- Buttons & Felder ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 650;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; }
.btn.block { display: flex; width: 100%; }
.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.field {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field::placeholder, .ex-name::placeholder, .ex-rest::placeholder { color: var(--text-2); opacity: 0.75; }
textarea.field { resize: none; overflow: hidden; line-height: 1.4; }

/* ---------- Übungen ---------- */

.day-notes { margin-bottom: 14px; }

.exercise-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.exercise {
  padding: 10px 12px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ex-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -6px 6px 0;
}

.ex-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 14px;
  font-weight: 800;
}

.ex-name {
  flex: 1;
  width: 0;
  min-width: 0;
  padding: 8px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 18px;
  font-weight: 650;
  outline: none;
}
.ex-name:focus { background: var(--surface-2); }

.sets { margin-bottom: 10px; }

.set-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 6px 6px 6px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}
.set-count-label { font-weight: 650; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--accent);
}
.stepper-btn .icon { width: 20px; height: 20px; }
.stepper-btn:active { background: var(--accent-soft); }
.stepper-btn:disabled { color: var(--text-2); opacity: 0.4; }
.stepper-value {
  width: 44px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 19px;
  font-weight: 750;
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
}
.stepper-value:focus { background: var(--surface); box-shadow: 0 0 0 2px var(--accent); }

.set-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  padding: 3px 0;
}

.set-head {
  padding-bottom: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
}
.set-head span { display: flex; justify-content: center; }
.set-head .icon { width: 15px; height: 15px; }

.set-no {
  text-align: center;
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.set-input {
  width: 100%;
  height: 44px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 16px;
  font-weight: 650;
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: background-color 0.15s ease;
}
.set-input:focus { border-color: var(--accent); background: var(--surface); }
.set-input::placeholder { color: var(--text-2); opacity: 0.5; }

.with-unit { position: relative; display: block; min-width: 0; }
.with-unit .set-input { padding: 0 28px; }
.unit {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  pointer-events: none;
}

.set-check {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.set-check .icon { width: 20px; height: 20px; }
.set-row.done .set-check { border-color: var(--success); background: var(--success); color: #fff; }
.set-row.done .set-input { background: var(--success-soft); }
.set-row.done .set-no { color: var(--success); }

.ex-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 4px;
  font-size: 15px;
  color: var(--text-2);
}
.ex-field .icon { width: 18px; height: 18px; }

.ex-rest {
  flex: 1;
  width: 0;
  min-width: 0;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px dashed var(--border);
  background: none;
  font-size: 16px;
  color: var(--text);
  outline: none;
}
.ex-rest:focus { border-bottom: 1px solid var(--accent); }

.ex-notes {
  border-color: transparent;
  background: var(--surface-2);
  font-size: 15px;
}

.add-exercise {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 58px;
  margin-top: 14px;
  border: 2px dashed var(--border);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 18px;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}
.add-exercise:active { background: var(--accent-soft); }

/* ---------- Login ---------- */

.login {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 420px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.login-logo {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 18px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-contrast);
}
.login-logo .icon { width: 36px; height: 36px; }
.login h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 24px; color: var(--text-2); }
.login-form { display: grid; gap: 14px; }
.label { display: grid; gap: 6px; font-size: 14px; font-weight: 650; color: var(--text-2); }
.form-error { min-height: 1.4em; margin: -4px 0 0; font-size: 14px; color: var(--danger); }

/* ---------- Dialoge ---------- */

dialog { color: var(--text); }
dialog::backdrop { background: rgba(8, 10, 14, 0.5); }

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.sheet[open] { animation: sheet-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet-inner {
  display: grid;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}
.sheet-group { overflow: hidden; border-radius: 16px; background: var(--surface); }
.sheet-title {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
.sheet-btn {
  display: block;
  width: 100%;
  min-height: 54px;
  border: 0;
  background: var(--surface);
  color: var(--accent);
  font-size: 17px;
}
.sheet-btn + .sheet-btn { border-top: 1px solid var(--border); }
.sheet-btn:active { background: var(--surface-2); }
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { border-radius: 16px; font-weight: 700; }

.modal {
  width: calc(100% - 32px);
  max-width: 420px;
  margin: 12vh auto auto;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal[open] { animation: modal-in 0.18s ease-out; }
.dialog-body { display: grid; gap: 16px; padding: 20px; }
.dialog-title { margin: 0; font-size: 19px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@keyframes modal-in { from { transform: scale(0.96); opacity: 0; } }

/* ---------- Hinweise ---------- */

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
body:has(.bottom-bar) .toasts { bottom: calc(96px + env(safe-area-inset-bottom)); }
.toast {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(8px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
