:root {
  --bg: #14161a;
  --surface: #1e2228;
  --surface-2: #262b33;
  --surface-3: #2f3641;
  --border: #333a44;
  --text: #e8eaed;
  --muted: #9aa3af;
  --faint: #6b7280;
  --accent: #c8452f;
  --accent-ink: #fff;
  --ok: #4caf7d;
  --walk: #3f8cc9;
  --run: #e0862b;
  --loaded: #c85a2f;
  --strength: #7a9a3c;
  --rest: #5b6470;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.35);
  --maxw: 780px;
  --nav-h: 60px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: var(--walk); text-decoration: none; }
h1,h2,h3,h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
small { color: var(--muted); }

/* layout */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 14px; }
header.app {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #1b1f25, #16191e);
  border-bottom: 1px solid var(--border);
  padding: 10px 0; box-shadow: var(--shadow);
}
header.app .wrap { display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 800; letter-spacing: .5px; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand .tag { background: var(--accent); color: #fff; border-radius: 6px; padding: 1px 7px; font-size: .72rem; letter-spacing: 1px; }
.brand-sub { color: var(--muted); font-size: .78rem; font-weight: 500; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

#view { padding: 16px 0 24px; }
.section { margin-bottom: 22px; }

/* progress bar */
.pbar { height: 8px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.pbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--strength), var(--ok)); }
.pbar.sm { height: 5px; }

/* countdown / meta chips */
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: .78rem; color: var(--muted); }
.chip strong { color: var(--text); }
.chip.count { border-color: var(--accent); color: #f1b6ab; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card h3 .muted { font-weight: 500; }

/* buttons */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 9px; padding: 9px 14px; transition: background .12s, border-color .12s; }
button:hover, .btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #d9543d; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn { background: transparent; border: none; color: var(--muted); padding: 6px; font-size: 1.2rem; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

input, select, textarea { font: inherit; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--walk); outline-offset: 0; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; color: var(--muted); font-size: .82rem; margin-bottom: 4px; }

/* modality accent */
.m-walk { --m: var(--walk); }
.m-run { --m: var(--run); }
.m-loaded-walk { --m: var(--loaded); }
.m-strength { --m: var(--strength); }
.m-rest { --m: var(--rest); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--m, var(--muted)); display: inline-block; }

