:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev2: #1f242e;
  --line: #2a303c;
  --text: #e7ebf2;
  --muted: #9aa4b2;
  --accent: #6ad19a;
  --accent-2: #4fb3ff;
  --red: #ff5d5d;
  --green: #43d17f;
  --ring-fill: #ffffff;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }

/* ---------------- Login ---------------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, #1b2330 0%, var(--bg) 60%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 26px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-logo { font-size: 46px; line-height: 1; }
.login-card h1 { margin: 10px 0 4px; font-size: 26px; letter-spacing: .5px; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.login-card input {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-error {
  background: rgba(255,93,93,.12);
  border: 1px solid rgba(255,93,93,.4);
  color: #ffb4b4;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
}
.btn-primary {
  margin-top: 6px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06210f;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
.btn-primary:active { transform: translateY(1px); }

/* ---------------- App layout ---------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.topbar-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  overflow: hidden;
}
.brand { font-size: 13px; color: var(--muted); }
.current-workout {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { background: var(--bg-elev2); }

/* Drawer */
.drawer {
  position: fixed;
  top: 0; left: 0;
  height: 100dvh;
  width: 84%;
  max-width: 340px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  transform: translateX(-105%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  font-weight: 700;
  font-size: 18px;
  border-bottom: 1px solid var(--line);
}
#navigation { flex: 1; overflow-y: auto; padding: 8px 0; }
.drawer-foot {
  border-top: 1px solid var(--line);
  padding: 14px 16px calc(14px + var(--safe-b));
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}
.drawer-foot .user { color: var(--muted); }
.drawer-foot .logout { color: var(--accent-2); text-decoration: none; font-weight: 600; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 40;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* Nav items */
.prog {
  border-bottom: 1px solid var(--line);
}
.prog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 600;
}
.prog-head .arrow { transition: transform .2s; color: var(--muted); font-size: 12px; }
.prog.open .prog-head .arrow { transform: rotate(90deg); }
.prog-days { display: none; padding: 4px 8px 10px; }
.prog.open .prog-days { display: block; }
.workout-item {
  display: block;
  padding: 10px 12px;
  margin: 4px 6px;
  border-radius: 10px;
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.workout-item:active { border-color: var(--accent); }
.workout-item.active { border-color: var(--accent); background: rgba(106,209,154,.12); }
.workout-item .tag { color: var(--muted); font-size: 12px; margin-right: 6px; }

/* Stage */
.stage {
  position: fixed;
  top: 56px;
  left: 0; right: 0;
  bottom: calc(96px + 68px + var(--safe-b)); /* controls + preview strip */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  gap: 12px;
}
.stage-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty-icon { font-size: 64px; }
.stage-empty h2 { color: var(--text); margin: 12px 0 6px; }
.kbd {
  display: inline-block;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
}

.exercise {
  margin: 0;
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.ex-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.ex-counter {
  background: var(--bg-elev2);
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.ex-name { font-size: 22px; font-weight: 700; text-align: center; }
.ex-side {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 3px 10px;
  border-radius: 999px;
}
.ex-side.rechts { background: rgba(79,179,255,.18); color: var(--accent-2); }
.ex-side.links { background: rgba(106,209,154,.18); color: var(--accent); }
.ex-side:empty { display: none; }
.ex-image-box {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 8px;
}
.ex-image-box img {
  max-width: 100%;
  max-height: 56dvh;
  object-fit: contain;
  border-radius: 10px;
}

/* Preview — fixed strip directly above the controls */
.preview {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(96px + var(--safe-b));
  height: 68px;
  z-index: 24;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
}
.preview[hidden] { display: none; }
.preview-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  flex: none;
  line-height: 1;
}
.preview-body { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.preview-body img {
  width: 48px; height: 48px;
  object-fit: contain;
  background: var(--bg-elev2);
  border-radius: 10px;
  border: 1px solid var(--line);
  flex: none;
}
.preview-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.preview-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-side { font-size: 12px; color: var(--muted); }

/* Controls */
.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  min-height: 96px;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 25;
}
.rings { display: flex; gap: 14px; }
.ring-group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ring {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
}
.ring.red { background: conic-gradient(var(--ring-fill) 0%, var(--red) 0% 100%); }
.ring.green { background: conic-gradient(var(--ring-fill) 0%, var(--green) 0% 100%); }
.ring span {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-elev);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.factor {
  background: var(--bg-elev2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 4px;
  font-size: 12px;
}
.transport { display: flex; align-items: center; gap: 12px; }
.ctrl {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ctrl:active { transform: scale(.95); }
.ctrl.play {
  width: 62px; height: 62px;
  border: none;
  font-size: 26px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06210f;
}

/* History */
.history-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100dvh;
  width: 88%;
  max-width: 400px;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  transform: translateX(105%);
  transition: transform .25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.history-panel.open { transform: translateX(0); }
.history-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.hist-item {
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.hist-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hist-name { font-weight: 700; }
.hist-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.hist-bar { height: 6px; background: var(--bg); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.hist-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.hist-sub { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.badge-done { color: var(--green); font-weight: 700; }
.hist-empty { color: var(--muted); text-align: center; margin-top: 40px; }

/* ---------------- Desktop ---------------- */
@media (min-width: 900px) {
  .stage { left: 340px; }
  .drawer {
    transform: none;
    z-index: 20;
  }
  #closeDrawer, #menuBtn { display: none; }
  .controls { left: 340px; }
  .preview { left: 340px; }
  .scrim { display: none; }
  .ex-image-box img { max-height: 64dvh; }
}
