/* Cadence — warm paper light, quiet dark. Both modes are chosen, not flipped. */

:root {
  color-scheme: light;
  /* Space the bottom of the screen that isn't ours: the hub's navbar when
     it is up (it already covers the home indicator), else the safe area. */
  --sab: var(--random-nav-h, env(safe-area-inset-bottom));
  --bg: #faf9f7;
  --card: #ffffff;
  --card-2: #f4f2ee;
  --ink: #1a1a1a;
  --ink-2: #52514e;
  --muted: #6b6b6b;
  --line: #e5e2dc;
  --line-strong: #d6d2ca;
  --accent: #b3542e;
  --accent-ink: #ffffff;
  --accent-wash: rgba(179, 84, 46, 0.10);
  --accent-soft: rgba(179, 84, 46, 0.18);
  --good: #0ca30c;
  --series: #b3542e;      /* chart mark: validated on the card surface */
  --grid: #e1e0d9;
  --axis: #6b6b6b;
  --line-check: #767676;
  --band: #6f9a7a;        /* exercise equipment: a resistance band, quiet sage */
  --skin: #b9aea3;        /* the 3D figure's skin, a quiet warm grey; it wears the accent */
  --towel: #c8b993;       /* a towel, oatmeal */
  --iron: #6b6a66;        /* dumbbells */
  --shadow: 0 1px 2px rgba(26, 26, 26, 0.05), 0 6px 20px rgba(26, 26, 26, 0.05);
  --radius: 0.85rem;
  --tap: 2.75rem;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #141414;
    --card: #1e1e1e;
    --card-2: #262626;
    --ink: #eceae6;
    --ink-2: #c3c2b7;
    --muted: #9a9a9a;
    --line: #2c2c2c;
    --line-strong: #3a3a3a;
    --accent: #e08554;
    --accent-ink: #1a1008;
    --accent-wash: rgba(212, 120, 63, 0.24);
    --accent-soft: rgba(212, 120, 63, 0.26);
    --good: #0ca30c;
    --series: #d4783f;    /* stepped for the dark surface, not the light hue reused */
    --grid: #2c2c2a;
    --axis: #9a9a9a;
    --line-check: #8a8a8a;
    --band: #7fae8b;
    --skin: #9a9088;
    --towel: #7d735f;
    --iron: #a8a7a1;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141414;
  --card: #1e1e1e;
  --card-2: #262626;
  --ink: #eceae6;
  --ink-2: #c3c2b7;
  --muted: #9a9a9a;
  --line: #2c2c2c;
  --line-strong: #3a3a3a;
  --accent: #e08554;
  --accent-ink: #1a1008;
  --accent-wash: rgba(212, 120, 63, 0.24);
  --accent-soft: rgba(212, 120, 63, 0.26);
  --good: #0ca30c;
  --series: #d4783f;
  --grid: #2c2c2a;
  --axis: #9a9a9a;
  --line-check: #8a8a8a;
  --band: #7fae8b;
  --skin: #9a9088;
  --towel: #7d735f;
  --iron: #a8a7a1;
  --shadow: none;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 0.35rem;
}

/* ---------- frame ---------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 44rem;
  margin: 0 auto;
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 0.5rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.6rem 0.5rem;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-bar h1 {
  /* pinned, so the title stays centred when the hub navbar hides the
     hub link in the first column */
  grid-column: 2;
  font-size: 1.05rem;
  font-weight: 800;
  font-style: italic;
  letter-spacing: -0.01em;
  text-align: center;
}

.hub-link, .icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 0.6rem;
  background: none;
  color: var(--muted);
  text-decoration: none;
  font-size: 1.05rem;
}
.hub-link:hover, .icon-btn:hover { background: var(--card-2); color: var(--ink); }

.views {
  flex: 1;
  padding: 1rem 1rem 1.5rem;
}

.view { display: block; }
.view[hidden] { display: none; }

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.25rem;
  padding: 0.35rem 0.4rem calc(0.35rem + var(--sab));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-height: var(--tap);
  padding: 0.35rem 0.25rem;
  border: 0;
  border-radius: 0.6rem;
  background: none;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}
