/* ═══════════════════════════════════════════
   Intervall – Fitness Timer
   Mobile-first, keine Abhängigkeiten
   ═══════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg:        #1e222a;
  --bg-elev:   #292e38;
  --bg-elev-2: #353b47;
  --line:      #454d5b;
  --line-soft: #333945;
  --text:      #f4f6fa;
  --muted:     #a8b1c0;
  --accent:    #ff7a59;
  --accent-ink:#20140f;

  --work:      #ff7a59;
  --rest:      #4fe0c4;
  --prepare:   #ffc861;
  --roundrest: #6cb8ff;
  --cooldown:  #b9a3ff;
  --danger:    #ff6b7a;

  --r-sm: 10px;
  --r:    16px;
  --r-lg: 22px;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --glow:      rgba(255,122,89,.09);
  --shadow: 0 10px 34px rgba(0,0,0,.28);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:        #f4f6f9;
  --bg-elev:   #ffffff;
  --bg-elev-2: #edf0f5;
  --line:      #dbe1ea;
  --line-soft: #e7ebf1;
  --text:      #1a1e26;
  --muted:     #6a7484;
  --accent:    #f2643a;
  --accent-ink:#ffffff;
  --work:      #f2643a;
  --rest:      #12a594;
  --prepare:   #e08a1e;
  --roundrest: #2f8fe0;
  --cooldown:  #7f61e8;
  --danger:    #e0475a;
  --glow:      rgba(242,100,58,.07);
  --shadow: 0 10px 30px rgba(26,30,38,.08);
  color-scheme: light;
}

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }

/* ── Views ───────────────────────────────── */
.view {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  background-image: radial-gradient(120% 60% at 50% -10%, var(--glow) 0%, transparent 70%);
  animation: viewIn .22s ease;
}
.view[hidden] { display: none; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 16px;
}
.scroll > * { flex: none; }

