/**
 * Sacred Scrolls — library + parchment reader styles.
 */
:root {
  --sc-bg: #140e0a;
  --sc-mid: #24180f;
  --sc-ink: #3a2412;
  --sc-ink-soft: #5c3d24;
  --sc-gold: #c9a050;
  --sc-saffron: #c45c26;
  --sc-text: #f3e8d8;
  --sc-muted: #b8a08a;
  --sc-border: rgba(201, 160, 80, 0.28);
  --sc-font: "Outfit", system-ui, sans-serif;
  --sc-display: "Fraunces", Georgia, serif;
  --sc-deva: "Noto Serif Devanagari", "Fraunces", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body.scrolls-page,
body.scroll-reader-page {
  margin: 0;
  min-height: 100%;
  font-family: var(--sc-font);
  background: var(--sc-bg);
  color: var(--sc-text);
}

/* ——— Shared chrome ——— */
.sc-top,
.sr-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--sc-border);
  background: rgba(20, 14, 10, 0.92);
  position: sticky;
  top: 0;
  z-index: 20;
}

.sc-top h1,
.sr-top h1 {
  margin: 0;
  font-family: var(--sc-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.sc-back {
  color: var(--sc-muted);
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
}

.sc-back:hover {
  color: var(--sc-gold);
}

.sc-badge {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #1a1008;
  background: var(--sc-gold);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-weight: 600;
}

.sc-badge.muted {
  background: transparent;
  color: var(--sc-muted);
  border: 1px solid var(--sc-border);
}

.sc-btn {
  display: inline-block;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  background: var(--sc-saffron);
  color: #1a1008;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ——— Library ——— */
.sc-library {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.sc-hero {
  text-align: center;
  margin-bottom: 2rem;
}

.sc-eyebrow {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--sc-gold);
}

.sc-hero h2 {
  margin: 0.4rem 0 0;
  font-family: var(--sc-display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.sc-lead {
  margin: 0.65rem auto 0;
  max-width: 36rem;
  color: var(--sc-muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.sc-loading {
  text-align: center;
  color: var(--sc-muted);
}

.sc-collection {
  margin-bottom: 2.25rem;
}

.sc-collection-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--sc-border);
}

.sc-collection-head h3 {
  margin: 0;
  font-family: var(--sc-display);
  font-size: 1.35rem;
  color: var(--sc-gold);
}

.sc-collection-head .sa {
  font-family: var(--sc-deva);
  color: var(--sc-muted);
  font-size: 1.05rem;
}

.sc-collection-blurb {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--sc-muted);
}

.sc-scroll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.1rem;
}

.sc-scroll-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  text-decoration: none;
  color: inherit;
  padding: 0.75rem 0.5rem 1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.sc-scroll-card:hover {
  transform: translateY(-4px);
  border-color: var(--sc-border);
  background: rgba(201, 160, 80, 0.08);
}

.sc-scroll-thumb {
  width: 110px;
  height: 170px;
  position: relative;
  margin-bottom: 0.75rem;
  /* CSS mini parchment (no bitmap) */
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 245, 220, 0.55), transparent 50%),
    linear-gradient(165deg, #e8d4a8 0%, #d4b888 40%, #c4a06a 100%);
  border-radius: 4px 4px 6px 6px;
  clip-path: polygon(
    2% 4%, 6% 0%, 94% 0%, 98% 4%,
    100% 8%, 97% 50%, 100% 92%,
    98% 96%, 94% 100%, 6% 100%, 2% 96%,
    0% 92%, 3% 50%, 0% 8%
  );
  box-shadow:
    inset 0 0 20px rgba(90, 50, 20, 0.18),
    0 10px 18px rgba(0, 0, 0, 0.45);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.25));
}

.sc-scroll-thumb::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: 0;
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, #4a3020, #7a5438 40%, #4a3020);
  box-shadow: 0 160px 0 0 #4a3020;
}

.sc-scroll-thumb::after {
  content: attr(data-label);
  position: absolute;
  inset: 28% 18% 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sc-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--sc-ink);
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
}

.sc-scroll-card strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.sc-scroll-card span {
  display: block;
  font-size: 0.72rem;
  color: var(--sc-muted);
  line-height: 1.35;
}

