:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: rgba(17, 21, 29, .92);
  --line: rgba(255,255,255,.12);
  --text: #f4f7fb;
  --muted: #98a2b2;
  --accent: #77f229;
  --accent-2: #00d5ff;
  --danger: #ff4d68;
  --page-ratio: 0.74628;
  --ease: cubic-bezier(.22,.75,.18,1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body { color: var(--text); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app {
  width: 100%; height: 100%;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) 64px;
  background:
    radial-gradient(circle at 50% 45%, rgba(0,213,255,.09), transparent 38%),
    radial-gradient(circle at 22% 15%, rgba(119,242,41,.06), transparent 28%),
    linear-gradient(145deg, #0a0d13 0%, #05070a 65%, #090b10 100%);
}

.topbar, .controlbar {
  z-index: 40;
  display: flex; align-items: center;
  border-color: var(--line);
  background: rgba(8,10,14,.86);
  backdrop-filter: blur(18px);
}
.topbar { padding: 0 20px; border-bottom: 1px solid var(--line); gap: 18px; }
.controlbar { padding: 0 18px; border-top: 1px solid var(--line); justify-content: space-between; gap: 18px; }

.brand { color: inherit; text-decoration: none; display: flex; align-items: center; flex: 0 0 auto; min-width: 320px; }
.brand-logo {
  display: block;
  width: min(31vw, 420px);
  height: auto;
  max-height: 48px;
  object-fit: contain;
  object-position: left center;
}
.issue-title { min-width: 0; margin-right: auto; display: grid; text-align: center; }
.issue-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.issue-title span { color: var(--muted); font-size: 11px; margin-top: 2px; }
.top-actions { display: flex; gap: 7px; }

.icon-button, .text-button, .turn-button, .panel-close {
  border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,.045); cursor: pointer;
  transition: background .2s, border-color .2s, color .2s, transform .2s;
}
.icon-button:hover, .text-button:hover, .turn-button:hover, .panel-close:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.25); }
.icon-button:active, .text-button:active, .turn-button:active { transform: scale(.94); }
.icon-button[aria-pressed="true"] { color: var(--accent); border-color: rgba(119,242,41,.42); background: rgba(119,242,41,.1); }
.icon-button { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.icon-button svg, .turn-button svg, .download-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:first-child svg { fill: currentColor; stroke: none; }
.icon-button:nth-child(2) svg { fill: currentColor; stroke: none; }

.workspace { position: relative; min-height: 0; display: flex; overflow: hidden; }
.reader { position: relative; min-width: 0; flex: 1; display: grid; place-items: center; overflow: auto; padding: 24px 70px; isolation: isolate; }
.reader::before {
  content: ""; position: fixed; inset: 68px 0 64px;
  pointer-events: none; opacity: .24;
  background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: radial-gradient(circle, black 10%, transparent 70%);
}
.ambient-glow { position: absolute; width: 68vw; height: 55vh; border-radius: 50%; background: rgba(0,180,255,.07); filter: blur(80px); z-index: -1; }

.book-wrap { display: grid; place-items: center; min-width: min-content; min-height: min-content; transition: padding .25s; }
.book {
  --book-height: min(72vh, 760px);
  position: relative;
  height: var(--book-height);
  aspect-ratio: var(--spread-ratio, 1.49256) / 1;
  transform: scale(1);
  transform-origin: center center;
  transition: transform .2s var(--ease), aspect-ratio .35s var(--ease);
  filter: drop-shadow(0 26px 35px rgba(0,0,0,.5));
  perspective: 2600px;
  user-select: none;
  touch-action: pan-y;
}
.book.single-mode { aspect-ratio: var(--page-ratio) / 1; }
.book.is-turning { pointer-events: none; }

.page {
  position: absolute; top: 0; width: 50%; height: 100%; overflow: hidden;
  background: #f4f1e7; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.page img { width: 100%; height: 100%; object-fit: fill; display: block; }
.page-left { left: 0; border-radius: 8px 2px 2px 8px; }
.page-right { right: 0; border-radius: 2px 8px 8px 2px; }
.page-left::after, .page-right::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.page-left::after { background: linear-gradient(90deg, rgba(0,0,0,.02) 55%, rgba(0,0,0,.18) 100%); }
.page-right::after { background: linear-gradient(90deg, rgba(0,0,0,.18) 0%, rgba(0,0,0,.015) 45%); }
.page-single { display: none; width: 100%; left: 0; border-radius: 8px; }
.book.single-mode .page-left, .book.single-mode .page-right, .book.single-mode .spine { display: none; }
.book.single-mode .page-single { display: block; }

.page-number {
  position: absolute; z-index: 3; bottom: 8px;
  min-width: 28px; padding: 4px 7px; border-radius: 20px;
  color: #fff; background: rgba(0,0,0,.5); backdrop-filter: blur(6px);
  font-size: 10px; line-height: 1; text-align: center; opacity: 0;
  transition: opacity .2s;
}
.book:hover .page-number { opacity: .72; }
.page-left .page-number { left: 8px; }
.page-right .page-number { right: 8px; }
.page-single .page-number { right: 8px; }

.spine {
  position: absolute; top: -.5%; bottom: -.5%; left: 50%; z-index: 8; width: 20px; transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.34) 42%, rgba(255,255,255,.12) 50%, rgba(0,0,0,.31) 58%, transparent);
  filter: blur(.15px);
}

