/* ─── Font stacks ─────────────────────────── */
:root {
  --font-latin:  'EB Garamond', Garamond, Georgia, serif;
  --font-greek:  'Gentium Plus', Georgia, serif;
  --font-hebrew: 'Noto Serif Hebrew', serif;

  --bg:          #fefefe;
  --bg-card:     #f5f4f1;
  --bg-sheet:    #eeecea;
  --bg-hover:    #e4e1dc;
  --accent:      #1e3a5f;
  --accent-dim:  #152a46;
  --text:        #111111;
  --text-dim:    #4a4540;
  --border:      #d4cfc6;
  --header-h:    56px;
  --nav-h:       64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);

  /* ── MD3 color system tokens ────────────────────────────── */
  --md-sys-color-primary:            #1e3a5f;
  --md-sys-color-primary-container:  #e4ecf5;
  --md-sys-color-on-primary:         #ffffff;
  --md-sys-color-secondary:          #3d5a8a;
  --md-sys-color-secondary-container:#dce8f5;
  --md-sys-color-on-secondary:       #ffffff;
  --md-sys-color-surface:            #f5f4f1;
  --md-sys-color-surface-variant:    #e4e1dc;
  --md-sys-color-surface-container:  #eeecea;
  --md-sys-color-background:         #fefefe;
  --md-sys-color-on-surface:         #111111;
  --md-sys-color-on-surface-variant: #4a4540;
  --md-sys-color-outline:            #d4cfc6;
  --md-sys-color-outline-variant:    #e0dbd3;
  --md-sys-color-error:              #b00020;

  /* ── MD3 elevation shadows (lighter for light theme) ────── */
  --md-sys-elevation-level1: 0 1px 2px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  --md-sys-elevation-level2: 0 1px 2px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.06);
  --md-sys-elevation-level3: 0 4px 8px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.06);

  /* ── MD3 shape tokens ───────────────────────────────────── */
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small:       8px;
  --md-sys-shape-corner-medium:      12px;
  --md-sys-shape-corner-large:       16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full:        9999px;

  /* ── MD3 motion tokens ──────────────────────────────────── */
  --md-sys-motion-easing-standard:       cubic-bezier(0.2, 0, 0, 1);
  --md-sys-motion-easing-emphasized:     cubic-bezier(0.2, 0, 0, 1);
  --md-sys-motion-duration-short2:       100ms;
  --md-sys-motion-duration-medium2:      300ms;
  --md-sys-motion-duration-long2:        500ms;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-latin);
  font-size: 18px;
  line-height: 1.7;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* ─── Header ─── */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 12px;
  z-index: 100;
}
.app-title {
  font-size: 18px; font-weight: 600;
  letter-spacing: .04em; color: var(--accent);
  pointer-events: none;
}
.header-btn {
  background: none; border: none;
  color: var(--text); cursor: pointer;
  padding: 8px; border-radius: 8px;
  font-size: 15px; transition: background .15s;
}
.header-btn:hover { background: var(--bg-hover); }
.icon-btn svg {
  width: 22px; height: 22px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#header-ref { font-size: 14px; font-weight: 500; color: var(--text-dim); }
.header-actions { display: flex; gap: 4px; }

/* ─── Main reading area ─── */
#app-main {
  margin-top: calc(var(--header-h) + var(--safe-top));
  margin-bottom: calc(var(--nav-h) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: calc(100vh - var(--header-h) - var(--safe-top) - var(--nav-h) - var(--safe-bottom));
  padding: 16px;
}

/* ─── Verse blocks ─── */
.version-block { margin-bottom: 32px; }
.version-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.verse-row {
  display: flex; gap: 10px;
  padding: 6px 4px; border-radius: 6px;
  transition: background .1s;
}
.verse-row:hover { background: var(--bg-hover); }
.verse-num {
  flex: 0 0 28px; font-size: 12px;
  font-weight: 700; color: var(--accent-dim);
  padding-top: 3px; text-align: right;
  user-select: none;
}
.verse-text { flex: 1; font-size: 17px; line-height: 1.85; }

/* ─── Language-specific styles ─── */
.lang-grc .verse-text, .lang-grc .word-token {
  font-family: var(--font-greek);
  font-size: 18px; line-height: 2;
}
.lang-heb .verse-text, .lang-heb .word-token {
  font-family: var(--font-hebrew);
  direction: rtl; text-align: right;
  font-size: 20px; line-height: 2.2;
  unicode-bidi: bidi-override;
}
.lang-heb .verse-row { flex-direction: row-reverse; }
.lang-heb .verse-num { text-align: left; }

/* ─── Tappable words (lexicon) ─── */
.word-token {
  display: inline; cursor: pointer;
  border-radius: 3px; padding: 1px 0;
  transition: background .1s, color .1s;
}
.word-token:hover, .word-token.active {
  background: var(--accent); color: #fff;
  border-radius: 3px; padding: 1px 3px;
}

/* ─── Error message ─── */
.error-msg {
  color: var(--text-dim); font-style: italic; font-size: 14px; padding: 8px 0;
}

/* ─── Bottom Nav ─── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex; z-index: 100;
}
.nav-tab {
  flex: 1; background: none; border: none;
  color: var(--text-dim);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; font-size: 11px; cursor: pointer;
  transition: color .15s;
}
.nav-tab svg {
  width: 22px; height: 22px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.nav-tab.active { color: var(--accent); }

/* ─── Bottom Sheets ─── */
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg-sheet);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border); border-bottom: none;
  padding: 12px 20px calc(20px + var(--safe-bottom));
  z-index: 200; max-height: 80vh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(0);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.bottom-sheet.hidden {
  transform: translateY(100%);
  pointer-events: none;
}
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border); border-radius: 2px;
  margin: 0 auto 16px;
}
.sheet-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 16px;
}
.sheet-header h2 { font-size: 17px; font-weight: 600; }

