:root {
  --bg:           #faf6ef;
  --cream:        #f4ede0;
  --card-bg:      #fdfaf6;
  --text:         #2a1f14;
  --muted:        #5c4a35;
  --border:       #e0d5c5;
  --primary:      #7a2d3a;
  --primary-dark: #561e28;
  --gold:         #c49a3c;
  --gold-light:   #f0e4b8;
  --green:        #2d6a4f;
  --green-light:  #e8f3ee;
  --green-mid:    #b7dfc8;
  --dark:         #1a1108;
  --white:        #fff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ── Login page ──────────────────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
.login-card {
  background: var(--card-bg);
  padding: 2rem 2.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(26,17,8,0.08);
  width: 320px;
}
.login-card h1 { font-size: 1.3rem; margin: 0 0 1.2rem; color: var(--primary); }
.login-card label { display: block; font-size: 0.85rem; margin: 0.6rem 0 0.2rem; color: var(--muted); }
.login-card input { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 1rem; background: var(--cream); color: var(--text); }
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card button {
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.6rem;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.login-card button:hover { background: var(--primary-dark); }
.login-card .error { color: var(--primary-dark); font-size: 0.85rem; margin-top: 0.6rem; }
.login-card .auth-links { text-align: center; font-size: 0.85rem; margin-top: 1rem; color: var(--muted); }
.login-card .auth-links a { color: var(--primary); text-decoration: none; }
.login-card .auth-links a:hover { text-decoration: underline; }
.login-card .hint { font-size: 0.85rem; color: var(--muted); margin-top: 0.6rem; }

/* ── Toolbar ─────────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.toolbar-group { display: flex; align-items: center; gap: 0.4rem; }
#search-form { flex: 1; display: flex; gap: 0.4rem; min-width: 220px; }
#search-input { flex: 1; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--cream); color: var(--text); font-size: 1rem; }
#toolbar select, #toolbar button, #toolbar a {
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--white);
  text-decoration: none;
}
#toolbar select { color: var(--text); background: var(--cream); border-color: var(--border); }
#toolbar button:hover, #toolbar a:hover { background: rgba(255,255,255,0.22); }

.book-picker { position: relative; }
.book-picker-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  display: flex;
  gap: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(26,17,8,0.18);
  padding: 0.8rem;
  z-index: 10;
  max-height: 70vh;
  overflow-y: auto;
}
.book-picker-col { display: flex; flex-direction: column; min-width: 150px; }
.book-picker-col h5 {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--white);
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
}
/* #toolbar button sets color:white at (1 id, 1 type) specificity, which beats
   a plain .book-option class rule — qualify with #toolbar so it wins. */
#toolbar .book-option {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  font-weight: 700;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
#toolbar .book-option:hover { background: var(--cream); color: var(--primary); }

#search-results {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  max-height: 40vh;
  overflow-y: auto;
}
.result-section h4 { margin: 0.4rem 0 0.2rem; font-size: 0.8rem; text-transform: uppercase; color: var(--gold); letter-spacing: 0.04em; }
.result-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.2rem;
  cursor: pointer;
}
.result-item:hover { background: var(--cream); }
.result-item strong { display: block; font-size: 0.85rem; color: var(--primary); }
.result-item span { font-size: 0.85rem; color: var(--muted); }

/* ── Reader split layout ────────────────────────────────────────────── */
#reader-split {
  --split: 50%;
  position: relative;
  padding: 0 0.5rem;
}
#column-headers {
  position: sticky;
  top: var(--toolbar-height, 56px);
  display: grid;
  grid-template-columns: var(--split) 1fr;
  column-gap: 1rem;
  padding: 0.5rem 0;
  z-index: 4;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.col-header-cell { display: flex; align-items: center; gap: 0.5rem; }
.left-header { padding-left: 2.2rem; }
.right-header { padding-right: 2.2rem; font-weight: 700; color: var(--primary); font-size: 0.95rem; letter-spacing: 0.02em; }
.header-label { font-weight: 700; color: var(--primary); font-size: 0.95rem; }
#translation-select {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}
.collapse-left .left-header { display: none; }
.collapse-left #column-headers { grid-template-columns: 1fr; }
.collapse-right .right-header { display: none; }
.collapse-right #column-headers { grid-template-columns: 1fr; }

