:root {
  --bg: #0f1115;
  --bg2: #171a21;
  --bg3: #1f2430;
  --fg: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #4fd18b;
  --accent2: #6aa9ff;
  --danger: #ff6b6b;
  --warn: #ffb347;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

#nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg2);
  border-bottom: 1px solid #262b36;
  position: sticky;
  top: 0;
  z-index: 10;
}
#nav .brand { font-weight: 700; color: var(--fg); }
#nav nav { display: flex; gap: 14px; }
#nav nav a { color: var(--muted); padding: 4px 2px; border-bottom: 2px solid transparent; }
#nav nav a.active { color: var(--fg); border-bottom-color: var(--accent); }
body.playing #nav { display: none; }

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
body.playing #app { max-width: none; padding: 0; }

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
h3 { font-size: 1rem; margin: 12px 0 6px; color: var(--muted); }
p.muted, span.muted, .muted { color: var(--muted); }
p.error, .error { color: var(--danger); }
.hint { color: var(--warn); font-size: 0.9rem; }

button, .btn {
  font: inherit;
  color: var(--fg);
  background: var(--bg3);
  border: 1px solid #2c3340;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover, .btn:hover { border-color: #3d4656; text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: #062; border-color: var(--accent); font-weight: 700; }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 4px 9px; font-size: 0.85rem; }
button.icon { padding: 4px 8px; min-width: 34px; }

input, select, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid #2c3340;
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
  max-width: 100%;
}
input[type="number"] { width: 6em; }
input[type="range"] { width: 100%; padding: 0; }
input[type="file"] { border: none; padding: 0; }
textarea { min-height: 60px; resize: vertical; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 3px; }

.card {
  background: var(--bg2);
  border: 1px solid #242a35;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stats { display: flex; flex-wrap: wrap; gap: 14px 22px; margin: 8px 0; }
.stats .stat b { display: block; font-size: 1.25rem; }
.stats .stat span { font-size: 0.8rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #242a35; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
tr.ok td:first-child::before { content: "✓ "; color: var(--accent); }
tr.abort td:first-child::before { content: "✕ "; color: var(--danger); }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg3);
  color: var(--muted);
}
.badge.frozen { color: var(--accent2); }

/* Übungen */
.ex-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.ex-card video { width: 100%; aspect-ratio: 9 / 16; max-height: 300px; background: #000; border-radius: 8px; object-fit: contain; }
.ex-card .fields { grid-template-columns: 1fr 1fr; }

/* Workout-Editor */
.sel-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #242a35;
}
.sel-list { list-style: none; padding: 0; margin: 0; }
.sel-list .ovr { display: flex; gap: 6px; align-items: center; font-size: 0.85rem; color: var(--muted); }
.sel-list .ovr input { width: 4.5em; padding: 4px 6px; }
.pool { display: flex; flex-wrap: wrap; gap: 6px; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2a3140;
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 100;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
#toast.error { background: #4a2020; color: #ffd0d0; }

/* Player */
.player { position: fixed; inset: 0; background: #000; display: flex; flex-direction: column; }
.player .stage { position: relative; flex: 1; overflow: hidden; background: #000; }
.player .stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 80ms linear;
}
.player .stage video.on { opacity: 1; }
.player .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9), 0 0 2px rgba(0,0,0,0.9);
}
.ov-top { display: flex; justify-content: space-between; font-size: 0.95rem; color: #ddd; }
.ov-bottom { display: flex; flex-direction: column; gap: 2px; }
.ov-name { font-size: 1.6rem; font-weight: 700; }
.ov-time { font-size: 3.2rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.ov-time.final { font-size: 6rem; color: var(--accent); }
.ov-next { color: #bbb; font-size: 0.95rem; }
.player .controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: #0a0c10;
  border-top: 1px solid #1d222b;
}
.player .controls button { flex: 1; padding: 12px 6px; font-size: 1rem; }
.player .controls .vol { flex: 0 0 110px; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.8rem; }
.player .prestart, .player .summary {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: var(--bg);
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.player .prestart .big { width: 100%; padding: 16px; font-size: 1.3rem; margin: 14px 0; }
.player .paused-flag {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
  font-weight: 800;
  background: rgba(0,0,0,0.6);
  padding: 10px 24px;
  border-radius: 12px;
  pointer-events: none;
}

@media (max-width: 480px) {
  .ov-name { font-size: 1.3rem; }
  .ov-time { font-size: 2.6rem; }
  .ov-time.final { font-size: 5rem; }
}

/* Sync-Status (Studio) */
.badge.pending { color: var(--warn); }
.badge.ok { color: var(--accent); }
#nav nav a[hidden] { display: none; }