/* ─── Overlay ─── */
#overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190; transition: opacity .25s;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

/* ─── Versions list ─── */
#versions-list { margin-bottom: 16px; }
.version-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.version-item:last-child { border-bottom: none; }
.version-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.version-check.on { background: var(--accent); border-color: var(--accent); }
.version-check.on::after { content: '✓'; color: #fff; font-size: 13px; }
.version-info { flex: 1; }
.version-name { font-size: 15px; font-weight: 600; }
.version-meta { font-size: 12px; color: var(--text-dim); }
.mode-toggle {
  display: flex; background: var(--bg);
  border-radius: 8px; padding: 3px; gap: 2px;
}
.mode-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 13px; padding: 5px 12px; border-radius: 6px;
  cursor: pointer; transition: background .15s, color .15s;
}
.mode-btn.active { background: var(--accent); color: #fff; }

/* ─── Lexicon panel ─── */
#lex-lemma { font-family: var(--font-greek); font-size: 24px; }
#lex-selector {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 6px 10px;
  border-radius: 8px; font-size: 13px;
}
.lex-row {
  display: flex; justify-content: space-between;
  align-items: baseline; padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px; gap: 12px;
}
.lex-label { color: var(--text-dim); flex-shrink: 0; }
.lex-def { font-size: 16px; line-height: 1.7; padding-top: 8px; }

/* ─── Nav panel ─── */
.nav-body { display: flex; flex-direction: column; gap: 12px; }
.nav-body select {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 12px; border-radius: 10px; font-size: 16px;
}
#nav-book optgroup { font-weight: 700; color: var(--accent); background: var(--bg); }
#nav-book option  { font-weight: 400; color: var(--text); background: var(--bg); }

/* ─── Buttons ─── */
.action-btn {
  width: 100%; background: var(--accent); color: #fff;
  border: none; border-radius: 12px; padding: 14px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.action-btn:hover { background: var(--accent-dim); }
.action-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ─── Settings ─── */
.settings-body { display: flex; flex-direction: column; gap: 16px; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 15px;
}
#offline-status { color: var(--text-dim); font-size: 14px; }

/* ─── Loading ─── */
.loading {
  text-align: center; color: var(--text-dim);
  padding: 48px 0; animation: pulse 1.4s infinite;
}
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:1} }