:root {
  --bg: #F5F4EF; --card: #FFFFFF; --line: #E4E2DA; --text: #15171C; --muted: #5B606B;
  --accent: #0B6E5B; --fail: #9A3409; --fail-bg: #FBE7DC; --radius: 15px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, .title { font-family: "Space Grotesk", Inter, system-ui, sans-serif; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.wrap { max-width: 900px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 420px; padding-top: 12vh; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.pad { padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.add-form { gap: 6px; padding: 10px; }
[data-msg]:empty { display: none; }
[data-msg] { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row.nowrap { flex-wrap: nowrap; }
label { font-weight: 600; font-size: 14px; }
input[type=text], input[type=password] {
  flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
}
input[type=file] { font: inherit; font-size: 14px; min-height: 44px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.small-btn { font-size: 14px; padding: 6px 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.err { color: var(--fail); margin: 0; }
.alert { background: var(--fail-bg); color: var(--fail); border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-weight: 500; }
.worker { margin: 0 0 12px; font-size: 14px; }
details.import { margin-bottom: 12px; padding: 0 14px; }
details.import[open] { padding-bottom: 14px; }
details.import summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.chips { scrollbar-width: none; -ms-overflow-style: none; display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; font-weight: 500; font-size: 14px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 8px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 880px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.vid { overflow: hidden; display: flex; flex-direction: column; }
.vid.failed { background: var(--fail-bg); border-color: #F0C9B6; }
.thumb-link { display: block; color: inherit; text-decoration: none; }
.thumb { position: relative; aspect-ratio: 9 / 12; background: #E9E7DF; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 500; }
.dur { position: absolute; right: 8px; bottom: 8px; background: rgba(21, 23, 28, .78); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 8px; }
.meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.meta p { margin: 0; }
.title { font-weight: 700; font-size: 15px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #EEF0F2; color: var(--muted); }
.pill.s-ready { background: #DDF1EA; color: var(--accent); }
.pill.s-downloading { background: #E6EEF9; color: #1F4E96; }
.pill.s-failed { background: #fff; color: var(--fail); }
.failed-box { width: 100%; margin-top: 6px; }
.failed-msg { color: var(--fail); font-size: 13px; margin: 0 0 8px; word-break: break-word; }
.failed-box .btn { width: 100%; font-size: 14px; }
.failed-box .row { flex-direction: column; }
.player { width: 100%; max-height: 45vh; object-fit: contain; background: #000; border-radius: var(--radius); display: block; }
.item-title { font-size: 22px; margin: 14px 0 4px; }
.caption { white-space: pre-wrap; word-break: break-word; }
.empty { text-align: center; padding: 28px 0; }
.pill, .chips[aria-label="Status"] .chip { text-transform: capitalize; }
.failed-msg a { color: var(--fail); font-weight: 600; }
.details p { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; }
.details summary { min-height: 32px; cursor: pointer; }

/* ---- Stage 2: bottom nav, tags, review ---- */
body.has-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
}
.bottom-nav a.on { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 7px; }
.badge[data-review-count="0"] { display: none; }
.wrapchips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0 0 6px; }
.group-label { margin: 8px 0 4px; }
.tag-filters { margin-bottom: 12px; padding: 0 14px; }
.tag-filters[open] { padding-bottom: 10px; }
.tag-filters summary, .edit summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.tagline { margin: 2px 0; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { background: #EEF0F2; color: var(--text); border-radius: 999px; font-size: 12px; padding: 2px 8px; }
.tag.type { background: #DDF1EA; color: var(--accent); font-weight: 600; }
.exercise-names { color: var(--text); word-break: break-word; }
.review-item { margin-bottom: 16px; }
.review-item .player { margin: 8px 0; }
.ex { margin-top: 10px; background: #FBFAF6; }
.ex-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.ex-name { margin: 0; }
.pill.lowconf { background: var(--fail-bg); color: var(--fail); }
.trim .row { align-items: center; margin: 6px 0; }
.trim-label { width: 40px; font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 500; }
.switch input { width: 22px; height: 22px; }
.edit label { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; }
.edit input[type=text] { min-height: 44px; padding: 6px 10px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; width: 100%; }
button.chip { font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
.btn.danger { color: var(--fail); }
.ex-read { margin: 8px 0; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; }
.active-filters:empty { display: none; }
.chip.removable { min-height: 36px; padding: 0 12px; font-size: 13px; }
.review-head { position: sticky; top: 0; z-index: 5; background: var(--card); padding: 8px 0; margin: -8px 0 0; border-bottom: 1px solid var(--line); }
.review-head .title { flex: 1; margin-right: 8px; text-decoration: none; color: var(--text); }

/* ---- Stage 4: routines and player ---- */
.tpl { margin: 8px 0; position: relative; cursor: pointer; }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tpl .title { text-decoration: none; color: var(--text); }
.today { margin-top: 12px; }
.today-title { font: 600 18px "Space Grotesk", Inter, sans-serif; margin: 0 0 8px; }
.today-list { padding-left: 22px; margin: 0 0 12px; }
.today-list li { margin: 4px 0; }
.today-list li.missing { color: var(--fail); list-style: none; margin-left: -22px; background: var(--fail-bg); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.slot { margin: 8px 0; }
.slot input[type=number], .slot select { min-height: 44px; font: inherit; font-size: 16px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 12px; width: 100%; background: #fff; }
.slot label.small { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.play-root { position: fixed; inset: 0; background: #0B0D10; color: #fff; display: flex; flex-direction: column; z-index: 20;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.play-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.play-exit { color: #fff; font-size: 30px; line-height: 1; text-decoration: none; min-width: 44px; min-height: 44px; display: flex; align-items: center; }
.play-progress { flex: 1; display: flex; gap: 4px; }
.play-progress span { flex: 1; height: 5px; background: #2B2F36; border-radius: 3px; overflow: hidden; }
.play-progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.play-stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.play-video { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; background: #000; }
.play-card, .play-start, .play-end, .play-tap { position: absolute; inset: 0; background: #0B0D10; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.play-tap { background: rgba(11, 13, 16, .7); }
.play-card[hidden], .play-start[hidden], .play-end[hidden], .play-tap[hidden] { display: none; }
.play-name { font: 700 30px "Space Grotesk", Inter, sans-serif; margin: 4px 0; }
.play-cue { font-size: 18px; margin: 0; color: #D7DAE0; }
.play-dose { font-size: 20px; font-weight: 600; color: #7FD6C2; margin: 4px 0; }
.play-by, .muted-dark { color: #9AA0AB; }
.play-count { font: 700 56px "Space Grotesk", sans-serif; margin: 12px 0 0; color: #7FD6C2; }
.play-bottom { padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.play-countdown { font: 700 28px "Space Grotesk", sans-serif; margin: 0; min-height: 34px; }
.play-upnext { margin: 0; text-align: center; }
.play-controls { display: flex; gap: 10px; width: 100%; max-width: 420px; }
.play-controls .btn { flex: 1; }
.btn.dark { background: #1B1F26; border-color: #2B2F36; color: #fff; }
.btn.dark.on { color: #FF8FA3; border-color: #FF8FA3; }
.btn.big { min-height: 56px; font-size: 18px; padding: 0 28px; }
.play-switch { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); background: rgba(11, 110, 91, .92); color: #fff;
  font: 700 28px "Space Grotesk", sans-serif; padding: 14px 26px; border-radius: 16px; z-index: 2; }
.play-switch[hidden] { display: none; }
.play-doseline { margin: 0; font-size: 18px; font-weight: 600; color: #7FD6C2; min-height: 24px; }
.dose-edit label { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.dose-edit input { min-height: 44px; font: inherit; font-size: 16px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 12px; width: 100%; }
.play-where { margin: 0; padding: 0 14px 6px; color: #9AA0AB; text-align: center; }
.play-panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 36px 16px 14px; text-align: center;
  background: linear-gradient(to top, rgba(11, 13, 16, .92) 55%, rgba(11, 13, 16, 0)); pointer-events: none; }
.play-panel[hidden] { display: none; }
.play-panel p { margin: 2px 0; }
.play-panel-name { font: 700 26px "Space Grotesk", Inter, sans-serif; }
.play-panel-cue { font-size: 16px; color: #D7DAE0; }
.play-panel-dose { font-size: 18px; font-weight: 600; color: #7FD6C2; }
.play-panel-by { color: #9AA0AB; }
.play-panel-name:empty, .play-panel-cue:empty, .play-panel-dose:empty, .play-panel-by:empty { display: none; }
.mute-btn { flex: 0 0 56px; min-width: 56px; font-size: 22px; padding: 0; }
button.chip[data-mute-chip] { margin: 8px 0 0; }
.tpl-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.tpl-edit { position: relative; z-index: 2; padding: 12px 8px; margin: -12px -8px; }
.tpl:hover { border-color: #9CC9BF; background: #FBFEFD; }
.tpl-link:focus-visible { outline: none; }
.tpl-link:focus-visible::after { outline: 3px solid var(--accent); outline-offset: 2px; }
.tpl-selected { display: inline-block; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 10px; font-weight: 600; margin-bottom: 4px; }
.pill.s-not_workout { background: #EEF0F2; color: var(--muted); }

/* ---- sections: Strength vs Mobility & Recovery ---- */
.seg { display: flex; background: #E9E7DF; border-radius: 14px; padding: 3px; margin: 4px 0 12px; }
.seg-opt { flex: 1; min-height: 44px; display: flex; align-items: center; justify-content: center; text-align: center;
  border-radius: 11px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; line-height: 1.15; padding: 0 6px; }
.seg-opt.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 2px rgba(21, 23, 28, .12); }
.section-badge { display: inline-block; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 2px 8px; margin: 0 4px 2px 0;
  letter-spacing: .01em; }
.section-badge.strength { background: #1F2A44; color: #fff; }
.section-badge.recovery { background: #DDF1EA; color: var(--accent); }
.tag.section.strength { background: #1F2A44; color: #fff; }
.tag.section.recovery { background: #DDF1EA; color: var(--accent); }
