/* ============================================================
   Hearth, calm, warm, unhurried. DARK MODE first.
   A warm low-light room: deep browns, candle gold, sage & clay.
   ============================================================ */
:root {
  color-scheme: dark;

  /* World / canvas, a warm low-light room at the edge of a moonlit garden. */
  --bg:        #1a1713;  /* app canvas                          */
  --bg-2:      #131009;  /* deeper well: tab track, segmented   */
  --bg-3:      #0d0b07;  /* deepest: map mat, behind-glass void */

  /* Surfaces (L1), each step up = closer to the light. */
  --surface-1: #211c15;
  --surface-2: #28221a;
  --surface-3: #312a20;
  --card:      var(--surface-1);  /* back-compat alias */
  --card-2:    var(--surface-2);  /* back-compat alias */
  --input:     #1d1811;

  /* Ink, warm, never pure white. */
  --ink:       #ece2d2;
  --ink-soft:  #b6ab97;
  --ink-faint: #8c8473;
  --ink-on-accent: #16140f;

  /* Lines & hairlines */
  --line:       #39322a;
  --line-soft:  #2c2620;
  --hair:       rgba(236, 226, 210, 0.14);
  --hair-strong: rgba(236, 226, 210, 0.22);

  /* Garden hues (parts + actions) */
  --sage: #93b187; --sage-deep: #76996a;
  --clay: #d39a78; --clay-deep: #c2825f;
  --self: #e9b65c;       /* the calm candle-gold core */
  --violet: #b3a4e6; --violet-deep: #9a8cc4;
  --manager: var(--sage);
  --firefighter: var(--clay);
  --exile: var(--violet);
  --other: #8a8170;
  --danger: #ea8b80; --danger-deep: #d6695d;

  /* On-glass vibrant tints (colored light, not paint). */
  --tint-sage:   rgba(147, 177, 135, 0.14);
  --tint-clay:   rgba(211, 154, 120, 0.14);
  --tint-violet: rgba(179, 164, 230, 0.16);
  --tint-gold:   rgba(233, 182, 92, 0.14);
  --tint-danger: rgba(234, 139, 128, 0.14);

  /* Gold ramp (the sacred + the gilded frame). */
  --gold: #caa24a; --gold-bright: #e6bf64; --gold-deep: #9c7c34;
  --gold-soft: rgba(202, 162, 74, 0.14);
  --gold-line: rgba(202, 162, 74, 0.30);
  --gold-glow: rgba(233, 182, 92, 0.45);

  /* World scene palette (the painting; identical in both themes). */
  --map-ground-1: #2c3d1d; --map-ground-2: #0f1a0c; --map-ground-3: #0d180c;
  --map-frame: #caa24a; --map-rim: #e6bf64;
  --map-scrim: rgba(7, 12, 7, 0.42);   /* dims the painted scenery so the parts read clearly */
  --map-trail: rgba(202, 162, 74, 0.42);
  --map-grid: rgba(150, 190, 120, 0.10);
  --map-foliage: #3f5e2c;
  --scene-sky-hi: #7c895f; --scene-sky-lo: #0d180c;
  --scene-water: #35565a; --scene-water-hi: #5b8086;
  --scene-sun: #fff0c2; --scene-firefly: #fbe6a8;
  --scene-leaf-1: #2c441e; --scene-leaf-2: #436a30; --scene-leaf-3: #54863c;
  --scene-stone: #8d8474; --scene-stone-hi: #cabfa6; --scene-stone-lo: #46402f;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.30), 0 2px 8px rgba(0,0,0,0.28);
  --shadow-2: 0 6px 18px rgba(0,0,0,0.32);
  --shadow-3: 0 16px 40px rgba(0,0,0,0.45);
  --shadow-4: 0 28px 70px rgba(0,0,0,0.55);
  --shadow-soft: var(--shadow-2);  /* back-compat */
  --shadow:      var(--shadow-3);  /* back-compat */
  --sheen-top:   inset 0 1px 0 rgba(255,240,210,0.06);
  --sheen-gold:  inset 0 2px 0 var(--gold-line);
  --inner-glow:  inset 0 0 40px rgba(233,182,92,0.04);
  --ring-focus:  var(--sage);

  /* Glass / materials */
  --glass-1: rgba(33, 28, 21, 0.72);
  --glass-2: rgba(36, 31, 23, 0.82);
  --glass-3: rgba(28, 24, 18, 0.78);
  --glass-blur: 16px; --glass-blur-sm: 10px; --glass-sat: 140%;

  /* Radii */
  --radius-xs: 8px; --radius-sm: 12px; --radius: 18px; --radius-lg: 24px; --radius-pill: 999px;

  /* Type & families */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Georgia", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --t-display: clamp(28px, 4.5vw, 34px);
  --t-title: 22px; --t-card: 18px; --t-body: 15px;
  --t-callout: 14px; --t-caption: 13px; --t-micro: 11px;
  --lh-tight: 1.2; --lh-snug: 1.35; --lh-body: 1.55;
  --ls-tight: 0; --ls-wide: 0.04em;

  /* Spacing scale (4pt grid) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 40px; --s-9: 56px;

  /* Texture */
  --grain-opacity: 0.04;

  /* Motion */
  --ease-spring: cubic-bezier(.2,.8,.2,1);
  --ease-out: cubic-bezier(.22,.61,.36,1);
  --dur-1: .12s; --dur-2: .2s; --dur-3: .32s; --dur-4: .5s;
}

* { box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(620px 380px at 96% -16%, rgba(202,162,74,0.06) 0%, transparent 72%),
    radial-gradient(1000px 760px at 12% 116%, rgba(147,177,135,0.05) 0%, transparent 64%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--sage); }

