/* app.css – App-Screens. Farben kommen aus base.css. */

:root {
  --calm: #1d7a5f;      /* Aufwärmen / Cool-down */
  --react: #7a3fc2;     /* Reaktionsrunde */
  --work-bg: #d9480f;   /* Bildschirmhintergrund Belastung */
  --rest-bg: #1d6a98;   /* Bildschirmhintergrund Pause */
  --touch: 56px;
}

html, body { height: 100%; }
body { overflow-x: hidden; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.screen[hidden] { display: none !important; }
.screen { min-height: 100%; display: flex; flex-direction: column; }
.accent { color: var(--work); }
.label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }

/* ---------- Kopfzeile ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px 0; }
.topbar h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
.icon-btn { width: var(--touch); height: var(--touch); padding: 0; display: grid; place-items: center; border-radius: 14px; }
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn-spacer { width: var(--touch); }

/* ---------- Start ---------- */
.home-body, .settings-body { padding: 0 16px 24px; flex: 1; max-width: 640px; width: 100%; margin: 0 auto; }
.presets { display: grid; gap: 10px; }
.preset {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline; text-align: left;
  min-height: 76px; padding: 14px 16px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface);
}
.preset[aria-checked="true"] { border-color: var(--work); background: color-mix(in srgb, var(--work) 12%, var(--surface)); }
.preset .p-name { font-size: 1.25rem; font-weight: 700; }
.preset .p-dur { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--work); }
.preset .p-sum { grid-column: 1 / -1; color: var(--muted); font-size: .88rem; }
.ex-list { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.ex-list li { background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: .88rem; }
.ex-list li.block { background: none; color: var(--muted); padding-left: 0; font-weight: 600; flex-basis: 100%; }
.links { margin-top: 20px; }
.start-bar {
  position: sticky; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.btn-primary {
  display: block; width: 100%; max-width: 640px; margin: 0 auto; min-height: 64px;
  font-size: 1.3rem; font-weight: 700; color: #fff; border: 0; border-radius: 16px; background: var(--work-bg);
}

/* ---------- Einstellungen ---------- */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--touch); padding: 6px 14px; border-bottom: 1px solid var(--line); }
.group > .row:last-child { border-bottom: 0; }
.row select { min-height: 40px; max-width: 60%; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 8px; }
.row input[type=range] { width: 50%; accent-color: var(--work); }
.note { color: var(--muted); font-size: .85rem; margin: 8px 14px 12px; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--work); border-color: var(--work); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- Training ---------- */
.train {
  --phase-bg: var(--rest-bg);
  position: fixed; inset: 0; z-index: 10; min-height: 0; overflow: hidden; color: #fff; background: var(--phase-bg);
  transition: background-color .35s;
  display: grid; grid-template-rows: auto auto auto minmax(80px, 1fr) auto auto auto auto auto;
  /* füllt den ganzen Bildschirm inkl. Notch-Bereich, Inhalte bleiben in der Safe Area */
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  /* Figur auf farbigem Grund */
  --fig: #fff; --fig-back: rgba(255,255,255,.5); --step: rgba(0,0,0,.22); --step-top: rgba(0,0,0,.32); --ground: rgba(255,255,255,.35);
}
.train[data-phase="work"] { --phase-bg: var(--work-bg); }
.train[data-phase="rest"], .train[data-phase="prep"] { --phase-bg: var(--rest-bg); }
.train[data-phase="warmup"], .train[data-phase="cooldown"] { --phase-bg: var(--calm); }
.train[data-phase="reaction"] { --phase-bg: var(--react); }
.t-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 1rem; min-height: 32px; }
.t-count { font-variant-numeric: tabular-nums; opacity: .85; }
.t-time { font-size: clamp(5.5rem, 30vw, 13rem); line-height: .95; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.train.final .t-time { animation: pulse 1s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(1.08); } 100% { transform: scale(1); } }
.t-title { font-size: clamp(1.6rem, 8vw, 2.6rem); font-weight: 800; text-align: center; line-height: 1.1; text-wrap: balance; margin-top: 4px; }
.t-fig { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; }
.t-fig svg { max-height: 100%; width: auto; max-width: 100%; height: 100%; }
.t-cmd { position: absolute; inset: 0; display: grid; place-items: center; overflow-wrap: anywhere; font-size: clamp(3rem, 15vw, 7rem); font-weight: 900; text-transform: uppercase; text-align: center; }
.t-info { text-align: center; font-size: .95rem; opacity: .9; min-height: 1.4em; text-wrap: balance; }
.t-next { text-align: center; font-size: 1.1rem; font-weight: 600; min-height: 1.5em; margin-top: 4px; }
.t-progress { height: 8px; border-radius: 4px; background: rgba(0,0,0,.25); overflow: hidden; margin-top: 10px; }
.t-bar { height: 100%; width: 0; background: #fff; border-radius: 4px; transition: width .2s linear; }
.t-meta { display: flex; justify-content: space-between; font-size: .85rem; opacity: .85; font-variant-numeric: tabular-nums; margin-top: 4px; }
.t-controls { display: grid; grid-template-columns: 72px 1fr 72px; gap: 12px; margin-top: 10px; }
.t-btn { min-height: 72px; border-radius: 18px; border: 2px solid rgba(255,255,255,.5); background: rgba(0,0,0,.18); color: #fff; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0; font-size: 1.25rem; font-weight: 700; }
.t-btn svg { width: 30px; height: 30px; }
.t-main { background: rgba(255,255,255,.95); color: #111; border-color: transparent; }
.t-paused { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); font-size: 2.6rem; font-weight: 800; pointer-events: none; }
.train .t-controls { position: relative; z-index: 2; }
.t-hint { position: absolute; left: 16px; right: 16px; top: calc(48px + env(safe-area-inset-top)); z-index: 3; min-height: 44px; border: 0; border-radius: 12px; background: rgba(0,0,0,.6); color: #fff; font-size: .9rem; padding: 10px 14px; text-align: left; }

/* niedrige Displays (iPhone SE, Querformat): Figur kleiner, Info weg */
@media (max-height: 640px) {
  .t-info { display: none; }
  .t-time { font-size: clamp(4rem, 22vw, 8rem); }
}

/* ---------- Geschafft ---------- */
.done-body { flex: 1; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 24px 16px; text-align: center; }
.done-icon { width: 96px; height: 96px; border-radius: 50%; background: var(--calm); color: #fff; display: grid; place-items: center; }
.done-icon svg { width: 56px; height: 56px; }
.done h1 { font-size: 2.4rem; margin: 8px 0; }
.stats { display: grid; grid-template-columns: repeat(3, auto); gap: 8px 28px; margin: 8px 0 0; }
.stats dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stats dd { margin: 2px 0 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Dialog ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.6); }
.modal[hidden] { display: none; }
.modal-box { width: 100%; max-width: 420px; background: var(--surface); color: var(--text); border-radius: 20px; padding: 22px 20px 18px; }
.modal-box h2 { margin: 0 0 6px; font-size: 1.4rem; }
.modal-box p { margin: 0 0 18px; color: var(--muted); }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions button { min-height: var(--touch); font-weight: 700; border-radius: 14px; }
.modal-actions .danger { background: var(--work-bg); color: #fff; border-color: transparent; }

@media (prefers-reduced-motion: reduce) {
  .train, .t-bar { transition: none; }
  .train.final .t-time { animation: none; }
}

/* ---------- Phase 3: Start-Ergänzungen ---------- */
.topbar-actions { display: flex; gap: 8px; }
.streak-line { margin: 10px 0 0; color: var(--muted); font-size: .95rem; }
.streak-line strong { color: var(--text); }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.home-actions button { min-height: var(--touch); font-weight: 600; border-radius: 14px; }
.preset .p-tag { grid-column: 1 / -1; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- Editor ---------- */
.ed-name { display: grid; gap: 0; }
.ed-name input { min-height: var(--touch); font-size: 1.15rem; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.ed-sum { margin: 10px 2px 0; font-weight: 600; color: var(--work); font-variant-numeric: tabular-nums; }
.ed-err { margin: 8px 2px 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--work) 18%, var(--surface)); }
.ed-fields > .note { margin: 10px 14px 4px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 48px; min-height: 44px; padding: 0; font-size: 1.4rem; font-weight: 700; border-radius: 12px; }
.stepper output { min-width: 64px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.ed-ex { list-style: none; margin: 0; padding: 4px 0; border-top: 1px solid var(--line); }
.ed-ex li { display: grid; grid-template-columns: 28px 1fr 44px 44px 44px; align-items: center; gap: 4px; padding: 4px 8px 4px 14px; min-height: 52px; }
.ed-ex li.empty { display: block; color: var(--muted); padding: 12px 14px; }
.ed-ex .ex-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.ed-ex .ex-name { min-width: 0; overflow-wrap: anywhere; }
.ed-ex button { min-height: 44px; padding: 0; border-radius: 10px; }
.ed-ex button:disabled { opacity: .3; }
.ed-add select { flex: 1; max-width: none; min-width: 0; }
.ed-add button { flex: none; }
.edit-bar { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; max-width: 640px; margin: 0 auto; width: 100%; }
.edit-bar .btn-primary { margin: 0; }
.btn-secondary { min-height: 64px; border-radius: 16px; font-weight: 700; font-size: 1.05rem; }
.edit-bar:has(#edDelete[hidden]) { grid-template-columns: 1fr; }

/* ---------- Verlauf ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .t-val { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile .t-lbl { color: var(--muted); font-size: .82rem; }
.chart-wrap { padding: 14px 14px 10px; }
.week-chart { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; align-items: end; height: 140px; border-bottom: 1px solid var(--line); }
.week-col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: pointer; border: 0; background: none; padding: 0 3px; min-height: 0; border-radius: 0; }
.week-col .bar { width: 100%; max-width: 28px; background: var(--work); border-radius: 4px 4px 0 0; min-height: 0; }
.week-col .val { font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 4px; color: var(--text); }
.week-col.sel .bar { outline: 2px solid var(--text); outline-offset: 2px; }
.week-col:focus-visible { outline: 2px solid var(--rest); }
.week-labels { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.week-labels span { text-align: center; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 4px; }
.chart-caption { margin: 8px 0 0; color: var(--muted); font-size: .85rem; min-height: 1.3em; }
.h-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.h-list li { display: grid; grid-template-columns: 1fr auto 44px; gap: 10px; align-items: center; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); min-height: 56px; }
.h-list li:last-child { border-bottom: 0; }
.h-list .h-name { font-weight: 600; }
.h-list .h-date { color: var(--muted); font-size: .82rem; }
.h-list .h-dur { font-variant-numeric: tabular-nums; text-align: right; font-size: .9rem; }
.h-list button { min-height: 44px; padding: 0; color: var(--muted); }
.h-list li.empty { display: block; color: var(--muted); padding: 16px 14px; }
.group.pad { padding: 4px 14px 14px; display: grid; gap: 8px; }
.group.pad .note { margin: 8px 0 0; }
.group.pad textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: .75rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.group.pad .label { margin: 8px 0 0; }
.done-streak { margin: 14px 0 0; font-size: 1.05rem; color: var(--muted); }

/* ---------- Reaktion ---------- */
.t-cmd.flash { animation: cmdflash .45s ease-out; }
@keyframes cmdflash { 0% { transform: scale(1.35); opacity: .3; } 100% { transform: scale(1); opacity: 1; } }
.t-cmd small { display: block; font-size: clamp(1.4rem, 7vw, 2.2rem); line-height: 1.35; font-weight: 700; text-transform: none; opacity: .9; }
@media (prefers-reduced-motion: reduce) { .t-cmd.flash { animation: none; } }
