:root {
  --app-height: 100dvh;
  --bg: #08111f;
  --bg-soft: #132338;
  --panel: rgba(10, 20, 35, 0.76);
  --panel-strong: rgba(11, 20, 34, 0.92);
  --paper: #efe1c4;
  --paper-edge: #d2ba93;
  --ink: #1a1410;
  --ink-soft: #4b392c;
  --accent: #c98b4a;
  --accent-soft: #e7b77f;
  --line: rgba(226, 199, 154, 0.2);
  --text: #f4ecd9;
  --muted: #cbb99f;
  --shadow: 0 24px 80px rgba(2, 8, 17, 0.45);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", "Georgia", serif;
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top, rgba(77, 113, 161, 0.18), transparent 34%),
    radial-gradient(circle at 20% 20%, rgba(201, 139, 74, 0.15), transparent 28%),
    linear-gradient(160deg, #07111d 0%, #0f1d31 52%, #08111f 100%);
  color: var(--text);
  font-family: var(--sans);
}

html.reader-open,
body.reader-open {
  overflow: hidden;
}

body.reader-open {
  height: var(--app-height);
}

button {
  border: 0;
  font: inherit;
}

.ambient {
  pointer-events: none;
  position: fixed;
  inset: auto;
  width: 24rem;
  height: 24rem;
  border-radius: 999px;
  filter: blur(90px);
  opacity: 0.45;
}

.ambient-a {
  top: -8rem;
  right: -6rem;
  background: rgba(77, 124, 185, 0.36);
}

.ambient-b {
  bottom: -8rem;
  left: -6rem;
  background: rgba(201, 139, 74, 0.28);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.app-shell.reader-mode {
  width: 100%;
  min-height: var(--app-height);
  padding: 0;
}

.app-shell.reader-mode .topbar {
  display: none;
}

.app-shell.reader-mode main {
  height: var(--app-height);
}

main {
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 28px;
  background: rgba(8, 16, 29, 0.56);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.topbar h1,
.hero-copy h2,
.book-card-title,
.panel-head h3,
.toolbar-title {
  margin: 0;
  font-family: var(--serif);
  letter-spacing: -0.03em;
}

.topbar h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-soft);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
}

.ghost-button,
.nav-button,
.icon-button,
.compact-button {
  cursor: pointer;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.ghost-button {
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.ghost-button:hover,
.ghost-button:focus-visible {
  background: rgba(201, 139, 74, 0.16);
  border-color: rgba(201, 139, 74, 0.4);
  outline: none;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.compact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.84rem;
}

.compact-button:hover,
.compact-button:focus-visible {
  background: rgba(201, 139, 74, 0.16);
  border-color: rgba(201, 139, 74, 0.3);
  outline: none;
}

.drawer-backdrop {
  display: none !important;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-top: 24px;
}

.hero-copy,
.hero-stat-grid,
.book-card,
.chapters-panel,
.reader-stage {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 32px;
  border-radius: 34px;
}

.hero-copy h2 {
  font-size: clamp(2.4rem, 5vw, 5rem);
  line-height: 0.95;
}

.hero-text {
  max-width: 42rem;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.8;
}

.hero-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 20px;
  border-radius: 34px;
}

.stat-card {
  padding: 18px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
}

.stat-value {
  margin: 0;
  font-size: 2rem;
  font-family: var(--serif);
}

.stat-label {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.book-card {
  padding: 22px;
  border-radius: 30px;
}

.book-card-top {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 18px;
}

.book-cover {
  position: relative;
  min-height: 184px;
  border-radius: 26px;
  padding: 18px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(6, 13, 24, 0.08)),
    linear-gradient(180deg, var(--cover-start, #34527a), var(--cover-end, #c98b4a));
  overflow: hidden;
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 38%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.08) 0,
      rgba(255, 255, 255, 0.08) 2px,
      transparent 2px,
      transparent 10px
    );
  opacity: 0.42;
}

.cover-sigil,
.cover-title {
  position: relative;
  z-index: 1;
}

.cover-sigil {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.8rem;
  font-family: var(--serif);
}

.cover-title {
  margin-top: 42px;
  font-family: var(--serif);
  font-size: 1.8rem;
  line-height: 1;
}

.book-card-title {
  font-size: 2rem;
}

.book-card-meta,
.book-card-summary,
.book-card-tags,
.toolbar-subtitle,
.chapter-blurb,
.directory-volume-label,
.directory-chapter-meta {
  color: var(--muted);
}

.book-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.88rem;
}

.book-card-summary {
  margin-top: 14px;
  line-height: 1.75;
}

.book-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.tag {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.8rem;
}

.book-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.primary-button {
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #e0a35f);
  color: #1c130c;
  font-weight: 700;
}

.primary-button:hover,
.primary-button:focus-visible,
.nav-button:hover,
.nav-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.reader-view {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: 24px;
}

.app-shell.reader-mode .reader-view {
  height: var(--app-height);
  margin-top: 0;
  padding: 12px;
}

.hidden {
  display: none !important;
}

