:root {
  --bg: #0b0e14;
  --bg2: #121722;
  --card: rgba(255, 255, 255, 0.045);
  --card-b: rgba(255, 255, 255, 0.08);
  --text: #eef2f7;
  --muted: #8c96a8;
  --acc: #b6ff3b;
  --acc2: #22d3a6;
  --back: #5aa9ff;
  --warn: #ff9f43;
  --danger: #ff5c7a;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(182, 255, 59, 0.08), transparent 60%),
    radial-gradient(900px 500px at -20% 10%, rgba(34, 211, 166, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* Kopf */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: linear-gradient(var(--bg) 60%, rgba(11, 14, 20, 0));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.top-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hello { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync { font-size: 10px; color: var(--muted); }
.sync.ok { color: var(--acc2); }
.sync.off { color: var(--warn); }
.gymclock {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(182, 255, 59, 0.12); color: var(--acc);
  font-variant-numeric: tabular-nums; font-weight: 700;
}
.gymclock .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--acc); animation: puls 1.6s infinite; }
@keyframes puls { 50% { opacity: 0.25; } }

main { flex: 1; padding: 0 16px calc(96px + var(--safe-b)); max-width: 720px; width: 100%; margin: 0 auto; }
.sec { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 4px 10px; font-weight: 650; }
.row-head { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

/* Karten */
.card, .item {
  background: var(--card); border: 1px solid var(--card-b);
  border-radius: var(--radius); padding: 16px;
}
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 14px; }
.item .meta { flex: 1; min-width: 0; }
.item .name { font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item .done { color: var(--acc); font-size: 13px; font-weight: 600; margin-top: 4px; }
.badge {
  width: 46px; height: 46px; flex: none; border-radius: 14px;
  display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, rgba(182, 255, 59, 0.18), rgba(34, 211, 166, 0.12));
}
.empty { text-align: center; color: var(--muted); padding: 28px 16px; border: 1px dashed var(--card-b); border-radius: var(--radius); }

/* Hero */
.hero {
  margin-top: 6px; border-radius: 24px; padding: 20px;
  background: linear-gradient(135deg, rgba(182, 255, 59, 0.16), rgba(34, 211, 166, 0.08) 60%, rgba(90, 169, 255, 0.06));
  border: 1px solid rgba(182, 255, 59, 0.2);
}
.hero h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.hero p { margin: 0 0 16px; color: var(--muted); }
.hero .kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.kpi { background: rgba(0, 0, 0, 0.25); border-radius: 14px; padding: 10px; text-align: center; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Knöpfe */
.btn {
  border: 1px solid var(--card-b); background: rgba(255, 255, 255, 0.07);
  border-radius: 14px; padding: 12px 18px; font-weight: 650; cursor: pointer;
  min-height: 46px; touch-action: manipulation; transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--acc), var(--acc2)); color: #0b0e14; border: 0; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; border-color: rgba(255, 92, 122, 0.35); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 64px; font-size: 19px; border-radius: 18px; }
.btn.go { min-width: 84px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--card-b); background: rgba(255, 255, 255, 0.06); font-size: 18px; cursor: pointer; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form input, .form select {
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--card-b); border-radius: 12px;
  padding: 12px 14px; font-size: 17px; color: var(--text); width: 100%; min-height: 48px;
}
.form input:focus, .form select:focus { outline: 2px solid var(--acc); outline-offset: 1px; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--text); }
.form label.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--acc); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.linkbox { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; padding: 12px; background: rgba(0, 0, 0, 0.3); border-radius: 12px; margin-bottom: 12px; }

/* Untere Leiste */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + var(--safe-b));
  background: rgba(14, 18, 27, 0.82);
  backdrop-filter: saturate(160%) blur(18px); -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-top: 1px solid var(--card-b);
}
.tabs button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; padding: 6px 0; cursor: pointer; }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button.on { color: var(--acc); }

