/* styles.css */
:root {
  --bg: #090909;
  --panel: rgba(24, 24, 24, 0.76);
  --panel-strong: rgba(35, 34, 31, 0.92);
  --gold: #e8b933;
  --gold-bright: #ffd86f;
  --gold-deep: #7d5a12;
  --gold-glow: rgba(232, 185, 51, 0.22);
  --text: #f5f1e8;
  --muted: rgba(245, 241, 232, 0.60);
  --soft: rgba(255, 255, 255, 0.09);
  --shadow: rgba(0, 0, 0, 0.72);
  --zoom: 1;
  --reader-width: min(88vw, 860px);
  --radius-page: 20px;
  --transition-fast: 0.18s ease;
  --transition-med: 0.32s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(ellipse at 60% -8%, rgba(255, 216, 111, 0.18) 0%, transparent 38%),
    radial-gradient(ellipse at -4% 18%, rgba(232, 185, 51, 0.12) 0%, transparent 36%),
    radial-gradient(ellipse at 50% 100%, rgba(100, 60, 0, 0.14) 0%, transparent 44%),
    linear-gradient(145deg, #040404 0%, #0e0e0e 46%, #050505 100%);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

/* ── AMBIENT LAYERS ── */
#starfield, .spotlight, .grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
#starfield { z-index: 0; opacity: 0.48; }
.spotlight {
  z-index: 1;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 24%), rgba(255, 215, 95, 0.14) 0%, transparent 30rem);
  mix-blend-mode: screen;
  transition: background 0.05s linear;
}
.grain {
  z-index: 2;
  opacity: 0.065;
  background-image:
    repeating-radial-gradient(circle at 17% 29%, rgba(255,255,255,.30) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(255,255,255,.09) 2px 3px);
}

/* ── LOADING SCREEN ── */
.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(3, 3, 3, 0.96);
  backdrop-filter: blur(18px);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.loading.done { opacity: 0; visibility: hidden; pointer-events: none; }

.loading-card {
  width: min(90vw, 460px);
  padding: 40px 36px 34px;
  border: 1px solid rgba(232, 185, 51, 0.32);
  border-radius: 32px;
  background: linear-gradient(155deg, rgba(38, 36, 30, 0.98) 0%, rgba(10, 10, 10, 0.94) 100%);
  box-shadow:
    0 32px 100px rgba(0, 0, 0, 0.72),
    0 0 60px rgba(232, 185, 51, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
}

.loading-mark {
  display: inline-grid;
  place-items: center;
  width: 80px;
  height: 80px;
  margin-bottom: 22px;
  border: 2.5px solid var(--gold);
  border-radius: 6px;
  transform: skew(-8deg);
  color: var(--gold-bright);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  text-shadow: 0 0 24px rgba(255, 216, 111, 0.5);
  box-shadow: 0 0 32px rgba(232, 185, 51, 0.16), inset 0 0 20px rgba(232, 185, 51, 0.06);
  animation: markPulse 2.4s ease-in-out infinite;
}
@keyframes markPulse {
  0%, 100% { box-shadow: 0 0 32px rgba(232,185,51,.16), inset 0 0 20px rgba(232,185,51,.06); }
  50% { box-shadow: 0 0 48px rgba(232,185,51,.30), inset 0 0 28px rgba(232,185,51,.12); }
}

.loading-title {
  margin-bottom: 24px;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}

.loading-bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}
.loading-bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold), var(--gold-bright), #fff);
  box-shadow: 0 0 24px rgba(255, 216, 111, 0.6);
  border-radius: 999px;
  transition: width 0.38s ease;
}

.loading-text {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.83rem;
  letter-spacing: 0.04em;
}

