/* ==========================================================================
   Physio — styles
   Palette: bg #E9EDF0 · ink #1F3247 · accent #B3123F · muted #5C6B78
   Dark mode is the inverted palette with an accent lightened for contrast.
   ========================================================================== */

:root {
  --bg: #E9EDF0;
  --surface: #F8FAFB;
  --ink: #1F3247;
  --accent: #B3123F;
  --accent-soft: rgba(179, 18, 63, 0.1);
  --muted: #5C6B78;
  --line: rgba(31, 50, 71, 0.14);
  --shadow: 0 1px 3px rgba(31, 50, 71, 0.1);
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --radius: 14px;
  --tabbar-h: 58px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1F3247;
    --surface: #28405A;
    --ink: #E9EDF0;
    --accent: #E0577E;
    --accent-soft: rgba(224, 87, 126, 0.16);
    --muted: #97A6B4;
    --line: rgba(233, 237, 240, 0.16);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px
           calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom)) 16px;
  outline: none;
}

h1, h2, h3 { margin: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

a { color: inherit; text-decoration: none; }

svg { display: block; }

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

/* main receives programmatic focus on route change — never show a ring there */
main:focus, main:focus-visible { outline: none; }

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

/* ---- Screen header ---- */

.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 18px;
}

.screen-head h1 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.screen-sub {
  color: var(--muted);
  font-size: 14px;
  margin: -12px 0 18px;
}

/* ---- Cards ---- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

a.card { display: block; }

.card h2 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
}

.card .subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 2px 0 0;
}

/* ---- Protocol card (Home) ---- */

.proto-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
}

.proto-meta strong { color: var(--ink); font-weight: 600; }

.spark-wrap {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.spark-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.session-dots { display: inline-flex; gap: 5px; vertical-align: -1px; margin-left: 2px; }
.session-dots i {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--muted);
}
.session-dots i.done { background: var(--accent); border-color: var(--accent); }

.status-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 10px;
  vertical-align: 3px;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
}

@media (prefers-color-scheme: dark) {
  .btn-primary { color: #1F3247; }
}

.btn-quiet {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--muted);
  min-height: 44px;
}

.btn-block { display: flex; width: 100%; }

.btn-danger-line { color: var(--accent); }

.btn-row { display: flex; gap: 10px; margin: 16px 0; }
.btn-row .btn { flex: 1; }

/* ---- Library ---- */

.search {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 12px;
}
.search::placeholder { color: var(--muted); }

.chip-group { margin-bottom: 10px; }
.chip-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 6px 2px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  color: var(--ink);
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.exercise-card .diagram {
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 10px;
  margin: 12px 0;
  padding: 4px;
}
.exercise-card .diagram svg { width: 100%; height: auto; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 10px;
}

.rx {
  font-size: 15px;
  font-weight: 600;
  margin-top: 10px;
}
.rx .sep { color: var(--muted); font-weight: 400; margin: 0 4px; }

.effort-band { margin-top: 10px; }
.effort-band .track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}
.effort-band .fill {
  position: absolute;
  top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 4px;
}
.effort-band .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }

.cue { margin: 10px 0 0; font-size: 15px; }
.note { margin: 8px 0 0; font-size: 14px; color: var(--muted); font-style: italic; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

/* ---- Protocol detail ---- */

.backlink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.rule-card { border-left: 4px solid var(--accent); }
.rule-card h3, .list-card h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.rule-card p { margin: 0; font-size: 16px; font-weight: 500; }

.list-card ul { margin: 0; padding-left: 20px; }
.list-card li { margin: 4px 0; font-size: 15px; }

.redflag-card { background: var(--accent-soft); }
.redflag-card p { margin: 0; font-size: 15px; font-weight: 500; }

.ex-order {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---- Session player ---- */

.player {
  min-height: calc(100vh - var(--tabbar-h) - 80px);
  min-height: calc(100dvh - var(--tabbar-h) - 80px);
  display: flex;
  flex-direction: column;
}

.player-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.player-progress {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.player-ex-name {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin: 8px 0 2px;
}

.player-phase {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  min-height: 20px;
}
.player-phase.working { color: var(--accent); }

.player-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0;
}

.big-count {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.big-count.resting { color: var(--muted); }

.set-counter {
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.player-diagram {
  width: min(300px, 80vw);
  color: var(--ink);
}
.player-diagram svg { width: 100%; height: auto; }

/* Tempo pacer: an expanding bar */
.pacer {
  width: min(280px, 76vw);
  height: 18px;
  border-radius: 9px;
  background: var(--line);
  overflow: hidden;
}
.pacer .pacer-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 9px;
}
.pacer-word {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  min-height: 22px;
}

.rep-counter {
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rep-counter small { font-size: 18px; color: var(--muted); font-weight: 600; }

.side-flag {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.switch-prompt {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  text-align: center;
}

.player-cue {
  font-size: 15px;
  color: var(--muted);
  text-align: center;
  max-width: 340px;
  margin: 0 auto;
}

.player-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 12px 0 4px;
}
.player-controls .btn { min-width: 84px; }

.next-up {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 6px;
}

/* Pain slider */
.pain-form { text-align: center; padding: 12px 0; }
.pain-form h2 { font-family: var(--serif); font-size: 26px; margin-bottom: 4px; }
.pain-value {
  font-size: 64px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 10px 0 2px;
  color: var(--accent);
}
.pain-scale-lbl { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 44px;
  margin: 0;
}

.note-input {
  width: 100%;
  min-height: 80px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 14px 0;
  resize: vertical;
}
.note-input::placeholder { color: var(--muted); }

/* ---- History ---- */

.filter-row { margin-bottom: 14px; }
.filter-row select {
  width: 100%;
  min-height: 48px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}

.chart-card .legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.legend .key { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.legend .swatch-tri {
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--ink);
}

.log-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.log-item:last-child { border-bottom: none; }
.log-item .what { font-weight: 600; font-size: 15px; }
.log-item .when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.log-item .log-note { color: var(--muted); font-size: 14px; margin-top: 2px; }
.log-item.flare .what { color: var(--accent); }

.pain-chip {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
}

/* ---- Tab bar ---- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  min-height: var(--tabbar-h);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

body.session-mode .tabbar { display: none; }
body.session-mode main { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 20;
  max-width: min(440px, calc(100vw - 32px));
}
.toast[hidden] { display: none; }
.toast button {
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  min-height: 44px;
  flex-shrink: 0;
}

/* ---- Utility ---- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