/* ===== Overview grid ===== */
.week-block { margin-bottom: 18px; }
.week-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.week-head .phase { color: var(--muted); font-size: .8rem; }
.day-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.daycell { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 5px; min-height: 74px; text-align: center; cursor: pointer; position: relative; display: flex; flex-direction: column; gap: 4px; }
.daycell:hover { border-color: var(--faint); }
.daycell .dn { font-size: .66rem; color: var(--faint); text-transform: uppercase; letter-spacing: .5px; }
.daycell .bars { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; }
.daycell .bar { width: 7px; height: 7px; border-radius: 2px; background: var(--m, var(--rest)); opacity: .85; }
.daycell.today { outline: 2px solid var(--accent); }
.daycell.complete { background: #1c2a20; border-color: #2f5a3c; }
.daycell.complete::after { content: "✓"; position: absolute; top: 3px; right: 5px; color: var(--ok); font-size: .8rem; }
.daycell.rest { opacity: .55; }
.daycell .lbl { font-size: .64rem; color: var(--muted); line-height: 1.15; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 6px 0 14px; font-size: .78rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ===== Calendar / week view ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-nav { display: flex; gap: 6px; }
.week-strip { display: grid; gap: 8px; }
.dayrow { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--rest); border-radius: 10px; padding: 10px 12px; }
.dayrow.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.dayrow.missed { border-left-color: var(--accent); }
.dayrow .drow-top { display: flex; align-items: center; gap: 8px; }
.dayrow .date { font-weight: 700; }
.dayrow .wd { color: var(--muted); font-size: .82rem; }
.dayrow .flag { margin-left: auto; font-size: .72rem; padding: 2px 8px; border-radius: 999px; }
.flag.missed { background: #3a1f1a; color: #f0a595; border: 1px solid #6e2f24; }
.flag.done { background: #16281d; color: var(--ok); border: 1px solid #2f5a3c; }
.flag.rest { background: var(--surface-2); color: var(--muted); }
.sess-line { display: flex; align-items: center; gap: 9px; padding: 7px 2px; border-top: 1px solid var(--border); }
.sess-line:first-of-type { border-top: none; }
.chk { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--faint); background: transparent; display: grid; place-items: center; flex: none; color: transparent; padding: 0; font-size: .8rem; cursor: pointer; }
.chk.on { background: var(--ok); border-color: var(--ok); color: #06210f; }
.session-card .shead .chk { width: 26px; height: 26px; }
.sess-line .stitle { flex: 1; }
.sess-line.done .stitle { color: var(--muted); text-decoration: line-through; }
.sess-line .go { color: var(--faint); }

/* ===== Session / day detail ===== */
.day-hero { border-left: 5px solid var(--m, var(--rest)); padding-left: 12px; margin-bottom: 14px; }
.session-card { border-top: 3px solid var(--m, var(--rest)); }
.session-card .shead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.session-card .shead h3 { margin: 0; flex: 1; }
.badge { font-size: .68rem; text-transform: uppercase; letter-spacing: .6px; padding: 2px 8px; border-radius: 6px; background: var(--m, var(--rest)); color: #10130f; font-weight: 700; }
.blocklist { list-style: none; margin: 0; padding: 0; }
.blocklist li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.blocklist li:first-child { border-top: none; }
.blocklist .blabel { font-weight: 600; min-width: 34%; }
.blocklist .bdetail { color: var(--walk); font-variant-numeric: tabular-nums; }
.blocklist .bnote { color: var(--muted); font-size: .84rem; }
.rpe { font-size: .72rem; background: var(--surface-3); border-radius: 6px; padding: 1px 6px; color: var(--run); }

/* exercise rows in a strength/circuit session */
.exrow { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); align-items: flex-start; }
.exrow:first-child { border-top: none; }
.exrow .thumb { width: 62px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--surface-3); flex: none; cursor: pointer; }
.exrow .exmain { flex: 1; min-width: 0; }
.exrow .exname { font-weight: 600; }
.exrow .exname .order { color: var(--faint); font-weight: 700; margin-right: 6px; }
.exrow .exmeta { color: var(--muted); font-size: .82rem; }
.exrow .prog { color: var(--strength); }
.exrow .equip { color: var(--faint); font-size: .78rem; }
.superset { border-left: 2px solid var(--strength); padding-left: 8px; margin-left: 2px; }
.superset-tag { font-size: .68rem; color: var(--strength); text-transform: uppercase; letter-spacing: .5px; }

/* logging inputs */
.logbox { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.logbox .setpair { display: flex; gap: 4px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px 4px; }
.logbox .setpair span { font-size: .7rem; color: var(--faint); padding: 0 2px; }
.logbox input.mini { width: 46px; padding: 5px 6px; text-align: center; }
.logbox .addset { font-size: .8rem; }
.log-hint { font-size: .76rem; color: var(--faint); }

/* notes */
textarea.note { min-height: 70px; resize: vertical; }

/* ===== Exercise library / detail ===== */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ex-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; }
.ex-card img { width: 100%; aspect-ratio: 16/10; object-fit: cover; background: var(--surface-3); }
.ex-card .cap { padding: 7px 9px; font-size: .84rem; font-weight: 600; }
.ex-card .cat { color: var(--faint); font-size: .72rem; font-weight: 500; }
.ex-detail img.hero { width: 100%; border-radius: 10px; background: var(--surface-3); }
.cues { padding-left: 18px; }
.cues li { margin-bottom: 5px; }
.watch { display: inline-flex; align-items: center; gap: 8px; background: #7a1f14; border: 1px solid #a5382a; color: #fff; padding: 9px 14px; border-radius: 9px; font-weight: 600; margin: 4px 0; }
.hist-item { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); font-size: .86rem; }
.hist-item .when { color: var(--faint); min-width: 92px; }

/* filter bar */
.filterbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filterbar .pill { font-size: .8rem; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.filterbar .pill.on { background: var(--strength); border-color: var(--strength); color: #10130f; font-weight: 600; }

/* reference */
.ref-nav { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 10px; }
.ref-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer; }
.ref-tile:hover { border-color: var(--faint); }
.ref-tile h3 { margin: 0 0 4px; }
.ref-tile p { margin: 0; color: var(--muted); font-size: .82rem; }
.force-comp { border-top: 1px solid var(--border); padding: 10px 0; }
.force-comp .std { color: var(--ok); font-weight: 700; }
.rpe-row { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.rpe-row .lv { font-weight: 800; color: var(--run); min-width: 42px; }
.running-pages img { width: 100%; border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--border); }

/* bottom nav */
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: #16191e; border-top: 1px solid var(--border);
}
nav.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .68rem; text-decoration: none; }
nav.tabbar a .ic { font-size: 1.25rem; line-height: 1; }
nav.tabbar a.active { color: var(--accent); }

/* modal / bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 0 0; width: 100%; max-width: var(--maxw); padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 20px rgba(0,0,0,.5); }
.sheet h3 { margin-bottom: 10px; }
.sheet .btn-row { margin-top: 12px; }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 10px; cursor: pointer; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* setup screen */
.setup-hero { text-align: center; padding: 10px 0 4px; }
.prog-choice { display: grid; gap: 12px; margin: 12px 0; }
.prog-choice .opt { text-align: left; padding: 14px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; }
.prog-choice .opt.sel { border-color: var(--accent); background: #221c1a; }
.prog-choice .opt h3 { margin-bottom: 4px; }
.prog-choice .opt p { margin: 0; color: var(--muted); font-size: .85rem; }

@media (min-width: 620px) {
  h1 { font-size: 1.7rem; }
  .daycell { min-height: 82px; }
}
@media (min-width: 720px) {
  nav.tabbar a { font-size: .74rem; }
}
