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

/* ─── LIGHT THEME (default) ──────────────────────────────────────────────── */
:root {
  --bg: #f5f0e8;
  --surface: #ede7db;
  --card: #ffffff;
  --card-hover: #faf7f2;
  --gold: #9a7010;
  --gold-dim: #b8920a;
  --gold-light: #c9a227;
  --purple: #6b5fd4;
  --blue: #2196c4;
  --teal: #1a9eae;
  --red-soft: #c0604a;
  --green: #3a9a5c;
  --text: #2c2416;
  --text-bright: #1a150c;
  --text-muted: #8a7860;
  --border: rgba(154,112,16,0.16);
  --border-active: rgba(154,112,16,0.5);
  --shadow: 0 2px 12px rgba(100,80,20,0.08);
  --radius: 12px;
}

/* ─── DARK THEME ──────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #07071a;
  --surface: #0f0f28;
  --card: #16163a;
  --card-hover: #1e1e4a;
  --gold: #c9a227;
  --gold-dim: #7a6018;
  --gold-light: #f0d060;
  --purple: #8b7fff;
  --blue: #4fc3f7;
  --teal: #26c6da;
  --red-soft: #ff9080;
  --green: #66bb6a;
  --text: #ddd0b8;
  --text-bright: #f2eada;
  --text-muted: #6a6a90;
  --border: rgba(201,162,39,0.13);
  --border-active: rgba(201,162,39,0.45);
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Lato', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.3s;
}

[data-theme="dark"] body::before {
  opacity: 1;
  background-image:
    radial-gradient(1px 1px at 15% 25%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 8%,  rgba(255,255,255,0.28) 0%, transparent 100%),
    radial-gradient(1px 1px at 38% 62%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px 1px at 67% 78%, rgba(255,255,255,0.2) 0%, transparent 100%),
    radial-gradient(1px 1px at 9%  88%, rgba(255,255,255,0.28) 0%, transparent 100%),
    radial-gradient(2px 2px at 58% 42%, rgba(255,255,255,0.1) 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 52%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 28% 12%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 52% 72%, rgba(255,255,255,0.16) 0%, transparent 100%),
    radial-gradient(1px 1px at 82% 32%, rgba(255,255,255,0.28) 0%, transparent 100%),
    radial-gradient(1px 1px at 44% 5%,  rgba(255,255,255,0.22) 0%, transparent 100%),
    radial-gradient(1px 1px at 3%  48%, rgba(255,255,255,0.18) 0%, transparent 100%),
    radial-gradient(1px 1px at 95% 20%, rgba(255,255,255,0.25) 0%, transparent 100%),
    radial-gradient(1px 1px at 22% 95%, rgba(255,255,255,0.2) 0%, transparent 100%);
}

/* ─── OVERLAY / WIZARD ───────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(245,240,232,0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

[data-theme="dark"] .overlay {
  background: rgba(7,7,26,0.96);
}

.wizard-panel {
  background: var(--card);
  border: 1px solid var(--border-active);
  border-radius: 20px;
  padding: 40px 44px;
  max-width: 480px;
  width: 94%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 48px rgba(100,80,20,0.12);
  animation: fadeUp 0.28s ease;
}

[data-theme="dark"] .wizard-panel {
  box-shadow: 0 8px 48px rgba(0,0,0,0.4);
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.wizard-glyph { font-size: 2.4rem; color: var(--gold); opacity: 0.65; text-align: center; margin-bottom: 12px; }

.wizard-panel h2 {
  font-family: 'Cinzel', serif;
  color: var(--gold);
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 6px;
}

.wizard-sub {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  margin-bottom: 28px;
  line-height: 1.65;
}

/* Wizard progress dots */
.wizard-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 28px;
}

.wdot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.2s;
}

.wdot.active { background: var(--gold); transform: scale(1.2); }
.wdot.done   { background: var(--gold-dim); }

/* Wizard form elements */
.w-field { margin-bottom: 16px; }