.tab-glyph { font-size: 1.05rem; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ---------- cards & type ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.85rem;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
}

.card h2 { font-size: 0.95rem; font-weight: 600; letter-spacing: -0.005em; }
.card h3 { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
}

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.section-title {
  margin: 1.4rem 0.2rem 0.6rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
}

/* ---------- today hero ---------- */

.hero { padding: 1.1rem 1rem 1rem; }
.hero-day { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; }
/* Headline type is athletic: heavy, tight and leaning forward, like a
   coach's whiteboard. Only the workout names and the big numbers wear it;
   the rows and buttons stay plain. */
.hero-workout, .session-name, .dial-time, .counter input, .summary-figure {
  font-weight: 800;
  font-style: italic;
  letter-spacing: -0.035em;
}
.hero-workout {
  margin-top: 0.35rem;
  font-size: 1.75rem;
  line-height: 1.1;
}
.hero-sub { margin-top: 0.2rem; color: var(--muted); font-size: 0.88rem; }

.progress-track {
  position: relative;
  height: 0.5rem;
  margin: 0.9rem 0 0.35rem;
  border-radius: 999px;
  background: var(--accent-wash);
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 200ms ease;
}
.progress-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap);
  padding: 0 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.7rem;
  background: var(--card);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 3.25rem; font-size: 1rem; }
.btn-sm { min-height: 2.25rem; padding: 0 0.7rem; font-size: 0.82rem; }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--card-2); color: var(--ink); }
.btn-danger { border-color: var(--line-strong); color: #c0392b; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hero .btn { margin-top: 0.85rem; }

/* The week at a glance, on the hero: "Calisthenics 1/3 · Mobility 0/3". */
.goal-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  margin: 0.55rem 0 0.9rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.84rem;
  color: var(--ink-2);
}
.goal-bit strong { font-weight: 600; color: var(--ink); }
.goal-bit.is-met strong { color: var(--good); }
.goal-days { margin-left: auto; color: var(--muted); }
.hero-eyebrow { font-size: 0.78rem; color: var(--accent); font-weight: 600; letter-spacing: 0.02em; }
.hero .hero-workout { margin-top: 0.15rem; }
.hero-tools { display: flex; justify-content: space-between; gap: 0.5rem; margin-top: 0.35rem; }
.hero .hero-tools .btn { margin-top: 0; }

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}
.session-row:last-child { border-bottom: 0; }
.session-row-main { min-width: 0; }
.session-row-name { font-weight: 500; }
.session-row.is-done .session-row-name { color: var(--muted); }
.card > h2 + .session-row, .card > .card-head + .session-row { margin-top: 0.3rem; }
.streak-line { text-align: center; margin: 1rem 0 0.5rem; }

/* ---------- program picker ---------- */

.picker-name { display: block; font-weight: 500; }
.pick-head { display: flex; justify-content: space-between; align-items: baseline; }
.pick-head .picker-goal { margin: 0; text-transform: none; letter-spacing: 0; }
.picker-choice {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: 0.45rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--card-2);
  color: var(--ink);
  text-align: left;
}
.picker-choice:hover { border-color: var(--accent); }

/* ---------- weekly schedule ---------- */

.sched { margin-top: 0.7rem; }
.sched-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}
.sched-row:last-child { border-bottom: 0; }
.sched-day { width: 2.4rem; font-weight: 600; font-size: 0.85rem; }
.sched-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1 1 10rem; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  min-height: 2rem;
  padding: 0 0.2rem 0 0.7rem;
  border-radius: 999px;
  background: var(--accent-wash);
  font-size: 0.82rem;
}
.chip-rest { padding-right: 0.7rem; background: var(--card-2); color: var(--muted); }
.chip-x {
  width: 1.9rem;
  height: 1.9rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 0.75rem;
}
.chip-x:hover { background: var(--accent-soft); color: var(--ink); }
.chip-add, .sched-add {
  min-height: 2.25rem;
  padding: 0 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.6rem;
  background: var(--card);
  color: var(--ink);
  font-size: 0.82rem;
}

