/* Woe — a quiet place to think.
   Calm, low-contrast surfaces; one accent colour used sparingly so that the
   things that matter (your words, the breathing circle) carry the emphasis. */

/* ---------------------------------------------------------------- */
/* Tokens                                                            */
/* ---------------------------------------------------------------- */

:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #eceee8;
  --line: #dde0d8;
  --text: #232824;
  --muted: #6b7269;
  --accent: #3f7a5f;
  --accent-soft: #e3efe7;
  --accent-text: #2c5a45;
  --user-bg: #3f7a5f;
  --user-text: #ffffff;
  --crisis: #a4443c;
  --crisis-soft: #fbeceb;
  --shadow: 0 1px 2px rgba(20, 30, 24, .06), 0 8px 24px rgba(20, 30, 24, .05);
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* Dark by OS preference, unless the user explicitly chose light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181a;
    --surface: #1d2225;
    --surface-2: #262c30;
    --line: #333a3e;
    --text: #e4e8e4;
    --muted: #99a29c;
    --accent: #78b295;
    --accent-soft: #23342c;
    --accent-text: #9ccdb3;
    --user-bg: #2f6650;
    --user-text: #f2f7f4;
    --crisis: #e08d85;
    --crisis-soft: #2f2220;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

/* Explicit toggle wins in both directions. */
:root[data-theme="dark"] {
  --bg: #14181a;
  --surface: #1d2225;
  --surface-2: #262c30;
  --line: #333a3e;
  --text: #e4e8e4;
  --muted: #99a29c;
  --accent: #78b295;
  --accent-soft: #23342c;
  --accent-text: #9ccdb3;
  --user-bg: #2f6650;
  --user-text: #f2f7f4;
  --crisis: #e08d85;
  --crisis-soft: #2f2220;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

/* Several components below set `display`, which would otherwise beat the
   `hidden` attribute and leave an invisible overlay swallowing every click. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* Top bar                                                           */
/* ---------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand .mark { font-size: 20px; }

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
}

.tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.tool {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  padding: 6px 10px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.tool:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tool-crisis { color: var(--crisis); }
.tool-crisis:hover { background: var(--crisis-soft); color: var(--crisis); }

.tool-icon { padding: 6px 9px; font-size: 15px; }
.tool-icon .moon { display: none; }

:root[data-theme="dark"] .tool-icon .sun { display: none; }
:root[data-theme="dark"] .tool-icon .moon { display: inline; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tool-icon .sun { display: none; }
  :root:not([data-theme="light"]) .tool-icon .moon { display: inline; }
}

/* ---------------------------------------------------------------- */
/* Banner                                                            */
/* ---------------------------------------------------------------- */

.banner {
  margin: 0;
  padding: 10px 16px;
  background: var(--crisis-soft);
  color: var(--crisis);
  font-size: 14px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

/* ---------------------------------------------------------------- */
/* Chat                                                              */
/* ---------------------------------------------------------------- */

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scrollbar-width: thin;
}

.row {
  display: flex;
  animation: rise .28s cubic-bezier(.22, 1, .36, 1);
}

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }
.row.wide > * { width: 100%; }

@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

.bubble {
  max-width: 82%;
  padding: 10px 15px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.row.bot .bubble { border-bottom-left-radius: 6px; }

.row.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-color: transparent;
  border-bottom-right-radius: 6px;
}

/* Typing indicator */
.bubble.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 16px;
}

.bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: .45;
  animation: blink 1.3s infinite;
}

.bubble.typing span:nth-child(2) { animation-delay: .18s; }
.bubble.typing span:nth-child(3) { animation-delay: .36s; }

@keyframes blink {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30% { opacity: .9; transform: translateY(-3px); }
}

/* ---------------------------------------------------------------- */
/* Option pills                                                      */
/* ---------------------------------------------------------------- */

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
  padding: 3px 0 5px;
  animation: rise .28s cubic-bezier(.22, 1, .36, 1);
}

.pill {
  appearance: none;
  font: inherit;
  font-size: 14.5px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--accent);
  background: var(--surface);
  color: var(--accent-text);
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.pill:hover:not(:disabled) { background: var(--accent-soft); }
.pill:active:not(:disabled) { transform: scale(.97); }

.pill:disabled {
  opacity: .4;
  cursor: default;
}

.pill:focus-visible,
.tool:focus-visible,
.send:focus-visible,
.sheet-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pill-crisis {
  border-color: var(--crisis);
  color: var(--crisis);
  text-decoration: none;
  display: inline-block;
}

.pill-crisis:hover { background: var(--crisis-soft); }

/* ---------------------------------------------------------------- */
/* Composer                                                          */
/* ---------------------------------------------------------------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 11px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 96px;
  max-height: 200px;
  line-height: 1.5;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.send {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.send svg { width: 19px; height: 19px; fill: currentColor; }
.send:hover { filter: brightness(1.08); }

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

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

.card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 650;
}

.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); font-size: 14.5px; }

.quoted, .evidence p {
  font-style: italic;
  color: var(--accent-text);
}

.card.polished {
  background: var(--accent-soft);
  border-color: transparent;
}

/* Evidence quote from the user's own thought */
.evidence {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 11px 15px;
}

.evidence-label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--accent-text);
  opacity: .8;
  margin-bottom: 3px;
}

.evidence p { margin: 0; }

.evidence-why {
  font-style: normal !important;
  color: var(--muted) !important;
  font-size: 14px;
  margin-top: 6px !important;
}

