:root {
  --bg: #0f0d09;
  --bg2: #17140e;
  --panel: #1e1a13;
  --panel2: #26211a;
  --line: #38322a;
  --text: #f4eddd;
  --muted: #a3957e;
  --gold: #f0b429;
  --gold-soft: rgba(240, 180, 41, 0.14);
  --gold-dim: #8a6d3b;
  --green: #4ade80;
  --red: #f87171;
  --verse-size: 20px;
  --radius: 16px;
  --level: 0;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(900px 420px at 85% -5%, rgba(240, 180, 41, 0.07), transparent 60%),
    radial-gradient(700px 380px at -10% 110%, rgba(240, 180, 41, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============ header ============ */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.logo {
  width: 42px; height: 42px;
  background: linear-gradient(150deg, #322a19, #191510);
  border: 1px solid rgba(240, 180, 41, 0.35);
  border-radius: 13px;
  display: grid; place-items: center;
  flex: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.titles h1 {
  margin: 0;
  font-size: 17.5px;
  font-weight: 750;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.status-line {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
  transition: color 0.3s;
}
.status-line.live { color: var(--green); }
.status-line.live::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: blink 1.4s ease-in-out infinite;
  vertical-align: 1px;
}
.status-line.warn { color: var(--gold); }
@keyframes blink { 50% { opacity: 0.35; } }

.icon-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 18px;
  width: 42px; height: 42px;
  border-radius: 13px;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { transform: scale(0.96); }

/* ============ listening dock ============ */
.dock {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 10px 16px 4px;
  padding: 14px 18px;
  background: linear-gradient(160deg, var(--panel2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  position: relative;
  overflow: hidden;
}
.dock::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(400px 120px at calc(60px + var(--level) * 100px) 50%, rgba(74, 222, 128, 0.10), transparent 65%);
  opacity: calc(var(--level) * 2.2);
  pointer-events: none;
  transition: opacity 0.12s;
}

.orb {
  position: relative;
  width: 84px; height: 84px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  flex: none;
  padding: 0;
}
.orb-core {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 32% 28%, #3a3327, #221d15);
  border: 2px solid var(--line);
  color: var(--muted);
  transition: all 0.25s;
  z-index: 2;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
}
.orb:active .orb-core { transform: scale(0.94); }

.orb-ring, .orb-ring2 {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(74, 222, 128, 0.0);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.orb.on .orb-core {
  background: radial-gradient(circle at 32% 28%, #2c4632, #14271a);
  border-color: rgba(74, 222, 128, 0.7);
  color: var(--green);
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.25), 0 6px 18px rgba(0,0,0,0.45);
}
.orb.on .orb-ring {
  opacity: 1;
  border-color: rgba(74, 222, 128, 0.55);
  transform: scale(calc(1 + var(--level) * 0.28));
  animation: pulse 2s ease-out infinite;
}
.orb.on .orb-ring2 {
  opacity: 0.6;
  border-color: rgba(240, 180, 41, 0.45);
  transform: scale(calc(1 + var(--level) * 0.5));
  animation: pulse 2s ease-out 0.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.25); }
  70% { box-shadow: 0 0 0 14px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.dock-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wave {
  width: 100%;
  height: 56px;
  display: block;
}
.ghost {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 20px;
  opacity: 0.92;
}
.transcript {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.7;
  min-height: 15px;
}

/* ============ detection banner ============ */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 16px;
  padding: 0 16px;
  background: linear-gradient(120deg, rgba(240,180,41,0.16), rgba(240,180,41,0.05));
  border: 1px solid rgba(240, 180, 41, 0.45);
  border-radius: var(--radius);
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(.2,.9,.3,1.2), opacity 0.3s, margin 0.3s, padding 0.3s;
  pointer-events: none;
}
.banner.visible {
  max-height: 90px;
  opacity: 1;
  margin: 8px 16px 0;
  padding: 12px 16px;
  pointer-events: auto;
}
.banner-icon { font-size: 26px; }
.banner-ref { font-size: 20px; font-weight: 800; color: var(--gold); letter-spacing: 0.2px; }
.banner-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.ref-chips { display: none; gap: 8px; padding: 0 16px; overflow-x: auto; }
.ref-chips.visible { display: flex; }
.ref-chip {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-weight: 700;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
}

/* ============ content: passage + related ============ */
.content {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 10px 16px 0;
}

.passage-wrap {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.28);
}
.passage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px 8px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel2), var(--bg2));
}
.passage-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 0.4px;
}
.chap-nav { display: flex; gap: 6px; }
.chap-btn {
  width: 36px; height: 36px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.chap-btn:disabled { opacity: 0.3; }
.chap-btn:not(:disabled):active { background: var(--gold-dim); }

.passage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px 30px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.verse {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--verse-size);
  line-height: 1.68;
  color: #ece4d2;
  padding: 6px 10px;
  border-radius: 10px;
  transition: background 0.45s;
}
.verse .vnum {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: #2c271f;
  border-radius: 6px;
  min-width: 21px;
  text-align: center;
  padding: 2px 4px;
  margin-right: 9px;
  vertical-align: 2px;
}
.verse.quoted {
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.20), rgba(240, 180, 41, 0.06));
  border-left: 3px solid var(--gold);
  color: #fff;
  font-weight: 600;
  animation: glow-in 1.2s ease;
}
.verse.quoted .vnum { background: var(--gold); color: #241b05; }
@keyframes glow-in {
  from { background: rgba(240, 180, 41, 0.45); }
}
.empty { color: var(--muted); font-style: italic; text-align: center; margin-top: 40px; }
.empty-s { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 4px 2px; }

.loading {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(15, 13, 9, 0.85);
  z-index: 5;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.4px;
  backdrop-filter: blur(3px);
}
.loading.visible { display: grid; }

/* related side panel */
.related {
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
}
.related-head {
  padding: 13px 16px 9px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel2), var(--bg2));
}
.related-head h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 750;
  color: var(--text);
}
.related-hint {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.related-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.related-chip {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.2s, transform 0.15s;
}
.related-chip:hover { border-color: var(--gold-dim); }
.related-chip:active { transform: scale(0.98); }
.rc-ref { display: block; font-weight: 700; font-size: 14px; color: var(--gold); }
.rc-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ============ error ============ */
.error-card {
  display: none;
  margin: 8px 16px;
  padding: 12px 14px;
  background: #2b1a17;
  border: 1px solid #7f2f28;
  border-radius: var(--radius);
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.error-card.visible { display: flex; }
.error-card p { margin: 0; font-size: 13.5px; line-height: 1.5; }

/* ============ controls ============ */
.controls {
  padding: 8px 16px calc(10px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.manual-row { display: flex; gap: 8px; }
.manual-row input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 13px;
  padding: 12px 15px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.manual-row input:focus { border-color: var(--gold-dim); }
.manual-row input::placeholder { color: #7d7361; }

.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 13px;
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary {
  background: linear-gradient(180deg, #f7c948, var(--gold));
  border-color: transparent;
  color: #241b05;
}
.btn:active { transform: scale(0.97); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  min-height: 34px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}
.chip:active { border-color: var(--gold); color: var(--gold); }

/* ============ settings sheet ============ */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.sheet.open { opacity: 1; pointer-events: auto; }
.sheet-card {
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 18px 20px calc(24px + var(--safe-bottom));
  transform: translateY(36px);
  transition: transform 0.28s cubic-bezier(.2,.9,.3,1.1);
}
.sheet.open .sheet-card { transform: none; }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sheet-head h3 { margin: 0; font-size: 17px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  font-size: 13.5px;
  color: var(--muted);
}
.field select { width: 100%; }
.field select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  font-size: 15px;
}
.field-note { color: #857a68; line-height: 1.45; }
.field.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
}
.field.check input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; }
.note {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
}

/* ============ iframe banner ============ */
.iframe-banner {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  padding: 10px 12px;
  background: #2b2415;
  border-bottom: 1px solid var(--gold-dim);
}
.iframe-banner.visible { display: block; }
.iframe-card { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.iframe-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.iframe-card .btn { align-self: flex-start; padding: 9px 14px; }

/* ============ toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translate(-50%, 16px);
  background: #000;
  color: #fff;
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  transition: all 0.35s;
  z-index: 80;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* scrollbars */
.passage::-webkit-scrollbar, .related-list::-webkit-scrollbar, .sheet-card::-webkit-scrollbar { width: 8px; }
.passage::-webkit-scrollbar-thumb, .related-list::-webkit-scrollbar-thumb, .sheet-card::-webkit-scrollbar-thumb { background: #38322a; border-radius: 8px; }

/* ============ responsive ============ */
@media (min-width: 900px) {
  .content { grid-template-columns: 1fr 290px; }
  .related { display: flex; }
  body { max-width: 1180px; margin: 0 auto; width: 100%; }
}
@media (max-width: 899px) {
  /* mobile: related becomes a compact row under the passage */
  .related { display: flex; max-height: 132px; }
  .related-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .related-chip { flex: none; min-width: 148px; }
  .empty-s { display: none; }
}
@media (max-height: 720px) {
  .orb { width: 70px; height: 70px; }
  .wave { height: 44px; }
  .verse { margin-bottom: 9px; }
}