.edge-toggle {
  position: absolute;
  top: 0.4rem;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--primary);
  border-radius: 6px;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  z-index: 6;
}
.edge-toggle:hover { background: var(--cream); }
.edge-toggle.left-edge { left: 0.1rem; }
.edge-toggle.right-edge { right: 0.1rem; }

#verse-list { padding-bottom: 4rem; }

.scroll-sentinel { height: 1px; }

/* These rows share the verse grid's column split so their content stays
   confined to the Bible column instead of spanning into Notes. */
.chapter-header-row, .book-turn-row {
  display: grid;
  grid-template-columns: var(--split) 1fr;
  column-gap: 1rem;
}
.collapse-left .chapter-header-row,
.collapse-left .book-turn-row,
.collapse-right .chapter-header-row,
.collapse-right .book-turn-row {
  grid-template-columns: 1fr;
}

.plan-marker-row {
  display: grid;
  grid-template-columns: var(--split) 1fr;
  column-gap: 1rem;
}
.collapse-left .plan-marker-row,
.collapse-right .plan-marker-row {
  grid-template-columns: 1fr;
}

.chapter-header {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--primary);
  padding: 2rem 0.5rem 1rem;
  text-align: center;
}

.book-turn-btn {
  display: block;
  width: calc(100% - 0.75rem);
  margin: 1.5rem 0.75rem 1.5rem 0;
  padding: 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: var(--white);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.book-turn-btn:disabled { background: var(--border); color: var(--muted); cursor: default; }
.book-turn-btn:hover:not(:disabled) { opacity: 0.92; }

.verse-row {
  display: grid;
  grid-template-columns: var(--split) 1fr;
  column-gap: 1rem;
}
.verse-row.highlight { background: var(--gold-light); }

.bible-cell {
  font-size: 1.05rem;
  line-height: 1.5;
  padding: 0 0.75rem 0 0.2rem;
  cursor: text;
}
.verse-num { font-weight: 700; color: var(--primary); margin-right: 0.3rem; font-size: 0.85rem; vertical-align: super; cursor: pointer; }

.notes-cell { display: flex; align-items: flex-start; padding: 0 0.2rem 0 0.75rem; cursor: text; }
.notes-cell:focus-within { background: rgba(196,154,60,0.12); }
.notes-cell .verse-num { flex-shrink: 0; }
.note-input {
  display: block;
  flex: 1;
  min-width: 0;
  /* Below 1rem (16px), iOS Safari auto-zooms the page on focus — this is
     the actual note editor, so it matters most here. */
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  color: var(--text);
}
.note-input:focus { outline: none; }

#divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 11px;
  margin-left: -5px;
  cursor: col-resize;
  background: transparent;
  z-index: 3;
}
#divider::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--border);
}
#divider:hover::after, #divider.dragging::after { background: var(--primary); width: 3px; margin-left: -1.5px; }

.collapse-left .bible-cell, .collapse-left .verse-num { display: none; }
.collapse-left .verse-row { grid-template-columns: 1fr; }
.collapse-right .notes-cell { display: none; }
.collapse-right .verse-row { grid-template-columns: 1fr; }

