/* Calm, warm, organic: soft sage and warm neutrals. No red/green pass-fail colours. */
:root {
  --bg: #f4f1ea;
  --surface: #fbf9f4;
  --ink: #2f3a32;
  --ink-soft: #5d6a60;
  --sage: #7d9a83;
  --sage-deep: #4f6b56;
  --sage-tint: #e3eadf;
  --line: #ddd6c8;
  /* Chart series: validated for colour-blind separation against --surface (dataviz validator). */
  --series-1: #007c60;
  --series-2: #ba782e;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: ui-serif, "New York", Georgia, serif;
  --radius: 16px;
  --tabbar-height: 60px;
  --gutter: 20px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d211e;
    --surface: #262b27;
    --ink: #e8e6df;
    --ink-soft: #a9b1a8;
    --sage: #9bb5a0;
    --sage-deep: #b9cfbd;
    --sage-tint: #2f3a32;
    --line: #3a413b;
    --series-1: #42a788;
    --series-2: #c77f3e;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html.has-overlay { overflow: hidden; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--gutter) 10px;
  background: var(--bg);
}

.app-header h1 {
  margin: 0;
  font: 600 1.75rem/1.2 var(--font-display);
  letter-spacing: -0.01em;
}

/* ---- Main view ---- */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px var(--gutter) calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 24px);
  outline: none;
}

.lede {
  margin: 0 0 20px;
  color: var(--ink-soft);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 6px;
  font: 600 1.1rem/1.3 var(--font-display);
}

.card p { margin: 0; color: var(--ink-soft); }

.placeholder {
  background: var(--sage-tint);
  border-style: dashed;
}

.section-title {
  margin: 0;
  font: 600 1.15rem/1.3 var(--font-display);
}

.section-note {
  margin: 2px 0 12px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---- Today: session slots ---- */
.slot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.slot {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.slot:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}

.slot-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1.5px solid var(--sage);
  border-radius: 50%;
}

.slot-mark svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.slot-label {
  display: block;
  font-weight: 500;
  line-height: 1.25;
}