/* ── Topbar ──────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 20px; font-weight: 650; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 12px;
  cursor: pointer; transition: background .15s;
}
.icon-btn:active { background: var(--bg-elev-2); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.danger { color: var(--danger); }

/* ── Buttons ─────────────────────────────── */
.btn {
  border: 0; border-radius: 999px;
  padding: 13px 20px;
  font-size: 15px; font-weight: 600;
  background: var(--bg-elev-2); color: var(--text);
  cursor: pointer;
  transition: transform .08s, filter .15s, background .15s;
  min-height: 46px;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-small { padding: 8px 14px; font-size: 13.5px; min-height: 36px; }
.file-btn { display: inline-flex; align-items: center; }

/* ── Home ────────────────────────────────── */
.quick-card {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.quick-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.quick-head h2 { font-size: 16px; font-weight: 650; }
.quick-total { font-size: 13px; color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qfield { display: flex; flex-direction: column; gap: 5px; }
.qfield span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; text-align: center; }
.qfield input {
  width: 100%; text-align: center;
  background: var(--bg-elev-2); border: 1px solid transparent; border-radius: var(--r-sm);
  color: var(--text); padding: 11px 2px; font-size: 18px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.qfield input::-webkit-outer-spin-button, .qfield input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qfield input:focus { outline: none; border-color: var(--accent); }
.quick-actions { display: flex; gap: 8px; margin-top: 14px; }
.quick-actions .btn { flex: 1; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.section-head h2 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }

.program-list, .history-list { display: flex; flex-direction: column; gap: 10px; }

.prog {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 14px;
  cursor: pointer; transition: transform .08s, border-color .15s;
}
.prog:active { transform: scale(.99); border-color: var(--line); }
.prog-main { flex: 1; min-width: 0; }
.prog-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog-meta { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.prog-chips { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.prog-play {
  width: 46px; height: 46px; flex: none; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer;
  transition: transform .08s;
}
.prog-play:active { transform: scale(.92); }
.prog-play svg { width: 20px; height: 20px; fill: currentColor; margin-left: 2px; }

.hist {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r-sm); font-size: 13.5px;
}
.hist-when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 28px 12px; color: var(--text); }
.empty .muted { color: var(--muted); font-size: 13px; margin-top: 6px; }
.footnote { font-size: 11.5px; color: var(--muted); text-align: center; padding: 6px 0 0; }

/* ── Felder / Karten ─────────────────────── */
.card {
  background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { font-size: 15px; font-weight: 650; }
.count-badge {
  font-size: 11px; color: var(--muted); background: var(--bg-elev-2);
  border-radius: 999px; padding: 2px 8px; margin-left: 4px; vertical-align: middle;
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field input[type="text"], .field input[type="number"] {
  width: 100%; background: var(--bg-elev-2); border: 1px solid transparent;
  border-radius: var(--r-sm); color: var(--text); padding: 13px 14px; font-size: 16px;
}
.field input:focus { outline: none; border-color: var(--accent); }
#view-edit .field:not(.card .field) { background: var(--bg-elev); border: 1px solid var(--line-soft); border-radius: var(--r-lg); padding: 14px 16px; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Presets ─────────────────────────────── */
.preset-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.preset-row::-webkit-scrollbar { display: none; }
.preset {
  flex: none; border: 1px solid var(--line); background: transparent;
  border-radius: 999px; padding: 9px 14px; font-size: 13px; cursor: pointer;
  white-space: nowrap; color: var(--muted);
}
.preset:active { background: var(--bg-elev-2); }

/* ── Stepper ─────────────────────────────── */
.stepper-list { display: flex; flex-direction: column; gap: 4px; }
.stepper {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
}
.stepper:last-child { border-bottom: 0; }
.stepper-label { flex: 1; min-width: 0; }
.stepper-label b { display: block; font-size: 14.5px; font-weight: 550; }
.stepper-label small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.stepper-ctl { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper-ctl button {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; font-size: 19px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; color: var(--text);
}
.stepper-ctl button:active { background: var(--bg-elev-2); }
.stepper-ctl input {
  width: 62px; text-align: center; background: var(--bg-elev-2);
  border: 1px solid transparent; border-radius: 10px; color: var(--text);
  padding: 9px 2px; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper-ctl input::-webkit-outer-spin-button, .stepper-ctl input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-ctl input:focus { outline: none; border-color: var(--accent); }

/* ── Übungsliste ─────────────────────────── */
.exercise-list { display: flex; flex-direction: column; gap: 8px; }
.ex-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev-2); border-radius: var(--r-sm); padding: 10px 12px;
}
.ex-num {
  width: 24px; height: 24px; flex: none; border-radius: 7px;
  background: var(--bg-elev); color: var(--muted);
  display: grid; place-items: center; font-size: 11.5px; font-weight: 600;
}
.ex-body { flex: 1; min-width: 0; cursor: pointer; }
.ex-title { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.ex-move { display: flex; flex-direction: column; gap: 2px; flex: none; }
.ex-move button {
  width: 30px; height: 22px; border: 0; background: transparent; color: var(--muted);
  cursor: pointer; border-radius: 6px; display: grid; place-items: center;
}
.ex-move button:active { background: var(--bg-elev); }
.ex-move svg { width: 14px; height: 14px; }
.media-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }

/* ── Switch / Slider / Segment ───────────── */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 3px 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 46px; height: 28px; flex: none; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  position: relative; transition: background .18s, border-color .18s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--muted);
  transition: transform .18s, background .18s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }
.switch .lbl { font-size: 14.5px; }

.slider-field { display: flex; flex-direction: column; gap: 8px; }
.slider-field > span { font-size: 12.5px; color: var(--muted); }
.slider-field b { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--bg-elev-2); border-radius: 999px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 0;
}
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 0; }

.seg { display: flex; background: var(--bg-elev-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 9px;
  padding: 9px 4px; font-size: 13.5px; cursor: pointer; color: var(--muted);
  transition: background .15s, color .15s;
}
.seg button.on { background: var(--bg-elev); color: var(--text); font-weight: 600; }
.seg.small button { font-size: 12.5px; padding: 8px 2px; }

.edit-footer { display: flex; gap: 8px; padding-top: 4px; }
.edit-footer .btn { flex: 1; }
.edit-footer .btn-primary { flex: 2; }

/* ═══════════ RUNNER ═══════════ */
.view.run { background: var(--bg); overflow: hidden; }
.run-bg {
  position: absolute; inset: -30%;
  background: radial-gradient(circle at 50% 42%, var(--phase-color, var(--work)) 0%, transparent 62%);
  opacity: .16; transition: background 1.2s ease, opacity .5s ease;
  pointer-events: none;
}
.run-top {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 8px 4px;
}
.run-meta {
  flex: 1; text-align: center; font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums; display: flex; gap: 7px; justify-content: center;
}
.run-meta .dot { opacity: .5; }

.run-media {
  position: relative; z-index: 2;
  margin: 4px 16px 0; border-radius: var(--r);
  overflow: hidden; background: #000;
  aspect-ratio: 16 / 9; max-height: 26vh;
  display: flex; align-items: center; justify-content: center;
}
.run-media[hidden] { display: none; }
.run-media img, .run-media video, .run-media iframe {
  width: 100%; height: 100%; object-fit: cover; border: 0; display: block;
}

.run-core {
  flex: 1; z-index: 2; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 8px 16px; min-height: 0;
}
.ring-wrap { position: relative; width: min(78vw, 42vh, 330px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--bg-elev-2); }
.ring-fg {
  stroke: var(--phase-color, var(--work)); stroke-linecap: round;
  stroke-dasharray: 678.58; stroke-dashoffset: 0;
  transition: stroke-dashoffset .16s linear, stroke .5s ease;
}
.ring-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 12%;
  text-align: center;
}
.phase {
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--phase-color, var(--work)); font-weight: 650;
}
.time {
  font-size: clamp(52px, 17vw, 88px); font-weight: 250; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
  transition: color .3s;
}
.time.warn { color: var(--phase-color, var(--work)); }
.exname {
  font-size: 16px; font-weight: 550; margin-top: 6px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-height: 1.25;
}
.next-up {
  font-size: 13.5px; color: var(--muted); text-align: center;
  max-width: 88%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.run-bottom { z-index: 2; position: relative; padding: 0 20px calc(20px + var(--safe-b)); }
.total-bar { height: 4px; border-radius: 999px; background: var(--bg-elev-2); overflow: hidden; }
.total-fill { height: 100%; width: 0%; background: var(--text); opacity: .5; border-radius: 999px; transition: width .2s linear; }
.total-labels {
  display: flex; justify-content: space-between; font-size: 11.5px;
  color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums;
}
.run-controls { display: flex; align-items: center; justify-content: center; gap: 24px; margin-top: 16px; }
.ctrl {
  width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; display: grid; place-items: center; cursor: pointer;
  color: var(--text); transition: transform .08s, background .15s;
}
.ctrl:active { transform: scale(.93); background: var(--bg-elev-2); }
.ctrl svg { width: 22px; height: 22px; }
.ctrl-main {
  width: 76px; height: 76px; background: var(--accent);
  border-color: var(--accent); color: var(--accent-ink);
}
.ctrl-main svg { width: 28px; height: 28px; }
.ctrl-main[hidden] { display: none; }

/* ── Fertig ──────────────────────────────── */
.view.done { align-items: center; justify-content: center; padding: 24px; }
.done-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 360px; width: 100%; }
.done-check {
  width: 80px; height: 80px; border-radius: 50%;
  background: color-mix(in srgb, var(--rest) 18%, transparent);
  color: var(--rest); display: grid; place-items: center; margin-bottom: 6px;
  animation: pop .4s cubic-bezier(.2,1.3,.4,1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.done-check svg { width: 38px; height: 38px; }
.view.done h1 { font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.done-name { color: var(--muted); font-size: 15px; }
.done-stats { display: flex; gap: 10px; margin: 18px 0 8px; width: 100%; }
.done-stat {
  flex: 1; background: var(--bg-elev); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 14px 8px;
}
.done-stat b { display: block; font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.done-stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.done-actions { display: flex; gap: 8px; width: 100%; margin-top: 10px; }
.done-actions .btn { flex: 1; }

/* ── Sheet ───────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .18s ease;
}
.sheet-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh;
  background: var(--bg-elev); border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; flex-direction: column;
  animation: sheetUp .26s cubic-bezier(.2,.9,.3,1);
  padding-bottom: var(--safe-b);
}
@keyframes sheetUp { from { transform: translateY(100%) } to { transform: none } }
.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 18px; }
.sheet-head h2 { font-size: 17px; font-weight: 650; }
.sheet-body { overflow-y: auto; padding: 4px 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line-soft); }
.sheet-foot .btn { flex: 1; }
.sheet-foot .btn-primary { flex: 2; }
.media-preview {
  border-radius: var(--r-sm); overflow: hidden; background: #000;
  aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center;
}
.media-preview img, .media-preview iframe, .media-preview video { width: 100%; height: 100%; object-fit: cover; border: 0; }

/* ── Toast ───────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  z-index: 100; box-shadow: var(--shadow);
  animation: toastIn .2s ease; max-width: 88vw; text-align: center;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px) } to { opacity: 1; transform: translate(-50%, 0) } }

/* ── Tablet / Desktop ────────────────────── */
@media (min-width: 720px) {
  .scroll { padding-left: max(16px, calc((100vw - 680px) / 2)); padding-right: max(16px, calc((100vw - 680px) / 2)); }
  .topbar { padding-left: max(12px, calc((100vw - 700px) / 2)); padding-right: max(12px, calc((100vw - 700px) / 2)); }
  .run-core { gap: 26px; }
  .run-bottom { padding-left: max(20px, calc((100vw - 560px) / 2)); padding-right: max(20px, calc((100vw - 560px) / 2)); }
  .run-media { margin-left: auto; margin-right: auto; width: min(560px, 92vw); }
}

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