/* ── Bold floating button ───────────────────────────────────────────── */
#bold-btn {
  position: absolute;
  z-index: 10;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--primary);
  cursor: pointer;
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(26,17,8,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal-content {
  background: var(--card-bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 1.5rem;
  width: 420px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal-content h3 { color: var(--primary); margin-top: 0; }
.modal-close { position: absolute; top: 0.6rem; right: 0.8rem; border: none; background: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); }
#word-search-form { display: flex; gap: 0.5rem; margin: 0.8rem 0; }
#word-search-input { flex: 1; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--cream); color: var(--text); font-size: 1rem; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* ── Generic table/list pages (journal, settings) ───────────────────── */
.page {
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.page h1 { font-size: 1.4rem; color: var(--primary); }
.page a.back { display: inline-block; margin-bottom: 1rem; color: var(--primary); text-decoration: none; }
.page a.back:hover { text-decoration: underline; }
.journal-day { margin-bottom: 1.2rem; }
.journal-day h3 { margin: 0 0 0.3rem; font-size: 1rem; color: var(--gold); }
.journal-entry {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.3rem;
  cursor: pointer;
  color: var(--text);
}
.journal-entry:hover { background: var(--cream); }
.abbrev-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.abbrev-row .book-name { width: 160px; font-weight: 600; color: var(--primary); }
.abbrev-row .abbrev-list { flex: 1; color: var(--muted); }
.abbrev-row button { border: none; background: var(--gold-light); color: var(--primary-dark); border-radius: 4px; padding: 0.1rem 0.4rem; cursor: pointer; }
.abbrev-row button:hover { background: var(--gold); color: var(--white); }
#add-abbrev-form { display: flex; gap: 0.5rem; margin: 1rem 0; }
#add-abbrev-form input { padding: 0.4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--cream); color: var(--text); font-size: 1rem; }
#add-abbrev-form button, #change-password-form button {
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
#add-abbrev-form button:hover, #change-password-form button:hover { background: var(--primary-dark); }

#change-password-form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
#change-password-form input { padding: 0.4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--cream); color: var(--text); font-size: 1rem; }
.page .error { color: var(--primary-dark); font-size: 0.85rem; }

/* ── Reading plans ───────────────────────────────────────────────────── */
.plan-card { border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); padding: 1rem 1.2rem; margin-bottom: 1.2rem; }
.plan-card h2 { margin: 0 0 0.3rem; font-size: 1.1rem; color: var(--primary); }
.start-plan-btn {
  background: var(--primary); color: var(--white); border: none; border-radius: 6px;
  padding: 0.5rem 1rem; cursor: pointer; font-size: 0.95rem;
}
.start-plan-btn:hover { background: var(--primary-dark); }
.plan-track-list { margin: 0.3rem 0 0.8rem; padding-left: 1.2rem; color: var(--muted); font-size: 0.9rem; }
.plan-preview { margin: 0.6rem 0; font-size: 0.85rem; }
.plan-preview summary { cursor: pointer; color: var(--primary); }
.plan-preview-body { max-height: 360px; overflow-y: auto; margin-top: 0.5rem; padding: 0.5rem 0.6rem; background: var(--cream); border-radius: 6px; }
.plan-cell-static { color: var(--muted); cursor: default; }
.track-toggles { display: flex; flex-wrap: wrap; gap: 0.8rem; margin: 0.6rem 0; }
.track-toggle { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.notif-settings { margin: 0.6rem 0; font-size: 0.85rem; }
.notif-settings summary { cursor: pointer; color: var(--primary); }
.notif-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.notif-form select, .notif-form input[type=number] { padding: 0.3rem; border: 1px solid var(--border); border-radius: 6px; background: var(--cream); color: var(--text); }
.notif-form button { background: var(--gold); color: var(--white); border: none; border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer; }
.plan-module { margin-top: 1rem; }
.plan-module-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.plan-module-header strong { color: var(--primary); min-width: 90px; }
.progress-bar { flex: 1; max-width: 220px; height: 8px; background: var(--cream); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--green); }
.plan-day-grid { display: flex; flex-direction: column; gap: 0.15rem; }
.plan-day-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; padding: 0.15rem 0; border-bottom: 1px solid var(--border); }
.plan-day-num { width: 1.6rem; color: var(--muted); flex-shrink: 0; }
.plan-cell { display: flex; align-items: center; gap: 0.3rem; flex: 1; }
.plan-cell a { color: var(--text); text-decoration: none; }
.plan-cell a:hover { color: var(--primary); text-decoration: underline; }

.plan-marker {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  background: var(--gold-light); border: 1px solid var(--gold);
  border-radius: 10px; padding: 0.9rem;
  margin: 1.5rem 0.75rem 1.5rem 0;
  font-size: 0.9rem; color: var(--primary-dark);
}
.plan-marker.plan-marker-done { background: var(--green-light); border-color: var(--green-mid); }
.plan-marker-mark, .plan-marker-continue {
  border: none; border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer; font-size: 0.85rem;
}
.plan-marker-mark { background: var(--cream); color: var(--text); }
.plan-marker-continue { background: var(--primary); color: var(--white); }
.plan-marker-continue:hover { background: var(--primary-dark); }

#update-banner {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: var(--white);
  padding: 0.7rem 1rem;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(26,17,8,0.25);
  font-size: 0.9rem;
}
#update-banner button {
  margin-left: 0.6rem;
  background: var(--white);
  color: var(--primary-dark);
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-weight: 700;
  cursor: pointer;
}
