/*
  Lucia's recovery guide: the whole stylesheet. No build step.
  Mobile first: everything is laid out for a phone, then given room on wider
  screens. Colours are tokens on :root and are redefined for dark mode, so
  components never use a raw colour. The palette matches Flexx.
*/

:root {
  --bg: #f5f1ea;
  --surface: #fffcf7;
  --surface-2: #f8f3ec;
  --ink: #1f1b17;
  --ink-2: #4b443d;
  --muted: #7b7168;
  --line: #e6ded2;

  --accent: #2e5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #e2ebe5;
  --hero-bg: #2e5c4d;
  --hero-ink: #fbf7f0;

  --green: #2f7a4f;
  --green-soft: #e1f0e6;
  --amber: #b9770e;
  --amber-soft: #faecd2;
  --red: #b03a2e;
  --red-soft: #f6e0dc;

  --radius-s: 10px;
  --radius: 16px;
  --radius-l: 22px;
  --shadow-1: 0 1px 2px rgb(60 40 20 / 0.06), 0 1px 1px rgb(60 40 20 / 0.03);
  --shadow-2: 0 10px 30px -12px rgb(60 40 20 / 0.25);

  --font-ui: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", ui-serif, Georgia, serif;
  --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1d1b18;
    --surface-2: #24221e;
    --ink: #f1ece4;
    --ink-2: #cfc7bc;
    --muted: #9c9388;
    --line: #34302a;
    --accent: #7fbfa6;
    --accent-ink: #0f1f19;
    --accent-soft: #1f322b;
    --hero-bg: #1f3a31;
    --hero-ink: #f1ece4;
    --green: #6cc08f;
    --green-soft: #1b3326;
    --amber: #e6aa4b;
    --amber-soft: #3a2c14;
    --red: #ec8576;
    --red-soft: #3d1f1b;
    --shadow-1: none;
    --shadow-2: 0 10px 30px -12px rgb(0 0 0 / 0.6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
svg { width: 1.1em; height: 1.1em; flex: none; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font: 600 2.1rem/1.1 var(--font-display); letter-spacing: -0.01em; }
h2 { font: 600 1.25rem/1.25 var(--font-display); }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 0.6em; }
p:last-child { margin-bottom: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 var(--gutter); }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.center { text-align: center; }
.eyebrow { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.4em; }
.loading { padding: 40px var(--gutter); text-align: center; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 50px; padding: 12px 18px;
  border-radius: 999px; border: 1.5px solid transparent;
  font-weight: 700; font-size: 1rem; text-decoration: none;
  transition: transform 0.1s, background 0.2s;
}
.btn:active { transform: scale(0.98); }
.btn.big { min-height: 58px; font-size: 1.08rem; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 600; min-height: 44px; }
.icon-btn { background: var(--surface-2); border: 0; border-radius: 999px; width: 44px; height: 44px; display: grid; place-items: center; }

/* ---------- home ---------- */
.hero {
  margin: 0 calc(var(--gutter) * -1) 18px;
  padding: calc(28px + var(--safe-top)) var(--gutter) 22px;
  background: var(--hero-bg); color: var(--hero-ink);
  border-radius: 0 0 var(--radius-l) var(--radius-l);
}
.hero .eyebrow { color: color-mix(in oklab, var(--hero-ink) 70%, transparent); }
.hero h1 { font-size: 2.4rem; margin-bottom: 4px; }
.hero-sub { opacity: 0.85; margin-bottom: 18px; }
.hero .btn.primary { background: var(--hero-ink); color: var(--hero-bg); }
.progress { height: 8px; background: color-mix(in oklab, var(--hero-ink) 22%, transparent); border-radius: 99px; overflow: hidden; margin-top: 20px; }
.progress span { display: block; height: 100%; background: var(--hero-ink); border-radius: 99px; }
.progress-label { font-size: 0.88rem; opacity: 0.85; margin-top: 6px; }

.legend { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.tile-demo { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; background: var(--surface); border: 1.5px solid var(--line); color: #fff; }
.tile-demo svg { width: 13px; height: 13px; }
.tile-demo.done { background: var(--green); border-color: var(--green); }
.tile-demo.min { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.tile-demo.next { border: 2.5px solid var(--accent); }
.legend .dot { position: static; }

.phase-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 16px 14px 12px; margin-bottom: 14px; box-shadow: var(--shadow-1); }
.phase-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.phase-head h2 { font-size: 1.12rem; }
.count { font-weight: 700; font-size: 0.9rem; background: var(--surface-2); border-radius: 99px; padding: 4px 10px; white-space: nowrap; color: var(--ink-2); }
.phase-block.complete .count { background: var(--green); color: #fff; }
.week-row { margin-bottom: 8px; }
.week-label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.tiles { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.tile {
  position: relative; display: grid; place-items: center; aspect-ratio: 1 / 1.08; min-height: 40px;
  border-radius: 11px; border: 1.5px solid var(--line); background: var(--surface-2);
  color: var(--ink); text-decoration: none; font-weight: 700; font-size: 0.98rem;
}
.tile .tick { position: absolute; top: 2px; right: 3px; line-height: 0; }
.tile .tick svg { width: 12px; height: 12px; }
.tile.done { background: var(--green); border-color: var(--green); color: #fff; }
.tile.min { background: var(--green-soft); border-color: var(--green); color: var(--green); }
.tile.next { border: 2.5px solid var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 18%, transparent); }
.dot { position: absolute; bottom: 5px; left: 50%; translate: -50% 0; width: 5px; height: 5px; border-radius: 99px; background: currentColor; opacity: 0.55; display: inline-block; }
.legend .dot { translate: none; background: var(--muted); opacity: 1; }

.home-links { display: grid; gap: 10px; margin: 18px 0; }
.link-card {
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; box-shadow: var(--shadow-1);
}
.link-card strong { grid-column: 1; }
.link-card span { grid-column: 1; font-size: 0.88rem; color: var(--muted); }
.link-card svg { grid-column: 2; grid-row: 1 / 3; color: var(--muted); }
.home > p:last-child { margin: 24px 0 calc(32px + var(--safe-bottom)); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in oklab, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); padding-top: var(--safe-top); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.back { display: flex; align-items: center; gap: 4px; font-weight: 700; text-decoration: none; padding: 10px 10px 10px 0; }

/* ---------- day ---------- */
.day-head { padding: 22px 0 8px; }
.day-head h1 { font-size: 2.6rem; margin-bottom: 8px; }
.lead { font-size: 1.05rem; color: var(--ink-2); }
.time-chips { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.time-chips li { font-size: 0.82rem; font-weight: 600; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 4px 10px; color: var(--ink-2); }
.done-banner { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-s); background: var(--green-soft); color: var(--green); font-weight: 700; }
.done-banner.big { justify-content: center; font-size: 1.1rem; padding: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-1); }
.intro { margin: 14px 0 6px; border-color: color-mix(in oklab, var(--accent) 35%, var(--line)); }
.intro h2 { margin-bottom: 4px; }
.note summary { margin-bottom: 0; }
.note { border-top: 0; margin-top: 0; }
.note[open] summary { margin-bottom: 8px; }
.intro h3 { margin: 14px 0 4px; }
blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--accent); font-style: italic; color: var(--ink-2); }

.steps { list-style: none; padding: 0; margin: 18px 0 0; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 10px; margin-bottom: 24px; }
.step-num { width: 30px; height: 30px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 0.95rem; margin-top: 1px; }
.step-body { min-width: 0; }
.step-title { margin: 3px 0 8px; }
.step-title .muted { font-family: var(--font-ui); font-size: 0.9rem; font-weight: 600; }
.step-sub { margin-top: -4px; }

.colours { display: grid; gap: 8px; margin-top: 10px; }
.colour {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 12px; text-align: left;
  padding: 11px 14px; border-radius: var(--radius-s); border: 1.5px solid var(--line); background: var(--surface-2);
}
.colour::before { content: ""; width: 16px; height: 16px; border-radius: 99px; grid-row: 1 / 3; }
.colour span { font-weight: 700; }
.colour small { color: var(--muted); font-size: 0.82rem; }
.colour.green::before { background: var(--green); }
.colour.amber::before { background: var(--amber); }
.colour.red::before { background: var(--red); }
.colour.green.on { border-color: var(--green); background: var(--green-soft); }
.colour.amber.on { border-color: var(--amber); background: var(--amber-soft); }
.colour.red.on { border-color: var(--red); background: var(--red-soft); }
.advice { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-s); font-size: 0.95rem; }
.advice.green { background: var(--green-soft); }
.advice.amber { background: var(--amber-soft); }
.advice.red { background: var(--red-soft); }

.exercises { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.ex {
  display: grid; grid-template-columns: 72px 1fr; gap: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow-1);
  transition: opacity 0.2s;
}
.ex.ticked { opacity: 0.6; }
.ex.ticked h3 { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.thumb {
  position: relative; width: 72px; height: 112px; padding: 0; border: 0; border-radius: 10px; overflow: hidden;
  background: #111; align-self: start;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; background: linear-gradient(transparent 40%, rgb(0 0 0 / 0.35)); }
.thumb .play svg { width: 30px; height: 30px; filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.5)); }
.thumb.none { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 0.75rem; text-align: center; height: 72px; }
.ex-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.ex h3 { font-size: 1rem; padding-top: 2px; }
.tickbox { position: relative; flex: none; width: 34px; height: 34px; }
.tickbox input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.tickbox span { pointer-events: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 99px; border: 2px solid var(--line); color: transparent; }
.tickbox input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.tickbox input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dose { margin: 8px 0 0; display: grid; grid-template-columns: auto auto auto; justify-content: start; gap: 6px; }
.dose div { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 4px 8px; }
.dose dt { font-size: 0.62rem; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.8; font-weight: 700; }
.dose dd { margin: 0; font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.how { grid-column: 1 / -1; font-size: 0.93rem; color: var(--ink-2); line-height: 1.45; margin: 0; }
.alt { grid-column: 1 / -1; justify-self: start; margin-top: -2px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 6px 12px; font-size: 0.86rem; font-weight: 600; color: var(--accent); }
.exercises.compact { margin-top: 10px; }
.exercises.compact .ex { box-shadow: none; background: var(--surface-2); }

details { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: 4px 0; list-style-position: outside; }
details[open] summary { margin-bottom: 6px; }
ul.plain { padding-left: 1.1em; margin: 6px 0 0; }
ul.plain li { margin-bottom: 8px; }

.minimum { background: var(--amber-soft); border-color: color-mix(in oklab, var(--amber) 35%, var(--line)); margin-bottom: 18px; }
.minimum h2 { font-size: 1.1rem; margin-bottom: 6px; }
.minimum ul { margin: 6px 0 0; padding-left: 1.2em; }

.review { margin-bottom: 18px; border-color: color-mix(in oklab, var(--accent) 35%, var(--line)); }
.review h2 { margin-bottom: 8px; }
.big-num { font: 600 2.2rem/1.1 var(--font-display); color: var(--accent); margin: 6px 0 10px; }
.big-num span { font: 600 1rem var(--font-ui); color: var(--ink-2); }
.review .btn { margin-top: 12px; }

.finish { display: grid; gap: 10px; margin: 8px 0 20px; }
.day-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 0 calc(32px + var(--safe-bottom)); border-top: 1px solid var(--line); font-size: 0.9rem; }
.day-nav a { display: flex; align-items: center; gap: 2px; font-weight: 600; text-decoration: none; padding: 8px 0; }

/* ---------- weekly check ---------- */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.field span, .field-label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; }
.field input { width: 100%; min-height: 48px; font: 700 1.15rem var(--font-ui); padding: 8px 12px; border-radius: var(--radius-s); border: 1.5px solid var(--line); background: var(--surface-2); color: var(--ink); }
.field input:focus { outline: none; border-color: var(--accent); }
.weekly h3 { margin-top: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { border: 1.5px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 7px 14px; font-weight: 600; font-size: 0.92rem; min-height: 40px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.saved { min-height: 1.4em; margin: 4px 0 0; }

/* ---------- log and help ---------- */
.log { list-style: none; padding: 0; margin: 12px 0 40px; display: grid; gap: 10px; }
.log-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.log-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.log-head a { margin-left: auto; }
.log dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.log dt { font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.log dd { margin: 0; font-weight: 600; }

.help .card { margin-bottom: 12px; }
.help .card h2 { margin-bottom: 8px; }
.help { padding-bottom: calc(32px + var(--safe-bottom)); }
.alert { background: var(--red-soft); border-color: color-mix(in oklab, var(--red) 40%, var(--line)); }
.alert ul { padding-left: 1.1em; margin: 0; }
.pill { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; color: #fff; margin-right: 4px; }
.pill.green { background: var(--green); }
.pill.amber { background: var(--amber); }
.pill.red { background: var(--red); }

/* ---------- video dialog ---------- */
dialog#video {
  width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 12px; border: 0; border-radius: var(--radius-l);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
}
dialog#video::backdrop { background: rgb(0 0 0 / 0.7); }
.video-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.video-head h2 { font-size: 1.05rem; }
.video-frame { aspect-ratio: 9 / 16; width: 100%; max-height: calc(100dvh - 110px); margin: 0 auto; border-radius: var(--radius); overflow: hidden; background: #000; }
.video-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); translate: -50% 20px; opacity: 0;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 99px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 0.92rem; z-index: 20;
  transition: opacity 0.25s, translate 0.25s; box-shadow: var(--shadow-2);
}
.toast.show { opacity: 1; translate: -50% 0; }

@media (min-width: 640px) {
  :root { --gutter: 24px; }
  .hero { margin: 16px 0 18px; border-radius: var(--radius-l); }
  .tile { min-height: 52px; font-size: 1.1rem; }
  .ex { grid-template-columns: 90px 1fr; }
  .thumb { width: 90px; height: 140px; }
}

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