.w-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.w-input, .w-select, .w-textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 0.875rem;
  font-family: 'Lato', sans-serif;
  transition: border-color 0.18s;
}

.w-input:focus, .w-select:focus, .w-textarea:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.w-textarea { resize: vertical; min-height: 100px; line-height: 1.55; }

.w-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Emoji picker */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.emoji-opt {
  width: 100%;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-opt:hover { border-color: var(--gold-dim); background: var(--card-hover); }
.emoji-opt.selected { border-color: var(--gold); background: rgba(154,112,16,0.08); }

/* Chart hint */
.chart-hint {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 14px;
}

.chart-hint a { color: var(--gold); text-decoration: none; }
.chart-hint a:hover { text-decoration: underline; }
.chart-hint strong { color: var(--text); }

/* Wizard nav */
.wizard-nav {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.wizard-nav .btn-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 11px 22px;
  border-radius: 9px;
  font-size: 0.875rem;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
}

.wizard-nav .btn-back:hover { border-color: var(--gold-dim); color: var(--text); }

.wizard-nav .btn-next {
  flex: 1;
  background: var(--gold);
  border: none;
  color: #fff;
  padding: 11px 22px;
  border-radius: 9px;
  font-size: 0.875rem;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.18s;
}

.wizard-nav .btn-next:hover { background: var(--gold-light); }

.w-optional { font-size: 0.68rem; color: var(--text-muted); margin-left: 6px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.key-hint { font-size: 0.72rem; color: var(--text-muted); line-height: 1.55; margin-top: 6px; }
.key-hint strong { color: var(--text); }

/* ─── PLACE AUTOCOMPLETE ─────────────────────────────────────────────────── */
.place-field { position: relative; }
.place-suggestions {
  position: absolute;
  top: calc(100% + 3px);
  left: 0; right: 0;
  background: var(--card);
  border: 1px solid var(--border-active);
  border-radius: 9px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  z-index: 200;
  overflow: hidden;
  animation: fadeUp 0.14s ease;
}
.ps-item {
  padding: 9px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.13s;
}
.ps-item:last-child { border-bottom: none; }
.ps-item:hover { background: var(--card-hover); }
.ps-city { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.ps-region { font-size: 0.71rem; color: var(--text-muted); margin-top: 1px; }

/* ─── PROFILE SWITCHER ───────────────────────────────────────────────────── */
.profile-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px 4px 7px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.18s;
  font-size: 0.78rem;
  color: var(--text-muted);
  user-select: none;
}

.profile-pill:hover { border-color: var(--gold-dim); color: var(--text); }

.profile-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(154,112,16,0.1);
  border: 1px solid var(--border-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.profile-dropdown {
  position: fixed;
  top: 62px;
  right: 22px;
  background: var(--card);
  border: 1px solid var(--border-active);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 200px;
  z-index: 500;
  overflow: hidden;
  animation: fadeUp 0.18s ease;
}

.pd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.pd-item:last-child { border-bottom: none; }
.pd-item:hover { background: var(--card-hover); color: var(--text); }
.pd-item.active { color: var(--gold); }
.pd-item .pd-emoji { font-size: 1rem; width: 22px; text-align: center; }
.pd-item .pd-check { margin-left: auto; font-size: 0.75rem; color: var(--gold); }
.pd-add { color: var(--text-muted); font-style: italic; }
.pd-add:hover { color: var(--gold); }

/* ─── LAYOUT ─────────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: calc(58px + env(safe-area-inset-top, 0px)) 1fr;
  grid-template-columns: 272px 1fr;
  /* --app-h is set from the visual viewport so the layout shrinks when the
     mobile keyboard opens; 100dvh is the fallback for the first paint. */
  height: var(--app-h, 100dvh);
  position: relative;
  z-index: 1;
}

/* ─── HEADER ─────────────────────────────────────────────────────────────── */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  padding-top: env(safe-area-inset-top, 0px);
  border-bottom: 1px solid var(--border);
  background: rgba(245,240,232,0.92);
  backdrop-filter: blur(14px);
  z-index: 10;
}

[data-theme="dark"] header { background: rgba(7,7,26,0.88); }

.h-left { display: flex; align-items: center; gap: 12px; }
.h-orb { width: 32px; height: 32px; border: 1px solid var(--gold-dim); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--gold); font-size: 0.95rem; flex-shrink: 0; }
.h-title { font-family: 'Cinzel', serif; font-size: 0.9rem; color: var(--gold); letter-spacing: 0.07em; }
.h-sub { font-size: 0.68rem; color: var(--text-muted); }
.h-right { display: flex; align-items: center; gap: 8px; }