.questions {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Crisis card */
.card.crisis {
  background: var(--crisis-soft);
  border-color: var(--crisis);
}

.card.crisis .card-lead { font-weight: 600; }

.resources {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.resources li {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.resources span { font-size: 14.5px; color: var(--muted); }
.resources .pill { margin-top: 4px; }

/* ---------------------------------------------------------------- */
/* Before / after                                                    */
/* ---------------------------------------------------------------- */

.compare {
  display: grid;
  gap: 9px;
  grid-template-columns: 1fr;
}

@media (min-width: 560px) {
  .compare { grid-template-columns: 1fr 1fr; }
}

.compare-side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 15px;
  box-shadow: var(--shadow);
}

.compare-side p { margin: 0; overflow-wrap: anywhere; }

.compare-label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 5px;
}

.compare-side.after {
  background: var(--accent-soft);
  border-color: transparent;
}

.compare-side.after .compare-label { color: var(--accent-text); }

/* ---------------------------------------------------------------- */
/* Breathing exercise                                                */
/* ---------------------------------------------------------------- */

.breath-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 16px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.breath-stage {
  height: 190px;
  display: grid;
  place-items: center;
}

.breath-circle {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, var(--accent-soft), var(--accent));
  color: #fff;
  font-size: 27px;
  font-variant-numeric: tabular-nums;
  font-weight: 300;
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 12%, transparent);
  will-change: transform;
}

.breath-phase {
  margin: 6px 0 2px;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -.01em;
}

.breath-meta {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--muted);
  min-height: 1.2em;
}

/* Without motion, the circle holds still and the count carries the pacing. */
.breath-card.reduced .breath-circle { transition: none !important; transform: none !important; }

/* ---------------------------------------------------------------- */
/* Sheet (reference / history / crisis)                              */
/* ---------------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 15, .42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fade .18s ease;
}

@media (min-width: 620px) {
  .sheet { align-items: center; }
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  background: var(--bg);
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: slide .26s cubic-bezier(.22, 1, .36, 1);
}

@media (min-width: 620px) {
  .sheet-panel { border-radius: 18px; max-height: 82vh; }
}

@keyframes slide { from { transform: translateY(18px); } to { transform: none; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 { margin: 0; font-size: 16.5px; font-weight: 650; }

.sheet-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.sheet-close:hover { background: var(--surface-2); color: var(--text); }

.sheet-body {
  overflow-y: auto;
  padding: 16px 18px max(20px, env(safe-area-inset-bottom));
}

/* Reference list */
.ref-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 11px 14px;
  margin-bottom: 8px;
}

.ref-item summary {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ref-item summary::marker { color: var(--accent); }
.ref-item p { margin: 9px 0 0; font-size: 14.5px; }
.ref-short { color: var(--muted); font-size: 14px; }
.ref-cue { color: var(--accent-text) !important; font-size: 13.5px !important; }
.ref-family {
  color: var(--muted);
  font-size: 12.5px !important;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 8px !important;
}

/* History */
.history h3 {
  margin: 18px 0 9px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
}

.history h3:first-child { margin-top: 0; }

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

.record-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}

.record-date { font-size: 12.5px; color: var(--muted); }

.record-del {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.record-del:hover { color: var(--crisis); background: var(--crisis-soft); }

.record-before {
  margin: 0 0 7px;
  padding-left: 10px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-size: 14.5px;
}

.record-after {
  margin: 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  font-size: 14.5px;
}

.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }

.tag {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Mood chart */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.mood-chart { width: 100%; height: auto; display: block; }
.mood-chart .grid { stroke: var(--line); stroke-width: 1; }
.mood-chart .axis { fill: var(--muted); font-size: 9px; font-family: var(--font); }
.mood-chart .mood-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mood-chart .mood-dot { fill: var(--accent); }
.chart-wrap .muted { margin: 8px 0 0; font-size: 13px; }

/* ---------------------------------------------------------------- */
/* Auth screen                                                       */
/* ---------------------------------------------------------------- */

.auth {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-panel {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 26px;
}

.auth-brand { font-size: 30px; text-align: center; margin-bottom: 4px; }

.auth-panel h2 {
  margin: 0 0 4px;
  font-size: 19px;
  text-align: center;
}

.auth-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.auth-label {
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 4px;
}

.auth-input {
  font: inherit;
  padding: 10px 13px;
  width: 100%;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  margin: 10px 0 0;
  color: var(--crisis);
  font-size: 13.5px;
}

.auth-submit { margin-top: 16px; }

/* ---------------------------------------------------------------- */
/* Account sheet                                                     */
/* ---------------------------------------------------------------- */

.account h3 { margin: 18px 0 8px; font-size: 15px; }
.account .muted { font-size: 13.5px; }

.account-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 4px;
}

.account-form input[type="text"],
.account-form input[type="password"] {
  font: inherit;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

.account-form input:focus { outline: none; border-color: var(--accent); }

.account-form .checkline {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  color: var(--muted);
}

.account-form .pill { align-self: flex-start; margin-top: 4px; }

.account-note { font-size: 13px; margin: 6px 0 0; }
.account-note.err { color: var(--crisis); }
.account-note.okay { color: var(--accent-text); }

.user-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.user-row:last-child { border-bottom: none; }

.user-name { font-weight: 600; }

.user-badge {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.user-cost { color: var(--muted); font-size: 12.5px; margin-left: auto; }

.user-row .mini {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.user-row .mini:hover { background: var(--surface-2); color: var(--text); }
.user-row .mini.danger { color: var(--crisis); border-color: var(--crisis); }
.user-row .mini.danger:hover { background: var(--crisis-soft); }

.usage-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
  padding: 4px 0;
}

.usage-line .muted { font-size: inherit; }

/* ---------------------------------------------------------------- */
/* Motion preferences                                                */
/* ---------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
