:root {
  --bg: #faf6f3;
  --surface: #ffffff;
  --border: #ece2dc;
  --text: #2e2422;
  --muted: #8a7a74;
  --accent: #a15c4a;
  --accent-dark: #7c4436;
  --accent-soft: #f3e3dd;
  --success: #5c8a6e;
  --warn: #c47a3d;
  --danger: #b3453f;
  --radius: 14px;
  --nav-height: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1614;
    --surface: #262019;
    --border: #3a2f2a;
    --text: #f2e9e4;
    --muted: #a99a92;
    --accent: #e08a6d;
    --accent-dark: #f0a488;
    --accent-soft: #3a2a24;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  padding: env(safe-area-inset-top, 0) 16px calc(var(--nav-height) + 24px + env(safe-area-inset-bottom, 0));
  max-width: 560px;
  margin: 0 auto;
}

h1 { font-size: 1.5rem; margin: 20px 0 4px; }
h2.section-title { font-size: 1.05rem; margin: 24px 0 10px; color: var(--accent-dark); }
h3 { font-size: 1rem; margin: 0 0 2px; }
p { line-height: 1.5; }
.muted { color: var(--muted); font-weight: 400; font-size: 0.85em; }

a { color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 600; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select, textarea {
  font: inherit;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-soft); color: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn:disabled { opacity: 0.5; }

.callout {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 14px 0;
}
.callout-warn { background: #fff2df; color: #6b4a1c; }
@media (prefers-color-scheme: dark) { .callout-warn { background: #3a2f18; color: #f0d9a8; } }

/* ---- Today page ---- */
.today-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.flare-toggle, .complete-toggle {
  display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.progress-bar {
  height: 10px; border-radius: 6px; background: var(--border); overflow: hidden; margin-top: 14px;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.progress-label { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }

.bodyweight-prompt { margin: 16px 0; }
.bodyweight-prompt label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 600; }

.movement-list { display: flex; flex-direction: column; gap: 12px; }
.movement-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.movement-card.is-complete { border-color: var(--success); }
.movement-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.scheme { display: block; margin-top: 2px; }
.badge { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; margin-top: 6px; }
.badge-warn { background: #fff2df; color: #a05a1c; }
@media (prefers-color-scheme: dark) { .badge-warn { background: #3a2f18; color: #f0b168; } }

.set-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.set-row { display: grid; grid-template-columns: 1fr 64px 64px; gap: 8px; align-items: center; }
.set-row .set-input-wide { grid-column: span 2; }
.set-label { font-size: 0.8rem; color: var(--muted); }
.set-input { padding: 8px 10px; font-size: 0.9rem; }

/* ---- Program page ---- */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.week-day {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 4px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.week-day.is-today { border-color: var(--accent); border-width: 2px; }
.week-day-name { font-size: 0.7rem; font-weight: 700; color: var(--muted); }
.week-day-type { font-size: 0.62rem; color: var(--muted); min-height: 26px; }
.week-day-dash { color: var(--muted); font-size: 0.9rem; }
.ring {
  --pct: 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--border) 0);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.55rem; font-weight: 700;
}
.ring span { background: var(--surface); width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: grid; grid-template-columns: 60px 1fr 50px; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 0.85rem;
}
.history-pct { font-weight: 700; color: var(--accent-dark); text-align: right; }

/* ---- Progress page ---- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.chart { width: 100%; height: auto; display: block; }
.chart-line { stroke: var(--accent); stroke-width: 2.5; }
.chart-dot { fill: var(--accent); }
.chart-goal-line { stroke: var(--success); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-goal-label { fill: var(--success); font-size: 9px; }
.chart-bar { fill: var(--accent); }
.chart-bar-label { fill: var(--muted); font-size: 9px; }

/* ---- Healing page ---- */
.search-input { margin-top: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip {
  font-size: 0.75rem; font-weight: 600; padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.chip.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.healing-list { display: flex; flex-direction: column; gap: 8px; }
.healing-entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.healing-entry summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-weight: 600; gap: 10px; }
.healing-entry summary::-webkit-details-marker { display: none; }
.healing-entry p { margin: 10px 0 0; font-size: 0.9rem; }
.healing-title { flex: 1; }

/* ---- Coach page ---- */
.coach { display: flex; flex-direction: column; height: calc(100vh - var(--nav-height) - 24px); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px 0; }
.chat-bubble { max-width: 82%; padding: 10px 14px; border-radius: 16px; font-size: 0.92rem; line-height: 1.4; }
.chat-bubble-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble-assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-bubble-error { border-color: var(--danger); color: var(--danger); }
.chat-input-row { display: flex; gap: 8px; padding-top: 10px; }
.chat-input-row input { flex: 1; }

/* ---- Bottom nav ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}
.bottom-nav.hidden { display: none; }
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-decoration: none; color: var(--muted); gap: 2px; font-size: 0.65rem; font-weight: 600;
}
.nav-item.is-active { color: var(--accent); }
.nav-icon { font-size: 1.1rem; }

.onboarding { padding-top: 12px; }
