:root {
  --bg: #f6f2e9;          /* warm parchment */
  --bg-elev: #fffdf8;     /* near-white, warm */
  --sidebar: #fcf9f1;
  --panel: #ffffff;
  --panel-2: #f1ece0;
  --line: #e4ddcb;        /* soft warm border */
  --text: #2b2a26;        /* ink */
  --text-dim: #716b5c;    /* muted brown-grey */
  --accent: #b58a2b;      /* temple gold */
  --accent-2: #8a6a1e;    /* deep gold (text on light) */
  --accent-soft: #e9c976; /* light gold for gradients */
  --outer: #5f8a5f;       /* court green */
  --holy: #b58a2b;        /* gold */
  --mhp: #7a5fc0;         /* veil violet */
  --user-bubble: #e9eef7; /* soft blue */
  --asst-bubble: #ffffff;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(80,66,30,.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 340px;
  max-width: 88vw;
  flex-shrink: 0;
  background: linear-gradient(180deg, #fcf9f1, #f3eedf);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 16px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.close-btn { display: none; margin-left: auto; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim); width: 34px; height: 34px; border-radius: 9px; font-size: 24px; line-height: 1; cursor: pointer; flex-shrink: 0; }
.close-btn:hover { color: var(--accent-2); border-color: var(--accent); }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px;
  background: radial-gradient(circle at 30% 30%, var(--accent-soft), var(--accent));
  color: #2b2206; font-weight: 800; font-size: 18px;
  display: grid; place-items: center;
  box-shadow: 0 4px 16px rgba(181,138,43,.32);
  font-family: 'Cormorant Garamond', serif;
}
.brand-text h1 { font-family: 'Cormorant Garamond', serif; font-size: 20px; line-height: 1.05; margin: 0; font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--accent-2); letter-spacing: .12em; text-transform: uppercase; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 1px 3px rgba(80,66,30,.05);
}
.panel-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); font-weight: 600; }

input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%23716b5c'><path d='M7 10l5 5 5-5z'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.panel-row { display: flex; gap: 8px; }
.panel-row select { flex: 1; }
.btn-ghost {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim);
  border-radius: 10px; padding: 0 14px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-ghost:hover { color: var(--accent-2); border-color: var(--accent); }

.passage-preview {
  font-size: 13px; color: var(--text-dim); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 120px; overflow-y: auto; line-height: 1.5;
}
.passage-preview .v { color: var(--accent-2); font-weight: 700; font-size: 10px; vertical-align: super; margin-right: 2px; }
.hidden { display: none; }