.date-chip { font-size: 0.7rem; color: var(--text-muted); padding: 4px 10px; border: 1px solid var(--border); border-radius: 20px; }

.btn-icon {
  width: 34px; height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { border-color: var(--gold-dim); color: var(--text); }

.lang-select {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-family: 'Lato', sans-serif;
  padding: 6px 6px;
  cursor: pointer;
  max-width: 92px;
  transition: all 0.18s;
}
.lang-select:hover { border-color: var(--gold-dim); color: var(--text); }
.lang-select option { background: var(--card); color: var(--text); }

.btn-sm {
  padding: 6px 13px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
}

.btn-sm:hover { border-color: var(--gold-dim); color: var(--text); }

/* ─── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sb-section { padding: 13px 15px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sb-label { font-family: 'Cinzel', serif; font-size: 0.58rem; color: var(--gold-dim); letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 9px; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.mode-btn { padding: 7px 3px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); font-size: 0.66rem; font-family: 'Lato', sans-serif; cursor: pointer; transition: all 0.18s; text-align: center; line-height: 1.3; }
.mode-btn:hover { border-color: var(--gold-dim); color: var(--text); }
.mode-btn.active { border-color: var(--gold); color: var(--gold); background: rgba(154,112,16,0.07); }
.mode-icon { display: block; font-size: 0.95rem; margin-bottom: 2px; }

.sb-scroll { flex: 1; overflow-y: auto; }
.sb-scroll::-webkit-scrollbar { width: 3px; }
.sb-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.planet-list { display: flex; flex-direction: column; gap: 3px; }
.prow { display: flex; justify-content: space-between; font-size: 0.7rem; padding: 1px 0; }
.pname { color: var(--gold-dim); font-weight: 700; width: 70px; }
.ppos { color: var(--text-muted); }

.sb-settings { padding: 11px 15px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sb-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 5px; }
.sb-row:last-child { margin-bottom: 0; }
.sb-row button { background: none; border: 1px solid var(--border); color: var(--text-muted); padding: 2px 8px; border-radius: 4px; font-size: 0.66rem; cursor: pointer; font-family: 'Lato', sans-serif; }
.sb-row button:hover { border-color: var(--gold-dim); color: var(--text); }

/* ─── MAIN ────────────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.tab { padding: 11px 20px; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.18s; letter-spacing: 0.03em; user-select: none; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-pane { flex: 1; display: none; flex-direction: column; overflow: hidden; }
.tab-pane.active { display: flex; }

/* ─── CONVERSATION ───────────────────────────────────────────────────────── */
.convo { flex: 1; overflow-y: auto; padding: 22px 26px; display: flex; flex-direction: column; gap: 16px; }
.convo::-webkit-scrollbar { width: 4px; }
.convo::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 40px; color: var(--text-muted); }
.welcome-orb { font-size: 2.6rem; opacity: 0.4; color: var(--gold); }
.welcome h3 { font-family: 'Cinzel', serif; color: var(--text-muted); font-size: 0.95rem; letter-spacing: 0.05em; }
.welcome p { font-size: 0.8rem; max-width: 320px; line-height: 1.65; }