/* ---------- Buttons ---------- */
.btn-primary {
  background: linear-gradient(180deg, var(--sage) 0%, var(--sage-deep) 100%);
  color: #16140f; border: none; border-radius: 999px;
  padding: 12px 22px; font-size: 15px; font-weight: 700;
  box-shadow: var(--shadow-1), var(--sheen-top); transition: transform .12s ease, filter .12s ease;
  touch-action: manipulation;
}
.btn-primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary.wide { width: 100%; }
.btn-soft {
  background: var(--card-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 600; touch-action: manipulation;
  box-shadow: var(--shadow-1), var(--sheen-top);
}
.btn-soft:hover { border-color: var(--sage); color: var(--sage); }
.btn-ghost {
  background: transparent; border: none; color: var(--ink-soft);
  padding: 10px 14px; border-radius: 999px; font-size: 14px; touch-action: manipulation;
}
.btn-ghost:hover { background: rgba(255,255,255,.05); color: var(--ink); }
#partDelete, #noteDelete { color: var(--danger); }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--glass-3);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
/* Instant first-paint splash. Covers the boot gap so no wrong screen flashes,
   then fades out smoothly the moment the real screen is ready. */
.splash {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  background: var(--bg-2, #131009); transition: opacity .4s ease;
}
.splash svg { animation: splashPulse 1.6s ease-in-out infinite; }
.splash.faded { opacity: 0; pointer-events: none; }
@keyframes splashPulse { 0%, 100% { opacity: .55; transform: scale(.96); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .splash svg { animation: none; } }
.modal {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); max-width: 520px; width: 100%;
  padding: 26px; max-height: 88vh; overflow: auto; border: 1px solid var(--line);
  animation: modalIn .18s cubic-bezier(.2,.8,.2,1);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { font-family: var(--serif); font-size: 22px; margin: 0 0 14px; font-weight: 600; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
/* Settings accordion */
details.settings-group { border-bottom: 1px solid var(--line); }
details.settings-group summary { list-style: none; }
details.settings-group summary::-webkit-details-marker { display: none; }
.settings-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; cursor: pointer; user-select: none;
  font-size: 14px; font-weight: 600; color: var(--ink);
}
.settings-chev { font-size: 18px; color: var(--ink-soft); transition: transform .2s; line-height: 1; }
details.settings-group[open] .settings-chev { transform: rotate(90deg); }
.settings-group-body { padding-bottom: 10px; }

.settings-misc-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.btn-ghost.small { font-size: 12px; padding: 5px 10px; }
.profile-block { padding: 12px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.profile-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.profile-email { font-size: 12px; color: var(--ink-soft); }
.profile-row { display: flex; align-items: center; gap: 10px; }
.profile-plan-badge { font-size: 11px; font-weight: 600; color: var(--gold); background: rgba(202,162,74,0.1); border: 1px solid rgba(202,162,74,0.22); border-radius: 999px; padding: 2px 9px; }
.btn-soft.small { font-size: 12px; padding: 4px 12px; }
.spacer { flex: 1; }

/* ---------- Onboarding ---------- */
.onboard-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border-radius: 24px; box-shadow: var(--shadow); border: 1px solid var(--line);
  max-width: 520px; width: 100%; padding: 36px 30px; text-align: center;
  max-height: 94vh; overflow: auto;
}
.brandmark { display: flex; justify-content: center; margin-bottom: 10px; filter: drop-shadow(0 0 18px rgba(233,182,92,0.35)); }
.onboard-title { font-family: var(--serif); font-size: 30px; margin: 6px 0 6px; font-weight: 600; }
.onboard-sub { color: var(--ink-soft); margin: 0 0 22px; font-size: 16px; line-height: 1.55; }
.onboard-step { transition: opacity .18s ease; }
.onboard-step.fading { opacity: 0; }
.onboard-quiet { color: var(--ink-soft); font-size: 13px; margin: 16px 0 0; font-style: italic; }
.onb-back { display: block; width: 100%; margin-top: 6px; color: var(--ink-faint); }
.name-field { text-align: left; margin: 4px 0 16px; }
.name-field span { font-size: 14px; color: var(--ink-soft); margin-bottom: 2px; }

.warm-facts { list-style: none; padding: 0; margin: 6px 0 18px; text-align: left; display: flex; flex-direction: column; gap: 14px; }
.warm-facts li { display: flex; gap: 13px; font-size: 14.5px; color: var(--ink-soft); line-height: 1.55; }
.warm-facts .ico { flex-shrink: 0; display: flex; align-items: flex-start; padding-top: 1px; }
.warm-facts em { color: var(--ink); font-style: normal; font-weight: 600; }

.check {
  display: flex; align-items: flex-start; gap: 11px; text-align: left;
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; margin: 10px 0; font-size: 14.5px; cursor: pointer; color: var(--ink);
}
.check.soft { background: rgba(147,177,135,0.08); border-color: rgba(147,177,135,0.25); }
.check input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--sage); flex-shrink: 0; }
.fineprint { font-size: 12px; color: var(--ink-soft); margin: 16px 0 0; }

.guide-choice { display: flex; gap: 14px; margin: 18px 0 10px; }
.guide-card { flex: 1; background: var(--card-2); border: 2px solid var(--line); border-radius: var(--radius); padding: 28px 12px; cursor: pointer; color: var(--ink); transition: border-color .18s, transform .14s, background .18s; text-align: center; touch-action: manipulation; }
.guide-card:hover { border-color: var(--sage); transform: translateY(-2px); }
.guide-card.selected { border-color: var(--sage); background: rgba(147,177,135,0.08); transform: translateY(-2px); }
.guide-card-name { display: block; font-size: 20px; font-weight: 700; letter-spacing: 0; }

.tour-card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border-radius: 24px; border-top: 2px solid var(--gold-line);
  box-shadow: var(--shadow-4), var(--sheen-gold), var(--inner-glow);
  max-width: 400px; width: 100%; padding: 32px 28px 26px;
  text-align: center; animation: rise .24s cubic-bezier(.2,.8,.2,1);
}
.tour-ico { color: var(--self); margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; }
.tour-label { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); min-height: 18px; margin-bottom: 4px; }
.tour-title { font-family: var(--serif); font-size: 26px; font-weight: 600; margin: 0 0 10px; }
.tour-body { color: var(--ink-soft); font-size: 15px; line-height: 1.6; margin: 0; }
.tour-dots { display: flex; gap: 7px; justify-content: center; margin: 20px 0 22px; }
.tour-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background .2s; }
.tour-dot.active { background: var(--sage); }
.tour-actions { display: flex; justify-content: space-between; align-items: center; }
.tour-nav { display: flex; gap: 8px; align-items: center; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; height: var(--app-height, 100dvh); max-width: 760px; margin: 0 auto; overflow: hidden; }
/* Talk view: chatScroll handles all scroll internally; document must not scroll */
#view-talk.active { overflow: hidden; }
/* Other views: their content may exceed viewport so let them scroll */
#view-parts.active, #view-map.active, #view-journal.active, #view-intentions.active, #view-learn.active { overflow-y: auto; }
/* The brand + tabs stay anchored at the top while the content below scrolls. */
.app-head {
  position: sticky; top: 0; z-index: 12;
  background: color-mix(in srgb, var(--bg) 68%, transparent);
  -webkit-backdrop-filter: blur(22px) saturate(1.18);
  backdrop-filter: blur(22px) saturate(1.18);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
}
/* ---------- New topbar ---------- */
.topbar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; height: calc(52px + env(safe-area-inset-top, 0px)); padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
.topbar-spacer { flex: 1; }
.topbar-icon-btn {
  width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--ink-soft); cursor: pointer; transition: background .12s, color .12s;
}
.topbar-icon-btn:hover { background: var(--card); color: var(--ink); }
.topbar-mode-wrap { position: relative; }
.topbar-mode-btn {
  display: flex; align-items: center; gap: 5px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 13px;
  font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.topbar-mode-btn.renegade-active {
  background: rgba(220,60,60,0.1); border-color: rgba(220,60,60,0.4); color: rgb(200,50,50);
}
.mode-dropdown {
  position: absolute; top: calc(100% + 7px); left: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; min-width: 150px;
  box-shadow: var(--shadow-3); z-index: 210; overflow: hidden;
}
.mode-option {
  display: block; width: 100%; padding: 11px 16px;
  text-align: left; font-size: 14px; color: var(--ink);
  background: none; border: none; cursor: pointer; touch-action: manipulation;
  transition: background .1s;
}
.mode-option:hover { background: var(--tint-gold); }
.mode-option.active { color: var(--self); font-weight: 600; }
.mode-option + .mode-option { border-top: 1px solid var(--line); }

/* Topbar mode wrap: hidden by default; JS shows it only in the Talk view */
.topbar-mode-wrap { display: none; }

/* Upgrade CTA pill in topbar (desktop only, shown for free users) */
.topbar-upgrade-btn {
  background: transparent; border: 1px solid rgba(233,182,92,0.45); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 700; color: var(--self);
  cursor: pointer; white-space: nowrap; transition: background .15s;
}
.topbar-upgrade-btn:hover { background: rgba(233,182,92,0.08); }
@media (max-width: 520px) { .topbar-upgrade-btn { display: none; } }

/* Checkbox row (used in part modal for map toggle) */
.check-row {
  display: flex; align-items: center; gap: 9px; font-size: 14px;
  color: var(--ink-soft); margin-bottom: 13px; cursor: pointer;
}
.check-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--sage); flex-shrink: 0; }

/* ---------- History drawer (slides from left) ---------- */
.history-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.42);
  z-index: 290; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.history-overlay.open { opacity: 1; pointer-events: auto; }