body.scrolls-page.is-locked .sc-scroll-card {
  pointer-events: none;
  opacity: 0.45;
  filter: grayscale(0.35);
}

/* ——— Gate ——— */
.sc-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(10, 6, 4, 0.72);
  backdrop-filter: blur(6px);
  padding: 1.5rem;
}

.sc-gate-card {
  max-width: 380px;
  text-align: center;
  background: #1c120c;
  border: 1px solid var(--sc-border);
  border-radius: 16px;
  padding: 2rem 1.5rem;
}

.sc-gate-om {
  display: block;
  font-size: 2rem;
  color: var(--sc-gold);
  margin-bottom: 0.5rem;
}

.sc-gate-card h2 {
  margin: 0;
  font-family: var(--sc-display);
}

.sc-gate-card p {
  color: var(--sc-muted);
  line-height: 1.45;
  font-size: 0.9rem;
}

/* ——— Reader ——— */
body.scroll-reader-page {
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 20%, #2a1c12 0%, transparent 55%),
    var(--sc-bg);
}

body.scroll-reader-page.is-fullscreen .sr-top {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
}

body.scroll-reader-page.is-fullscreen .sr-hint {
  opacity: 0;
  height: 0;
  margin: 0;
  overflow: hidden;
}

body.scroll-reader-page.is-fullscreen .sr-stage {
  height: 100vh;
  padding: 1rem;
}

body.scroll-reader-page.is-fullscreen .sr-parchment {
  width: min(96vw, 520px);
  max-height: min(86vh, 780px);
}

body.scroll-reader-page.is-fullscreen .sr-controls {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  opacity: 0.35;
  transition: opacity 0.3s ease;
}

body.scroll-reader-page.is-fullscreen .sr-controls:hover,
body.scroll-reader-page.is-fullscreen .sr-controls:focus-within {
  opacity: 1;
}

.sr-heading {
  text-align: center;
  min-width: 0;
  flex: 1;
}

.sr-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--sc-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sr-icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--sc-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--sc-text);
  cursor: pointer;
  font-size: 1rem;
}