/* Sanctuary picker */
.sanctuary .level { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 10px; background: var(--panel-2); border-left: 3px solid var(--line); }
.level-outer { border-left-color: var(--outer); }
.level-holy { border-left-color: var(--holy); }
.level-mhp { border-left-color: var(--mhp); }
.level-head { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.level-head em { font-style: normal; color: var(--text-dim); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.level-outer .dot { background: var(--outer); }
.level-holy .dot { background: var(--holy); }
.level-mhp .dot { background: var(--mhp); }
.lens-profile { font-size: 12px; color: var(--accent-2); text-align: center; padding: 8px; background: rgba(181,138,43,.1); border-radius: 8px; border: 1px dashed rgba(181,138,43,.4); font-weight: 600; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-btn { background: transparent; border: none; color: var(--text-dim); padding: 7px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #2b2206; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-soft), var(--accent));
  color: #2b2206; border: none; border-radius: 10px; padding: 12px; font-weight: 700; font-size: 14px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(181,138,43,.28);
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-primary:disabled { opacity: .6; cursor: wait; }

.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); padding-top: 8px; }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: #b8b09b; }
.health-dot.ok { background: #3f9f6b; box-shadow: 0 0 8px rgba(63,159,107,.6); }
.health-dot.warn { background: #cf9a2f; }
.health-dot.bad { background: #cf4a44; }

/* ---------------- Main ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.main-head { display: flex; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--bg-elev); }
.menu-btn { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }
.head-title h2 { font-family: 'Cormorant Garamond', serif; margin: 0; font-size: 20px; font-weight: 700; }
.head-title span { font-size: 12px; color: var(--text-dim); }
.badge { margin-left: auto; font-size: 11px; font-weight: 700; padding: 5px 11px; border-radius: 20px; text-transform: lowercase; letter-spacing: .03em; }
.badge-quick { background: rgba(95,138,95,.16); color: #3c7a3c; border: 1px solid rgba(95,138,95,.4); }
.badge-deep { background: rgba(122,95,192,.16); color: #5a3fb0; border: 1px solid rgba(122,95,192,.4); }

.messages { flex: 1; overflow-y: auto; padding: 26px 0; }
.welcome { max-width: 680px; margin: 30px auto; text-align: center; padding: 0 20px; }
.welcome-seal { width: 70px; height: 70px; margin: 0 auto 18px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, var(--accent-soft), var(--accent)); color: #2b2206; font-family: 'Cormorant Garamond', serif; font-weight: 800; font-size: 26px; display: grid; place-items: center; box-shadow: 0 6px 24px rgba(181,138,43,.32); }
.welcome h3 { font-family: 'Cormorant Garamond', serif; font-size: 26px; margin: 0 0 10px; }
.welcome p { color: var(--text-dim); line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--text-dim); padding: 9px 14px; border-radius: 20px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--text); }

.msg { max-width: 820px; margin: 0 auto 22px; padding: 0 22px; display: flex; gap: 14px; }
.msg .avatar { width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.msg.user .avatar { background: var(--user-bubble); color: #2b4a7a; }
.msg.assistant .avatar { background: linear-gradient(180deg, var(--accent-soft), var(--accent)); color: #2b2206; font-family: 'Cormorant Garamond', serif; }
.bubble { background: var(--asst-bubble); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; line-height: 1.65; font-size: 15px; overflow-x: auto; box-shadow: 0 1px 3px rgba(80,66,30,.05); }
.msg.user .bubble { background: var(--user-bubble); border-color: #cdd8ea; }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-family: 'Cormorant Garamond', serif; margin: 14px 0 8px; line-height: 1.2; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble code { background: #f0ebdd; padding: 2px 6px; border-radius: 5px; font-size: 13px; color: #7a5e14; }
.bubble pre { background: #f5f1e6; border: 1px solid var(--line); padding: 12px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: transparent; color: var(--text); }
.bubble blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding: 4px 14px; color: var(--text-dim); font-style: italic; }
.bubble strong { color: var(--accent-2); }

.msg-source { font-size: 10px; color: var(--text-dim); margin-top: 6px; text-transform: uppercase; letter-spacing: .06em; }

/* Sanctuary 3-column result */
.sanctuary-result { max-width: 980px; margin: 0 auto 24px; padding: 0 22px; }
.sanctuary-head { font-family: 'Cormorant Garamond', serif; font-size: 20px; text-align: center; margin-bottom: 4px; }
.sanctuary-ref { text-align: center; color: var(--accent-2); font-size: 13px; margin-bottom: 16px; }
.sanctuary-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.scol { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; border-top: 4px solid var(--line); box-shadow: 0 1px 3px rgba(80,66,30,.05); }
.scol.outer { border-top-color: var(--outer); }
.scol.holy { border-top-color: var(--holy); }
.scol.mhp { border-top-color: var(--mhp); }
.scol h4 { margin: 0 0 2px; font-family: 'Cormorant Garamond', serif; font-size: 17px; }
.scol .axis { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); }
.scol .theory-key { display: inline-block; margin: 8px 0; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 12px; background: var(--panel-2); color: var(--accent-2); }
.scol p { font-size: 13px; line-height: 1.55; color: var(--text-dim); margin: 6px 0; }
.scol .impact { color: var(--text); }
.scol .gematria { margin-top: 10px; padding: 8px; background: rgba(181,138,43,.1); border-radius: 8px; font-size: 12px; }
.scol .gematria b { color: var(--accent-2); font-size: 16px; }

@media (max-width: 760px) { .sanctuary-cols { grid-template-columns: 1fr; } }

/* Typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: blink 1.4s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 16px 22px 20px; background: var(--bg-elev); }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.composer-inner:focus-within { border-color: var(--accent); }
#input { background: transparent; border: none; resize: none; max-height: 200px; padding: 6px; color: var(--text); }
#input:focus { border: none; }
.send-btn { background: linear-gradient(180deg, var(--accent-soft), var(--accent)); color: #2b2206; border: none; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.send-btn:hover { filter: brightness(1.04); }
.send-btn:disabled { opacity: .5; cursor: wait; }
.composer-hint { max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 11px; color: var(--text-dim); }

/* Backdrop (shown behind the open sidebar on mobile) */
.backdrop { display: none; position: fixed; inset: 0; z-index: 25; background: rgba(43,42,38,.45); opacity: 0; transition: opacity .25s; }
.backdrop.show { display: block; opacity: 1; }

/* Mobile / tablet */
@media (max-width: 860px) {
  .sidebar { position: fixed; top: 0; left: 0; z-index: 30; height: 100%; height: 100dvh; transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .close-btn { display: grid; place-items: center; }
  .main-head { padding: 12px 16px; }
  .head-title h2 { font-size: 18px; }
  .composer { padding: 12px 14px 16px; }
  .msg, .sanctuary-result { padding-left: 16px; padding-right: 16px; }
}

/* Small phones */
@media (max-width: 480px) {
  .head-title span { display: none; }
  .head-title h2 { font-size: 17px; }
  .welcome { margin: 12px auto; }
  .welcome h3 { font-size: 22px; }
  .chips { gap: 8px; }
  .composer-hint { font-size: 10px; }
}
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d8d0bc; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }


/* ---------- ElevenLabs voice controls ---------- */
.voice-auto {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.voice-auto input { width: auto; cursor: pointer; }

/* Listen / Stop button on each assistant answer */
.speak-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-2);
  background: rgba(181, 138, 43, .1);
  border: 1px solid rgba(181, 138, 43, .4);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.speak-btn:hover { background: rgba(181, 138, 43, .2); border-color: var(--accent); }
.speak-btn.loading { opacity: .7; cursor: progress; }
.speak-btn.playing {
  background: var(--accent);
  color: #2b2206;
  border-color: var(--accent);
}


/* ---------------- Original-language index + canon guard (v5) ---------------- */
.panel-note { font-size: 12px; color: var(--text-dim); margin: 0; line-height: 1.45; }

.guard-badge {
  margin: 8px 0 2px; padding: 9px 12px; border-radius: 10px;
  font-size: 13px; line-height: 1.45; border: 1px solid;
}
.guard-badge.guard-ok { background: #eef6ee; border-color: #c5e0c5; color: #2f5d2f; }
.guard-badge.guard-warn { background: #fbe7e3; border-color: #e7b7a7; color: #8a3414; }

.grounding-panel {
  margin: 8px 0 2px; padding: 10px 12px; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px; background: var(--bg-elev);
}
.grounding-head { font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--accent-2); margin-bottom: 6px; }
.grounding-verse { padding: 6px 0; border-top: 1px dashed var(--line); }
.grounding-verse:first-of-type { border-top: 0; }
.gv-ref { font-weight: 700; color: var(--text); }
.gv-lang { font-size: 11px; font-weight: 600; color: #fff; background: var(--accent);
  padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.gv-text { font-family: 'Cormorant Garamond', serif; font-size: 18px; line-height: 1.5;
  color: var(--text); margin: 3px 0; }
.gv-words { margin-top: 4px; font-size: 18px; line-height: 1.7; color: var(--accent-2); }
.gv-words.rtl { direction: rtl; text-align: right; }
.origword { cursor: help; border-bottom: 1px dotted var(--accent); padding: 0 1px; }
.origword:hover { background: var(--accent-soft); }

.orig-card {
  margin: 10px 0; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow);
}
.orig-head { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 700;
  color: var(--text); margin-bottom: 4px; }
.orig-count { font-size: 12px; font-weight: 600; color: #fff; background: var(--accent);
  padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.orig-note { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.orig-reject { background: #fbe7e3; border: 1px solid #e7b7a7; color: #8a3414;
  padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.orig-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.orig-table th { text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-dim); border-bottom: 2px solid var(--line);
  padding: 6px 8px; }
.orig-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.orig-table .ow-orig { font-family: 'Cormorant Garamond', serif; font-size: 20px;
  color: var(--accent-2); font-weight: 600; white-space: nowrap; }
.orig-table .ow-orig.rtl { direction: rtl; text-align: right; }
.orig-table .ow-tr { font-style: italic; color: var(--text-dim); }
.orig-table .ow-st { font-variant-numeric: tabular-nums; color: var(--accent-2); font-weight: 600; }
.orig-table .ow-gl { color: var(--text); }

/* === v7: MarkYourBible AI Search Engine indicator + study sources === */
.engine-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.engine-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #5a4210;
  background: rgba(181, 138, 43, 0.14);
  border: 1px solid var(--accent, #b58a2b);
  white-space: nowrap;
}
.engine-pill::before {
  content: "\1F50D";
  font-weight: 400;
}
.sources-panel {
  margin: 8px 0 4px;
  padding: 10px 12px;
  border: 1px dashed var(--accent, #b58a2b);
  border-radius: 10px;
  background: rgba(181, 138, 43, 0.06);
}
.sources-head {
  font-size: 0.82rem;
  font-weight: 700;
  color: #5a4210;
  margin-bottom: 6px;
}
.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.source-chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: #4a3a12;
  background: rgba(181, 138, 43, 0.12);
  border: 1px solid rgba(181, 138, 43, 0.35);
}

/* ---- v9: Terms & Agreement links ---- */
.terms-link {
  color: var(--accent);
  text-decoration: none;
  opacity: 0.85;
}
.terms-link:hover { text-decoration: underline; opacity: 1; }
.sidebar-terms {
  display: block;
  margin-top: 8px;
  font-size: 12px;
}

/* ---- v11: internal nav links to content pages ---- */
.welcome-nav{margin-top:18px;display:flex;flex-wrap:wrap;gap:16px;justify-content:center}
.welcome-nav a{color:var(--accent);text-decoration:none;font-size:14px;opacity:.9}
.welcome-nav a:hover{text-decoration:underline;opacity:1}
.sidebar-nav{display:flex;flex-wrap:wrap;gap:10px;margin-top:10px}
.sidebar-nav a{color:var(--text-dim);text-decoration:none;font-size:12px}
.sidebar-nav a:hover{color:var(--accent)}
