:root {
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --ink: #2b2620;
  --muted: #8a8275;
  --line: #e3dccb;
  --accent: #8a6d3b;
  --accent-soft: #f3e6c8;
  --highlight: #fff3b0;
  --shadow: 0 2px 14px rgba(60, 50, 30, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Start screen ---------- */
.start {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.start-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.start-card h1 {
  margin: 0 0 4px;
  font-size: 30px;
  letter-spacing: 0.3px;
}
.tagline { margin: 0 0 22px; color: var(--muted); font-size: 15px; }
.start-card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.start-card input,
.start-card select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
button {
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 15px;
}
#join-btn {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-size: 16px;
}
#join-btn:hover { filter: brightness(1.05); }
.hint { color: var(--muted); font-size: 12.5px; margin: 16px 0 0; }

/* ---------- Reading screen ---------- */
.app { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.nav { display: flex; align-items: center; gap: 8px; }
.nav select {
  padding: 7px 9px;
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
/* ---------- Unified topbar controls (every icon the same single colour) ---------- */
.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
  padding: 7px 11px;
  font-size: 14px;
  font-family: -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tbtn:hover { background: #faf4e3; }
.tbtn.icon-only { padding: 7px 8px; }
.ic {
  width: 16px; height: 16px;
  stroke: var(--accent);   /* one colour for all icons */
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.room-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 5px 10px;
  max-width: 32vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.room-name .ic { width: 14px; height: 14px; }
.badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.right { display: flex; align-items: center; gap: 14px; }
.follow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.follow input { width: 16px; height: 16px; accent-color: var(--accent); }
.presence { display: flex; align-items: center; gap: 6px; }
.dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 20px;
  padding: 3px 10px 3px 8px;
}
.dot::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4caf50;
}
/* ---------- Chat side panel ---------- */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: 340px;
  max-width: 88vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -4px 0 24px rgba(60, 50, 30, 0.12);
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}
.chat-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
  color: var(--muted);
}
.chat-close:hover { color: var(--ink); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: -apple-system, system-ui, sans-serif;
}
.chat-msg { max-width: 85%; }
.chat-msg .who {
  font-size: 11.5px;
  color: var(--accent);
  margin-bottom: 2px;
}
.chat-msg .bubble {
  display: inline-block;
  padding: 7px 11px;
  border-radius: 12px;
  background: #f0eadf;
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat-msg.mine { align-self: flex-end; text-align: right; }
.chat-msg.mine .bubble { background: var(--accent); color: #fff; }
.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.chat-form input {
  flex: 1;
  padding: 9px 11px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.chat-form button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
}

/* ---------- Bookmarks (reuses .chat-panel / .chat-head / .chat-close) ---------- */
.bm-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.bm-actions { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.bm-add {
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
}
.bm-add:hover { filter: brightness(1.05); }
.bm-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: -apple-system, system-ui, sans-serif;
}
.bm-item { display: flex; align-items: stretch; gap: 6px; }
.bm-open {
  flex: 1;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bm-open:hover { background: #faf4e3; }
.bm-label { font-size: 14px; color: var(--ink); line-height: 1.3; }
.bm-meta { font-size: 11.5px; color: var(--muted); }
.bm-del {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 10px;
}
.bm-del:hover { color: #a23b3b; background: #faf4e3; }
.bm-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  padding: 0 8px;
}

/* ---------- Commentary (per-line shared notes) ---------- */
.verse { position: relative; }
.cmt-btn {
  position: absolute;
  top: 1px;
  right: 2px;
  display: none;
  align-items: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 2px 4px;
  cursor: pointer;
}
.verse:hover .cmt-btn,
.verse.highlighted .cmt-btn,
.verse.has-comments .cmt-btn { display: inline-flex; }
.cmt-btn .ic { width: 15px; height: 15px; }
.cmt-count { font-family: -apple-system, system-ui, sans-serif; font-size: 11px; font-weight: 600; }
.verse.has-comments { box-shadow: inset 3px 0 0 var(--accent); }

.comment-popover {
  position: absolute;
  z-index: 45;
  width: 300px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  max-height: 60vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-family: -apple-system, system-ui, sans-serif;
}
.cp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.cp-close { border: none; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); padding: 0 4px; cursor: pointer; }
.cp-close:hover { color: var(--ink); }
.cp-list { flex: 1; overflow-y: auto; padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.cp-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }
.cp-note { font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.cp-by { display: block; font-size: 11px; color: var(--accent); margin-bottom: 1px; }
.cp-del { float: right; border: none; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.cp-del:hover { color: #a23b3b; }
.cp-form { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.cp-form textarea {
  resize: vertical; font-family: inherit; font-size: 13px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff;
}
.cp-form button { align-self: flex-end; background: var(--accent); color: #fff; border-color: var(--accent); font-size: 13px; padding: 6px 12px; }

/* ---------- Reader ---------- */
.reader {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 24px 120px;
}
#passage-title {
  font-size: 26px;
  margin: 8px 0 24px;
  text-align: center;
  letter-spacing: 0.3px;
}
.verses { font-size: 20px; line-height: 1.9; }
.verse {
  display: block;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
.verse:hover { background: #faf4e3; }
.verse.highlighted { background: var(--highlight); }
.vnum {
  font-size: 12px;
  color: var(--accent);
  vertical-align: super;
  margin-right: 4px;
  font-family: -apple-system, system-ui, sans-serif;
  user-select: none;
}
.loading, .error { text-align: center; color: var(--muted); padding: 40px; }
.error { color: #a23b3b; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (max-width: 520px) {
  .verses { font-size: 18px; }
  #passage-title { font-size: 22px; }
  .topbar { gap: 8px; }
}

/* ---------- Byline ---------- */
.byline {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.spacer { height: 0.8em; }
.library-btn { background: var(--accent-soft); border-color: var(--accent-soft); font-size: 14px; }
.nav select { max-width: 46vw; }

/* ---------- Library drawer ---------- */
.library-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 34, 24, 0.38);
  z-index: 50;
  display: flex;
  justify-content: flex-start;
}
.library-panel {
  width: 100%;
  max-width: 460px;
  height: 100%;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 18px 18px 24px;
  overflow-y: auto;
}
.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.library-head h2 { margin: 0; font-size: 22px; }
.icon-btn { border: none; background: none; font-size: 18px; color: var(--muted); padding: 4px 8px; }
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.search-row select {
  padding: 8px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.search-status { color: var(--muted); font-size: 13px; margin: 10px 2px 6px; }

.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
}
.result:hover { background: #faf4e3; }
.r-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.r-title { font-size: 16px; }
.r-tag {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 2px 8px;
  white-space: nowrap;
}
.r-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.r-snip {
  margin-top: 6px;
  font-size: 14px;
  color: var(--ink);
  font-style: italic;
  line-height: 1.5;
}

/* Era section header (sticky so it labels the band while you scroll) */
.era-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -18px;
  padding: 9px 18px;
  background: var(--accent-soft);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--accent);
}
.era-count {
  font-weight: 600;
  color: var(--muted);
  background: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
}
.browse-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  border-radius: 0;
  padding: 9px 4px;
}
.browse-item:hover { background: #faf4e3; }
.bi-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bi-title { font-size: 15px; line-height: 1.25; }
.bi-sub {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 11.5px;
  color: var(--muted);
}
.bi-year {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 520px) {
  .library-panel { max-width: 100%; }
}
