:root {
  color-scheme: dark;
  --bg: #050d18;
  --bg-soft: #091728;
  --panel: rgba(8, 19, 34, .84);
  --line: rgba(177, 196, 217, .16);
  --line-strong: rgba(177, 196, 217, .28);
  --text: #f6f8fb;
  --muted: #91a2b5;
  --accent: #62c7ff;
  --accent-soft: #b9e8ff;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 35%, rgba(33, 78, 122, .24), transparent 38%),
    linear-gradient(155deg, #071426 0%, #040d19 62%, #020711 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.reader {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 68px 2px minmax(0, 1fr) 30px;
  padding-inline: max(14px, env(safe-area-inset-left));
  isolation: isolate;
}

.topbar {
  position: relative;
  z-index: 50;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.brand { width: max-content; max-width: 100%; display: grid; gap: 3px; color: inherit; text-decoration: none; }
.brand span { color: var(--accent); font-size: 9px; line-height: 1; font-weight: 850; letter-spacing: .20em; }
.brand strong { max-width: 310px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 clamp(20px, 1.8vw, 30px)/1 Georgia, "Times New Roman", serif; }
.toolbar { display: flex; align-items: center; justify-content: center; gap: 7px; }
.tool, .page-control {
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(4, 13, 25, .72);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.035), 0 8px 22px rgba(0,0,0,.08);
  backdrop-filter: blur(16px);
}
.tool { display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; cursor: pointer; transition: transform .2s ease, border-color .2s ease, background .2s ease, opacity .2s ease; }
.tool:hover { transform: translateY(-1px); border-color: rgba(98,199,255,.62); background: rgba(15, 40, 68, .82); }
.tool:disabled { opacity: .22; cursor: default; transform: none; }
.tool--square { width: 40px; padding: 0; }
.tool--text { min-width: 48px; padding: 0 12px; font-size: 11px; font-weight: 760; }
.tool--read { color: #fff; }
.tool--pdf { color: var(--accent-soft); }
.page-control { display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--muted); font-size: 11px; }
.page-control input { width: 40px; padding: 2px 1px 3px; border: 0; border-bottom: 1px solid rgba(173,200,232,.45); background: transparent; color: #fff; text-align: center; outline: none; }
.toolbar-separator { width: 1px; height: 24px; margin: 0 3px; background: var(--line); }
.close-button { justify-self: end; width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: transparent; color: #fff; opacity: .7; cursor: pointer; transition: opacity .2s ease, transform .25s ease; }
.close-button:hover { opacity: 1; transform: rotate(90deg); }
.close-button svg { width: 24px; height: 24px; }

.reading-progress { position: relative; z-index: 55; height: 2px; background: rgba(73,105,141,.20); }
.reading-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg,#35b5ff,#b9eaff); box-shadow: 0 0 14px rgba(98,199,255,.5); transition: width .3s var(--ease); }
.reader-main { position: relative; min-height: 0; display: grid; }
.stage { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.stage-light { position: absolute; width: min(78vw, 1450px); height: min(70vw, 980px); border-radius: 50%; background: radial-gradient(circle, rgba(45,108,166,.16), transparent 68%); filter: blur(36px); pointer-events: none; }

.book-shell { position: absolute; z-index: 5; inset: 8px 70px 6px; display: flex; align-items: center; justify-content: center; overflow: visible; opacity: 0; transform: translateY(8px); transition: opacity .35s ease, transform .35s ease; }
.reader.is-ready .book-shell { opacity: 1; transform: none; }
.book-mount { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 34px 56px rgba(0,0,0,.34)); }
.book-mount .stf__parent { margin: auto !important; }
.book-mount .stf__block { perspective: 3600px !important; }
.book-mount .stf__item { overflow: visible !important; }

.mag-page { background: #fff; }
.mag-page__paper { position: relative; width: 100%; height: 100%; overflow: hidden; background: #fff; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.035); }
.mag-page__paper::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 22px rgba(10,18,28,.035); }
.mag-page img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: contain; background: #fff; opacity: 0; transition: opacity .22s ease; user-select: none; -webkit-user-drag: none; }
.mag-page.is-rendered img { opacity: 1; }
.mag-page__placeholder { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 11px; background: linear-gradient(110deg,#f7f7f5 20%,#ececea 36%,#f7f7f5 52%); background-size: 230% 100%; animation: shimmer 1.3s linear infinite; color: #8792a0; }
.mag-page.is-rendered .mag-page__placeholder { opacity: 0; visibility: hidden; }
.mag-page__placeholder span { width: 32px; height: 32px; border: 2px solid rgba(54,90,121,.18); border-top-color: #3f8ec7; border-radius: 50%; animation: spin .8s linear infinite; }
.mag-page__placeholder small { font-size: 10px; }
.mag-page__folio { position: absolute; z-index: 3; bottom: 8px; right: 9px; min-width: 22px; padding: 4px 6px; border-radius: 999px; background: rgba(7,15,25,.55); color: rgba(255,255,255,.82); font-size: 8px; line-height: 1; text-align: center; opacity: 0; transition: opacity .2s ease; backdrop-filter: blur(7px); }
.mag-page:hover .mag-page__folio { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -230% 0; } }

.edge { position: absolute; z-index: 20; top: 50%; width: 48px; height: 112px; transform: translateY(-50%); display: grid; place-items: center; border: 1px solid rgba(145,188,226,.08); border-radius: 17px; background: rgba(4,15,31,.14); color: rgba(255,255,255,.70); backdrop-filter: blur(8px); cursor: pointer; transition: background .2s ease, color .2s ease, border-color .2s ease, transform .2s ease, opacity .2s ease; }
.edge svg { width: 31px; height: 31px; stroke-width: 1.45; }
.edge:hover { color: #fff; border-color: rgba(111,193,244,.24); background: rgba(15,49,84,.42); transform: translateY(-50%) scale(1.035); }
.edge:disabled { opacity: .14; cursor: default; transform: translateY(-50%); }
.edge--prev { left: 3px; }
.edge--next { right: 3px; }

.loading-card { position: relative; z-index: 30; width: min(360px, calc(100% - 40px)); display: grid; justify-items: center; gap: 11px; padding: 24px 28px 22px; border: 1px solid rgba(135,181,222,.16); border-radius: 18px; background: rgba(4,13,25,.90); box-shadow: 0 26px 60px rgba(0,0,0,.26), inset 0 1px 0 rgba(255,255,255,.03); backdrop-filter: blur(22px); color: var(--muted); text-align: center; transition: opacity .25s ease, transform .25s ease, visibility .25s ease; }
.loading-card.is-hidden { opacity: 0; visibility: hidden; transform: translateY(8px) scale(.98); pointer-events: none; }
.loading-card strong { color: #f6faff; font: 500 23px Georgia,serif; }
.loading-card > span { font-size: 12px; }
.loader-ring { width: 50px; height: 50px; display: grid; place-items: center; border: 1px solid rgba(93,184,241,.22); border-radius: 50%; }
.loader-ring i { width: 30px; height: 30px; border: 2px solid rgba(108,190,240,.18); border-top-color: var(--accent); border-radius: 50%; animation: spin .78s linear infinite; }
.loader-track { width: 100%; height: 2px; margin-top: 7px; overflow: hidden; background: rgba(132,160,193,.16); }
.loader-track i { display: block; width: 2%; height: 100%; background: linear-gradient(90deg,#38b4ff,#b8e7ff); transition: width .2s ease; }
.error-card { position: relative; z-index: 35; max-width: 560px; padding: 26px; border: 1px solid rgba(255,145,160,.25); border-radius: 16px; background: rgba(67,17,29,.42); color: #ffdbe1; text-align: center; line-height: 1.55; }
.error-card strong { font: 500 24px Georgia,serif; }
.error-card p { margin: 10px 0 18px; color: #e9bbc4; font-size: 13px; }
.error-card a { color: #8bd7ff; }

.thumbs-drawer { position: absolute; z-index: 70; inset: 0 auto 0 0; width: min(340px, calc(100vw - 42px)); display: grid; grid-template-rows: auto minmax(0,1fr); border-right: 1px solid var(--line); background: rgba(4,13,25,.97); box-shadow: 24px 0 60px rgba(0,0,0,.42); backdrop-filter: blur(22px); transform: translateX(-105%); visibility: hidden; transition: transform .32s var(--ease), visibility .32s; }
.thumbs-drawer.is-open { transform: translateX(0); visibility: visible; }
.thumbs-head { min-height: 70px; display: flex; align-items: center; justify-content: space-between; padding: 14px 17px; border-bottom: 1px solid var(--line); }
.thumbs-head div { display: grid; gap: 3px; }
.thumbs-head span { color: var(--accent); font-size: 9px; font-weight: 850; letter-spacing: .16em; }
.thumbs-head strong { font: 500 21px Georgia,serif; }
.thumbs-head button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: #fff; cursor: pointer; font-size: 22px; }
.thumbs-list { min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-content: start; gap: 14px; padding: 18px; }
.thumb { display: grid; gap: 7px; padding: 7px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #b4c4d7; cursor: pointer; text-align: center; transition: border-color .2s ease, background .2s ease, color .2s ease; }
.thumb:hover { background: rgba(26,61,98,.42); color: #fff; }
.thumb.is-active { border-color: rgba(74,187,255,.7); background: rgba(27,74,117,.48); color: #fff; }
.thumb__image { aspect-ratio: 680 / 907; overflow: hidden; background: rgba(255,255,255,.07); box-shadow: 0 9px 18px rgba(0,0,0,.3); }
.thumb__image img { width: 100%; height: 100%; display: block; object-fit: contain; background: #fff; }
.thumb > span:last-child { font-size: 10px; }

.reader-footer { min-height: 30px; display: flex; align-items: center; justify-content: center; gap: 9px; color: rgba(153,175,201,.62); font-size: 9px; letter-spacing: .02em; }
.reader-footer i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .42; }

.focus-viewer { position: fixed; z-index: 200; inset: 0; display: grid; grid-template-rows: 62px minmax(0,1fr); background: rgba(2,7,14,.98); backdrop-filter: blur(20px); opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility .25s; }
.focus-viewer.is-open { opacity: 1; visibility: visible; }
.focus-viewer header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.focus-viewer header > button { width: 42px; height: 42px; display: grid; place-items: center; border: 0; background: transparent; color: #fff; cursor: pointer; }
.focus-viewer header > button svg { width: 25px; height: 25px; }
.focus-tools { grid-column: 2; display: flex; gap: 7px; }
.focus-tools button { height: 40px; min-width: 42px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: rgba(10,27,50,.82); color: #fff; cursor: pointer; }
.focus-viewport { min-height: 0; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 22px; cursor: zoom-in; }
.focus-viewport.is-zoomed { justify-content: flex-start; cursor: grab; }
.focus-viewport img { display: block; width: min(100%, 1120px); height: auto; transform-origin: top center; box-shadow: 0 26px 80px rgba(0,0,0,.56); transition: transform .18s ease; }
.focus-open { overflow: hidden; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: minmax(160px,1fr) auto 44px; gap: 12px; }
  .toolbar { gap: 5px; }
  .tool--text span { display: none; }
  .tool--text { min-width: 40px; width: 40px; padding: 0; }
  .toolbar-separator { display: none; }
  .book-shell { inset-inline: 56px; }
}

@media (max-width: 820px) {
  .reader { grid-template-rows: 108px 2px minmax(0,1fr) 26px; padding-inline: max(8px,env(safe-area-inset-left)); }
  .topbar { grid-template-columns: minmax(0,1fr) 40px; align-content: center; gap: 7px 10px; padding: 8px 0 7px; }
  .brand { grid-column: 1; grid-row: 1; }
  .brand strong { max-width: min(72vw,330px); font-size: 19px; }
  .close-button { grid-column: 2; grid-row: 1; }
  .toolbar { grid-column: 1 / -1; grid-row: 2; width: 100%; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool, .page-control { flex: 0 0 auto; height: 38px; }
  .tool--square, .tool--text { width: 38px; min-width: 38px; }
  .book-shell { inset: 7px 30px 5px; }
  .edge { width: 25px; height: 68px; border: 0; background: transparent; backdrop-filter: none; }
  .edge svg { width: 27px; height: 27px; }
  .edge--prev { left: -2px; }
  .edge--next { right: -2px; }
  .reader-footer { min-height: 26px; white-space: nowrap; overflow: hidden; padding-inline: 8px; }
  .reader-footer span:nth-of-type(n+2), .reader-footer i { display: none; }
  .focus-viewport { padding: 12px; }
}

@media (max-width: 520px) {
  .brand span { font-size: 8px; }
  .brand strong { font-size: 17px; }
  .page-control { padding-inline: 9px; }
  .page-control > span:first-child { display: none; }
  .tool--pdf { display: none; }
  .book-shell { inset-inline: 22px; }
  .thumbs-list { gap: 10px; padding: 14px; }
}

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