:root {
  --bg: #090d18;
  --surface: rgba(17, 24, 39, .78);
  --surface-strong: #111827;
  --surface-soft: #151d2f;
  --text: #f8fafc;
  --muted: #96a3b8;
  --line: rgba(148, 163, 184, .18);
  --accent: #6d5dfc;
  --accent-2: #35d0ba;
  --danger: #ff647c;
  --shadow: 0 24px 80px rgba(0, 0, 0, .38);
  --radius: 22px;
  --topbar-h: 76px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  --bg: #eef2f7;
  --surface: rgba(255,255,255,.86);
  --surface-strong: #ffffff;
  --surface-soft: #f5f7fb;
  --text: #101522;
  --muted: #64748b;
  --line: rgba(15, 23, 42, .12);
  --shadow: 0 24px 70px rgba(15, 23, 42, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 15% 15%, rgba(109, 93, 252, .18), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(53, 208, 186, .12), transparent 28%),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(109,93,252,.35); outline-offset: 2px; }
.hidden { display: none !important; }

.app-shell { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 0 clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), #8b7cff);
  box-shadow: 0 10px 30px rgba(109, 93, 252, .28);
}
.brand-mark svg { width: 24px; fill: white; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.btn, .icon-btn {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease, opacity .16s ease;
}
.btn:hover, .icon-btn:hover { transform: translateY(-1px); border-color: rgba(109,93,252,.5); }
.btn:active, .icon-btn:active { transform: translateY(0) scale(.98); }
.btn { min-height: 44px; border-radius: 13px; padding: 0 17px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; }
.btn svg, .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { border: 0; background: linear-gradient(135deg, var(--accent), #8f7cff); color: #fff; box-shadow: 0 14px 34px rgba(109,93,252,.3); }
.btn-ghost { background: transparent; }
.icon-btn { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; padding: 0; }

.main { min-height: calc(100dvh - var(--topbar-h)); }
.welcome {
  width: min(1180px, calc(100% - 32px)); margin: 0 auto;
  min-height: calc(100dvh - var(--topbar-h));
  display: grid; grid-template-columns: 1.05fr .95fr; gap: clamp(26px, 5vw, 70px); align-items: center;
  padding: 44px 0 64px;
}
.hero-copy { max-width: 650px; }
.eyebrow { display: inline-flex; padding: 7px 11px; border: 1px solid rgba(53,208,186,.28); background: rgba(53,208,186,.08); color: #56dfcc; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.hero-copy h1 { font-size: clamp(38px, 5.1vw, 70px); line-height: .99; letter-spacing: -.055em; margin: 18px 0 20px; }
.hero-copy h1 em { font-style: normal; color: transparent; background: linear-gradient(100deg, #a89cff, #64e2cf); -webkit-background-clip: text; background-clip: text; }
.hero-copy p { color: var(--muted); font-size: clamp(15px, 1.4vw, 18px); line-height: 1.75; max-width: 590px; }
.feature-chips { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 28px; }
.feature-chips span { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 12px; color: var(--muted); font-size: 12px; font-weight: 700; }

.upload-card {
  position: relative; min-height: 390px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 36px; border: 1px dashed rgba(148,163,184,.38); border-radius: 30px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--surface-strong) 88%, transparent), color-mix(in srgb, var(--surface-soft) 80%, transparent));
  box-shadow: var(--shadow); overflow: hidden; isolation: isolate;
}
.upload-card::before { content: ""; position: absolute; width: 240px; height: 240px; right: -90px; top: -90px; border-radius: 50%; background: rgba(109,93,252,.18); filter: blur(4px); z-index: -1; }
.upload-card.dragover { border-color: var(--accent-2); transform: scale(1.01); }
.upload-icon { width: 74px; height: 74px; border-radius: 22px; display: grid; place-items: center; margin-bottom: 18px; color: #fff; background: linear-gradient(145deg, #1b2740, #111827); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 16px 35px rgba(0,0,0,.25); }
.upload-icon svg { width: 34px; fill: none; stroke: var(--accent-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.upload-card h2 { margin: 0 0 8px; font-size: 24px; }
.upload-card p { margin: 0 0 22px; color: var(--muted); max-width: 330px; line-height: 1.6; }
.upload-card small { color: var(--muted); margin-top: 13px; }
.url-card { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 18px; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 18px; padding: 15px 18px; }
.url-card strong, .url-card span { display: block; }
.url-card strong { font-size: 13px; }
.url-card span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.url-card code { color: #9f93ff; background: rgba(109,93,252,.1); border: 1px solid rgba(109,93,252,.18); border-radius: 9px; padding: 8px 10px; white-space: nowrap; }

.viewer { height: calc(100dvh - var(--topbar-h)); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.viewer-toolbar { min-height: 66px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(80px, 1fr); align-items: center; gap: 15px; padding: 10px clamp(12px, 3vw, 30px); background: color-mix(in srgb, var(--surface-strong) 72%, transparent); }
.doc-info { min-width: 0; display: flex; align-items: center; gap: 10px; }
.pdf-badge { font-size: 9px; letter-spacing: .08em; font-weight: 900; color: white; background: #ef476f; border-radius: 7px; padding: 5px 6px; }
.doc-name-wrap { min-width: 0; }
.doc-name-wrap strong, .doc-name-wrap small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-name-wrap strong { font-size: 13px; max-width: min(32vw, 430px); }
.doc-name-wrap small { color: var(--muted); margin-top: 3px; font-size: 10px; }
.reader-controls { display: flex; align-items: center; gap: 7px; }
.control { width: 38px; height: 38px; }
.page-counter { height: 38px; display: flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 0 10px; color: var(--muted); font-size: 12px; }
.page-counter input { width: 44px; height: 28px; border: 0; border-radius: 7px; color: var(--text); background: var(--surface-soft); text-align: center; font-weight: 800; outline: none; }
.page-counter input::-webkit-inner-spin-button { display: none; }
.viewer-actions { justify-self: end; }

.book-stage { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 18px 76px; overflow: hidden; perspective: 2000px; }
.book-stage::before { content: ""; position: absolute; width: min(74vw, 1000px); height: 55%; bottom: 4%; border-radius: 50%; background: rgba(0,0,0,.24); filter: blur(70px); transform: scaleY(.28); pointer-events: none; }
.book-wrap { width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; position: relative; z-index: 2; }
.book { margin: auto; }
.pdf-page { background: #fff; overflow: hidden; position: relative; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.pdf-page::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(0,0,0,.055), transparent 3.5%, transparent 96.5%, rgba(0,0,0,.035)); mix-blend-mode: multiply; }
.pdf-page img { display: block; width: 100%; height: 100%; object-fit: contain; background: #fff; user-select: none; -webkit-user-drag: none; }
.pdf-page .page-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: #94a3b8; background: #fff; font-size: 13px; }
.stf__parent { margin: auto !important; }

.edge-nav { position: absolute; z-index: 10; top: 50%; transform: translateY(-50%); width: 46px; height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(12px); }
.edge-nav:hover { border-color: rgba(109,93,252,.5); }
.edge-nav svg { width: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.edge-prev { left: 18px; }
.edge-next { right: 18px; }
.edge-nav:disabled { opacity: .25; cursor: default; }
.reader-footer { min-height: 38px; padding: 8px 18px 12px; display: flex; justify-content: center; gap: 24px; color: var(--muted); font-size: 10px; }

.loading-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(4, 8, 18, .78); backdrop-filter: blur(18px); padding: 20px; }
.loading-card { width: min(420px, 100%); text-align: center; border: 1px solid rgba(255,255,255,.1); border-radius: 26px; background: #111827; color: #f8fafc; box-shadow: 0 30px 100px rgba(0,0,0,.5); padding: 34px; }
.loading-card strong { display: block; font-size: 18px; margin-top: 18px; }
.loading-card p { color: #94a3b8; font-size: 12px; margin: 7px 0 18px; }
.book-loader { height: 44px; display: flex; justify-content: center; align-items: end; gap: 4px; }
.book-loader i { display: block; width: 16px; height: 36px; border-radius: 3px 8px 8px 3px; background: linear-gradient(160deg, #8e7eff, #6655ef); transform-origin: left center; animation: leaf 1.1s ease-in-out infinite; }
.book-loader i:nth-child(2) { animation-delay: .12s; }
.book-loader i:nth-child(3) { animation-delay: .24s; }
@keyframes leaf { 0%,100% { transform: rotateY(0deg) translateY(0); } 50% { transform: rotateY(-55deg) translateY(-3px); } }
.progress { height: 7px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.09); }
.progress span { display: block; width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #6d5dfc, #35d0ba); transition: width .2s ease; }
.loading-card small { display: block; color: #7f8ba0; margin-top: 8px; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: 24px; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; max-width: min(520px, calc(100% - 28px)); border: 1px solid var(--line); background: var(--surface-strong); color: var(--text); border-radius: 13px; box-shadow: var(--shadow); padding: 11px 15px; font-size: 12px; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255,100,124,.4); }

body.embed .topbar { display: none; }
body.embed { --topbar-h: 0px; }
body.embed .viewer { height: 100dvh; }
body.embed .welcome { min-height: 100dvh; }

@media (max-width: 800px) {
  :root { --topbar-h: 66px; }
  .topbar { padding: 0 12px; }
  .brand small { display: none; }
  .brand strong { max-width: 48vw; }
  .btn-ghost { width: 42px; padding: 0; font-size: 0; }
  .welcome { grid-template-columns: 1fr; width: min(100% - 24px, 620px); padding: 34px 0 44px; gap: 26px; }
  .hero-copy { text-align: center; }
  .hero-copy p { margin-left: auto; margin-right: auto; }
  .feature-chips { justify-content: center; }
  .upload-card { min-height: 330px; padding: 26px; }
  .url-card { flex-direction: column; align-items: flex-start; }
  .viewer-toolbar { grid-template-columns: minmax(0,1fr) auto auto; gap: 7px; padding: 8px 10px; min-height: 58px; }
  .doc-name-wrap small, .pdf-badge { display: none; }
  .doc-name-wrap strong { max-width: 26vw; }
  .page-counter > span:first-child { display: none; }
  .reader-controls { gap: 4px; }
  .page-counter { padding: 0 7px; }
  .book-stage { padding: 10px 46px; }
  .edge-nav { width: 38px; height: 54px; border-radius: 13px; }
  .edge-prev { left: 5px; }
  .edge-next { right: 5px; }
  .reader-footer { gap: 10px; justify-content: space-between; padding-inline: 10px; }
  .reader-footer span:nth-child(2) { display: none; }
}

@media (max-width: 520px) {
  .brand-mark { width: 38px; height: 38px; }
  .brand strong { font-size: 13px; max-width: 42vw; }
  .themeBtn { display: none; }
  .hero-copy h1 { font-size: clamp(38px, 12vw, 54px); }
  .url-card { display: none; }
  .viewer-toolbar { grid-template-columns: minmax(0,1fr) auto; }
  .viewer-actions { display: none; }
  .doc-name-wrap strong { max-width: 34vw; }
  .book-stage { padding: 8px 32px; }
  .edge-nav { width: 30px; height: 48px; border: 0; background: transparent; }
  .edge-prev { left: 0; }
  .edge-next { right: 0; }
  .reader-footer { font-size: 9px; }
}
