:root {
  /* Calm blue and gray palette (issue #17): soft enough for people who may be
     emotionally fragile, with text contrast at WCAG AA or better. */
  color-scheme: light dark;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --text: #1e2a36;
  --muted: #5b6876;
  --accent: #2a6496;
  --accent-text: #2a6496;
  --accent-soft: #e3eef8;
  --border: #d5dde5;
  --danger: #0f2a44;
  --danger-soft: #e3eef8;
  --user: #2a6496;
  --user-text: #ffffff;
  --bot: #ffffff;
  --warn: #fff4d6;
  --on-strong: #ffffff;
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --text: #1e2a36;
  --muted: #5b6876;
  --accent: #2a6496;
  --accent-text: #2a6496;
  --accent-soft: #e3eef8;
  --border: #d5dde5;
  --danger: #0f2a44;
  --danger-soft: #e3eef8;
  --user: #2a6496;
  --user-text: #ffffff;
  --bot: #ffffff;
  --warn: #fff4d6;
  --on-strong: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1520;
    --surface: #13212f;
    --text: #f1f5f9;
    --muted: #a3b3c2;
    --accent: #2f74b0;
    --accent-text: #8fbfe8;
    --accent-soft: #16304a;
    --border: #2a3a4b;
    --danger: #8fbfe8;
    --danger-soft: #16304a;
    --user: #2f74b0;
    --user-text: #ffffff;
    --bot: #13212f;
    --warn: #3a3420;
    --on-strong: #ffffff;
  }
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1520;
  --surface: #13212f;
  --text: #f1f5f9;
  --muted: #a3b3c2;
  --accent: #2f74b0;
  --accent-text: #8fbfe8;
  --accent-soft: #16304a;
  --border: #2a3a4b;
  --danger: #8fbfe8;
  --danger-soft: #16304a;
  --user: #2f74b0;
  --user-text: #ffffff;
  --bot: #13212f;
  --warn: #3a3420;
  --on-strong: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.top {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
@media (min-width: 641px) {
  .top {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
.top-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--accent-text); font-size: 20px; text-decoration: none; }
.brand-logo { width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0; display: block; }
a.brand:hover, a.brand:focus-visible { text-decoration: underline; }
.top-version { color: var(--muted); font-size: 11px; line-height: 1.2; }
.top-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--border); color: var(--accent-text);
  text-decoration: none; font-weight: 700; font-size: 17px; line-height: 1;
  background: var(--surface); flex-shrink: 0;
}
.top-help:hover, .top-help:focus-visible { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.help-back-link { color: var(--accent-text); font-size: 15px; font-weight: 600; text-decoration: none; }
.help-back-link:hover, .help-back-link:focus-visible { text-decoration: underline; }
.help-question { font-size: 18px; margin: 0 0 10px; color: var(--text); }
.help-answer { color: var(--text); font-size: 15px; line-height: 1.6; }
.help-answer p { margin: 8px 0; }
.help-answer p:first-child { margin-top: 0; }
.help-answer p:last-child { margin-bottom: 0; }
.help-answer a { color: var(--accent); text-decoration: underline; overflow-wrap: break-word; }
.help-answer a:hover, .help-answer a:focus-visible { color: var(--accent-text); }
.help-answer code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 5px;
  border-radius: 4px;
}
.help-answer .help-list { margin: 8px 0; padding-left: 20px; }
.help-answer .help-list li + li { margin-top: 6px; }
.help-answer blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
}
.help-answer h3, .help-answer h4 { margin: 12px 0 6px; font-size: 16px; color: var(--text); }
main { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }
h1 { font-size: 24px; margin: 4px 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin: 12px 0; }
.label { display: block; font-weight: 600; margin: 16px 0 6px; }
.label-checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.label-checkbox input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent); }
.card .label:first-child { margin-top: 0; }
.privacy-list { margin: 8px 0 0; padding-left: 20px; }
.privacy-list li + li { margin-top: 6px; }
.muted { color: var(--muted); font-size: 15px; }
input[type=text], input[type=password], input[type=email], textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
textarea {
  resize: vertical; min-height: 120px;
}
/* Dropdowns (Settings language, theme, exercise picker) match the text fields above; the arrow is drawn
   with two gradients so it uses the theme's muted color in light and dark mode. */
select {
  width: 100%; padding: 12px 40px 12px 12px; border: 1px solid var(--border); border-radius: 10px;
  background-color: var(--surface); cursor: pointer;
  -webkit-appearance: none; appearance: none; color-scheme: light dark;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 20px center, right 14px center;
  background-size: 6px 6px; background-repeat: no-repeat;
}
.link-inline {
  color: var(--accent-text); font-weight: 600; text-decoration: underline;
}
.link { background: none; border: 0; color: var(--accent-text); padding: 12px 0; font-weight: 600; cursor: pointer; display: block; }
.primary {
  display: block; width: 100%; margin-top: 20px; background: var(--accent); color: #fff; border: 0;
  border-radius: 12px; padding: 14px; font-weight: 700; min-height: 48px; cursor: pointer;
}
.primary { color: var(--on-strong); }
.danger-outline {
  display: block; width: 100%; margin-top: 12px; background: none; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 12px; padding: 12px; cursor: pointer;
}
.chip {
  flex: none; background: var(--accent-soft); color: var(--accent-text); border: 0; border-radius: 999px;
  padding: 8px 14px; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 40px;
}
.messages { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 12px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bot); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.note { align-self: center; background: var(--danger-soft); color: var(--text); font-size: 15px; text-align: center; }
.msg.typing { color: var(--muted); }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; margin: 0 auto;
  width: 100%; max-width: 640px; display: flex; background: var(--surface);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