.chapters-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100vw;
  max-width: none;
  height: var(--app-height);
  min-height: 0;
  padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  border-radius: 0;
  background: var(--panel-strong);
  opacity: 0;
  pointer-events: none;
  transform: translateY(2%);
  transition:
    opacity 180ms ease,
    transform 220ms ease;
}

.chapters-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h3 {
  font-size: 1.25rem;
}

.chapter-directory {
  display: grid;
  gap: 14px;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding: 4px 2px 40px 0;
}

.directory-volume {
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.directory-volume-label {
  margin: 0 0 12px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.chapter-button {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
  border: 1px solid transparent;
  cursor: pointer;
}

.chapter-button + .chapter-button {
  margin-top: 8px;
}

.chapter-button:hover,
.chapter-button:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(201, 139, 74, 0.3);
  outline: none;
}

.chapter-button.active {
  background: rgba(201, 139, 74, 0.14);
  border-color: rgba(201, 139, 74, 0.36);
}

.chapter-button-title {
  display: block;
  color: var(--text);
  font-weight: 600;
  font-size: 0.96rem;
}

.directory-chapter-meta {
  display: block;
  margin-top: 4px;
  font-size: 0.76rem;
}

.reader-stage {
  height: 100%;
  min-height: 0;
  padding: 6px;
  border-radius: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 4px;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.reader-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 0;
}

.toolbar-meta {
  min-width: 0;
  text-align: center;
}

.toolbar-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.toolbar-title,
.toolbar-subtitle,
.toolbar-separator {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-title {
  font-size: clamp(0.94rem, 1.2vw, 1.12rem);
}

.toolbar-subtitle,
.toolbar-separator {
  font-size: 0.76rem;
  color: var(--muted);
}

.page-frame {
  min-height: 0;
  height: 100%;
  padding: 2px;
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 245, 226, 0.12), transparent 32%),
    rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.06);
  perspective: 1800px;
}

.paper-page {
  position: relative;
  height: 100%;
  min-height: 0;
  padding: 10px clamp(12px, 2.2vw, 22px) 8px;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.45), transparent 10%, transparent 90%, rgba(98, 73, 38, 0.12)),
    linear-gradient(180deg, #f8eed8, var(--paper));
  color: var(--ink);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(124, 88, 41, 0.12);
  transform-origin: center center;
  backface-visibility: hidden;
  will-change: transform, box-shadow, filter;
}

.paper-page::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(45, 29, 12, 0.18), transparent 18%, transparent 80%, rgba(45, 29, 12, 0.1));
  opacity: 0;
  pointer-events: none;
}

.paper-page.turn-next {
  animation: page-turn-next 340ms cubic-bezier(0.2, 0.85, 0.22, 1);
}

.paper-page.turn-prev {
  animation: page-turn-prev 340ms cubic-bezier(0.2, 0.85, 0.22, 1);
}

.paper-page.turn-next::after,
.paper-page.turn-prev::after {
  opacity: 1;
}

.paper-head,
.paper-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.paper-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 2px 0;
  font-family: var(--serif);
  font-size: clamp(0.98rem, 1vw, 1.08rem);
  line-height: 1.82;
}

.paper-content p {
  margin: 0;
  text-indent: 2em;
}

.paper-content p + p {
  margin-top: 1.05em;
}

.mobile-only {
  display: none;
}

@keyframes page-turn-next {
  0% {
    transform: translateX(0) rotateY(0) scale(1);
    filter: brightness(1);
  }
  40% {
    transform: translateX(-8px) rotateY(-6deg) scale(0.995);
    filter: brightness(0.985);
  }
  100% {
    transform: translateX(0) rotateY(0) scale(1);
    filter: brightness(1);
  }
}

@keyframes page-turn-prev {
  0% {
    transform: translateX(0) rotateY(0) scale(1);
    filter: brightness(1);
  }
  40% {
    transform: translateX(8px) rotateY(6deg) scale(0.995);
    filter: brightness(0.985);
  }
  100% {
    transform: translateX(0) rotateY(0) scale(1);
    filter: brightness(1);
  }
}

@media (max-width: 1024px) {
  .hero-panel {
    grid-template-columns: 1fr;
  }

  .app-shell.reader-mode .reader-view {
    padding: 0;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .reader-stage {
    padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom));
  }

  .toolbar-meta {
    text-align: center;
  }

  .page-frame {
    padding: 0;
  }

  .paper-page {
    padding: 10px 10px 8px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 100%);
    padding-top: 14px;
  }

  .topbar,
  .hero-copy,
  .hero-stat-grid,
  .book-card {
    border-radius: 24px;
  }

  .book-card-top {
    grid-template-columns: 1fr;
  }

  .book-cover {
    min-height: 150px;
  }

  .hero-copy h2 {
    line-height: 1.02;
  }

  .hero-stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .page-frame {
    padding: 0;
  }

  .paper-page {
    border-radius: 12px;
    padding: 8px 8px 6px;
  }

  .paper-head,
  .paper-foot {
    flex-direction: row;
    align-items: center;
    font-size: 0.68rem;
  }

  .paper-content {
    font-size: 0.92rem;
    line-height: 1.76;
  }
}

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