.chip-add {
  -webkit-appearance: none;
  appearance: none;
  width: 2rem;
  min-height: 2rem;
  padding: 0;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-align-last: center;
}
.chip-add:hover, .chip-add:focus-visible { border-color: var(--accent); }
.log-add { margin-top: 0.9rem; }
.day-head.is-quiet .day-name { color: var(--muted); font-weight: 400; }
div.day-head { cursor: default; }

/* A day with more than one program in the Week view. */
.day-program + .day-program { margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.day-program-name { font-size: 0.92rem; font-weight: 600; margin-bottom: 0.3rem; }

.program-fields { padding: 0.4rem 0 0.2rem; }
.new-program { margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.new-program h3 { font-size: 0.95rem; margin-bottom: 0.6rem; }

/* ---------- meters & stats ---------- */

.meter-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.meter-label .value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter-track {
  display: flex;
  gap: 2px;                 /* the surface gap does the separating */
  height: 0.55rem;
}
.meter-pip {
  flex: 1;
  border-radius: 999px;
  background: var(--accent-wash);
}
.meter-pip.is-on { background: var(--accent); }
.meter + .meter { margin-top: 0.9rem; }


.banner {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.85rem;
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  background: var(--accent-wash);
  font-size: 0.88rem;
}
.banner-glyph { line-height: 1.4; }

/* ---------- exercise rows ---------- */

.rows { border-top: 1px solid var(--line); }

.row {
  display: grid;
  grid-template-columns: 1fr auto var(--tap);
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}
.row-main {
  min-width: 0;
  text-align: left;
  border: 0;
  background: none;
  padding: 0.15rem 0;
}
.row-name {
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actual { font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }
.row-target {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.row.is-done .row-name { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

.check {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  background: none;
  color: var(--muted);
}
.check span {
  display: grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border: 1.5px solid var(--line-check);
  border-radius: 0.45rem;
  font-size: 0.85rem;
  line-height: 1;
}
.check[aria-pressed="true"] span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.block-head {
  padding: 0.7rem 0 0.3rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

/* ---------- week view ---------- */

.week-nav {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.week-nav-title { text-align: center; }
.week-nav-title strong { display: block; font-size: 0.98rem; }

.day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.6rem;
  overflow: hidden;
}
.day.is-today { border-color: var(--accent); }

.day-head {
  display: grid;
  grid-template-columns: 2.6rem 1fr auto;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 0;
  background: none;
  text-align: left;
}
.day-key { font-weight: 600; font-size: 0.85rem; color: var(--muted); }
.day.is-today .day-key { color: var(--accent); }
.day-name { font-size: 0.95rem; font-weight: 500; }
.day-meta { font-size: 0.76rem; color: var(--muted); margin-top: 0.1rem; }
.day-count {
  font-size: 0.76rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.day-body { padding: 0 0.9rem 0.8rem; }
.day-body[hidden] { display: none; }
.day-done-dot { color: var(--good); font-size: 0.9rem; }

.note-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0.5rem 0.65rem;
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--card-2);
  font-size: 0.85rem;
  resize: vertical;
}

/* ---------- charts ---------- */

.chart-wrap { position: relative; width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart-band { fill: var(--series); opacity: 0.12; }
/* A 1.1:1 wash is not a perceivable boundary; the edges carry it. */
.chart-band-edge { stroke: var(--axis); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-line { stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--series); stroke: var(--card); stroke-width: 2; }
.chart-dot.is-active { r: 6; }
.chart-crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart-axis { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-endlabel { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.chart-empty { color: var(--muted); font-size: 0.88rem; padding: 1.5rem 0; text-align: center; }

.chart-tip {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--card);
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip[hidden] { display: none; }
.chart-tip strong { font-size: 0.9rem; }
.chart-tip span { font-size: 0.74rem; color: var(--muted); }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
table.data th, table.data td {
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
table.data th { color: var(--muted); font-weight: 600; font-size: 0.76rem; }
table.data td.num, table.data th.num { text-align: right; }

.field { margin-bottom: 0.8rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.field select, .field input[type="number"], .field input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--card-2);
}
.field-row { display: flex; gap: 0.6rem; }
.field-row .field { flex: 1; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--tap);
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.switch:last-child { border-bottom: 0; }
.switch-text { font-size: 0.9rem; }
.switch-text small { display: block; color: var(--muted); font-size: 0.76rem; }
.switch input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

/* ---------- routine editor ---------- */

.editor-workout { border-bottom: 1px solid var(--line); }
.editor-workout:last-child { border-bottom: 0; }
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  min-height: var(--tap);
  padding: 0.5rem 0;
  border: 0;
  background: none;
  text-align: left;
  font-weight: 500;
  font-size: 0.92rem;
}
.editor-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.editor-item:last-child { border-bottom: 0; }
.editor-item-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
}
.editor-item-name { font-size: 0.9rem; }
.editor-item-target { font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.editor-tools { display: flex; gap: 0.15rem; }
.editor-tools button {
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
}
.editor-tools button:hover { background: var(--card-2); color: var(--ink); }
.editor-form { padding: 0.6rem 0 0.2rem; }

/* ---------- guided session ---------- */

.session-root {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.session-root[hidden] { display: none; }

.session-bar {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 0.5rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.6rem 0.5rem;
}
.session-bar-title { text-align: center; font-size: 0.85rem; color: var(--muted); }

.session-progress {
  height: 3px;
  margin: 0 0.9rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-wash);
  overflow: hidden;
}
.session-progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 220ms ease;
}

.session-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  max-width: 30rem;
  width: 100%;
  margin: 0 auto;
  text-align: center;
  overflow-y: auto;
}

.session-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.session-scroll > .session-body { flex: 1 0 auto; overflow: visible; justify-content: flex-start; }
.session-scroll > .session-actions { flex: none; padding-bottom: 0.75rem; }
.session-scroll > .demo-notes { flex: none; }

.session-block { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; }
.session-name { font-size: 1.95rem; line-height: 1.1; }
.session-target { color: var(--muted); font-size: 0.95rem; }
.session-setline { font-size: 0.82rem; color: var(--accent); font-weight: 600; letter-spacing: 0.02em; }
.session-hint { font-size: 0.8rem; color: var(--muted); min-height: 1.2rem; }

.dial {
  position: relative;
  width: min(15rem, 62vw);
  aspect-ratio: 1;
  margin: 0.4rem auto;
  display: grid;
  place-items: center;
}
.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dial-track { fill: none; stroke: var(--accent-wash); stroke-width: 8; }
.dial-fill { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 240ms linear; }
.dial-fill.is-over { stroke: var(--good); }
.dial-time {
  font-size: 3.1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.dial-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }

.counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  margin: 0.8rem 0 0.2rem;
}
.counter button {
  width: 3.25rem;
  height: 3.25rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.4rem;
  line-height: 1;
}
.counter button:hover { border-color: var(--accent); }
.counter input {
  width: 5.5rem;
  border: 0;
  border-bottom: 2px solid var(--line-strong);
  background: none;
  text-align: center;
  font-size: 2.6rem;
  padding: 0.1rem 0;
  -moz-appearance: textfield;
}
.counter input::-webkit-outer-spin-button,
.counter input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.counter input:focus { border-bottom-color: var(--accent); }
.counter input:focus:not(:focus-visible) { outline: none; }
.counter-unit { font-size: 0.8rem; color: var(--muted); }

.session-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem calc(1rem + var(--sab));
  max-width: 30rem;
  width: 100%;
  margin: 0 auto;
}
.session-actions .btn-row { justify-content: center; }

.set-pips { display: flex; gap: 0.35rem; justify-content: center; margin-top: 0.1rem; }
.set-pip {
  width: 1.9rem;
  height: 0.3rem;
  border-radius: 999px;
  background: var(--accent-wash);
}
.set-pip.is-done { background: var(--accent); }
.set-pip.is-current { background: var(--accent-soft); background: color-mix(in srgb, var(--accent) 45%, transparent); }

.summary-figure {
  font-size: 3.4rem;
  line-height: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(4.75rem + var(--sab));
  transform: translateX(-50%);
  z-index: 30;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  max-width: calc(100vw - 2rem);
}
.toast[hidden] { display: none; }
/* During a session the toast would sit right on the primary button. */
body.is-session .toast { top: 4.5rem; bottom: auto; }

.toast-action {
  margin-left: 0.6rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

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

@media (min-width: 40rem) {
  .views { padding: 1.25rem 1.25rem 2rem; }
  .session-name { font-size: 2.1rem; }
}

/* An iPad (and wider): two columns. Today keeps the plan on the left and
   the list of programs on the right; Plan puts the long program editor
   beside the goals and the week; Progress keeps its chart across the top.
   Week and Settings stay one readable column. */
@media (min-width: 48rem) {
  .app { max-width: 72rem; }
  #view-today:not([hidden]), #view-plan:not([hidden]), #view-progress:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 1rem;
    align-items: start;
  }
  #view-today > *, #view-plan > * { grid-column: 1; }
  #view-today > .pick-card { grid-column: 2; grid-row: 1 / span 12; }
  #view-plan > .programs-card { grid-column: 2; grid-row: 1 / span 4; }
  #view-progress > * { grid-column: 1 / -1; }
  /* the two tables, side by side and level (not the empty state's card) */
  #view-progress > :nth-last-child(-n + 2):not(:nth-child(-n + 2)) { grid-column: auto; align-self: stretch; }
  #view-week, #view-settings { max-width: 44rem; margin: 0 auto; }
  /* the bar spans the app; its tabs keep to the width of one column */
  .tabbar { padding-inline: max(0.4rem, calc((100% - 44rem) / 2)); }
}

/* Wider still (an iPad on its side): the programs two across, so the list
   is about as tall as the plan beside it rather than twice as tall. */
@media (min-width: 64rem) {
  #view-today > .pick-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 0.45rem;
    align-content: start;
  }
  #view-today > .pick-card > :not(.picker-choice) { grid-column: 1 / -1; justify-self: start; }
  #view-today > .pick-card > .pick-head { justify-self: stretch; }
}

/* ---------- the demonstration panel ---------- */

.demo { margin-bottom: 0.8rem; }

.demo-stage {
  display: grid;
  place-items: center;
  height: clamp(7rem, 23vh, 10.5rem);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.figure { display: block; width: 100%; height: 100%; }

.fig3d { position: relative; width: 100%; height: 100%; }
/* Sideways drags turn the figure; up-and-down still scrolls the page. */
.fig3d-canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; cursor: grab; }
.fig3d-canvas:active { cursor: grabbing; }
.fig3d-hint {
  position: absolute;
  right: 0.55rem;
  bottom: 0.4rem;
  font-size: 0.7rem;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 400ms ease;
}
.fig3d.is-turned .fig3d-hint { opacity: 0; }

/* The figure is drawn in body units — a limb is as thick as a limb, at any
   size — so no non-scaling strokes here. The far side is the same colour,
   faded as a whole group, so overlapping far limbs don't stack darker. */
.fig-limb { stroke: var(--accent); fill: none; }
.fig-far { opacity: 0.4; }
.fig-head { fill: var(--accent); }
.fig-eye { fill: var(--card-2); }
.fig-prop {
  stroke: var(--line-strong);
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
  fill: none;
}
.fig-rod { fill: var(--line-strong); }
.fig-box {
  fill: var(--card);
  stroke: var(--line-strong);
  stroke-width: 1.5px;
  vector-effect: non-scaling-stroke;
}
/* Equipment, in body units like the limbs. */
.fig-band { stroke: var(--band); fill: none; }
.fig-anchor { fill: var(--band); }
.fig-towel {
  fill: var(--towel);
  stroke: var(--line-strong);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}
.fig-towel-flat { stroke: var(--towel); fill: none; }
.fig-bell { stroke: var(--iron); fill: none; }

.demo-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--card-2);
}