.msg { max-width: 82%; animation: fadeUp 0.25s ease; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.bubble { padding: 12px 16px; border-radius: 16px; font-size: 0.875rem; line-height: 1.72; overflow-wrap: anywhere; }
/* Long unbroken strings (links, gate lists) must wrap, not widen the page */
.ch-msg, .portrait-p, .portrait-h1, .portrait-h3, .j-text, .chapter-title, .welcome p { overflow-wrap: anywhere; }
.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }

.msg.user .bubble { background: rgba(154,112,16,0.08); border: 1px solid rgba(154,112,16,0.2); border-bottom-right-radius: 3px; color: var(--text-bright); }
[data-theme="dark"] .msg.user .bubble { background: rgba(201,162,39,0.1); border-color: rgba(201,162,39,0.22); }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 3px; color: var(--text); box-shadow: var(--shadow); }

.msg-meta { font-size: 0.66rem; color: var(--text-muted); margin-top: 3px; padding: 0 3px; }
.msg.user .msg-meta { text-align: right; }

.typing { align-self: flex-start; display: flex; gap: 5px; padding: 13px 17px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; border-bottom-left-radius: 3px; }
.dot { width: 5px; height: 5px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out; }
.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-6px); opacity: 1; } }

.err-msg { align-self: center; background: rgba(192,96,74,0.07); border: 1px solid rgba(192,96,74,0.2); border-radius: 8px; padding: 9px 14px; font-size: 0.78rem; color: var(--red-soft); max-width: 80%; }

/* ─── STARTERS ───────────────────────────────────────────────────────────── */
.starters { display: flex; gap: 6px; padding: 0 26px 12px; flex-wrap: wrap; flex-shrink: 0; }
.starter { padding: 5px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 20px; font-size: 0.74rem; color: var(--text-muted); cursor: pointer; transition: all 0.18s; user-select: none; box-shadow: var(--shadow); }
.starter:hover { border-color: var(--gold-dim); color: var(--text); }
.starter.tg-on { border-color: var(--gold); color: var(--gold); background: rgba(154,112,16,0.07); }