/* ── MASTHEAD ── */
.masthead {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px clamp(16px, 3vw, 42px);
  border-bottom: 1px solid rgba(232, 185, 51, 0.14);
  background: linear-gradient(180deg, rgba(6, 6, 6, 0.92) 0%, rgba(6, 6, 6, 0.60) 100%);
  backdrop-filter: blur(24px) saturate(160%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  transition: opacity var(--transition-fast);
}
.brand:hover { opacity: 0.88; }

.brand-logo {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 56px;
  border: 2px solid var(--gold);
  border-radius: 5px;
  transform: skew(-8deg);
  color: var(--gold-bright);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  box-shadow: 0 0 28px rgba(232, 185, 51, 0.18), inset 0 0 24px rgba(232, 185, 51, 0.07);
  flex-shrink: 0;
}

.brand strong {
  display: block;
  font-size: clamp(0.92rem, 2vw, 1.25rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  line-height: 1.1;
}
.brand em {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-style: normal;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ── TOP NAV BUTTONS ── */
.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.top-actions button {
  border: 1px solid rgba(232, 185, 51, 0.24);
  color: var(--text);
  background: linear-gradient(180deg, rgba(42, 42, 42, 0.90) 0%, rgba(14, 14, 14, 0.90) 100%);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 0.83rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 8px 24px rgba(0, 0, 0, 0.24);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.top-actions button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 216, 111, 0.68);
  background: linear-gradient(180deg, rgba(52, 48, 32, 0.92) 0%, rgba(20, 18, 10, 0.92) 100%);
  box-shadow: 0 0 24px rgba(232, 185, 51, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.09);
}
.top-actions button:active { transform: translateY(0); }

/* ── LAYOUT GRID ── */
.masthead, .layout, .footer-note { position: relative; z-index: 5; }

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: clamp(16px, 2.5vw, 32px);
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px clamp(14px, 3vw, 42px) 16px;
}

/* ── THUMBNAIL PANEL ── */
.thumb-panel {
  align-self: start;
  position: sticky;
  top: 100px;
  padding: 18px 14px;
  border: 1px solid rgba(232, 185, 51, 0.14);
  border-radius: 28px;
  background: linear-gradient(170deg, rgba(28, 28, 24, 0.82) 0%, rgba(8, 8, 8, 0.60) 100%);
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 64px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.panel-title {
  margin-bottom: 14px;
  padding: 0 4px;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.20em;
  text-transform: uppercase;
}

.thumb-rail { display: grid; gap: 8px; }

.thumb {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  text-align: left;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}
.thumb:hover {
  transform: translateX(2px);
  border-color: rgba(255, 216, 111, 0.40);
  background: rgba(232, 185, 51, 0.07);
}
.thumb.active {
  transform: translateX(4px);
  border-color: rgba(255, 216, 111, 0.70);
  background: rgba(232, 185, 51, 0.12);
  box-shadow: 0 0 20px rgba(232, 185, 51, 0.10);
}

.thumb img {
  width: 52px;
  height: 76px;
  object-fit: cover;
  object-position: top;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.44);
  display: block;
}
.thumb .num {
  display: block;
  color: var(--gold-bright);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  margin-bottom: 2px;
}
.thumb .name {
  display: block;
  font-size: 0.80rem;
  line-height: 1.2;
  color: var(--text);
}

/* ── READER AREA ── */
.reader { min-width: 0; padding-bottom: 36px; }

.reader-topline {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
  margin: 0 auto 20px;
  max-width: calc(var(--reader-width) + 112px);
}

.eyebrow {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 0.94;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 0 48px rgba(232, 185, 51, 0.14);
  margin-bottom: 8px;
}

.reader-topline p {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.5;
}

.page-count {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-shadow: 0 0 24px rgba(255, 216, 111, 0.24);
}
.page-count #pageNow {
  font-size: 2.8rem;
  font-family: 'Bebas Neue', sans-serif;
  color: var(--gold-bright);
  line-height: 1;
}
.page-count span:not(#pageNow) { color: rgba(255, 255, 255, 0.30); }

/* ── BOOK SHELL ── */
.book-shell {
  position: relative;
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr) 60px;
  align-items: start;
  gap: 16px;
}