.history-drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 300px; max-width: 85vw;
  background: var(--card); border-right: 1px solid var(--line);
  box-shadow: var(--shadow-4); z-index: 300;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(0.32,0.72,0,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.history-drawer.open { transform: translateX(0); }
.history-drawer-head {
  display: flex; align-items: center; padding: 16px 8px 14px 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.history-drawer-title { flex: 1; font-family: var(--serif); font-size: 1.05rem; font-weight: 600; color: var(--ink); }
.history-drawer .history-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.history-drawer .empty-hint { padding: 16px; text-align: center; }
.h-edit {
  background: transparent; border: none; color: var(--ink-soft); cursor: pointer;
  padding: 8px; border-radius: 8px; flex: 0 0 auto; display: flex; align-items: center;
  min-width: 44px; min-height: 44px; justify-content: center;
  touch-action: manipulation;
}
.h-edit:hover { color: var(--self); background: var(--tint-gold); }
.h-rename-inp {
  width: 100%; background: var(--input); border: 1px solid var(--self);
  border-radius: 6px; padding: 2px 6px; font-size: 15px; color: var(--ink);
  font-family: var(--serif); outline: none;
}

/* ---------- Nav drawer (bottom sheet) ---------- */
.nav-drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 199; opacity: 0; pointer-events: none; transition: opacity .22s;
}
.nav-drawer-overlay.open { opacity: 1; pointer-events: auto; }
.nav-drawer {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: color-mix(in srgb, var(--card) 85%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
  z-index: 200; padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  visibility: hidden;
}
.nav-drawer.open { transform: translateY(0); visibility: visible; }
.nav-drawer-handle {
  width: 36px; height: 4px; background: var(--line); border-radius: 999px;
  margin: 0 auto 14px;
}
.nav-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 15px 8px 11px; font-size: 12px; font-weight: 600;
  color: var(--ink-soft); cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.tab:active { background: var(--card-2); color: var(--ink); border-color: var(--ink-soft); }
.tab.active { color: var(--self); border-color: rgba(233,182,92,0.5); background: rgba(233,182,92,0.09); }
.nav-utilities {
  display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px;
}
.nav-util-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 500; color: var(--ink-soft);
  cursor: pointer; touch-action: manipulation; transition: background .12s, color .12s;
}
.nav-util-btn:hover { background: var(--card-2); color: var(--ink); }
.nav-util-danger { color: var(--danger); border-color: rgba(234,139,128,0.35); }
.nav-util-danger:hover { background: rgba(234,139,128,0.08); }
.nav-util-upgrade { color: var(--self); border-color: rgba(233,182,92,0.4); font-weight: 700; }
.nav-util-upgrade:hover { background: rgba(233,182,92,0.08); }

/* ---------- Stage / views ---------- */
.stage { flex: 1; padding: 8px 16px 0; padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px)); display: flex; min-height: 0; overflow: hidden; }
.view { display: none; flex: 1; flex-direction: column; animation: fade .2s ease; min-height: 0; }
.view.active { display: flex; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.view-head h2 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 600; }

/* ---------- Chat ---------- */
.chat-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }
.scroll-latest {
  position: absolute; right: 14px; bottom: 118px; z-index: 6;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--hair);
  background: var(--glass-2); -webkit-backdrop-filter: blur(10px) saturate(140%); backdrop-filter: blur(10px) saturate(140%);
  color: var(--ink); font-size: 18px; line-height: 1;
  box-shadow: var(--shadow-2), var(--sheen-top); cursor: pointer; touch-action: manipulation;
  opacity: 0; pointer-events: none; transform: translateY(6px);
  transition: opacity .2s ease, transform .2s ease, border-color .12s ease;
}
.scroll-latest.show { opacity: 1; pointer-events: auto; transform: none; }
.scroll-latest:hover { border-color: var(--sage); }
.chat-scroll { flex: 1; overflow-y: auto; overscroll-behavior-y: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 48px 2px 100px; display: flex; flex-direction: column; gap: 12px; }
.bubble {
  position: relative;
  max-width: 82%; padding: 12px 16px; border-radius: 18px; font-size: 15px;
  line-height: 1.55; box-shadow: var(--shadow-1), var(--sheen-top);
  white-space: pre-wrap; word-wrap: break-word;
}
.bubble.new { animation: bubbleIn .28s var(--ease-spring); }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.bubble.guide { align-self: flex-start; background: rgba(202,162,74,0.05); border: 1px solid rgba(202,162,74,0.13); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: #252e1e; border: 1px solid #35452a; border-bottom-right-radius: 6px; color: #dce8d2; }
.bubble .who { display: none; user-select: none; -webkit-user-select: none; }
.bubble.guide .who { display: block; font-size: 10.5px; font-weight: 400; letter-spacing: 0; color: var(--gold); opacity: 0.6; margin-bottom: 5px; font-style: italic; text-transform: none; }
/* User bubble: show name at top-left, leave right margin for the dots */
.bubble.me .who { display: block; font-size: 10.5px; color: var(--ink-soft); opacity: 0.5; margin-bottom: 4px; padding-right: 26px; }
.msg-actions {
  position: absolute; top: 8px; right: 8px;
  opacity: 0; transform: translateY(-2px); pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.bubble:hover .msg-actions, .bubble:focus-within .msg-actions { opacity: 1; transform: none; pointer-events: auto; }
@media (hover: none) { .msg-actions { opacity: .6; transform: none; pointer-events: auto; } }
/* Naked dots: no border, no background, just the ··· character */
.msg-act-trigger {
  border: none; background: none;
  padding: 2px 4px; font-size: 15px; letter-spacing: 1.5px; line-height: 1;
  min-width: 44px; min-height: 44px;
  color: var(--ink-soft); cursor: pointer; font-family: var(--sans); touch-action: manipulation;
}
.msg-act-trigger:hover { color: var(--ink); }
.msg-menu {
  position: absolute; top: 0; right: calc(100% + 8px);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5); min-width: 140px; padding: 4px; z-index: 200;
}
@media (max-width: 520px) {
  .msg-menu { right: 0; top: calc(100% + 4px); }
}
.msg-menu.hidden { display: none; }
.msg-menu-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 9px 13px; border-radius: 8px; font-size: 13.5px;
  color: var(--ink-soft); cursor: pointer; font-family: var(--sans); touch-action: manipulation;
}
.msg-menu-item:hover { background: var(--card-2); color: var(--ink); }
.msg-menu-item.danger { color: var(--danger); }
.msg-act:hover { background: rgba(0,0,0,.18); color: var(--ink); }
@media (hover: none) { .msg-actions { opacity: .55; transform: none; pointer-events: auto; } }
.resources-card {
  align-self: flex-start; max-width: 88%; margin: 2px 0 4px; padding: 12px 14px;
  background: var(--card-2); border: 1px solid var(--line); border-left: 3px solid var(--self);
  border-radius: 14px; box-shadow: var(--shadow-soft); animation: rise .25s ease;
}
.resources-card .rc-head { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--self); margin-bottom: 8px; }
.resources-card ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.resources-card li { display: flex; flex-direction: column; }
.resources-card .rc-name { font-size: 13.5px; font-weight: 650; color: var(--ink); }
.resources-card .rc-action { font-size: 13px; color: var(--sage); font-weight: 600; }
/* Gentle conversation starters on a fresh chat. */
.chat-starters { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 8px; max-width: 92%; margin: 4px 0 2px; animation: rise .25s ease; }
.starter-chip {
  background: rgba(202,162,74,0.06); color: var(--ink-soft); border: 1px solid rgba(202,162,74,0.16);
  border-radius: 10px; padding: 9px 16px; font-size: 13.5px; font-weight: 400; font-style: italic;
  cursor: pointer;
  transition: color var(--dur-1) var(--ease-spring), background var(--dur-1) var(--ease-spring), border-color var(--dur-1) var(--ease-spring);
}
.starter-chip:hover { color: var(--ink); background: rgba(202,162,74,0.11); border-color: rgba(202,162,74,0.30); }
.starter-chip:active { color: var(--ink); background: rgba(202,162,74,0.18); border-color: rgba(202,162,74,0.45); }
.typing { align-self: flex-start; display: flex; gap: 6px; padding: 14px 18px; background: rgba(202,162,74,0.05); border: 1px solid rgba(202,162,74,0.13); border-radius: 18px; border-bottom-left-radius: 6px; box-shadow: var(--shadow-1); animation: bubbleIn .28s var(--ease-spring); }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--sage), var(--sage-deep)); opacity: .5; animation: typingPulse 1.4s cubic-bezier(.2,.8,.2,1) infinite; }
.typing i:nth-child(2){ animation-delay:.18s } .typing i:nth-child(3){ animation-delay:.36s }
@keyframes typingPulse { 0%,100%{ opacity:.35; transform: scale(.65) } 50%{ opacity:.95; transform: scale(1.05) } }
@keyframes blink { 0%,100%{ opacity:.3; transform: translateY(0) } 50%{ opacity:.95; transform: translateY(-3px) } }

