:root {
  --app-height: 100vh;
  --bg: #272421;
  --bg-deep: #191715;
  --panel: rgba(22, 21, 18, 0.78);
  --panel-strong: rgba(17, 16, 14, 0.9);
  --surface: rgba(35, 33, 28, 0.92);
  --surface-soft: rgba(255, 255, 255, 0.04);
  --border: rgba(246, 228, 35, 0.18);
  --border-strong: rgba(246, 228, 35, 0.38);
  --accent: #f6e423;
  --accent-rgb: 246, 228, 35;
  --text: #fffef7;
  --text-soft: rgba(255, 254, 247, 0.76);
  --text-faint: rgba(255, 254, 247, 0.56);
  --shadow: 0 26px 70px rgba(0, 0, 0, 0.38);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  position: relative;
  background:
    radial-gradient(circle at top center, rgba(var(--accent-rgb), 0.1), transparent 28%),
    linear-gradient(180deg, #2c2824 0%, #1b1917 100%);
  color: var(--text);
  font-family: "Poppins", Arial, Helvetica, sans-serif;
}

body.page-library {
  overflow-x: hidden;
}

body.page-viewer {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.grid-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  background-image:
    linear-gradient(rgba(var(--accent-rgb), 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--accent-rgb), 0.055) 1px, transparent 1px);
  background-size: 72px 72px;
  opacity: 0.6;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.2));
  animation: gridDrift 34s linear infinite;
}

.ambient {
  position: fixed;
  inset: auto;
  z-index: -2;
  border-radius: 999px;
  filter: blur(70px);
  opacity: 0.36;
  pointer-events: none;
}

.ambient-a {
  top: 82px;
  right: 6vw;
  width: 280px;
  height: 280px;
  background: rgba(var(--accent-rgb), 0.26);
}

.ambient-b {
  bottom: 10vh;
  left: 4vw;
  width: 340px;
  height: 340px;
  background: rgba(153, 110, 30, 0.18);
}

.topbar {
  position: fixed;
  top: 18px;
  left: 20px;
  right: 20px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 22px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(14, 13, 11, 0.44);
  backdrop-filter: blur(16px) saturate(145%);
  -webkit-backdrop-filter: blur(16px) saturate(145%);
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: auto;
  height: 28px;
  display: block;
}

.brand-copy {
  color: var(--text-soft);
  font-size: 0.96rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.primary-button,
.ghost-button,
.stat-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition:
    transform 0.26s ease,
    border-color 0.26s ease,
    background 0.26s ease,
    color 0.26s ease,
    box-shadow 0.26s ease;
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-2px);
}

.primary-button {
  border-color: rgba(var(--accent-rgb), 0.6);
  background: var(--accent);
  color: #111;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(var(--accent-rgb), 0.2);
}

.ghost-button,
.stat-pill {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-soft);
}

.ghost-button:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: rgba(var(--accent-rgb), 0.08);
}

.library-main {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 122px 0 40px;
}

.hero-panel,
.library-section,
.reader-sidebar,
.viewer-card {
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(29, 27, 24, 0.94), rgba(17, 16, 14, 0.96));
  box-shadow: var(--shadow);
}

.hero-panel {
  position: relative;
  overflow: hidden;
  padding: clamp(28px, 5vw, 54px);
  border-radius: var(--radius-xl);
}

.hero-panel::before,
.library-section::before,
.viewer-card::before,
.reader-sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at top right, rgba(var(--accent-rgb), 0.16), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0));
}

