/* ==========================================================================
   reader.css — Bible Reader. Desktop-first.
   Mobile overrides live inside ONE @media block.
   No wrapper classes. No leftover state.
   ========================================================================== */

/* ──────────────────────────────────────────────────────────────────
   1. Page & layout
   ────────────────────────────────────────────────────────────────── */

body.pg-reader {
  background: var(--at-bg, #efe1c0);
  color: var(--at-ink, #1e1408);
  font-family: var(--at-serif, "Iowan Old Style", Palatino, Georgia, serif);
}

.rdr-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 320px;
  gap: 1.25rem;
  max-width: 1560px;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  align-items: start;
}

@media (max-width: 1200px) {
  .rdr-layout {
    grid-template-columns: 200px minmax(0, 1fr) 280px;
  }
}

/* ──────────────────────────────────────────────────────────────────
   2. Sidebar (book list + chapter grid)
   ────────────────────────────────────────────────────────────────── */

.rdr-sidebar {
  background: linear-gradient(180deg, #f8edd4 0%, #ecdcb8 100%);
  border: 1px solid rgba(92, 63, 36, .30);
  border-left: 3px solid #d4af37;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .55),
    0 14px 34px rgba(58, 34, 10, .10);
  padding: 1rem;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.rdr-sidebar h4 {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: #a8822a;
  margin: 1rem 0 .4rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid rgba(74, 14, 24, .2);
}

.rdr-sidebar h4:first-child {
  margin-top: 0;
}

.rdr-book-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rdr-book-list li {
  margin: 0;
}

.rdr-book-list a {
  display: block;
  padding: .35rem .55rem;
  color: #3a2a18;
  text-decoration: none;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .84rem;
  border-left: 2px solid transparent;
  border-radius: 0 3px 3px 0;
  transition: background .12s, border-color .12s, color .12s;
}

.rdr-book-list a:hover {
  background: rgba(212, 175, 55, .12);
  border-left-color: #a8822a;
  color: #4a0e18;
}

.rdr-book-list a.active {
  background: rgba(212, 175, 55, .2);
  border-left-color: #4a0e18;
  color: #4a0e18;
  font-weight: 700;
}

.rdr-chapter-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .25rem;
}

.rdr-chapter-btn {
  display: block;
  text-align: center;
  padding: .35rem .05rem;
  background: rgba(255, 251, 240, .7);
  border: 1px solid rgba(74, 14, 24, .22);
  border-radius: 3px;
  text-decoration: none;
  color: #3a2a18;
  font-size: .8rem;
  font-weight: 700;
  font-family: ui-sans-serif, system-ui, sans-serif;
  transition: background .12s, border-color .12s, color .12s;
}

.rdr-chapter-btn:hover {
  background: rgba(255, 251, 240, .95);
  border-color: #a8822a;
  color: #4a0e18;
}

.rdr-chapter-btn.active {
  background: #4a0e18;
  border-color: #4a0e18;
  color: #f5e0a0;
}

/* ──────────────────────────────────────────────────────────────────
   3. Text area
   ────────────────────────────────────────────────────────────────── */

.rdr-text-area {
  background: linear-gradient(180deg, #f8edd4 0%, #ecdcb8 100%);
  border: 1px solid rgba(92, 63, 36, .30);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .55),
    0 14px 34px rgba(58, 34, 10, .10);
  padding: 1.5rem 1.75rem 1.75rem;
  min-height: 60vh;
}

.rdr-toolbar {
  display: flex;
  justify-content: center;
  gap: .35rem;
  margin: 0 0 1.25rem;
  flex-wrap: wrap;
}

.rdr-tab {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
  padding: .5rem 1rem;
  background: rgba(255, 251, 240, .6);
  border: 1px solid rgba(74, 14, 24, .22);
  color: #6a5538;
  cursor: pointer;
  border-radius: 3px;
  transition: background .12s, color .12s, border-color .12s;
}

.rdr-tab:hover {
  background: rgba(255, 251, 240, .95);
  color: #4a0e18;
}

.rdr-tab.active {
  background: #4a0e18;
  border-color: #4a0e18;
  color: #f5e0a0;
}

.rdr-current-heading {
  font-family: var(--at-serif, "Iowan Old Style", Palatino, Georgia, serif);
  font-size: 1.65rem;
  font-weight: 400;
  color: #4a0e18;
  text-align: center;
  margin: 0 0 1.25rem;
  padding-bottom: .65rem;
  border-bottom: 1px solid rgba(74, 14, 24, .22);
  position: relative;
}

.rdr-current-heading::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  transform: translateX(-50%);
  width: 88px;
  height: 2px;
  background: linear-gradient(90deg, #d4af37, #4a0e18);
}

.rdr-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.rdr-columns[data-layout="kjv"] .rdr-col-web {
  display: none;
}

.rdr-columns[data-layout="kjv"] {
  grid-template-columns: 1fr;
}

.rdr-columns[data-layout="web"] .rdr-col-kjv {
  display: none;
}

.rdr-columns[data-layout="web"] {
  grid-template-columns: 1fr;
}

.rdr-col {
  min-width: 0;
}

.rdr-col-title {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: #a8822a;
  margin: 0 0 .85rem;
  padding-bottom: .45rem;
  border-bottom: 1px solid rgba(74, 14, 24, .2);
}

.rdr-text-body {
  font-size: 1.05rem;
  line-height: 1.8;
  color: #1e1408;
}

.rdr-verse {
  display: inline;
}

.rdr-vnum {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .6rem;
  font-weight: 800;
  color: #a8822a;
  vertical-align: super;
  line-height: 0;
  padding: 0 .15em 0 .35em;
}

.rdr-loading,
.rdr-error {
  text-align: center;
  font-style: italic;
  color: #6a5538;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .9rem;
}

.rdr-error {
  color: #4a0e18;
  font-weight: 700;
  font-style: normal;
}

/* ──────────────────────────────────────────────────────────────────
   4. Context panel
   ────────────────────────────────────────────────────────────────── */

.rdr-context-panel {
  background: linear-gradient(180deg, #f8edd4 0%, #ecdcb8 100%);
  border: 1px solid rgba(92, 63, 36, .30);
  border-left: 3px solid #d4af37;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .55),
    0 14px 34px rgba(58, 34, 10, .10);
  padding: 1.1rem 1.15rem 1.2rem;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.rdr-context-panel h3 {
  font-family: var(--at-serif, "Iowan Old Style", Palatino, Georgia, serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: #4a0e18;
  margin: 0 0 .55rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid rgba(74, 14, 24, .22);
  position: relative;
}

.rdr-context-panel h3::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 56px;
  height: 2px;
  background: linear-gradient(90deg, #d4af37, #4a0e18);
}

.rdr-context-panel h4 {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: #a8822a;
  margin: 1rem 0 .35rem;
}

.rdr-context-panel p {
  margin: 0 0 .7rem;
  font-size: .92rem;
  line-height: 1.6;
  color: #3a2a18;
}

.rdr-ctx-meta {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .65rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #6a5538;
  margin: 0 0 .5rem;
}

.rdr-ctx-empty {
  font-style: italic;
  color: #6a5538;
}

.rdr-ctx-chapter-title {
  font-family: var(--at-serif, "Iowan Old Style", Palatino, Georgia, serif);
  font-size: 1rem;
  font-weight: 400;
  color: #6d1828;
  margin: 0 0 .5rem !important;
}

.rdr-ctx-people {
  list-style: none;
  margin: 0 0 .6rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.rdr-ctx-people li {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .75rem;
  padding: .2rem .55rem;
  background: rgba(255, 251, 240, .7);
  border: 1px solid rgba(74, 14, 24, .22);
  border-left: 2px solid #d4af37;
  border-radius: 2px;
  color: #3a2a18;
}

/* ──────────────────────────────────────────────────────────────────
   5. Term hover
   ────────────────────────────────────────────────────────────────── */

.rdr-term {
  border-bottom: 1px dotted #a8822a;
  color: #4a0e18;
  font-weight: 600;
  padding: 0 .04em;
  cursor: help;
  transition: background .12s;
}

.rdr-term:hover {
  background: rgba(212, 175, 55, .22);
}

.rdr-term-popup {
  position: fixed;
  z-index: 9999;
  max-width: 320px;
  padding: .75rem .95rem .85rem;
  background: linear-gradient(180deg, #f8edd4 0%, #ecdcb8 100%);
  border: 1px solid rgba(74, 14, 24, .4);
  border-left: 4px solid #4a0e18;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .6),
    0 18px 40px rgba(0, 0, 0, .35);
  color: #1e1408;
  font-family: var(--at-serif, "Iowan Old Style", Palatino, Georgia, serif);
  font-size: .92rem;
  line-height: 1.6;
  pointer-events: none;
}

/* ──────────────────────────────────────────────────────────────────
   6. Mobile-only UI is hidden on desktop
   ────────────────────────────────────────────────────────────────── */

.rdr-mobile-bar,
.rdr-backdrop,
.rdr-drawer-close {
  display: none;
}

/* ──────────────────────────────────────────────────────────────────
   7. MOBILE — single @media block, nothing leaks out
   ────────────────────────────────────────────────────────────────── */

@media (max-width: 960px) {

  /* Layout becomes a single column */
  .rdr-layout {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  /* Text area fills the screen and sits above the bottom bar */
  .rdr-text-area {
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    padding: 1rem 1rem 6rem 1rem;
    min-height: auto;
    background: #efe1c0;
  }

  .rdr-columns {
    grid-template-columns: 1fr;
    gap: 1.4rem;
  }

  /* Typography */
  .rdr-current-heading {
    font-size: 1.22rem;
    margin-bottom: .85rem;
  }

  .rdr-text-body {
    font-size: 1.06rem;
    line-height: 1.82;
  }

  .rdr-vnum {
    font-size: .66rem;
  }

  /* Bigger tap targets */
  .rdr-book-list a {
    padding: .7rem .8rem;
    min-height: 46px;
    display: flex;
    align-items: center;
    font-size: .96rem;
  }

  .rdr-chapter-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: .3rem;
  }

  .rdr-chapter-btn {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
  }

  .rdr-tab {
    min-height: 42px;
    padding: .6rem .8rem;
    flex: 1 1 auto;
  }

  /* Sidebar and context panel become bottom sheets.
     Hidden by default. Only .is-open shows them. */
  .rdr-sidebar,
  .rdr-context-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    height: 78vh;
    max-height: 78vh;
    margin: 0;
    padding: 3.5rem 1.1rem 1.5rem;
    background: linear-gradient(180deg, #f8edd4 0%, #ecdcb8 100%);
    border: none;
    border-top: 3px solid #d4af37;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -14px 34px rgba(0, 0, 0, .5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 9001;
    display: none;
  }

  .rdr-sidebar.is-open,
  .rdr-context-panel.is-open {
    display: block;
  }

  /* Drag handle */
  .rdr-sidebar::before,
  .rdr-context-panel::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 4px;
    background: rgba(74, 14, 24, .28);
    border-radius: 2px;
  }

  /* Close button */
  .rdr-drawer-close {
    display: inline-flex;
    position: absolute;
    top: .75rem;
    right: .75rem;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: #4a0e18;
    color: #f5e0a0;
    border: 2px solid #d4af37;
    border-radius: 50%;
    font-family: Arial, sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    z-index: 5;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  }

  /* Bottom action bar */
  .rdr-mobile-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9000;
    gap: .5rem;
    padding: .55rem .6rem calc(.55rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, #1a1408 0%, #0e0a04 100%);
    border-top: 2px solid #d4af37;
    box-shadow: 0 -6px 22px rgba(0, 0, 0, .5);
  }

  .rdr-mobile-btn {
    flex: 1 1 0;
    min-height: 48px;
    padding: .7rem .5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: #e8d9b6;
    background: rgba(212, 175, 55, .12);
    border: 1px solid rgba(212, 175, 55, .45);
    border-radius: 4px;
    cursor: pointer;
  }

  .rdr-mobile-btn .ico {
    font-size: 1rem;
    line-height: 1;
  }

  /* Backdrop */
  .rdr-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 8999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  .rdr-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Lock background scroll when a sheet is open */
  body.rdr-drawer-open {
    overflow: hidden;
  }
}

/* ──────────────────────────────────────────────────────────────────
   8. Reduced motion
   ────────────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .rdr-backdrop,
  .rdr-book-list a,
  .rdr-chapter-btn,
  .rdr-tab,
  .rdr-term {
    transition: none !important;
  }
}