.composer { padding: 3px 0 2px; }
.name-part-btn {
  background: transparent; border: 1px dashed var(--line); color: var(--sage);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; margin-bottom: 8px;
}
.name-part-btn:hover { border-color: var(--sage); background: rgba(147,177,135,0.1); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#chatInput {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 16px;
  padding: 13px 16px; font-size: 16px; font-family: inherit; color: var(--ink);
  background: var(--input); box-shadow: var(--shadow-soft); max-height: 160px;
}
#chatInput::placeholder { color: var(--ink-soft); }
#chatInput:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(147,177,135,0.18); outline: none; }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sage), var(--sage-deep)); color: #16140f;
  font-size: 17px; box-shadow: var(--shadow-1), var(--sheen-top);
  transition: transform var(--dur-1) var(--ease-spring), filter var(--dur-1) var(--ease-spring), box-shadow var(--dur-1) var(--ease-spring);
  touch-action: manipulation; cursor: pointer;
}
.send-btn:hover { filter: brightness(1.08); transform: translateY(-1px) scale(1.05); box-shadow: var(--shadow-2), var(--sheen-top), 0 0 16px var(--tint-sage); }
.send-btn:active { transform: translateY(0) scale(.95); filter: brightness(.98); }
.composer-meta { display: flex; flex-direction: column; gap: 4px; margin: 3px 4px 0; }
/* ---------- Guide memory list ---------- */
.mem-privacy-note { margin: 8px 0 12px; }
.mem-add-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.mem-add-input { flex: 1; font-size: 16px; padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-family: inherit; }
.mem-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mem-item { display: flex; align-items: flex-start; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }
.mem-item-text { flex: 1; color: var(--ink); line-height: 1.4; }
.mem-item-del { background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 14px; padding: 8px; min-width: 44px; min-height: 44px; line-height: 1; flex-shrink: 0; transition: color .12s; touch-action: manipulation; }
.mem-item-del:hover { color: var(--danger); }
.mem-count { font-size: 11px; color: var(--ink-faint); text-align: right; margin: 6px 0 0; }
.msg-counter { font-size: 9.5px; color: var(--ink-faint); text-align: left; margin: 0; min-height: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; transition: color .3s; }
.count-pill { font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 8px; line-height: 1.6; }
.count-pill.green { background: rgba(147,177,135,0.20); color: var(--sage); }
.count-pill.amber { background: rgba(233,182,92,0.20); color: var(--self); }
.count-pill.red { background: rgba(234,139,128,0.22); color: var(--danger); }
.count-label { font-size: 9.5px; color: var(--ink-faint); }
.top-up { font-size: 9.5px; color: var(--self); font-weight: 600; text-decoration: underline; cursor: pointer; }
.composer-note { display: none; }