.sr-top {
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.sr-stage {
  height: calc(100vh - 3.6rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem 1.25rem;
  gap: 0.75rem;
  touch-action: none;
}

/* ——— CSS / JS parchment object ——— */
.sr-parchment {
  position: relative;
  width: min(92vw, 400px);
  max-height: min(72vh, 640px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  filter: drop-shadow(0 22px 48px rgba(0, 0, 0, 0.55));
}

.sr-roller {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 1.35rem;
  flex-shrink: 0;
}

.sr-roller-bar {
  flex: 1;
  height: 0.85rem;
  border-radius: 999px;
  background:
    repeating-linear-gradient(
      90deg,
      #3d2818 0 3px,
      #5a3c28 3px 6px,
      #2a1810 6px 8px
    ),
    linear-gradient(180deg, #7a5438 0%, #4a3020 45%, #2a1810 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 220, 160, 0.25),
    inset 0 -2px 4px rgba(0, 0, 0, 0.45),
    0 2px 6px rgba(0, 0, 0, 0.35);
  margin: 0 0.15rem;
}

.sr-roller-knob {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #a07850, #5a3820 55%, #2a1810);
  box-shadow:
    inset 0 2px 3px rgba(255, 220, 180, 0.35),
    0 2px 4px rgba(0, 0, 0, 0.4);
  flex-shrink: 0;
}

.sr-sheet {
  position: relative;
  flex: 1 1 auto;
  min-height: 280px;
  margin: -0.15rem 0.85rem;
  /* Aged parchment — layered CSS gradients */
  background:
    radial-gradient(ellipse at 18% 12%, rgba(255, 248, 230, 0.55), transparent 42%),
    radial-gradient(ellipse at 82% 88%, rgba(160, 100, 50, 0.18), transparent 45%),
    radial-gradient(ellipse at 50% 50%, rgba(210, 170, 100, 0.15), transparent 70%),
    linear-gradient(
      168deg,
      #f0e0c0 0%,
      #e4cfa0 22%,
      #d8bc88 48%,
      #c9a870 72%,
      #d4b888 100%
    );
  /* Soft torn / deckled side edges */
  clip-path: polygon(
    0% 1%, 1.5% 0%, 3% 1.2%, 5% 0.2%, 8% 1%, 12% 0%, 18% 0.8%,
    25% 0%, 35% 0.6%, 50% 0%, 65% 0.7%, 75% 0%, 85% 0.5%, 92% 0%,
    96% 1%, 98.5% 0.2%, 100% 1.5%,
    99% 8%, 100% 18%, 98.5% 30%, 100% 42%, 99% 55%, 100% 68%,
    98.8% 80%, 100% 90%, 99% 96%,
    100% 98.5%, 98% 100%, 94% 98.8%, 88% 100%, 78% 99%, 65% 100%,
    50% 99.2%, 35% 100%, 22% 99%, 12% 100%, 6% 98.5%, 2% 100%, 0% 98%,
    1% 90%, 0% 78%, 1.5% 65%, 0% 52%, 1.2% 38%, 0% 25%, 1% 12%
  );
  box-shadow:
    inset 0 0 40px rgba(90, 50, 20, 0.12),
    inset 0 0 80px rgba(60, 30, 10, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sr-texture {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.45;
  mix-blend-mode: multiply;
  z-index: 1;
}

.sr-flourish {
  position: relative;
  z-index: 2;
  width: 72%;
  max-width: 220px;
  height: auto;
  margin: 0.85rem auto 0;
  opacity: 0.72;
  flex-shrink: 0;
}

.sr-flourish-bottom {
  margin: auto auto 0.85rem;
}

.sr-text {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0.35rem 12% 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.sr-text.is-exit-up {
  opacity: 0;
  transform: translateY(-18px);
}

.sr-text.is-exit-down {
  opacity: 0;
  transform: translateY(18px);
}

.sr-text.is-enter {
  animation: sr-enter 0.35s ease forwards;
}

@keyframes sr-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.sr-ref {
  margin: 0 0 0.55rem;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sc-ink-soft);
  font-weight: 600;
}

.sr-sa {
  margin: 0;
  font-family: var(--sc-deva);
  font-size: clamp(0.95rem, 3.6vw, 1.25rem);
  font-weight: 700;
  color: var(--sc-ink);
  line-height: 1.55;
}

.sr-en {
  margin: 0.65rem 0 0;
  font-family: var(--sc-display);
  font-size: clamp(0.78rem, 2.8vw, 0.98rem);
  color: var(--sc-ink-soft);
  line-height: 1.45;
  font-style: italic;
}

.sr-meaning {
  margin: 0.7rem 0 0;
  font-size: clamp(0.72rem, 2.5vw, 0.86rem);
  color: #4a3220;
  line-height: 1.45;
  border-top: 1px solid rgba(58, 36, 18, 0.2);
  padding-top: 0.55rem;
  max-width: 100%;
}

.sr-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-shrink: 0;
}

.sr-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--sc-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--sc-text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.sr-nav-btn:hover:not(:disabled) {
  border-color: var(--sc-gold);
  color: var(--sc-gold);
}

.sr-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.sr-progress {
  margin: 0;
  font-variant-numeric: tabular-nums;
  color: var(--sc-gold);
  font-size: 0.9rem;
  min-width: 3.5rem;
  text-align: center;
}

.sr-hint {
  margin: 0;
  font-size: 0.7rem;
  color: var(--sc-muted);
  text-align: center;
  max-width: 22rem;
  line-height: 1.4;
  transition: opacity 0.3s ease;
}

/* Floating FS exit when native chrome is hidden */
.sr-fs-exit {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--sc-border);
  background: rgba(20, 14, 10, 0.75);
  color: var(--sc-gold);
  cursor: pointer;
  display: none;
  place-items: center;
  font-size: 1.1rem;
}

body.scroll-reader-page.is-fullscreen .sr-fs-exit {
  display: grid;
}

@media (max-width: 480px) {
  .sc-scroll-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .sr-nav-btn span {
    display: none;
  }

  .sr-hint {
    display: none;
  }

  .sr-parchment {
    width: min(96vw, 360px);
  }

  .sr-text {
    margin-left: 10%;
    margin-right: 10%;
  }
}