.flip-layer {
  display: none; position: absolute; top: 0; right: 0; width: 50%; height: 100%; z-index: 20;
  transform-style: preserve-3d; transform-origin: left center;
}
.flip-layer.active { display: block; animation: flipNext 720ms var(--ease) forwards; }
.flip-layer.reverse { left: 0; right: auto; transform-origin: right center; animation-name: flipPrev; }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; overflow: hidden; background: #f4f1e7; }
.flip-face img { width: 100%; height: 100%; object-fit: fill; display: block; }
.flip-front { box-shadow: inset 20px 0 28px rgba(0,0,0,.12), 8px 8px 20px rgba(0,0,0,.24); }
.flip-back { transform: rotateY(180deg); box-shadow: inset -20px 0 28px rgba(0,0,0,.14), -8px 8px 20px rgba(0,0,0,.24); }
.flip-front::after, .flip-back::after { content: ""; position: absolute; inset: 0; animation: pageShade 720ms var(--ease) forwards; pointer-events: none; }
.flip-back::after { animation-name: pageShadeBack; }
@keyframes flipNext { from { transform: rotateY(0); } 55% { filter: brightness(.72); } to { transform: rotateY(-180deg); filter: brightness(1); } }
@keyframes flipPrev { from { transform: rotateY(0); } 55% { filter: brightness(.72); } to { transform: rotateY(180deg); filter: brightness(1); } }
@keyframes pageShade { 0% { background: linear-gradient(90deg, transparent 50%, rgba(0,0,0,.02)); } 55% { background: rgba(0,0,0,.34); } 100% { background: rgba(0,0,0,.03); } }
@keyframes pageShadeBack { 0% { background: rgba(0,0,0,.28); } 55% { background: rgba(0,0,0,.14); } 100% { background: linear-gradient(90deg, rgba(0,0,0,.14), transparent 42%); } }

.turn-button {
  position: fixed; top: 50%; z-index: 30; width: 48px; height: 68px; margin-top: -34px;
  display: grid; place-items: center; border-radius: 14px; background: rgba(10,13,18,.72); backdrop-filter: blur(12px);
}
.turn-button:disabled, .text-button:disabled { opacity: .25; cursor: default; transform: none; }
.turn-prev { left: 18px; }
.turn-next { right: 18px; }
.turn-button svg { width: 25px; height: 25px; }