.demo-loading { color: var(--muted); font-size: 0.82rem; }

.demo-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.45rem;
}
.demo-notes {
  max-width: 30rem;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.25rem calc(1.25rem + var(--sab));
}
.demo-cue {
  margin: 0;
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink);
}
.demo-controls { display: flex; gap: 0.3rem; flex: 0 0 auto; }
.demo-how {
  margin-top: 0.5rem;
  text-align: left;
  font-size: 0.84rem;
  line-height: 1.45;
}
.demo-how summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  list-style: none;
}
.demo-how summary::-webkit-details-marker { display: none; }
.demo-how summary::after { content: '▾'; margin-left: 0.35rem; transition: transform 0.2s; }
.demo-how[open] summary::after { transform: rotate(180deg); }
.demo-how-stop { border-left: 3px solid var(--accent); padding-left: 0.6rem; }
.hold-status {
  min-height: 1.6rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hold-status.is-relax { color: var(--muted); }
.hold-btn { align-self: center; min-width: 11rem; min-height: var(--tap); }
.session-howto {
  align-self: center;
  min-height: var(--tap);
  padding: 0 0.8rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.demo-how-row { margin-top: 0.45rem; }
.demo-how-row b { display: block; font-size: 0.74rem; letter-spacing: 0.02em; color: var(--muted); font-weight: 600; }
.demo-how-row p { margin: 0.1rem 0 0; }
.demo-btn {
  min-height: var(--tap);
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}
.demo-btn:hover { border-color: var(--accent); color: var(--ink); }

/* The figure has to share the screen with the dial, so the dial gives way. */
.session-body.has-demo .dial { width: min(10.5rem, 40vw); }
.session-body.has-demo .dial-time { font-size: 2.2rem; }
.session-body.has-demo .session-name { font-size: 1.5rem; }

.demo-rest {
  height: 5rem;
  margin-top: 0.7rem;
  opacity: 0.85;
}
.demo-rest .figure { height: 5rem; }

.editor-demo { display: flex; gap: 0.7rem; align-items: center; }
.editor-demo-thumb {
  flex: 0 0 4.5rem;
  height: 3.4rem;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  overflow: hidden;
}
.editor-demo-body { flex: 1; min-width: 0; }

/* Visible to assistive technology only. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- quick logging from a checklist row ---------- */

.quick-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0 0.7rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.quick-step {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.1rem;
  line-height: 1;
}
.quick-step:hover { border-color: var(--accent); }
.quick-input {
  width: 3.6rem;
  min-height: 2.4rem;
  padding: 0 0.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  background: var(--card-2);
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  -moz-appearance: textfield;
}
.quick-input::-webkit-outer-spin-button,
.quick-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.quick-unit { font-size: 0.78rem; color: var(--muted); margin-right: auto; }

/* ---------- session summary ---------- */

.summary-list {
  margin-top: 1rem;
  text-align: left;
  border-top: 1px solid var(--line);
}
.summary-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.summary-name { flex: 1; min-width: 0; }
.summary-sets { color: var(--muted); font-variant-numeric: tabular-nums; }
.summary-delta { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.summary-delta.is-up { color: var(--good); }

/* The two things you read from arm's length were the smallest text here. */
.session-setline { font-size: 1.2rem; }

.picker-goal { display: block; margin-top: 0.15rem; font-size: 0.78rem; color: var(--accent); font-weight: 500; }

/* An iPad on its side (and wider): an exercise's figure beside its timer
   or counter, so the whole step fits the short screen. The body's children
   join the scroller's grid; the figure takes the left column, everything
   else (the controls, the buttons, the cue) stacks on the right. */
@media (min-width: 48rem) and (orientation: landscape) {
  .session-scroll {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 2rem;
    align-content: safe center;
    width: 100%;
    max-width: 60rem;
    margin: 0 auto;
    padding: 0 1.25rem;
    text-align: center;
  }
  .session-scroll > .session-body { display: contents; }
  .session-scroll > .session-body > *, .session-scroll > .session-actions, .session-scroll > .demo-notes { grid-column: 2; margin-block: 0.25rem; }
  .session-scroll > .session-body > .demo { grid-column: 1; grid-row: 1 / span 12; align-self: center; margin: 0; }
  .session-scroll .demo-stage { height: min(26rem, 62vh); }
  .session-scroll > .session-actions, .session-scroll > .demo-notes { max-width: none; padding-inline: 0; }
  .session-scroll > .session-body.has-demo .dial { width: min(13rem, 30vh); }
}

/* An iPad standing up has height to spare: a bigger figure. */
@media (min-width: 48rem) and (orientation: portrait) {
  .session-body.has-demo .demo-stage { height: min(22rem, 30vh); }
}