/* ---------- Gentle pause note ---------- */
.pause-note { align-self: center; max-width: 92%; text-align: center; background: rgba(233,182,92,0.08); border: 1px solid rgba(233,182,92,0.28); border-radius: 16px; padding: 14px 18px; margin: 8px 0; animation: rise .25s ease; }
.pause-note p { margin: 0 0 12px; font-size: 14px; color: var(--ink); line-height: 1.55; }
.pause-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Parts ---------- */
.parts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.part-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-1), var(--sheen-top); cursor: pointer; position: relative;
  transition: transform .12s ease, box-shadow .12s ease; border-left: 4px solid var(--other);
  touch-action: manipulation;
}
.part-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-3), var(--sheen-top); }
.part-card.manager { border-left-color: var(--manager); }
.part-card.firefighter { border-left-color: var(--firefighter); }
.part-card.exile { border-left-color: var(--exile); }
/* Each part carries a whisper of its role color: a tinted tag + a matching hover glow. */
.part-card.manager .role-tag { color: var(--manager); }
.part-card.firefighter .role-tag { color: var(--firefighter); }
.part-card.exile .role-tag { color: var(--exile); }
.part-card.manager:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-sage); }
.part-card.firefighter:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-clay); }
.part-card.exile:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-violet); }
.part-card h4 { font-family: var(--serif); margin: 0 0 4px; font-size: 18px; color: var(--ink); }
.part-card .role-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); }
.part-card p { font-size: 13.5px; color: var(--ink-soft); margin: 8px 0 0; }
.part-card p.needs { color: var(--sage); margin-top: 5px; }
.cluster-chip { display: inline-block; margin-top: 6px; font-size: 11px; font-weight: 600; color: var(--clay); background: rgba(201,138,107,0.12); border: 1px solid rgba(201,138,107,0.3); border-radius: 999px; padding: 2px 9px; }
.part-card .meta { font-size: 12px; color: var(--ink-soft); margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Part emoji ---------- */
.emoji-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.emoji-row #pEmoji { width: 64px; text-align: center; font-size: 20px; flex: 0 0 auto; }
.emoji-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-chip { background: var(--card-2); border: 1px solid var(--line); border-radius: 9px; width: 34px; height: 34px; font-size: 18px; line-height: 1; cursor: pointer; padding: 0; touch-action: manipulation; }
.emoji-chip:hover { border-color: var(--sage); transform: translateY(-1px); }
.p-emoji { font-size: 18px; }

/* ---------- Map ---------- */
.map-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.map-controls .seg-btn { padding: 6px 14px; font-size: 13px; }
.map-view-row { display: flex; align-items: center; gap: 8px; }
.map-tip-wrap { position: relative; }
.map-tip-btn { min-width: 44px; min-height: 44px; padding: 11px; background-clip: content-box; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-family: var(--sans); }
.map-tip-btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.map-tip-popup { position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; width: 240px; box-shadow: var(--shadow); z-index: 20; }
.map-tip-popup p { font-size: 13px; color: var(--ink-soft); margin: 0 0 8px; line-height: 1.5; }
.map-tip-popup p:last-child { margin: 0; }
.map-tip-popup strong { color: var(--ink); }
.legend { font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.dot.manager { background: var(--manager); } .dot.firefighter { background: var(--firefighter); }
.dot.exile { background: var(--exile); } .dot.self { background: var(--self); }
.map-canvas { aspect-ratio: 460 / 620; min-height: 0; width: 100%; max-height: 80vh; margin: 0 auto; background: #0c130d; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-soft); overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.map-canvas svg { width: 100%; height: 100%; display: block; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.map-canvas svg text { user-select: none; -webkit-user-select: none; }
/* Parts and groves own touch-action: none so dragging them works in all directions */
.map-node, .map-grove { cursor: pointer; touch-action: none; }
.map-node text { font-size: 12px; fill: var(--ink); font-family: var(--sans); }
.map-canvas .cluster-label { fill: var(--ink-soft); font-size: 12px; font-family: var(--sans); font-style: italic; opacity: 0.85; }
.self-core circle { filter: drop-shadow(0 0 16px rgba(233,182,92,0.45)); }
.self-core text { font-family: var(--serif); font-size: 15px; font-weight: 700; fill: #2a1f08; }

/* ---------- Adventure-map skin ---------- */
.map-canvas { background: var(--map-ground-2); }
#mapGround .g1 { stop-color: var(--map-ground-1); }
#mapGround .g2 { stop-color: var(--map-ground-2); }
.map-grid line { stroke: var(--map-grid); stroke-width: 1; }
.map-frame.outer { fill: none; stroke: var(--map-frame); stroke-width: 2.5; opacity: 0.85; }
.map-frame.inner { fill: none; stroke: var(--map-frame); stroke-width: 1; stroke-dasharray: 1 5; opacity: 0.7; }
.map-corner { fill: none; stroke: var(--map-frame); stroke-width: 2; opacity: 0.9; }
.compass { opacity: 0.9; }
.compass circle { fill: none; stroke: var(--map-frame); stroke-width: 1.4; }
.compass circle:last-of-type { fill: var(--map-frame); }
.compass .needle-n { fill: var(--clay); stroke: none; }
.compass .needle-s { fill: var(--map-frame); stroke: none; }
.compass text { fill: var(--map-frame); font-family: var(--serif); font-size: 11px; font-style: italic; }
.map-node text { fill: #ece2d2; paint-order: stroke; stroke: var(--map-ground-2); stroke-width: 3.5px; stroke-linejoin: round; font-family: var(--serif); font-size: 13px; }
.map-node circle[fill="none"] { stroke: var(--map-rim); stroke-width: 2.5; opacity: 0.9; }
.map-canvas .cluster-label { fill: var(--map-frame); font-family: var(--serif); font-style: italic; font-size: 13.5px; opacity: 0.95; }
.map-foliage path { fill: var(--map-foliage); opacity: 0.55; stroke: none; }
.map-scrim { fill: var(--map-scrim); pointer-events: none; }

/* ---------- Groves (Apple-style folders on the map) ---------- */
/* Spring used for every grove motion. */
.map-node .node-inner { transform-box: fill-box; transform-origin: center; transition: transform .15s ease; }
.map-grove .node-inner { cursor: pointer; transform-box: fill-box; transform-origin: center; transition: transform .2s cubic-bezier(.2,.8,.2,1); filter: drop-shadow(0 7px 12px rgba(0,0,0,.45)); }
.map-node.hold-ready .node-inner,
.map-grove.hold-ready .node-inner { transform: scale(1.15); }
.map-grove { cursor: pointer; }
.grove-shadow { fill: #04070a; opacity: .42; }
.grove-halo   { fill: var(--gold-soft); opacity: .9; }
.grove-back   { fill: #14180f; opacity: .94; }
.grove-face   { fill: rgba(202,162,74,0.18); }                    /* warmer gold tint, distinct from part sage/clay/violet */
.grove-ring   { fill: none; stroke: var(--gold); stroke-width: 2; opacity: .9; }
.grove-count  { fill: #15110a; font-family: var(--sans); font-size: 11px; font-weight: 700; }
.grove-label  { fill: var(--gold-bright); font-family: var(--serif); font-style: italic; font-size: 13.5px; paint-order: stroke; stroke: var(--map-ground-2); stroke-width: 3.5px; stroke-linejoin: round; }
.map-grove:hover .node-inner { transform: scale(1.08); }
.map-grove:focus, .map-grove:focus-visible { outline: none; }
.map-grove:focus-visible .node-inner { transform: scale(1.08); }
.map-grove:focus-visible .grove-ring { stroke: var(--gold-bright); }
.map-grove.dragging .node-inner { filter: drop-shadow(0 14px 22px rgba(0,0,0,.5)); cursor: grabbing; }

/* "This will combine" cue: the armed part or grove swells with a gold ring. */
.map-node.grove-armed .node-inner,
.map-grove.grove-armed .node-inner { transform: scale(1.18); }
.map-node.grove-armed circle[fill="none"] { stroke: var(--gold-bright); stroke-width: 3; opacity: 1; }
.map-grove.grove-armed .grove-ring { stroke: var(--gold-bright); stroke-width: 3; opacity: 1; }
.map-grove.grove-armed .grove-halo { opacity: 1; }

/* Drop target: the node under an active drag glows gold to confirm the combine. */
.map-node.drop-target .node-inner { stroke: var(--self); stroke-width: 2.5px; filter: drop-shadow(0 0 8px rgba(202,162,74,0.5)); }

/* ---------- Folder-open: scrim + shelf + member bloom ---------- */
.grove-scrim { fill: #05080a; opacity: 0; cursor: pointer; animation: groveScrim .34s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes groveScrim { to { opacity: .58; } }
.grove-shelf rect { fill: rgba(26,30,18,.88); stroke: var(--gold-line); stroke-width: 1; transform-box: fill-box; transform-origin: center; animation: shelfOpen .42s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes shelfOpen { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.grove-title { fill: var(--gold-bright); font-family: var(--serif); font-style: italic; font-size: 15px; }
.grove-close { cursor: pointer; }
.grove-close text { fill: var(--ink-soft); font-size: 22px; font-family: var(--sans); }
.grove-close:hover text, .grove-close:focus-visible text { fill: var(--ink); }
.grove-close:focus-visible { outline: none; }
/* Members bloom outward from the centre with the iOS folder spring. */
.grove-open .map-node .node-inner { transform-box: fill-box; transform-origin: center; animation: memberBloom .4s cubic-bezier(.2,.8,.2,1) backwards; }
@keyframes memberBloom { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Light theme: the scene stays painted-night, but the scrim/shelf warm up so the
   dim reads as candlelit shade, not a black hole. */
[data-theme="light"] .grove-back { fill: #fff8ec; opacity: .96; }
[data-theme="light"] .grove-face { fill: #f1ead8; }
[data-theme="light"] .grove-count { fill: #5a4413; }
[data-theme="light"] .grove-label { fill: #8a6a1f; }
[data-theme="light"] .grove-scrim { fill: #2a241a; animation-name: groveScrimLight; }
@keyframes groveScrimLight { to { opacity: .42; } }
[data-theme="light"] .grove-shelf rect { fill: rgba(255,250,238,.94); stroke: rgba(120,95,40,.30); }
[data-theme="light"] .grove-title { fill: #8a6a1f; }
[data-theme="light"] .grove-close text { fill: #6b5a3a; }
[data-theme="light"] .grove-close:hover text { fill: #2a241a; }

/* ---------- Gilded surfaces (the painted aesthetic, carried app-wide) ---------- */
/* A whisper of paper grain over everything, like aged parchment. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px; opacity: 0.04; mix-blend-mode: overlay;
}
.app, .onboard { position: relative; z-index: 1; }
/* Warm top-sheen on the main surfaces, like candlelight catching a painted panel. */
.part-card, .journal-card, .intention-card, .learn-item, .history-item, .modal, .onboard-card, .pause-note {
  background-image: linear-gradient(180deg, rgba(255, 244, 222, 0.045), rgba(255, 244, 222, 0) 46%);
}
.modal, .onboard-card { border-top: 2px solid var(--gold-line); box-shadow: var(--shadow-4), var(--sheen-gold), var(--inner-glow); }
/* A small gilded flourish under each section title. */
.view-head h2 { position: relative; }
.view-head h2::after {
  content: ""; display: block; width: 46px; height: 2px; margin-top: 7px;
  background: linear-gradient(90deg, var(--gold-bright), rgba(202, 162, 74, 0)); border-radius: 2px;
}
/* The active tab and the brand take on a candle-gold note. */
.tab.active { box-shadow: 0 0 0 1px rgba(233,182,92,0.18); }
.brand-name { color: var(--self); }

/* ---------- Journal ---------- */
.journal-list { display: flex; flex-direction: column; gap: 10px; }
.journal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 17px; box-shadow: var(--shadow-1), var(--sheen-top); cursor: pointer;
  touch-action: manipulation;
}
.journal-card:hover { border-color: var(--sage); }
.journal-card h4 { font-family: var(--serif); margin: 0 0 3px; font-size: 17px; color: var(--ink); }
.journal-card .date { font-size: 12px; color: var(--ink-soft); }
.journal-card p { font-size: 13.5px; color: var(--ink-soft); margin: 7px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Intentions ---------- */
.view-intro { color: var(--ink-soft); font-size: 13.5px; margin: -4px 0 14px; line-height: 1.5; }
.intentions-list { display: flex; flex-direction: column; gap: 10px; }
.intention-card {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--other);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1), var(--sheen-top);
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; touch-action: manipulation;
}
.intention-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2), var(--sheen-top); }
.intention-card.heal { border-left-color: var(--exile); }
.intention-card.achieve { border-left-color: var(--sage); }
.intention-card.moment { border-left-color: var(--self); }
/* Each intention glows in its kind's color on hover, matching the parts + map system. */
.intention-card.heal:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-violet); }
.intention-card.achieve:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-sage); }
.intention-card.moment:hover { box-shadow: var(--shadow-2), var(--sheen-top), 0 6px 22px var(--tint-gold); }
.intention-card.done { opacity: 0.72; }
.intention-card.done h4 { text-decoration: line-through; text-decoration-color: var(--ink-soft); }
.i-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 10px; }
.kind-badge { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.kind-badge.heal { color: var(--exile); background: rgba(179,164,230,0.14); }
.kind-badge.achieve { color: var(--sage); background: rgba(147,177,135,0.16); }
.kind-badge.moment { color: var(--self); background: rgba(233,182,92,0.14); }
.i-status { font-size: 12px; color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.intention-card h4 { font-family: var(--serif); margin: 0; font-size: 18px; color: var(--ink); }
.intention-card p { font-size: 13.5px; color: var(--ink-soft); margin: 7px 0 0; }

/* ---------- Session history ---------- */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px; background: var(--card-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px;
  box-shadow: var(--shadow-1), var(--sheen-top);
}
.history-item .h-main { flex: 1; min-width: 0; cursor: pointer; }
.history-item h4 { font-family: var(--serif); margin: 0 0 2px; font-size: 15.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-meta { font-size: 12px; color: var(--ink-soft); }
.history-item:hover { border-color: var(--sage); }
.h-del { background: transparent; border: none; color: var(--ink-soft); font-size: 16px; cursor: pointer; padding: 8px; border-radius: 8px; flex: 0 0 auto; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; touch-action: manipulation; }
.h-del:hover { color: var(--danger); background: rgba(234,139,128,0.12); }

/* ---------- Learn ---------- */
.learn-list { display: flex; flex-direction: column; gap: 10px; }
.learn-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1), var(--sheen-top); overflow: hidden; }
.learn-q { width: 100%; text-align: left; background: transparent; border: none; padding: 16px 18px; font-size: 16px; font-weight: 600; color: var(--ink); font-family: var(--serif); display: flex; justify-content: space-between; align-items: center; cursor: pointer; touch-action: manipulation; }
.learn-q .chev { color: var(--gold-bright); transition: transform .2s ease; }
.learn-item.open .chev { transform: rotate(90deg); }
.learn-a { max-height: 0; overflow: hidden; transition: max-height .3s ease; }
.learn-item.open .learn-a { max-height: 700px; }
/* Gilded inscription: an open entry glows like gold leaf on carved stone. */
.learn-q:hover { color: var(--self); }
.learn-item.open { border-color: var(--gold-line); box-shadow: var(--shadow-2), var(--sheen-top), var(--inner-glow); }
.learn-item.open .learn-q { color: var(--self); }
.learn-a-inner { padding: 0 18px 16px; font-size: 14.5px; color: var(--ink-soft); }
.learn-a-inner p { margin: 0 0 10px; }
.learn-a-inner strong { color: var(--ink); }

/* ---------- Google sign-in step ---------- */
.btn-link { background: none; border: none; color: var(--ink-soft); font-size: 13px; cursor: pointer; padding: 4px 0; font-family: var(--sans); text-decoration: underline; text-underline-offset: 3px; }
.btn-link:hover { color: var(--ink); }
.btn-link.small { font-size: 12px; color: var(--ink-faint); }
.auth-sent { font-size: 13px; color: var(--sage); margin: 0; }
.auth-fields.compact { margin-top: 10px; }
.auth-fields { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 0; }
.auth-fields input { background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 15px; color: var(--ink); font-family: var(--sans); width: 100%; box-sizing: border-box; }
.auth-fields input:focus { outline: 2px solid var(--self); border-color: transparent; }
.auth-err { font-size: 13px; color: var(--danger); margin: 0; }
.auth-sep { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--ink-faint); font-size: 13px; }
.auth-sep::before, .auth-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.auth-google-btn { width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 13px; font-size: 15px; font-weight: 600; color: var(--ink); cursor: pointer; font-family: var(--sans); transition: border-color .15s; }
.auth-google-btn:hover { border-color: var(--ink-soft); }

/* ---------- Burger menu ---------- */
.burger-wrap { position: relative; }
.burger-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-soft); transition: color .15s, border-color .15s; }
.burger-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
.burger-menu { position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 180px; padding: 6px; z-index: 200; display: flex; flex-direction: column; gap: 2px; }
.burger-item { background: none; border: none; border-radius: 8px; padding: 9px 14px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; font-family: var(--sans); text-align: left; transition: background .12s; }
.burger-item:hover { background: var(--card-2); }
.burger-item-pro { color: var(--self); font-weight: 700; }
.burger-divider { height: 1px; background: var(--line); margin: 4px 0; }

/* ---------- Pricing modal ---------- */
.pricing-sheet { background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--line); width: 100%; max-width: 560px; padding: 32px 28px 36px; box-sizing: border-box; box-shadow: var(--shadow); position: relative; }
.pricing-title { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 0 0 24px; text-align: center; }
.pricing-cards { display: flex; gap: 16px; }
.pricing-card { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px; display: flex; flex-direction: column; gap: 10px; }
.pricing-card-pro { border-color: var(--self); background: var(--card-2); }
.pricing-card-badge { font-size: 11px; font-weight: 700; letter-spacing: .5px; color: var(--self); text-transform: uppercase; }
.pricing-card-name { font-size: 17px; font-weight: 700; }
.pricing-card-price { font-size: 32px; font-weight: 800; font-family: var(--serif); }
.pricing-per { font-size: 15px; font-weight: 500; color: var(--ink-soft); }
.pricing-features { margin: 4px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.pricing-features li { font-size: 13.5px; color: var(--ink-soft); padding-left: 18px; position: relative; }
.pricing-features li::before { content: ''; position: absolute; left: 0; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--self); opacity: .6; }
.pricing-card-pro .pricing-features li { color: var(--ink); }
.pricing-card-pro .pricing-features li::before { opacity: 1; }
/* Therapist CTA below pricing cards */
.pricing-therapist { margin-top: 24px; padding: 18px 20px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-align: center; }
.pricing-therapist-note { margin: 0 0 12px; font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
.pricing-therapist-note strong { color: var(--ink); }
.pricing-therapist-sessions { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pricing-session-pill { background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.pricing-therapist-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 9px 22px; font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; touch-action: manipulation; transition: background .12s, border-color .12s; font-family: var(--sans); }
.pricing-therapist-btn:hover { background: var(--card-2); border-color: var(--ink-soft); }

/* ---------- Help CTA (settings) ---------- */
.btn-help-now { display: block; width: 100%; padding: 14px 20px; background: var(--danger); color: #fff; border: none; border-radius: var(--radius); font-size: 15px; font-weight: 600; text-align: center; cursor: pointer; }
.btn-help-now:hover { filter: brightness(1.12); }

/* ---------- Feedback button (topbar) ---------- */
.topbar-text-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; font-family: var(--sans); transition: color .15s, border-color .15s; }
.topbar-text-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
.feedback-btn { background: var(--self); border: 1px solid transparent; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--ink-on-accent); cursor: pointer; font-family: var(--sans); transition: opacity .15s; }
.feedback-btn:hover { opacity: .88; }

/* ---------- Feedback panel (bottom sheet) ---------- */
.feedback-overlay { background: rgba(8,6,4,0.45); -webkit-backdrop-filter: blur(5px) saturate(115%); backdrop-filter: blur(5px) saturate(115%); }
.feedback-sheet { background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--line); width: 100%; max-width: 520px; padding: 22px 20px 24px; box-sizing: border-box; max-height: 88vh; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); overflow: hidden; }
.feedback-sheet-head { display: flex; align-items: center; justify-content: space-between; }
.feedback-sheet-head h3 { font-family: var(--serif); font-size: 18px; font-weight: 600; color: var(--ink); margin: 0; }
.feedback-explainer { font-size: 13.5px; color: var(--ink-soft); margin: 0; line-height: 1.55; }
.feedback-thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; max-height: 220px; }
.fb-sent-msg { display: flex; flex-direction: column; gap: 5px; padding: 8px 10px; background: var(--card-2); border-radius: 8px; }
.fb-sent-bar { width: 100%; height: 2px; background: var(--line); border-radius: 1px; }
.fb-sent-preview { font-size: 13px; color: var(--ink-soft); white-space: pre-wrap; word-break: break-word; }
.fb-sent-time { font-size: 11px; color: var(--ink-soft); opacity: 0.7; }
.fb-msg-text { font-size: 14px; color: var(--ink); margin: 0 0 5px; white-space: pre-wrap; word-break: break-word; }
.fb-msg-meta { font-size: 11.5px; color: var(--ink-faint); }
.feedback-compose { display: flex; flex-direction: column; gap: 8px; }
.feedback-compose input, .feedback-compose textarea { background: var(--input); border: 1px solid var(--line); border-radius: 8px; padding: 10px 13px; font-size: 14px; color: var(--ink); font-family: var(--sans); width: 100%; box-sizing: border-box; }
.feedback-compose input::placeholder, .feedback-compose textarea::placeholder { color: var(--ink-faint); opacity: .7; }
.feedback-compose input:focus, .feedback-compose textarea:focus { outline: 2px solid var(--self); border-color: transparent; }
.feedback-compose textarea { resize: none; }
.feedback-send-btn { background: var(--self); color: var(--ink-on-accent); border: none; border-radius: var(--radius); padding: 12px; font-size: 15px; font-weight: 600; cursor: pointer; font-family: var(--sans); transition: opacity .15s; }
.feedback-send-btn:hover:not(:disabled) { opacity: .88; }
.feedback-send-btn:disabled { opacity: .5; cursor: not-allowed; }
.feedback-status { min-height: 16px; font-size: 13px; margin: 0; color: var(--danger); }
.fb-thanks { font-size: 13px; color: var(--self); padding: 6px 10px; line-height: 1.4; }
.paywall-sheet { background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--line); width: 100%; max-width: 380px; padding: 36px 28px 32px; box-sizing: border-box; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; box-shadow: var(--shadow); max-height: 88vh; overflow-y: auto; }
.paywall-ico { color: var(--self); }
.paywall-sheet h2 { font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--ink); margin: 0; }
.paywall-sheet > p { font-size: 14px; color: var(--ink-soft); margin: 0; line-height: 1.6; }
.paywall-note { font-size: 12px !important; color: var(--ink-faint) !important; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; font-size: 14px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 15px; font-family: inherit; color: var(--ink); background: var(--input); resize: vertical;
}
.field input::placeholder, .field textarea::placeholder { color: var(--ink-soft); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--sage); }
.field-row { display: flex; gap: 12px; }
.field.small { flex: 1; }

/* ---------- Crisis ---------- */
.modal.crisis { border-top: 5px solid var(--danger); }
.modal.crisis h3 { color: var(--danger); }
/* "Get help" bottom sheet, a hand extended, not a gate. Slides up; the garden stays visible behind it. */
.help-overlay { background: rgba(8,6,4,0.45); -webkit-backdrop-filter: blur(5px) saturate(115%); backdrop-filter: blur(5px) saturate(115%); }
.help-sheet {
  background-color: var(--surface-3);
  background-image: linear-gradient(180deg, rgba(255,244,222,0.05) 0%, rgba(255,244,222,0) 40%);
  border: 1px solid var(--line); border-top: 2px solid var(--gold-line);
  border-radius: var(--radius);
  padding: 22px 24px 26px; max-width: 520px; width: 100%; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-4), var(--sheen-gold), var(--inner-glow);
}
.help-handle { width: 36px; height: 4px; border-radius: 999px; background: var(--line); margin: 0 auto 16px; opacity: .6; }
.help-sheet h3 { font-family: var(--serif); font-size: 22px; font-weight: 600; margin: 0 0 10px; color: var(--ink); }
.help-intro { font-size: 15px; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.55; }
.crisis-msg { font-size: 15px; color: var(--ink); margin: 0 0 14px; }
.crisis-list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; }
.crisis-list li { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 14px; }
.crisis-list .r-name { font-weight: 700; font-size: 14.5px; color: var(--ink); }
.crisis-list .r-action { font-size: 14px; color: var(--sage); font-weight: 600; }
.crisis-list .r-region { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.crisis-fine { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Doc modal ---------- */
.doc-body { font-size: 13.5px; color: var(--ink-soft); max-height: 60vh; overflow: auto; }
.doc-body h4 { color: var(--ink); font-family: var(--serif); margin: 16px 0 6px; }
.doc-body p { margin: 0 0 10px; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 3px 16px; font-size: 10.5px; color: var(--ink-soft); display: flex; gap: 8px 12px; justify-content: center; flex-wrap: wrap; line-height: 1.2; }
.footer a { color: var(--danger); font-weight: 600; }
.empty-hint { color: var(--ink-soft); font-size: 14px; text-align: center; padding: 30px 16px; }
.map-hint { color: var(--ink-soft); font-size: 13px; text-align: center; margin: 10px auto 0; opacity: 0.78; }
.map-hint:empty { display: none; }
.empty-state { text-align: center; padding: 46px 18px; animation: fade .25s ease; }
.empty-ico { margin-bottom: 10px; filter: drop-shadow(0 0 16px rgba(233,182,92,0.2)); color: var(--self); }
.empty-state h3 { font-family: var(--serif); color: var(--ink); font-size: 20px; margin: 0 0 7px; font-weight: 600; }
.empty-state p { color: var(--ink-soft); font-size: 14.5px; max-width: 360px; margin: 0 auto 18px; line-height: 1.55; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Top-bar icon buttons ---------- */
.icon-btn {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 999px;
  width: 44px; height: 44px; font-size: 15px; line-height: 1; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-soft);
  transition: transform .12s ease, border-color .12s ease;
}
.icon-btn:hover { border-color: var(--sage); transform: translateY(-1px); }

/* ---------- Composer actions + chips ---------- */
.composer-actions { display: flex; flex-wrap: nowrap; gap: 8px; margin-bottom: 6px; overflow-x: auto; scrollbar-width: none; padding-right: 16px; }
.composer-actions::-webkit-scrollbar { display: none; }
.composer-actions .chip-btn { flex-shrink: 0; }
/* Desktop mode seg inside composer-actions (hidden on mobile) */
.chat-fab {
  position: absolute; top: 8px; right: 12px; z-index: 6;
  width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--hair);
  background: var(--glass-2); -webkit-backdrop-filter: blur(12px) saturate(150%); backdrop-filter: blur(12px) saturate(150%);
  color: var(--ink-soft); box-shadow: var(--shadow-2), var(--sheen-top);
  cursor: pointer; touch-action: manipulation;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.chat-fab:hover { border-color: var(--sage); color: var(--ink); background: var(--card-2); }
.chip-btn {
  background: transparent; border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 600;
  touch-action: manipulation;
}
.chip-btn:hover { border-color: var(--sage); color: var(--sage); }
.chip-btn:active { background: var(--card-2); border-color: var(--sage); color: var(--sage); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; filter: none; transform: scale(0.92); }

/* ---------- Settings: segmented + data ---------- */
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px; }
.seg-btn { background: transparent; border: none; border-radius: 999px; padding: 7px 18px; font-size: 14px; font-weight: 600; color: var(--ink-soft); cursor: pointer; touch-action: manipulation; }
.seg-btn.active { background: var(--card-2); color: var(--ink); box-shadow: var(--shadow-soft); }
.field-hint { font-size: 12.5px; color: var(--ink-soft); margin: 0 0 8px; }
.data-counts { font-size: 12.5px; color: var(--sage); margin: 0 0 10px; }
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-soft.danger { color: var(--danger); }
.btn-soft.danger:hover { border-color: var(--danger); color: var(--danger); }
/* Destructive action is visually quarantined so it can't be mis-tapped beside Export. */
.data-danger { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--tint-danger); border: 1px solid rgba(234,139,128,0.3); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.data-danger-hint { font-size: 12.5px; color: var(--ink-soft); margin: 0; line-height: 1.5; }

/* ---------- Breathe ---------- */
.breathe-wrap { display: flex; flex-direction: column; align-items: center; gap: 26px; text-align: center; }
.breathe-orb {
  width: 150px; height: 150px; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, var(--self), #b8893b);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 50px rgba(233,182,92,0.45);
  animation: breathe 11s ease-in-out infinite;
}
.breathe-word { font-family: var(--serif); font-size: 17px; font-weight: 600; color: #2a1f08; }
.breathe-hint { color: var(--ink); font-size: 15px; max-width: 320px; margin: 0; }
@keyframes breathe {
  0%   { transform: scale(0.62); }   /* exhale rest */
  36%  { transform: scale(1.08); }   /* inhale ~4s */
  60%  { transform: scale(1.08); }   /* hold ~2.5s */
  100% { transform: scale(0.62); }   /* exhale ~4.5s */
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px);
  background: var(--card-2); color: var(--ink); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
  z-index: 80; opacity: 0; transition: opacity .2s ease, transform .2s ease; pointer-events: none;
  max-width: min(480px, calc(100vw - 32px)); white-space: normal; word-wrap: break-word; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Calm scrollbars ---------- */
.chat-scroll, .doc-body, .modal { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.chat-scroll::-webkit-scrollbar, .doc-body::-webkit-scrollbar, .modal::-webkit-scrollbar { width: 9px; }
.chat-scroll::-webkit-scrollbar-thumb, .doc-body::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box;
}

/* ---------- Skip link ---------- */
.skip-link { position: absolute; top: -40px; left: 0; z-index: 9999; padding: 8px 14px; background: var(--card); color: var(--ink); font-size: 14px; font-weight: 600; border-radius: 0 0 var(--radius-sm) 0; text-decoration: none; transition: top .15s ease; }
.skip-link:focus { top: 0; outline: 2px solid var(--sage); outline-offset: 2px; }

/* ---------- Screen-reader only utility ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Keyboard focus ---------- */
:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; border-radius: 6px; }
.tab:focus-visible, .btn-primary:focus-visible { outline-offset: 3px; }

/* ---------- Map parts: still by default, lively on hover, enhanced when selected ---------- */
/* Parts no longer float (that bobbing was the jitter, and it moved every part at once).
   They sit still; only the one you touch comes alive. The scale lives on an inner group
   so it never fights the drag transform on the node itself. */
.map-node { cursor: grab; touch-action: none; }
.map-node.dragging { cursor: grabbing; }
.map-node .node-inner { transform-box: fill-box; transform-origin: center; transition: transform .18s cubic-bezier(.2,.8,.2,1), filter .15s ease; will-change: transform; filter: drop-shadow(0 3px 5px rgba(0,0,0,0.6)) drop-shadow(0 0 2px rgba(0,0,0,0.55)); }
.map-node:hover .node-inner { filter: drop-shadow(0 5px 9px rgba(0,0,0,0.62)) drop-shadow(0 0 3px rgba(0,0,0,0.5)); }
.map-node:hover .node-inner { transform: scale(1.16); }
.map-node:hover .node-inner circle:first-child { filter: brightness(1.14); }
.map-node.dragging .node-inner { transform: scale(1.08); opacity: 0.85; filter: drop-shadow(0 8px 16px rgba(0,0,0,0.4)); }
/* Selected: a larger, glowing, candle-gold form (the part's "enhanced" image). */
.map-node.selected .node-inner { transform: scale(1.26); }
.map-node.selected .node-inner circle:first-child { filter: drop-shadow(0 0 7px rgba(233,182,92,0.8)) brightness(1.12); }
.map-node.selected .node-inner circle[fill="none"] { stroke: var(--self); stroke-width: 3; opacity: 1; }
/* No square focus box: keyboard focus shows the same gentle magnify instead. */
.map-node:focus { outline: none; }
.map-node:focus-visible { outline: none; }
.map-node:focus-visible .node-inner { transform: scale(1.16); }
@keyframes drift { 0%,100% { transform: translate(0,0); opacity: .3; } 30% { opacity: .9; } 50% { transform: translate(7px,-10px); opacity: .65; } 80% { opacity: .85; } }

/* ---------- Light theme (dark is default) ---------- */
[data-theme="light"] {
  color-scheme: light;

  --bg: #f5efe6; --bg-2: #ece3d4; --bg-3: #e3d8c5;
  --surface-1: #fffdf9; --surface-2: #fbf5ea; --surface-3: #fffefb;
  --card: var(--surface-1); --card-2: var(--surface-2); --input: #fffdf9;

  --ink: #38332c; --ink-soft: #6f675b; --ink-faint: #968d7e;
  --ink-on-accent: #ffffff;

  --line: #e6dccb; --line-soft: #efe7d8;
  --hair: rgba(86,70,45,0.12); --hair-strong: rgba(86,70,45,0.20);

  --sage: #6f9068; --sage-deep: #557a4f;
  --clay: #be7e5e; --clay-deep: #a4623f;
  --self: #cf972f;
  --violet: #8f7fbe; --violet-deep: #75649c;
  --manager: var(--sage); --firefighter: var(--clay); --exile: var(--violet);
  --other: #b9b1a3; --danger: #b4524a; --danger-deep: #9a4139;

  --tint-sage:   rgba(111,144,104,0.14);
  --tint-clay:   rgba(190,126,94,0.14);
  --tint-violet: rgba(143,127,190,0.16);
  --tint-gold:   rgba(207,151,47,0.14);
  --tint-danger: rgba(180,82,74,0.12);

  --gold: #b08a36; --gold-bright: #cf972f; --gold-deep: #8a6a26;
  --gold-soft: rgba(176,138,54,0.12); --gold-line: rgba(176,138,54,0.26);
  --gold-glow: rgba(207,151,47,0.30);

  --shadow-1: 0 1px 2px rgba(86,70,45,0.06), 0 2px 8px rgba(86,70,45,0.07);
  --shadow-2: 0 4px 14px rgba(86,70,45,0.09);
  --shadow-3: 0 10px 30px rgba(86,70,45,0.12);
  --shadow-4: 0 22px 54px rgba(86,70,45,0.16);
  --shadow-soft: var(--shadow-2); --shadow: var(--shadow-3);
  --sheen-top:  inset 0 1px 0 rgba(255,255,255,0.7);
  --sheen-gold: inset 0 2px 0 var(--gold-line);
  --inner-glow: inset 0 0 40px rgba(207,151,47,0.03);

  --glass-1: rgba(255, 253, 249, 0.68);
  --glass-2: rgba(251, 245, 234, 0.80);
  --glass-3: rgba(245, 239, 230, 0.72);

  --grain-opacity: 0.03;
}
[data-theme="light"] .btn-primary, [data-theme="light"] .send-btn { color: #fff; }
[data-theme="light"] .bubble.me { background: #e8f0e2; border-color: #cddac5; color: var(--ink); }
[data-theme="light"] .bubble.guide { background: rgba(202,162,74,0.07); border-color: rgba(202,162,74,0.20); }
[data-theme="light"] .typing { background: rgba(202,162,74,0.07); border-color: rgba(202,162,74,0.20); }
[data-theme="light"] .self-core text { fill: #2a1f08; }
[data-theme="light"] .breathe-word { color: #2a1f08; }

/* ---------- Search input ---------- */
.search-input {
  width: 100%; border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; font-size: 14.5px; font-family: inherit; color: var(--ink);
  background: var(--input); box-shadow: var(--shadow-soft); margin-bottom: 12px;
}
.search-input::placeholder { color: var(--ink-soft); }
.search-input:focus { border-color: var(--sage); }

/* ---------- Journal part chip ---------- */
.journal-card .part-chip {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px;
  font-size: 12px; font-weight: 600; color: var(--sage);
  background: rgba(147,177,135,0.12); border: 1px solid rgba(147,177,135,0.28);
  border-radius: 999px; padding: 3px 10px;
}

/* ---------- Keyboard shortcuts sheet ---------- */
.shortcuts { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 10px; }
.shortcuts li { display: flex; align-items: center; gap: 14px; font-size: 14.5px; color: var(--ink-soft); }
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 28px;
  padding: 0 8px; font-family: var(--sans); font-size: 13px; font-weight: 700; color: var(--ink);
  background: var(--card-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 7px;
}

/* ---------- Comfort text size (whole-UI zoom) ---------- */
html[data-text="small"] { zoom: 0.92; }
html[data-text="large"] { zoom: 1.12; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .breathe-orb { animation: none; transform: scale(0.9); }
  .map-node { animation: none; }
  .firefly { animation: none; opacity: 0.7; }
}

/* Honor an OS request for more contrast: drop the glass blur, go solid, promote
   secondary text, and firm up hairlines. Only applies under prefers-contrast: more,
   so it never affects the default experience. */
@media (prefers-contrast: more) {
  :root, [data-theme="light"] { --ink-soft: var(--ink); --line: var(--hair-strong); }
  .app-head, .help-sheet, .scroll-latest {
    -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--surface-2);
  }
  .overlay, .help-overlay {
    -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(0,0,0,0.72);
  }
}

/* ---------- Mobile polish ---------- */
@media (max-width: 520px) {
  .field-row { flex-direction: column; gap: 0; }
  .bubble { max-width: 88%; }
  .help-btn { background: none; border-color: rgba(234,139,128,0.35); }
  .stage { padding: 6px 12px 0; }
  .chip-btn { padding: 7px 13px; }
  .topbar-mode-btn, .seg-btn, .chip-btn, .starter-chip { min-height: 44px; }
  .btn-ghost.small { min-height: 44px; }
  .seg-btn { display: inline-flex; align-items: center; }
  .footer { padding: 3px 14px calc(3px + env(safe-area-inset-bottom)); }
  .modal-actions { flex-wrap: wrap; justify-content: flex-end; }
  .modal-actions .spacer { display: none; }
  .data-actions { flex-direction: column; }
  .data-actions .btn-soft { width: 100%; }
  .pricing-cards { flex-direction: column; }
  .pricing-sheet { padding: 24px 18px 28px; }
}