.thumbnail-panel {
  position: absolute; inset: 0 auto 0 0; width: min(370px, 88vw); z-index: 50;
  display: grid; grid-template-rows: auto 1fr;
  background: var(--panel); border-right: 1px solid var(--line); backdrop-filter: blur(24px);
  transform: translateX(-105%); transition: transform .35s var(--ease); box-shadow: 25px 0 60px rgba(0,0,0,.35);
}
.thumbnail-panel.open { transform: translateX(0); }
.panel-head { height: 66px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--line); }
.panel-head > div { display: grid; }
.panel-head strong { font-size: 15px; }
.panel-head span { font-size: 11px; color: var(--muted); margin-top: 3px; }
.panel-close { width: 34px; height: 34px; border-radius: 9px; font-size: 22px; line-height: 1; }
.thumbnail-grid { overflow: auto; padding: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-content: start; }
.thumb { position: relative; padding: 0; border: 1px solid rgba(255,255,255,.1); border-radius: 8px; overflow: hidden; cursor: pointer; background: #11151c; aspect-ratio: 3 / 4; transition: transform .2s, border-color .2s, box-shadow .2s; }
.thumb:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.35); }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(119,242,41,.17), 0 0 20px rgba(119,242,41,.12); }
.thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.thumb span { position: absolute; right: 5px; bottom: 5px; min-width: 23px; padding: 3px 5px; border-radius: 10px; font-size: 9px; background: rgba(0,0,0,.72); }

.page-controls, .zoom-controls { display: flex; align-items: center; gap: 6px; }
.text-button { min-width: 34px; height: 34px; padding: 0 9px; border-radius: 9px; font-weight: 700; }
.page-jump { height: 34px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.035); color: var(--muted); font-size: 11px; }
.page-jump input { width: 44px; border: 0; outline: 0; color: var(--text); background: transparent; text-align: center; font-weight: 750; appearance: textfield; }
.page-jump input::-webkit-outer-spin-button, .page-jump input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.progress-area { flex: 1; max-width: 520px; display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 11px; }
.progress-track { flex: 1; height: 4px; border-radius: 10px; background: rgba(255,255,255,.09); overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); box-shadow: 0 0 12px rgba(0,213,255,.4); transition: width .35s var(--ease); }
#spreadLabel { min-width: 76px; text-align: right; white-space: nowrap; }
#zoomLabel { min-width: 46px; text-align: center; color: var(--muted); font-size: 11px; }
.download-button { height: 34px; display: flex; align-items: center; gap: 6px; margin-left: 6px; padding: 0 11px; border: 1px solid rgba(119,242,41,.34); border-radius: 9px; color: var(--accent); background: rgba(119,242,41,.07); text-decoration: none; font-weight: 800; font-size: 11px; }
.download-button:hover { background: rgba(119,242,41,.14); }
.download-button svg { width: 16px; height: 16px; }

.help { position: fixed; z-index: 80; left: 50%; bottom: 78px; transform: translate(-50%, 20px); display: flex; gap: 18px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(5,7,10,.84); color: var(--muted); backdrop-filter: blur(16px); font-size: 11px; opacity: 0; pointer-events: none; transition: opacity .4s, transform .4s; }
.help.show { opacity: 1; transform: translate(-50%, 0); }
kbd { padding: 2px 5px; border: 1px solid rgba(255,255,255,.18); border-bottom-width: 2px; border-radius: 4px; background: rgba(255,255,255,.07); color: var(--text); font-size: 10px; }

@media (max-width: 1100px) {
  .brand { min-width: 240px; }
  .brand-logo { width: min(28vw, 330px); max-height: 40px; }
  .engine-badge { display: none; }
}