@media (min-width: 641px) {
  .tabs {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
.tabs button { flex: 1; background: none; border: 0; padding: 14px 0; font-size: 14px; color: var(--muted); min-height: 56px; cursor: pointer; }
.tabs button.on { color: var(--accent-text); font-weight: 700; }
.crisis {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center;
}
.crisis-box {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.crisis-box h2 { margin: 0 0 4px; font-size: 22px; }
.crisis-box .link { width: 100%; text-align: center; }
#namePromptForm input { margin-top: 12px; }
.big {
  display: block; text-align: center; text-decoration: none; font-weight: 700; font-size: 18px;
  border-radius: 12px; padding: 14px; margin: 10px 0; min-height: 52px;
}
.help-number { text-align: center; font-size: 17px; margin: 6px 0 4px; }
.help-number b { font-size: 22px; letter-spacing: 1px; }
.big.call { background: var(--accent); color: var(--on-strong); }
.big.text { background: var(--accent-soft); color: var(--accent-text); }
.help-disabled { background: var(--accent-soft); color: var(--accent-text); border-radius: 12px; padding: 16px; margin: 16px 0; font-size: 16px; line-height: 1.5; text-align: center; }
.nextbar {
  /* Not sticky (issue #96): sits right after the last message and scrolls away with the chat. */
  padding: 8px 0 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.nextbar button { min-width: 160px; }
.nextbar .primary { margin-top: 0; }
.nextbar .link { font-size: 14px; padding: 4px 12px; margin: 0; font-weight: 500; }
.diff-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.diff-row button { min-width: auto; }
.diff-row select {
  width: auto; max-width: 240px; padding: 6px 28px 6px 10px; font-size: 14px;
  background-position: right 14px center, right 9px center;
}
.diff-label { font-size: 14px; font-weight: 500; cursor: pointer; }
.retry { align-self: center; }
.moodbar { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; }
.moodbar-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 600; font-size: 15px; margin-bottom: 8px; }
/* New chat: only the intensity question shows until they pick a number. */
.gate .messages, .gate .nextbar, .gate #newChatBtn { display: none; }
.yesno { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 320px; }
.yesno .wide { grid-column: 1 / -1; } /* a third choice gets its own full-width row */
.moodbar-head .muted { font-weight: 400; font-size: 13px; }
.mood-scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.mood-btn {
  min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font-weight: 700; cursor: pointer; padding: 0;
}
.mood-btn.on { background: var(--accent); color: var(--on-strong); border-color: var(--accent); }
.moodcheck { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; margin: 4px 0 8px; }
.summary { background: var(--accent-soft); color: var(--text); border-radius: 14px; padding: 14px 16px; margin: 4px 0 8px; text-align: center; }
.summary-title { font-weight: 700; font-size: 20px; color: var(--accent-text); }
.summary p { margin: 6px 0 0; line-height: 1.5; }
.moodcheck .moodbar-head { font-weight: 600; font-size: 15px; margin-bottom: 8px; }
/* Report page (public/report.html, issue #30) */
main.report { max-width: 960px; }
.report h2 { font-size: 20px; margin: 24px 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.tile-value { font-size: 22px; font-weight: 700; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.report table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 15px; }
.report th, .report td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.report th { font-weight: 600; color: var(--muted); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
}
pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.45;
}
pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
.db-instructions {
  margin-top: 32px;
}
.db-instructions h2 {
  font-size: 20px;
  margin: 0 0 10px;
}
.db-instructions h3 {
  font-size: 16px;
  margin: 20px 0 6px;
}
.db-instructions ul {
  margin: 8px 0 12px;
  padding-left: 20px;
}
.db-instructions li + li {
  margin-top: 4px;
}
/* Future ideas page (public/future.html) */
.future h2 { margin-top: 0; }
.future h3 { font-size: 16px; margin: 12px 0 4px; }
.future ul { margin: 0; padding-left: 20px; }
.future li + li { margin-top: 4px; }
h1.brand { margin: 0; }
/* Landing page (public/index.html, issue #77). The app itself is at /app/. */
.landing h2 { font-size: 20px; margin: 0 0 8px; }
.landing .landing-ask { font-size: 24px; font-weight: 700; text-align: center; margin: 0 0 12px; }
.landing .lead { font-size: 15px; font-weight: 400; color: var(--muted); text-align: center; margin: 8px 0 16px; display: block; }
.landing a.primary { text-align: center; text-decoration: none; margin: 12px 0 8px; }
.landing figure { margin: 12px 0 0; }
.landing img { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; }
.landing figcaption { font-size: 14px; margin-top: 6px; }
.landing .landing-logo { margin: 8px 0 16px; }
.landing .landing-logo a { display: block; width: 240px; margin: 0 auto; }
.landing .landing-logo img { width: 240px; margin: 0 auto; border: 0; border-radius: 24px; }