.eyebrow,
.reader-badge,
.viewer-kicker,
.doc-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero-panel h1 {
  max-width: 920px;
  margin: 18px 0 0;
  font-size: clamp(2.2rem, 5vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.hero-copy {
  max-width: 760px;
  margin: 18px 0 0;
  color: var(--text-soft);
  font-size: 1.05rem;
  line-height: 1.8;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 34px;
}

.hero-stat,
.meta-card {
  position: relative;
  padding: 18px 20px;
  border-radius: 20px;
  border: 1px solid rgba(var(--accent-rgb), 0.14);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.hero-stat strong,
.meta-card strong {
  display: block;
  font-size: 1.08rem;
  color: var(--text);
}

.hero-stat span,
.meta-label {
  display: block;
  margin-top: 5px;
  color: var(--text-faint);
  font-size: 0.88rem;
}

.status-banner,
.empty-state {
  margin-top: 20px;
  padding: 18px 20px;
  border-radius: 22px;
  border: 1px solid rgba(255, 117, 117, 0.26);
  background: rgba(66, 18, 18, 0.78);
  color: #ffe6e6;
}

.empty-state {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border);
  color: var(--text-soft);
}

.empty-state strong {
  display: block;
  color: var(--text);
}

.empty-state p {
  margin: 8px 0 0;
}

.library-section {
  position: relative;
  overflow: hidden;
  margin-top: 22px;
  padding: 28px;
  border-radius: var(--radius-xl);
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.section-head h2 {
  margin: 10px 0 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  line-height: 1.08;
}

.section-copy {
  max-width: 440px;
  margin: 0;
  color: var(--text-faint);
  line-height: 1.7;
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.doc-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 18px;
  min-height: 360px;
  padding: 20px;
  border-radius: 26px;
  border: 1px solid rgba(var(--accent-rgb), 0.15);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    linear-gradient(180deg, rgba(34, 32, 28, 0.95), rgba(19, 18, 16, 0.98));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
  transform: translateY(16px);
  opacity: 0;
  animation: riseIn 0.7s ease forwards;
  animation-delay: calc(var(--card-index, 0) * 70ms);
  transition:
    transform 0.28s ease,
    border-color 0.28s ease,
    box-shadow 0.28s ease,
    background 0.28s ease;
}

.doc-card:hover {
  transform: translateY(-6px);
  border-color: rgba(var(--accent-rgb), 0.34);
  box-shadow:
    0 26px 60px rgba(0, 0, 0, 0.34),
    0 0 0 1px rgba(var(--accent-rgb), 0.08) inset;
}

.doc-card::after {
  content: "";
  position: absolute;
  inset: auto -60px -80px auto;
  width: 180px;
  height: 180px;
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.13);
  filter: blur(18px);
  pointer-events: none;
}

.doc-card-visual {
  position: relative;
  min-height: 170px;
  padding: 18px;
  border-radius: 22px;
  background:
    radial-gradient(circle at top right, rgba(var(--accent-rgb), 0.2), transparent 34%),
    linear-gradient(145deg, rgba(246, 228, 35, 0.08), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(var(--accent-rgb), 0.1);
}

.doc-preview-sheet {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(130px, 42%);
  aspect-ratio: 0.72;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #fffef9, #f2efe2);
  box-shadow:
    -10px 12px 26px rgba(0, 0, 0, 0.24),
    -18px 18px 0 rgba(var(--accent-rgb), 0.12);
}

.doc-preview-sheet::before {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent);
}

.doc-preview-lines {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  top: 64px;
  border-radius: 10px;
  background-image: linear-gradient(#dad6c8 2px, transparent 2px);
  background-size: 100% 18px;
  opacity: 0.8;
}

.doc-card-body {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
}

.doc-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-faint);
  font-size: 0.84rem;
}

.doc-card h3 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.08;
}

.doc-card p {
  margin: 0;
  color: var(--text-faint);
  line-height: 1.6;
  word-break: break-word;
}

.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 600;
}

.doc-link::after {
  content: "->";
  font-size: 0.92rem;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 20px;
  height: calc(var(--app-height) - 126px);
  margin: 106px 20px 20px;
}

.reader-sidebar {
  position: relative;
  overflow: hidden;
  padding: 28px;
  border-radius: var(--radius-xl);
}

.reader-sidebar h1 {
  margin: 16px 0 0;
  font-size: clamp(2rem, 3.2vw, 3rem);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.reader-lead,
.reader-notes p {
  margin: 14px 0 0;
  color: var(--text-soft);
  line-height: 1.75;
}

.reader-meta {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.reader-notes {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid rgba(var(--accent-rgb), 0.12);
}

.flipbook-section {
  min-width: 0;
  height: 100%;
}

.viewer-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-xl);
}

.viewer-card-head,
.floating-tools,
.pager,
.book-viewport,
.corner-button {
  position: relative;
  z-index: 1;
}

.viewer-card-head {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(58%, 420px);
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid rgba(var(--accent-rgb), 0.16);
  background: rgba(20, 19, 17, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.viewer-title {
  font-size: 1rem;
  line-height: 1.4;
}

.floating-tools {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 5;
  display: flex;
  gap: 10px;
}

.tool-button,
.pager-button,
.corner-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 0.24s ease,
    border-color 0.24s ease,
    background 0.24s ease,
    box-shadow 0.24s ease,
    color 0.24s ease;
}

.tool-button:hover,
.pager-button:hover,
.corner-button:hover {
  transform: translateY(-2px);
}

.tool-button,
.corner-button {
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  background: rgba(21, 20, 18, 0.82);
}

.tool-button-primary {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.56);
  box-shadow:
    0 0 16px rgba(var(--accent-rgb), 0.22),
    inset 0 0 10px rgba(var(--accent-rgb), 0.1);
}

.pager-button {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 1.3rem;
  border: 1px solid rgba(var(--accent-rgb), 0.58);
  background: rgba(var(--accent-rgb), 0.08);
  box-shadow:
    0 0 14px rgba(var(--accent-rgb), 0.18),
    inset 0 0 10px rgba(var(--accent-rgb), 0.08);
}

