/* =========================================================
   Digital Library – styles
   ========================================================= */
:root {
  --ui-font: 'Heebo', 'Assistant', system-ui, sans-serif;
  --display-font: 'Frank Ruhl Libre', 'David Libre', serif;
  --accent: #6c8cff;
  --accent-2: #8f6bff;
  --glass: rgba(255, 255, 255, .08);
  --glass-border: rgba(255, 255, 255, .55);
  --text-on-dark: #f3f6ff;
  --muted-on-dark: rgba(230, 236, 255, .75);
  --card-radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ui-font);
  background: #0b1424;
  color: var(--text-on-dark);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; }

/* ======================= HOME ======================= */
.home {
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: calc(18px + var(--safe-top)) clamp(12px, 3vw, 44px) calc(18px + var(--safe-bottom));
}
.home-bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, rgba(6, 12, 28, .55) 0%, rgba(6, 12, 28, .15) 35%, rgba(6, 12, 28, .25) 60%, rgba(6, 12, 28, .85) 100%),
    url('../resources/Madus_Atlantic_Back.jpg') center / cover no-repeat;
}

.hero-frame {
  position: relative;
  border: 2px solid var(--glass-border);
  border-bottom: none;
  border-radius: 34px 34px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,0) 80%);
  padding: 18px clamp(14px, 3vw, 34px) clamp(90px, 14vh, 150px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}

.topnav {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: #fff; text-decoration: none;
  font-family: var(--display-font); font-weight: 700; font-size: 1.35rem;
  text-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 999px;
  padding: 8px 14px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  width: min(280px, 46vw);
}
.search input {
  all: unset; flex: 1; min-width: 0; color: #fff; font-size: .95rem;
}
.search input::placeholder { color: rgba(255,255,255,.7); }

.hero { text-align: center; margin-top: clamp(28px, 7vh, 70px); }
.pill {
  display: inline-block;
  padding: 6px 14px;
  font-size: .85rem;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.3);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.hero h1 {
  font-family: var(--display-font);
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 4.2rem);
  line-height: 1.1;
  margin: 18px auto 12px;
  max-width: 16ch;
  text-shadow: 0 4px 30px rgba(0,0,0,.55);
}
.hero p {
  margin: 0 auto; max-width: 52ch;
  color: var(--muted-on-dark);
  font-size: clamp(.95rem, 1.6vw, 1.1rem);
  text-shadow: 0 2px 10px rgba(0,0,0,.6);
}

/* ---------- shelf ---------- */
.shelf {
  position: relative;
  margin-top: calc(-1 * clamp(70px, 11vh, 120px));
}
.shelf-track {
  display: flex;
  gap: clamp(16px, 2.5vw, 34px);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  padding: 10px clamp(4px, 2vw, 24px) 24px;
  scrollbar-width: none;
}
.shelf-track::-webkit-scrollbar { display: none; }
.shelf-track.is-centered { justify-content: center; }