@media (max-width: 900px) {
  .app { grid-template-rows: 58px minmax(0,1fr) 60px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .brand { min-width: 0; }
  .brand-logo { width: min(36vw, 280px); max-height: 34px; }
  .issue-title span { display: none; }
  .issue-title { text-align: left; }
  .top-actions { gap: 4px; }
  .icon-button { width: 36px; height: 36px; }
  .reader { padding: 18px 42px; }
  .book { --book-height: min(76vh, calc(100vw / var(--page-ratio))); }
  .turn-button { width: 38px; height: 56px; border-radius: 11px; }
  .turn-prev { left: 4px; } .turn-next { right: 4px; }
  .progress-area { display: none; }
  .controlbar { padding: 0 8px; gap: 7px; }
  .page-controls { gap: 3px; }
  .page-controls .text-button:first-child, .page-controls .text-button:last-child { display: none; }
  .zoom-controls { margin-left: auto; gap: 3px; }
  .download-button span { display: none; }
  .download-button { width: 34px; padding: 0; justify-content: center; margin-left: 2px; }
  .page-jump label { display: none; }
  .help { display: none; }
}

@media (max-width: 680px) {
  .issue-title { display: none; }
  .topbar { justify-content: space-between; }
  .brand-logo { width: min(48vw, 260px); max-height: 32px; }
}

@media (max-width: 540px) {
  .brand-logo { width: min(51vw, 220px); max-height: 27px; }
  .reader { padding-left: 30px; padding-right: 30px; }
  .book { --book-height: min(72vh, calc((100vw - 60px) / var(--page-ratio))); }
  .page-jump { padding: 0 7px; gap: 3px; }
  .zoom-controls .text-button, #zoomLabel { display: none; }
  .thumbnail-grid { grid-template-columns: repeat(2, 1fr); }
}

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


.engine-badge { display:flex; align-items:center; gap:7px; flex:0 0 auto; padding:7px 10px; border:1px solid rgba(119,242,41,.25); border-radius:999px; color:#bdfc96; background:rgba(119,242,41,.06); font-size:9px; font-weight:900; letter-spacing:.08em; }
.engine-badge span { width:7px; height:7px; border-radius:50%; background:var(--accent); box-shadow:0 0 10px rgba(119,242,41,.8); }
.page img:not([src]), .flip-face img:not([src]) { background:linear-gradient(110deg,#e7e4da 8%,#f7f4ea 18%,#e7e4da 33%); background-size:200% 100%; animation:shimmer 1.25s linear infinite; }
@keyframes shimmer { to { background-position-x:-200%; } }
.thumb img:not([src]) { background:linear-gradient(110deg,#151b24 8%,#222b37 18%,#151b24 33%); background-size:200% 100%; animation:shimmer 1.25s linear infinite; }
.loading-overlay, .error-overlay { position:fixed; inset:0; z-index:150; display:grid; place-items:center; padding:22px; background:rgba(3,5,8,.78); backdrop-filter:blur(18px); transition:opacity .35s, visibility .35s; }
.loading-overlay.done { opacity:0; visibility:hidden; pointer-events:none; }
.loading-card, .error-card { width:min(390px,92vw); padding:28px; border:1px solid rgba(255,255,255,.13); border-radius:18px; background:#0f141c; box-shadow:0 30px 90px rgba(0,0,0,.55); text-align:center; }
.loading-card { display:grid; justify-items:center; gap:9px; }
.loading-card strong { margin-top:4px; font-size:16px; }
.loading-card small { color:var(--muted); font-size:11px; }
.loader { width:36px; height:36px; border-radius:50%; border:3px solid rgba(255,255,255,.12); border-top-color:var(--accent); animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.loading-track { width:100%; height:4px; margin-top:10px; border-radius:10px; overflow:hidden; background:rgba(255,255,255,.09); }
.loading-track span { display:block; width:8%; height:100%; border-radius:inherit; background:linear-gradient(90deg,var(--accent),var(--accent-2)); transition:width .2s; }
.error-overlay[hidden] { display:none; }
.error-card strong { color:#ff8da0; font-size:17px; }
.error-card p { color:#c2cad5; line-height:1.55; font-size:13px; white-space:pre-line; }
.error-card button { padding:10px 15px; border:1px solid rgba(119,242,41,.4); border-radius:9px; color:#081006; background:var(--accent); font-weight:800; cursor:pointer; }
@media(max-width:900px){.engine-badge{display:none}}