.tool-button:disabled,
.pager-button:disabled,
.corner-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
  box-shadow: none;
}

.book-viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 96px 18px 90px;
  background:
    radial-gradient(circle at top center, rgba(var(--accent-rgb), 0.08), transparent 36%),
    linear-gradient(180deg, rgba(39, 36, 33, 0.86), rgba(19, 18, 16, 0.98));
}

.book-viewport::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(var(--accent-rgb), 0.12);
  border-radius: 26px;
  pointer-events: none;
}

.flipbook-host {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.flipbook-mount {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 16px 16px 64px;
}

.pager {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(-50%);
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  background: rgba(16, 15, 13, 0.88);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.page-pill {
  min-width: 116px;
  padding: 0 8px;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
}

.corner-button {
  position: absolute;
  bottom: 16px;
  z-index: 5;
}

.corner-button-left {
  left: 16px;
}

.corner-button-right {
  right: 16px;
}

.state-card {
  position: absolute;
  z-index: 6;
  display: grid;
  place-items: center;
  width: min(460px, calc(100% - 40px));
  min-height: 132px;
  padding: 20px 24px;
  text-align: center;
  color: var(--text);
  border-radius: 24px;
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  background: rgba(20, 19, 17, 0.94);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
}

.state-error {
  border-color: rgba(251, 113, 133, 0.35);
  color: #ffe4ea;
  background: rgba(57, 11, 18, 0.95);
}

.state-card[hidden] {
  display: none !important;
}

.stf__wrapper {
  margin: 0 auto;
  filter: drop-shadow(0 26px 40px rgba(0, 0, 0, 0.4));
}

.stf__block {
  overflow: visible;
}

.flipbook-host .stf__parent {
  transition: transform 0.28s ease;
}

.flipbook-host[data-book-state="front-cover"] .stf__parent {
  transform: translate3d(-25%, 0, 0);
}

.flipbook-host[data-book-state="back-cover"] .stf__parent {
  transform: translate3d(25%, 0, 0);
}

.stf__item,
.stf__item img {
  background: #ffffff;
}

.page-sheet {
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  outline: 1px solid rgba(var(--accent-rgb), 0.28);
  outline-offset: -1px;
  box-shadow:
    0 24px 50px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.page-sheet img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  background: #ffffff;
}

@keyframes gridDrift {
  from {
    background-position: 0 0, 0 0;
  }

  to {
    background-position: 720px 720px, 720px 720px;
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(22px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1120px) {
  .docs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-layout {
    grid-template-columns: 1fr;
    height: auto;
    margin-top: 104px;
  }

  .reader-sidebar {
    min-height: auto;
  }

  body.page-viewer {
    overflow-y: auto;
  }

  .flipbook-section {
    height: min(78vh, 860px);
  }
}

@media (max-width: 820px) {
  .topbar {
    left: 12px;
    right: 12px;
    top: 12px;
    padding: 14px 16px;
    border-radius: 20px;
    flex-wrap: wrap;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .brand-copy {
    font-size: 0.9rem;
  }

  .library-main {
    width: calc(100% - 24px);
    padding-top: 120px;
  }

  .hero-panel,
  .library-section {
    padding: 22px;
    border-radius: 24px;
  }

  .hero-stats,
  .docs-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    align-items: start;
    flex-direction: column;
  }

  .reader-layout {
    margin: 114px 12px 12px;
    gap: 12px;
  }

  .reader-sidebar,
  .viewer-card {
    border-radius: 24px;
  }

  .viewer-card-head {
    position: static;
    max-width: none;
    margin: 12px 12px 0;
  }

  .floating-tools {
    top: 76px;
    right: 12px;
    flex-direction: column;
    align-items: flex-end;
  }

  .tool-button {
    min-height: 42px;
    padding: 10px 14px;
    font-size: 0.84rem;
  }

  .book-viewport {
    padding: 130px 8px 90px;
  }

  .flipbook-mount {
    padding: 16px 10px 62px;
  }

  .pager {
    bottom: 10px;
    gap: 8px;
    padding: 8px;
  }

  .corner-button {
    bottom: 10px;
    min-height: 42px;
    padding: 10px 14px;
    font-size: 0.84rem;
  }

  .corner-button-left {
    left: 10px;
  }

  .corner-button-right {
    right: 10px;
  }

  .pager-button {
    width: 42px;
    height: 42px;
  }

  .page-pill {
    min-width: 90px;
    font-size: 0.92rem;
  }
}

@media (max-width: 560px) {
  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .ghost-button,
  .stat-pill {
    width: 100%;
  }

  .hero-panel h1,
  .reader-sidebar h1 {
    line-height: 1.02;
  }

  .doc-card {
    min-height: 320px;
  }

  .doc-card-visual {
    min-height: 150px;
  }
}
