:root {
  --bg: #14170f;
  --bg-raised: #1e2317;
  --bg-card: #252c1c;
  --olive: #6b7c3f;
  --olive-bright: #8fa653;
  --sand: #d8cfae;
  --text: #e8e6dc;
  --text-dim: #9a9a8a;
  --danger: #c0392b;
  --ok: #7cb342;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

#app {
  min-height: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--bg-card);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
}
.btn:active { filter: brightness(1.2); }
.btn-primary { background: var(--olive); color: #fff; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-big {
  padding: 22px;
  font-size: 1.4rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--olive);
  color: #fff;
  box-shadow: 0 6px 24px rgb(107 124 63 / 40%);
}

input[type="password"], input[type="text"], textarea, select {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid #3a4229;
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--olive); }

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; }
.dim { color: var(--text-dim); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error-msg { color: var(--danger); font-weight: 600; min-height: 1.2em; }

/* ---------- Top navigation ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar .brand { font-size: 1.1rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.topbar .brand span { color: var(--olive-bright); }
.navrow { display: flex; gap: 6px; }
.navrow a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.3rem;
  padding: 6px 9px;
  border-radius: 10px;
}
.navrow a.active { background: var(--bg-card); color: var(--text); }

/* ---------- Login ---------- */
.login-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.login-logo { text-align: center; margin-bottom: 30px; }
.login-logo .mark { font-size: 3rem; }

/* ---------- Dashboard ---------- */
.hero { text-align: center; padding: 26px 18px; }
.hero .day-label { color: var(--olive-bright); font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.85rem; }
.hero h1 { font-size: 2rem; margin: 6px 0 4px; }
.hero .focus { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 18px; }

.week-strip { display: flex; gap: 6px; justify-content: space-between; }
.week-day {
  flex: 1;
  text-align: center;
  padding: 10px 2px;
  border-radius: 10px;
  background: var(--bg-raised);
  font-size: 0.75rem;
  color: var(--text-dim);
  border: 1px solid transparent;
}
.week-day .mark { display: block; font-size: 1.1rem; margin-bottom: 2px; }
.week-day.done { background: var(--bg-card); color: var(--ok); border-color: rgb(124 179 66 / 35%); }
.week-day.today { border-color: var(--olive-bright); color: var(--text); }

.stats-row { display: flex; gap: 12px; }
.stat { flex: 1; text-align: center; padding: 14px 6px; background: var(--bg-card); border-radius: var(--radius); }
.stat .value { font-size: 1.6rem; font-weight: 800; }
.stat .label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.banner {
  background: linear-gradient(135deg, #4a3c17, #6b5a1e);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  font-weight: 600;
}

/* ---------- Player ---------- */
.player {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 14px) 18px calc(var(--safe-bottom) + 14px);
  max-width: 640px;
  margin: 0 auto;
}
.player-head { display: flex; justify-content: space-between; align-items: center; color: var(--text-dim); font-size: 0.85rem; }
.player-phase { font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--olive-bright); }

.timer-wrap { position: relative; margin: 10px auto; width: min(62vw, 260px); }
.timer-wrap svg.ring { width: 100%; height: auto; transform: rotate(-90deg); }
.ring-bg { stroke: var(--bg-card); }
.ring-fg { stroke: var(--olive-bright); transition: stroke-dashoffset 0.3s linear; }
.ring-fg.rest { stroke: var(--sand); }
.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
.timer-text .time { font-size: 3.2rem; font-weight: 800; }
.timer-text .sub { color: var(--text-dim); font-size: 0.85rem; }

.exercise-name { text-align: center; font-size: 1.5rem; margin-bottom: 4px; }
.exercise-cues { text-align: center; color: var(--olive-bright); font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; }

.exercise-figure { width: min(38vw, 170px); margin: 0 auto; color: var(--sand); }
.exercise-figure svg { width: 100%; height: auto; }

.steps-toggle { text-align: center; margin-top: 6px; }
.steps-list { font-size: 0.85rem; color: var(--text-dim); padding: 10px 16px 0 30px; }
.steps-list li { margin-bottom: 5px; }

.next-up {
  margin-top: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 8px 0;
}

.player-controls { display: flex; gap: 10px; margin-top: 8px; }
.player-controls .btn { padding: 14px 8px; font-size: 0.9rem; }

.music-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.music-bar .title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.music-bar button { background: none; font-size: 1.2rem; padding: 4px 8px; color: var(--text); }

/* ---------- Done screen ---------- */
.done-screen { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.done-screen .medal { font-size: 4.5rem; animation: pop 0.6s ease-out; }
@keyframes pop { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Library ---------- */
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lib-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
}
.lib-card .figure { color: var(--sand); width: 80%; margin: 0 auto 8px; }
.lib-card .name { font-size: 0.85rem; font-weight: 700; }

.modal {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 70%);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-body {
  background: var(--bg-raised);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px 20px calc(var(--safe-bottom) + 22px);
}

/* ---------- Settings / forms ---------- */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #2c3320; gap: 12px; }
.setting-row:last-child { border-bottom: none; }
.setting-row label { flex: 1; }
input[type="range"] { flex: 1; accent-color: var(--olive-bright); max-width: 45%; }

.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--bg-card);
  border-radius: 15px;
  transition: background 0.2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 24px; height: 24px;
  left: 3px; top: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + .slider { background: var(--olive); }
.switch input:checked + .slider::before { transform: translateX(22px); background: #fff; }

.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--olive-bright); flex-shrink: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