/* Verlauf */
.day .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.day .date { font-weight: 700; }
.day .dur { color: var(--acc); font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 650; }
.day ul { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.day li { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.day li span:last-child { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.day .del { margin-top: 10px; }
.stats { display: flex; flex-direction: column; gap: 10px; }
.stat .head { display: flex; justify-content: space-between; align-items: baseline; }
.stat .best { color: var(--acc); font-weight: 700; font-variant-numeric: tabular-nums; }
.stat svg { width: 100%; height: 64px; margin-top: 8px; display: block; }

/* Dialoge */
dialog {
  width: min(520px, calc(100vw - 24px)); border: 1px solid var(--card-b); border-radius: 24px;
  background: var(--bg2); color: var(--text); padding: 20px;
  max-height: calc(100dvh - 24px - var(--safe-t)); overflow: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog h3 { margin: 0; font-size: 20px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.welcome-logo { text-align: center; }
.welcome-logo img { width: 72px; height: 72px; }
.stepper { display: grid; grid-template-columns: 70px 56px 1fr 56px 24px; align-items: center; gap: 8px; }
.stepper span { color: var(--muted); font-size: 14px; }
.stepper button { height: 56px; border-radius: 14px; border: 1px solid var(--card-b); background: rgba(255, 255, 255, 0.07); font-size: 26px; cursor: pointer; }
.stepper input { text-align: center; font-size: 28px !important; font-weight: 750; font-variant-numeric: tabular-nums; height: 56px; }
.stepper em { font-style: normal; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  background: #eef2f7; color: #0b0e14; padding: 10px 18px; border-radius: 999px;
  font-weight: 650; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* ===== Cockpit ===== */
.cockpit {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 14px;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 16px);
  background:
    radial-gradient(800px 500px at 50% 35%, rgba(182, 255, 59, 0.08), transparent 70%),
    #07090d;
  overflow: hidden;
}
.cockpit.back { background: radial-gradient(800px 500px at 50% 35%, rgba(90, 169, 255, 0.1), transparent 70%), #07090d; }
.ck-top { display: flex; align-items: center; gap: 12px; }
.ck-title { flex: 1; min-width: 0; }
.ck-title > div:first-child { font-weight: 750; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ck-sub { color: var(--muted); font-size: 14px; }
.ck-clock { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--acc); font-size: 18px; }

.ck-phase {
  text-align: center; margin-top: 2vh;
  font-size: clamp(30px, 9vw, 64px); font-weight: 850; letter-spacing: 0.04em;
  color: var(--acc); text-shadow: 0 0 30px rgba(182, 255, 59, 0.35);
}
.cockpit.back .ck-phase { color: var(--back); text-shadow: 0 0 30px rgba(90, 169, 255, 0.35); }
.cockpit.hold .ck-phase, .cockpit.paused .ck-phase { color: var(--warn); text-shadow: none; }
.ck-reps { text-align: center; font-variant-numeric: tabular-nums; line-height: 1; }
.ck-reps span { font-size: clamp(80px, 30vw, 180px); font-weight: 850; letter-spacing: -0.04em; }
.ck-reps small { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.1em; }

.ck-track {
  position: relative; height: clamp(110px, 20vh, 190px); border-radius: 26px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.09);
  overflow: hidden; margin-top: auto;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6);
}
.ck-ticks {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(255, 255, 255, 0.07) calc(10% - 1px) 10%);
}
.ck-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, rgba(182, 255, 59, 0.05), rgba(182, 255, 59, 0.45));
}
.cockpit.back .ck-fill { background: linear-gradient(90deg, rgba(90, 169, 255, 0.05), rgba(90, 169, 255, 0.45)); }
.ck-bar {
  position: absolute; top: 10px; bottom: 10px; left: 0; width: 22%;
  border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  box-shadow: 0 0 40px rgba(182, 255, 59, 0.55), inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  color: #07090d; font-size: 30px; font-weight: 900;
  will-change: transform;
}
.cockpit.back .ck-bar { background: linear-gradient(135deg, #8cc4ff, var(--back)); box-shadow: 0 0 40px rgba(90, 169, 255, 0.55), inset 0 0 0 2px rgba(255, 255, 255, 0.35); }
.ck-dir { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding: 0 6px; text-transform: uppercase; letter-spacing: 0.08em; }
.ck-sets { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 32px; }
.ck-sets span { padding: 6px 12px; border-radius: 999px; background: rgba(182, 255, 59, 0.12); color: var(--acc); font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.ck-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

@media (min-height: 820px) { .ck-phase { margin-top: 5vh; } }
.ck-track, .ck-actions, #ck-finish { flex-shrink: 0; }
.cockpit:not([hidden]) ~ .toast { bottom: auto; top: calc(var(--safe-t) + 72px); }

/* Querformat: Balken rechts gross, Zähler links */
@media (orientation: landscape) and (max-height: 560px) {
  .cockpit {
    display: grid; gap: 8px 16px;
    grid-template-columns: minmax(180px, 1fr) 2fr;
    grid-template-rows: auto 1fr 1fr auto auto;
    grid-template-areas: "top top" "phase track" "reps track" "sets dir" "finish actions";
    padding-left: calc(env(safe-area-inset-left, 0px) + 16px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 16px);
  }
  .ck-top { grid-area: top; }
  .ck-phase { grid-area: phase; margin: 0; font-size: 30px; align-self: end; }
  .ck-reps { grid-area: reps; align-self: start; }
  .ck-reps span { font-size: 72px; }
  .ck-track { grid-area: track; height: auto; margin: 0; }
  .ck-dir { grid-area: dir; }
  .ck-sets { grid-area: sets; min-height: 0; }
  .ck-actions { grid-area: actions; }
  .ck-actions .btn.big { min-height: 52px; }
  #ck-finish { grid-area: finish; min-height: 52px; }
}
@media (prefers-reduced-motion: reduce) { .gymclock .dot { animation: none; } }