.book-viewport {
  max-height: calc(100vh - 220px);
  min-height: 600px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 28px 30px 38px;
  border: 1px solid rgba(232, 185, 51, 0.13);
  border-radius: 34px;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.06) 0%, transparent 26%),
    radial-gradient(ellipse at 50% 0%, rgba(232, 185, 51, 0.09) 0%, transparent 34rem),
    rgba(8, 8, 8, 0.60);
  box-shadow:
    0 36px 100px rgba(0, 0, 0, 0.50),
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -1px 0 rgba(0, 0, 0, 0.30);
  backdrop-filter: blur(12px);
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 185, 51, 0.40) rgba(255, 255, 255, 0.04);
  transition: box-shadow var(--transition-med);
}
.book-viewport::-webkit-scrollbar { width: 6px; }
.book-viewport::-webkit-scrollbar-track { background: rgba(255,255,255,.04); border-radius: 999px; }
.book-viewport::-webkit-scrollbar-thumb { background: rgba(232,185,51,.38); border-radius: 999px; }
.book-viewport:focus { outline: 2px solid rgba(255, 216, 111, 0.42); outline-offset: 3px; }

.book {
  position: relative;
  width: min(calc(var(--reader-width) * var(--zoom)), 100%);
  margin: 0 auto;
  perspective: 2000px;
  transform-style: preserve-3d;
  transition: width var(--transition-fast);
}
.book.fit-height {
  width: auto;
  max-width: 100%;
  height: calc(100vh - 310px);
}

/* ── PAGE IMAGE ── */
.page-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-page);
  user-select: none;
  background: #0e0e0e;
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow:
    0 40px 100px rgba(0, 0, 0, 0.64),
    0 0 0 1px rgba(232, 185, 51, 0.10),
    0 0 80px rgba(232, 185, 51, 0.08);
  transition: opacity 0.22s ease;
}
.page-image.loading-img { opacity: 0.4; }
.book.fit-height .page-image {
  width: auto;
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
}

/* ── PAGE FX ── */
.page-glow {
  position: absolute;
  inset: 0% -6% auto;
  height: 22%;
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 216, 111, 0.20) 0%, transparent 70%);
  filter: blur(32px);
  opacity: 0.60;
  z-index: -1;
  pointer-events: none;
}

.page-shine {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-page);
  background: linear-gradient(112deg, transparent 18%, rgba(255,255,255,0.12) 40%, transparent 56%);
  mix-blend-mode: screen;
  pointer-events: none;
  transform: translateX(-150%);
}
.book.turning .page-shine { animation: shineSweep 0.76s ease; }
@keyframes shineSweep { to { transform: translateX(150%); } }

/* ── PAGE TURN FLIP SHEET ── */
.flip-sheet {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  display: none;
  background-size: 200% 100%;
  background-repeat: no-repeat;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.flip-sheet.next {
  display: block;
  right: 0;
  border-radius: 0 var(--radius-page) var(--radius-page) 0;
  background-position: right top;
  transform-origin: left center;
  animation: flipNext 0.76s cubic-bezier(0.18, 0.80, 0.14, 1) forwards;
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.50);
}
.flip-sheet.prev {
  display: block;
  left: 0;
  border-radius: var(--radius-page) 0 0 var(--radius-page);
  background-position: left top;
  transform-origin: right center;
  animation: flipPrev 0.76s cubic-bezier(0.18, 0.80, 0.14, 1) forwards;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.50);
}
@keyframes flipNext {
  0%   { transform: rotateY(0deg); filter: brightness(1); }
  45%  { filter: brightness(0.72); }
  100% { transform: rotateY(-172deg); filter: brightness(0.28); }
}
@keyframes flipPrev {
  0%   { transform: rotateY(0deg); filter: brightness(1); }
  45%  { filter: brightness(0.72); }
  100% { transform: rotateY(172deg); filter: brightness(0.28); }
}