.slot-status {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.slot.is-done {
  background: var(--sage-tint);
  border-color: transparent;
}

.slot.is-done .slot-mark {
  background: var(--sage-deep);
  border-color: var(--sage-deep);
}

.slot.is-done .slot-mark svg { opacity: 1; }

@media (max-width: 359px) {
  .slot-grid { grid-template-columns: 1fr; gap: 8px; }
  .slot { min-height: 64px; }
}

@media (prefers-reduced-motion: no-preference) {
  .slot, .slot-mark, .slot-mark svg { transition: background-color 0.3s ease, border-color 0.3s ease, opacity 0.3s ease; }
}

/* ---- Today: extra practice ---- */
.relief { margin-bottom: 20px; }

.relief-note,
.relief-log {
  margin: 12px 8px 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: center;
}

.save-error {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: center;
}

/* ---- Progress: timeline ---- */
.card .card-note {
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.card .timeline-day {
  margin: 0;
  color: var(--ink);
  font: 600 1.25rem/1.3 var(--font-display);
}

.card .timeline-week { margin: 2px 0 0; }

.weeks {
  display: flex;
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.weeks li {
  flex: 1;
  padding: 4px 0;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 0.75rem;
  text-align: center;
}

.weeks li.is-past { background: var(--sage-tint); }

.weeks li.is-current {
  background: var(--sage-deep);
  color: var(--bg);
  font-weight: 600;
}

/* ---- Progress: check-in ---- */
.scale { margin-bottom: 22px; }

.scale-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.scale-head label { font-weight: 500; }

.scale-head output {
  min-width: 2ch;
  font: 600 1.4rem/1 var(--font-display);
  text-align: right;
}

.scale input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--sage-deep);
  touch-action: manipulation;
}

.scale.is-unset input[type="range"] { opacity: 0.55; }
.scale.is-unset output { color: var(--ink-soft); }

.scale-ends {
  display: flex;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.function-check {
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

.function-check legend {
  margin-bottom: 6px;
  padding: 0;
  font-weight: 500;
}

.optional { color: var(--ink-soft); font-weight: 400; }

.yn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.yn-question { font-size: 0.95rem; }

.yn-options { display: flex; flex: none; gap: 6px; }

.chip {
  appearance: none;
  min-width: 54px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font: 500 0.9rem/1 var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
}

.chip[aria-pressed="true"] {
  background: var(--sage-tint);
  border-color: var(--sage);
  color: var(--sage-deep);
  font-weight: 600;
}

.chip:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}

.card .checkin-status {
  min-height: 1.5em;
  margin: 10px 0 0;
  font-size: 0.85rem;
  text-align: center;
}

/* ---- Progress: trend chart ---- */
.trend-card h2 { margin-bottom: 12px; }

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.trend-legend li { display: flex; align-items: center; gap: 6px; }

.line-key {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 2px;
  border-radius: 1px;
}

.line-key.series-1 { background: var(--series-1); }
.line-key.series-2 { background: var(--series-2); }

.trend-plot {
  margin: 0 -4px;
  border-radius: 8px;
  touch-action: pan-y;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}

.trend-plot:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}

.trend-plot svg { display: block; overflow: visible; }

.trend-grid { stroke: var(--line); stroke-width: 1; }

.trend-axis,
.trend-end {
  fill: var(--ink-soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.trend-end { font-weight: 600; fill: var(--ink); }

.trend-crosshair { stroke: var(--ink-soft); stroke-width: 1; opacity: 0.6; }

.trend-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-line.series-1 { stroke: var(--series-1); }
.trend-line.series-2 { stroke: var(--series-2); }

/* Dots carry a 2px ring in the surface colour so they stay legible where lines cross. */
.trend-dot,
.trend-focus { stroke: var(--surface); stroke-width: 2; }

.trend-dot.series-1, .trend-focus.series-1 { fill: var(--series-1); }
.trend-dot.series-2, .trend-focus.series-2 { fill: var(--series-2); }

.card .trend-readout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  min-height: 1.6em;
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.readout-date { color: var(--ink); font-weight: 500; }

.readout-row { display: inline-flex; align-items: center; gap: 5px; }
.readout-row strong { color: var(--ink); }

.card .trend-note { margin: 12px 0 0; }

.trend-table { margin-top: 12px; }

.trend-table summary {
  padding: 12px 0;
  color: var(--sage-deep);
  font-size: 0.9rem;
  cursor: pointer;
}

.table-scroll { overflow-x: auto; margin-top: 6px; }

.trend-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.trend-table th,
.trend-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.trend-table thead th { color: var(--ink-soft); font-weight: 500; }
.trend-table tbody th { font-weight: 500; }
.trend-table .num { font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
.btn {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 14px 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: 500 1.05rem/1.2 var(--font-body);
  text-wrap: balance;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary {
  background: var(--sage-deep);
  border-color: var(--sage-deep);
  color: var(--bg);
}

.btn.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.stepper button:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 3px;
}

.icon-btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ---- Guided practice (full screen) ---- */
.practice {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-y: auto;
}

.practice::backdrop { background: var(--bg); }

.practice-inner {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 20px);
}

.practice-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.practice-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.practice-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
  text-align: center;
}

.movement {
  /* Shrinks on short screens (e.g. iPhone SE) so the session fits without scrolling. */
  width: min(78vw, 300px, 36dvh);
  height: auto;
}

.arc {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
}

.arc-rib { stroke: var(--sage-deep); }
.arc-belly { stroke: var(--sage); }

.cue {
  min-height: 2.6em;
  margin: 16px 0 4px;
  font: 500 1.5rem/1.3 var(--font-display);
}

.clock {
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

.is-paused .practice-stage { opacity: 0.5; }

@media (prefers-reduced-motion: no-preference) {
  .practice-stage { transition: opacity 0.4s ease; }
  .cue-in { animation: cue-in 0.6s ease; }
}

@media (max-height: 700px) {
  .practice-stage { padding: 4px 0; }
  .cue { margin-top: 8px; font-size: 1.35rem; }
  .stepper { margin-bottom: 14px; }
  .practice-reminder { margin-top: 12px; }
}

@keyframes cue-in {
  from { opacity: 0; }
}

.setup-label {
  margin: 0 0 8px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.stepper button {
  appearance: none;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.stepper button:disabled { opacity: 0.35; cursor: default; }

.stepper output {
  min-width: 5ch;
  text-align: center;
  font: 600 1.25rem/1 var(--font-display);
}

.practice-controls { display: grid; gap: 6px; }

.practice-done { text-align: center; }

.done-title {
  margin: 0 0 6px;
  font: 600 1.4rem/1.3 var(--font-display);
}

.done-note {
  margin: 0 0 20px;
  color: var(--ink-soft);
}

.practice-reminder {
  margin: 18px 0 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* ---- Bottom tab bar ---- */
.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  touch-action: manipulation;
}

.tab svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[aria-current="page"] { color: var(--sage-deep); }

.tab:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: -6px;
  border-radius: 10px;
}

@media (prefers-reduced-motion: no-preference) {
  .tab { transition: color 0.25s ease; }
}

/* ---- Guide ---- */
.card.guide p + p,
.card.guide p + ol,
.card.guide p + ul,
.card.guide ol + p,
.card.guide ul + p,
.card.guide dl + h3 { margin-top: 10px; }

.card.guide h3 {
  margin: 14px 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
}

.card.guide ol,
.card.guide ul {
  margin: 0;
  padding-left: 1.3em;
  color: var(--ink-soft);
}

.card.guide li + li { margin-top: 6px; }
.card.guide strong { color: var(--ink); font-weight: 600; }

.card .guide-cue {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--sage-tint);
  color: var(--ink);
  font: 500 1.05rem/1.4 var(--font-display);
}

.guide-weeks { margin: 10px 0 0; }
.guide-weeks dt { font-weight: 600; }
.guide-weeks dd { margin: 2px 0 10px; color: var(--ink-soft); }
.guide-weeks dd:last-child { margin-bottom: 0; }

/* Clear but not alarming: the same sage tint as the rest of the app, no warning colours. */
.card.guide-review {
  background: var(--sage-tint);
  border-color: var(--sage);
}

.guide-faq { margin-top: 24px; }
.guide-faq .section-title { margin-bottom: 12px; }
.guide-faq details { padding: 0; }

.guide-faq summary {
  padding: 14px 18px;
  font-weight: 500;
  cursor: pointer;
}

.guide-faq summary:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: -2px;
  border-radius: var(--radius);
}

.guide-faq details p { padding: 0 18px 16px; }

.guide-source {
  margin: 20px 0 8px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.guide-source a { color: var(--sage-deep); }

/* ---- Progress: backup ---- */
.backup-actions { display: grid; gap: 6px; }

.card .backup-status {
  margin: 10px 0 0;
  font-size: 0.85rem;
  text-align: center;
}

.card .backup-status:empty { display: none; }