.book {
  flex: 0 0 auto;
  width: clamp(150px, 20vw, 230px);
  scroll-snap-align: center;
  text-align: center;
  background: none; border: 0; padding: 0;
  animation: rise .6s both;
}
.book-cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--card-radius);
  overflow: hidden;
  background: linear-gradient(160deg, #ffffff, #e9edf7);
  box-shadow: 0 18px 40px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.4);
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s;
}
.book-cover img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  padding: 6px;
}
.book:hover .book-cover, .book:focus-visible .book-cover {
  transform: translateY(-8px) rotate(-1deg);
  box-shadow: 0 28px 50px rgba(0,0,0,.55), 0 0 0 2px var(--accent);
}
.book:focus-visible { outline: none; }
.badge {
  position: absolute; bottom: 10px; left: 10px;
  background: rgba(255,255,255,.95); color: #222;
  font-size: .75rem; font-weight: 600;
  padding: 4px 8px; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.badge.progress { background: var(--accent); color: #fff; }
.book-title {
  margin: 12px 0 2px;
  font-family: var(--display-font); font-weight: 700;
  font-size: 1.05rem; line-height: 1.25;
  text-shadow: 0 2px 10px rgba(0,0,0,.6);
}
.book-author { margin: 0; font-size: .85rem; color: var(--muted-on-dark); min-height: 1.2em; }

.shelf-arrow {
  position: absolute; top: 38%; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.4);
  background: rgba(10,20,40,.55);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center;
}
.shelf-arrow.prev { right: 0; }
.shelf-arrow.next { left: 0; }
.shelf-empty { text-align: center; color: var(--muted-on-dark); padding: 40px 10px; }

/* ---------- footer ---------- */
.site-footer {
  margin-top: auto;
  padding: 18px 10px 4px;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px;
  font-size: .8rem;
  color: var(--muted-on-dark);
  text-shadow: 0 1px 6px rgba(0,0,0,.7);
  letter-spacing: .02em;
}
.site-footer .version {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  font-variant-numeric: tabular-nums;
}

@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

/* ======================= DETAILS ======================= */
.details { z-index: 10; display: grid; place-items: center; padding: 16px; }
.details-backdrop {
  position: absolute; inset: 0;
  background: rgba(4, 8, 20, .55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .25s both;
}
.details-card {
  position: relative;
  width: min(880px, 100%);
  max-height: 100%;
  overflow: auto;
  background: #fff; color: #1b1b1f;
  border-radius: 32px;
  padding: 20px clamp(18px, 3vw, 34px) 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
  animation: pop .35s cubic-bezier(.2,.9,.3,1.1) both;
}
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bar-title { margin: 0; font-size: 1.05rem; font-weight: 500; }
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.12);
  background: transparent;
  display: grid; place-items: center;
}
.icon-btn[aria-pressed="true"] { background: #111; color: #fff; }

.details-body {
  display: grid;
  grid-template-columns: minmax(200px, 300px) 1fr;
  gap: clamp(18px, 4vw, 40px);
  margin-top: 18px;
  align-items: start;
}
.details-cover img {
  width: 100%; display: block; border-radius: 14px;
}
.details-info h3 {
  font-family: var(--display-font); font-size: clamp(1.5rem, 3vw, 2.1rem);
  margin: 6px 0 4px; line-height: 1.2;
}
.by { color: #777; margin: 0 0 18px; }
.by b { color: #1b1b1f; font-weight: 500; }

.tabs { display: flex; gap: 22px; border-bottom: 1px solid #eee; margin-bottom: 14px; }
.tab {
  background: none; border: 0; padding: 8px 0; color: #aaa;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.is-active { color: #111; border-color: #111; font-weight: 500; }
.tab-panel { min-height: 120px; }
#dDesc {
  margin: 0; line-height: 1.75; font-size: .95rem; color: #444;
  max-height: 14em; overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
          mask-image: linear-gradient(#000 70%, transparent);
  white-space: pre-line;
}
.muted { color: #999 !important; }
.facts { display: grid; gap: 10px; margin: 0 0 14px; }
.facts div { display: flex; justify-content: space-between; border-bottom: 1px dashed #eee; padding-bottom: 8px; }
.facts dt { color: #888; }
.facts dd { margin: 0; font-weight: 500; }
.link-btn { color: #3b5bdb; font-size: .9rem; }

.primary-btn {
  width: 100%; margin-top: 18px;
  padding: 16px; border: 0; border-radius: 16px;
  background: #0d0d0f; color: #fff; font-size: 1.05rem; font-weight: 500;
  transition: transform .15s, background .2s;
}
.primary-btn:hover { background: #2a2a33; }
.primary-btn:active { transform: scale(.98); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(30px) scale(.97); } }

/* ======================= READER ======================= */
.reader {
  z-index: 20;
  display: flex; flex-direction: column;
  --r-bg: #f6ead6; --r-fg: #2a2117; --r-muted: #9a8b75; --r-line: rgba(0,0,0,.1);
  background: var(--r-bg); color: var(--r-fg);
  transition: background .3s, color .3s;
  --r-font: 'Frank Ruhl Libre', serif;
  --r-size: 19px;
  --r-align: justify;
}
.reader[data-bg="white"] { --r-bg: #ffffff; --r-fg: #1b1b1f; --r-muted: #999; }
.reader[data-bg="black"] { --r-bg: #111113; --r-fg: #e4e1da; --r-muted: #777; --r-line: rgba(255,255,255,.14); }
.reader .icon-btn { border-color: var(--r-line); }

.reader-top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-top)) clamp(12px, 3vw, 28px) 8px;
  transition: opacity .25s;
}
.reader-heading {
  flex: 1; min-width: 0; text-align: center;
  display: flex; flex-direction: column; gap: 2px;
}
.reader-heading .eyebrow {
  font-size: .72rem; letter-spacing: .08em; color: var(--r-muted);
  min-height: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-heading strong {
  font-family: var(--display-font); font-size: 1.05rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.reader-stage { position: relative; flex: 1; min-height: 0; }

.page-viewport {
  position: absolute;
  inset: 8px clamp(20px, 6vw, 80px) 8px;
  overflow: hidden;
}
.flow {
  height: 100%;
  column-fill: auto;
  font-family: var(--r-font);
  font-size: var(--r-size);
  line-height: 1.75;
  text-align: var(--r-align);
  hyphens: auto;
  will-change: transform;
  transition: transform .45s cubic-bezier(.25,.8,.25,1);
}
.flow.no-anim { transition: none; }
.flow p { margin: 0 0 .9em; text-indent: 1.4em; orphans: 2; widows: 2; }
.flow p.first, .flow h2 + p { text-indent: 0; }
.flow p.first::first-letter {
  float: right; font-size: 3.1em; line-height: .9; padding-inline-end: .08em; font-weight: 700;
}
.flow[dir="ltr"] p.first::first-letter { float: left; }
.flow h2 {
  break-before: column;
  font-family: var(--display-font);
  text-align: center;
  font-size: 1.35em; line-height: 1.3;
  margin: .6em 0 1.1em;
}
.flow h2:first-child { break-before: auto; }
.flow .end-mark { display: block; height: 1px; }

.reader[data-mode="pdf"] .page-viewport,
.reader[data-mode="pdf"] .turn,
.reader[data-mode="pdf"] .text-only { display: none; }

.pdf-scroll {
  position: absolute; inset: 0;
  overflow: auto;
  padding: 10px clamp(8px, 3vw, 30px) 30px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  border-radius: 4px;
  max-width: 100%;
}
.pdf-page canvas { display: block; width: 100%; height: 100%; border-radius: 4px; }

.turn {
  position: absolute; top: 0; bottom: 0; width: 22%;
  background: transparent; border: 0; padding: 0; z-index: 2;
}
.turn-prev { right: 0; }
.turn-next { left: 0; }
.flow[dir="ltr"] ~ .turn-prev, .reader[data-dir="ltr"] .turn-prev { right: auto; left: 0; }
.reader[data-dir="ltr"] .turn-next { left: auto; right: 0; }
.turn:focus-visible { outline: none; background: linear-gradient(90deg, transparent, rgba(0,0,0,.04)); }

.reader-bottom {
  display: flex; align-items: center; gap: 14px;
  padding: 6px clamp(16px, 4vw, 40px) calc(12px + var(--safe-bottom));
  transition: opacity .25s;
}
.reader-bottom input[type="range"] { flex: 1; accent-color: var(--r-fg); direction: rtl; }
.reader[data-dir="ltr"] .reader-bottom input[type="range"] { direction: ltr; }
.page-num { font-size: .85rem; color: var(--r-muted); min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }

.reader.immersive .reader-top,
.reader.immersive .reader-bottom { opacity: 0; pointer-events: none; }

.loader {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--r-bg); color: var(--r-muted);
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--r-line); border-top-color: var(--r-fg);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- settings sheet ---------- */
.sheet-scrim { position: absolute; inset: 0; z-index: 29; background: rgba(0,0,0,.25); animation: fade .2s both; }
.sheet {
  position: absolute; z-index: 30;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(560px, 100%);
  max-height: 80%;
  overflow: auto;
  background: #fff; color: #1b1b1f;
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  animation: sheetUp .3s cubic-bezier(.2,.9,.3,1) both;
  font-family: var(--ui-font);
}
@keyframes sheetUp { from { transform: translate(-50%, 100%); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: #ddd; margin: 0 auto 10px; }
.setting h4 { margin: 14px 0 8px; font-size: .9rem; font-weight: 600; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  background: #f3f3f5; border-radius: 12px; padding: 4px;
}
.seg button {
  border: 0; background: transparent; border-radius: 9px;
  padding: 9px 4px; font-size: .85rem; color: #888;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.seg button.is-active { background: #fff; color: #111; box-shadow: 0 1px 4px rgba(0,0,0,.1); font-weight: 500; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }

/* ======================= RESPONSIVE ======================= */
@media (max-width: 760px) {
  .hero-frame { border-radius: 26px 26px 0 0; padding-bottom: 80px; }
  .brand span { font-size: 1.1rem; }
  .shelf-arrow { display: none; }
  .book { width: 46vw; max-width: 200px; }

  .details { padding: 0; }
  .details-card { border-radius: 0; height: 100%; padding-top: calc(14px + var(--safe-top)); }
  .details-body { grid-template-columns: 1fr; text-align: center; }
  .details-cover { width: min(230px, 60vw); margin: 0 auto; }
  .tabs { justify-content: center; }
  .details-info { text-align: start; }
  .details-info h3, .by { text-align: center; }
  .primary-btn { position: sticky; bottom: calc(8px + var(--safe-bottom)); }

  .page-viewport { inset: 4px 22px 4px; }

  /* footer: smaller, same look as the hero subtitle */
  .site-footer {
    font-size: .68rem;
    gap: 5px;
    padding-top: 12px;
    color: var(--muted-on-dark);
    text-shadow: 0 2px 10px rgba(0,0,0,.6);
  }
  .site-footer .version {
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
  }
  .seg button { font-size: .78rem; padding: 9px 2px; }
}

@media (max-width: 420px) {
  .search { width: 42vw; padding: 7px 10px; }
  .seg[data-setting="size"] button small,
  .seg[data-setting="size"] button big { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