/* ── TURN BUTTONS ── */
.turn-btn {
  position: sticky;
  top: 46%;
  z-index: 10;
  width: 58px;
  height: 80px;
  border: 1px solid rgba(232, 185, 51, 0.32);
  border-radius: 999px;
  color: var(--gold-bright);
  background: linear-gradient(180deg, rgba(44, 42, 36, 0.95) 0%, rgba(8, 8, 8, 0.95) 100%);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.38), 0 0 30px rgba(232, 185, 51, 0.08);
  font-size: 3.2rem;
  line-height: 1;
  transition: transform var(--transition-fast), opacity var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.turn-btn:hover:not(:disabled) {
  transform: scale(1.07);
  border-color: rgba(255, 216, 111, 0.72);
  box-shadow: 0 0 40px rgba(232, 185, 51, 0.26), 0 16px 48px rgba(0, 0, 0, 0.40);
}
.turn-btn:active:not(:disabled) { transform: scale(0.97); }
.turn-btn:disabled { opacity: 0.18; cursor: not-allowed; }

/* ── CONTROL STRIP ── */
.control-strip {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  gap: 14px;
  align-items: center;
  max-width: calc(var(--reader-width) + 112px);
  margin: 20px auto 0;
  padding: 16px 18px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 26px;
  background: rgba(14, 14, 14, 0.76);
  backdrop-filter: blur(18px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24);
}

.control-strip button {
  border: 1px solid rgba(232, 185, 51, 0.24);
  color: var(--text);
  background: linear-gradient(180deg, rgba(42, 42, 42, 0.90) 0%, rgba(14, 14, 14, 0.90) 100%);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 0.83rem;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 8px 24px rgba(0,0,0,.22);
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.control-strip button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 216, 111, 0.64);
  box-shadow: 0 0 20px rgba(232, 185, 51, 0.16), inset 0 1px 0 rgba(255,255,255,.09);
}
.control-strip button:disabled { opacity: 0.22; cursor: not-allowed; transform: none; }

/* ── RANGE SLIDER ── */
input[type="range"] {
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) var(--progress, 0%), rgba(255,255,255,.10) var(--progress, 0%));
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #0e0e0e;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 20px rgba(255,216,111,.44);
  transition: transform var(--transition-fast);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.14); }
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2px solid #0e0e0e;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 20px rgba(255,216,111,.44);
}

/* ── FOOTER ── */
.footer-note {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 20px 32px;
  color: rgba(255, 255, 255, 0.28);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.footer-note span {
  display: flex;
  align-items: center;
  gap: 10px;
}
.footer-note span::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(255, 216, 111, 0.80);
  flex-shrink: 0;
}

/* ── RESPONSIVE ── */
@media (max-width: 1060px) {
  .layout { grid-template-columns: 1fr; }
  .thumb-panel { position: relative; top: auto; overflow-x: auto; padding: 14px; }
  .thumb-rail { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
  .thumb { min-width: 178px; flex-shrink: 0; }
  .book-shell { grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 10px; }
  .turn-btn { width: 46px; height: 66px; font-size: 2.6rem; }
}

@media (max-width: 680px) {
  .masthead { flex-direction: column; align-items: flex-start; }
  .top-actions { width: 100%; justify-content: flex-start; }
  .reader-topline { flex-direction: column; align-items: flex-start; }
  .book-shell { grid-template-columns: 1fr; }
  .turn-btn { position: fixed; top: 50%; transform: translateY(-50%); }
  .turn-left { left: 8px; transform: translateY(-50%); }
  .turn-right { right: 8px; transform: translateY(-50%); }
  .turn-btn:hover:not(:disabled) { transform: translateY(-50%) scale(1.07); }
  .book-viewport { min-height: 520px; padding: 14px 12px 22px; border-radius: 24px; }
  .control-strip { grid-template-columns: 1fr; }
  :root { --reader-width: 96vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