/* ─── INPUT ──────────────────────────────────────────────────────────────── */
.input-area { padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
textarea.input-box { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; color: var(--text); font-size: 0.875rem; font-family: 'Lato', sans-serif; resize: none; min-height: 44px; max-height: 130px; line-height: 1.5; transition: border-color 0.18s; box-shadow: var(--shadow); }
textarea.input-box:focus { outline: none; border-color: var(--gold-dim); }
textarea.input-box::placeholder { color: var(--text-muted); }
.send-btn { width: 44px; height: 44px; background: var(--gold); border: none; border-radius: 11px; color: #fff; font-size: 1.1rem; font-weight: 700; cursor: pointer; transition: all 0.18s; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.send-btn:hover { background: var(--gold-light); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── JOURNAL ────────────────────────────────────────────────────────────── */
.journal-wrap { flex: 1; overflow-y: auto; padding: 22px 26px; }
.journal-wrap::-webkit-scrollbar { width: 4px; }
.journal-wrap::-webkit-scrollbar-thumb { background: var(--border); }
.j-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow); }
.j-form-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 10px; }
.type-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 11px; }
.chip { padding: 4px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 0.71rem; cursor: pointer; transition: all 0.18s; color: var(--text-muted); background: transparent; font-family: 'Lato', sans-serif; }
.chip.active { background: rgba(154,112,16,0.08); border-color: var(--gold); color: var(--gold); }
.j-textarea { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 11px 13px; color: var(--text); font-size: 0.875rem; font-family: 'Lato', sans-serif; resize: vertical; min-height: 76px; line-height: 1.65; margin-bottom: 11px; }
.j-textarea:focus { outline: none; border-color: var(--gold-dim); }
.j-entries { display: flex; flex-direction: column; gap: 9px; }
.j-entry { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.j-entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.j-type-badge { font-size: 0.63rem; font-weight: 700; letter-spacing: 0.07em; padding: 2px 9px; border-radius: 20px; }
.badge-milestone  { background: rgba(33,150,196,0.1);   color: var(--blue);     border: 1px solid rgba(33,150,196,0.22);  }
.badge-celebration { background: rgba(154,112,16,0.1);  color: var(--gold);     border: 1px solid rgba(154,112,16,0.22);  }
.badge-insight     { background: rgba(26,158,174,0.1);  color: var(--teal);     border: 1px solid rgba(26,158,174,0.22);  }
.badge-doubt       { background: rgba(107,95,212,0.1);  color: var(--purple);   border: 1px solid rgba(107,95,212,0.22);  }
.badge-intention   { background: rgba(58,154,92,0.1);   color: var(--green);    border: 1px solid rgba(58,154,92,0.22);   }
[data-theme="dark"] .badge-milestone  { background: rgba(79,195,247,0.1);   color: #4fc3f7; border-color: rgba(79,195,247,0.2);   }
[data-theme="dark"] .badge-celebration { background: rgba(201,162,39,0.1); color: #c9a227; border-color: rgba(201,162,39,0.2); }
[data-theme="dark"] .badge-insight    { background: rgba(38,198,218,0.1);  color: #26c6da; border-color: rgba(38,198,218,0.2);  }
[data-theme="dark"] .badge-doubt      { background: rgba(139,127,255,0.1); color: #8b7fff; border-color: rgba(139,127,255,0.2); }
[data-theme="dark"] .badge-intention  { background: rgba(102,187,106,0.1); color: #66bb6a; border-color: rgba(102,187,106,0.2); }
.j-date { font-size: 0.66rem; color: var(--text-muted); }
.j-text { font-size: 0.845rem; line-height: 1.65; color: var(--text); }

/* ─── BOOK ───────────────────────────────────────────────────────────────── */
.book-wrap { flex: 1; overflow-y: auto; padding: 22px 26px; }
.book-wrap::-webkit-scrollbar { width: 4px; }
.book-wrap::-webkit-scrollbar-thumb { background: var(--border); }
.book-header { text-align: center; padding-bottom: 24px; }
.book-header h3 { font-family: 'Cinzel', serif; color: var(--gold); font-size: 1.05rem; letter-spacing: 0.06em; margin-bottom: 4px; }
.book-header p { font-size: 0.76rem; color: var(--text-muted); }
.book-empty { text-align: center; color: var(--text-muted); font-size: 0.81rem; padding: 28px 0; }
.chapter { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; box-shadow: var(--shadow); }
.chapter-head { padding: 13px 17px; display: flex; justify-content: space-between; align-items: flex-start; cursor: pointer; transition: background 0.18s; gap: 11px; }
.chapter-head:hover { background: var(--card-hover); }
.chapter-title { font-size: 0.835rem; color: var(--text); font-weight: 600; line-height: 1.4; }
.chapter-meta { font-size: 0.66rem; color: var(--text-muted); margin-top: 2px; }
.chapter-arrow { color: var(--text-muted); font-size: 0.72rem; flex-shrink: 0; margin-top: 2px; }
.chapter-body { padding: 0 17px; max-height: 0; overflow: hidden; transition: max-height 0.3s ease, padding 0.3s; }
.chapter-body.open { max-height: 30000px; padding: 3px 17px 14px; }
.ch-msg { font-size: 0.78rem; line-height: 1.65; color: var(--text-muted); margin-bottom: 8px; padding-left: 9px; border-left: 2px solid var(--border); }
.ch-msg.assistant { border-left-color: var(--gold-dim); color: var(--text); }
.ch-msg strong { color: var(--text-muted); font-size: 0.65rem; display: block; margin-bottom: 1px; text-transform: uppercase; letter-spacing: 0.06em; }
.ch-msg.assistant strong { color: var(--gold-dim); }

/* ─── PORTRAIT ───────────────────────────────────────────────────────────── */
.portrait-wrap { flex: 1; overflow-y: auto; padding: 28px 32px; max-width: 720px; margin: 0 auto; width: 100%; }
.portrait-wrap::-webkit-scrollbar { width: 4px; }
.portrait-wrap::-webkit-scrollbar-thumb { background: var(--border); }
.portrait-h1 { font-family: 'Cinzel', serif; color: var(--gold); font-size: 1.15rem; letter-spacing: 0.05em; margin: 0 0 6px; text-align: center; }
.portrait-tagline { font-size: 0.8rem; color: var(--text-muted); font-style: italic; text-align: center; margin-bottom: 28px; }
.portrait-h2 { font-family: 'Cinzel', serif; color: var(--gold-dim); font-size: 0.82rem; letter-spacing: 0.12em; text-transform: uppercase; margin: 32px 0 16px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.portrait-h3 { font-size: 0.92rem; font-weight: 700; color: var(--text-bright); margin: 22px 0 8px; }
.portrait-hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.portrait-p { font-size: 0.875rem; line-height: 1.78; color: var(--text); margin-bottom: 0.75em; }
.portrait-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 60px 20px; text-align: center; color: var(--text-muted); }
.portrait-empty p { font-size: 0.82rem; max-width: 300px; line-height: 1.65; }
.portrait-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.pt-switch { display: flex; gap: 4px; }
.pt-tab { padding: 5px 14px; border: 1px solid var(--border); border-radius: 20px; font-size: 0.75rem; cursor: pointer; color: var(--text-muted); transition: all 0.18s; user-select: none; }
.pt-tab:hover { border-color: var(--gold-dim); color: var(--text); }
.pt-tab.active { border-color: var(--gold); color: var(--gold); background: rgba(154,112,16,0.07); }
.pt-actions { display: flex; gap: 6px; }
.portrait-pre { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 0.72rem; overflow-x: auto; margin: 12px 0; line-height: 1.65; font-family: monospace; color: var(--text); }

/* ─── BUTTONS (shared) ───────────────────────────────────────────────────── */
.btn-primary-full {
  display: block;
  width: 100%;
  padding: 11px;
  background: var(--gold);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: 0.875rem;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
}

.btn-primary-full:hover { background: var(--gold-light); }

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────── */
.menu-btn { display: none; }

@media (max-width: 680px) {
  /* minmax(0,1fr) lets the column shrink to the screen instead of the header's
     content forcing the whole app wider than the viewport. Fixed positioning
     pins the layout so the iOS keyboard can't shove the page around, and
     overflow clipping stops any stray pixel from widening the canvas. */
  .app { grid-template-columns: minmax(0, 1fr); position: fixed; top: 0; left: 0; width: 100%; overflow: hidden; }
  .menu-btn { display: flex; }
  .sidebar {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top, 0px)); left: 0; bottom: 0;
    width: min(82vw, 300px);
    z-index: 600;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 28px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }

  /* Condense the header so all controls fit a phone width */
  header { padding-left: 10px; padding-right: 10px; }
  .h-left { gap: 8px; min-width: 0; }
  .h-right { gap: 6px; min-width: 0; }
  .h-sub { display: none; }
  .h-title { display: none; }          /* the orb stays as the logo */
  .date-chip { display: none; }
  .lang-select { display: none; }      /* language moves to the sidebar drawer */
  #profileName { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .profile-pill { flex-shrink: 1; min-width: 0; }
  .btn-sm { padding: 6px 10px; white-space: nowrap; }

  /* Tabs scroll horizontally if they don't all fit */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; flex-shrink: 0; }

  .msg { max-width: 92%; }
  .convo { padding: 16px 14px; }
  .starters { padding: 0 14px 10px; }
  .input-area { padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
  /* Wizard fits comfortably on a narrow phone */
  .wizard-panel { padding: 28px 20px; max-height: 86vh; }
  .wizard-panel h2 { font-size: 1.12rem; }
  .emoji-grid { grid-template-columns: repeat(6, 1fr); }
  /* Language selector shown inside the sidebar on mobile */
  .sb-lang-row { display: flex !important; }
}
.sb-lang-row { display: none; }
