:root {
  color-scheme: light;
  --bg: #f3ede4;
  --bg-strong: #e7dccb;
  --panel: rgba(255, 250, 243, 0.82);
  --panel-strong: rgba(255, 252, 247, 0.96);
  --text: #241c15;
  --muted: #67584b;
  --line: rgba(67, 46, 28, 0.12);
  --accent: #a85d2b;
  --accent-strong: #7f3d16;
  --chapter-accent: #2f8b7e;
  --shadow: 0 24px 60px rgba(61, 34, 15, 0.14);
  --reader-bg: #fff9f1;
  --reader-fg: #221b14;
  --reader-width: 760px;
  --reader-font: 19px;
  --reader-line: 1.75;
  --reader-dim: 0;
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

[data-theme="night"] {
  color-scheme: dark;
  --bg: #101014;
  --bg-strong: #17171f;
  --panel: rgba(22, 22, 30, 0.82);
  --panel-strong: rgba(26, 26, 35, 0.96);
  --text: #f5efe8;
  --muted: #b6a99a;
  --line: rgba(236, 221, 197, 0.12);
  --accent: #dd8758;
  --accent-strong: #ffad7a;
  --chapter-accent: #68c7ba;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --reader-bg: #16161d;
  --reader-fg: #f4ede5;
}

[data-theme="oled"] {
  color-scheme: dark;
  --bg: #000;
  --bg-strong: #050505;
  --panel: rgba(10, 10, 12, 0.88);
  --panel-strong: rgba(16, 16, 18, 0.98);
  --text: #f7f7f7;
  --muted: #b7b7b7;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #8bd3ff;
  --accent-strong: #bde7ff;
  --chapter-accent: #8cffd2;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.58);
  --reader-bg: #000;
  --reader-fg: #f2f2f2;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(168, 93, 43, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(96, 78, 58, 0.14), transparent 32%),
    linear-gradient(160deg, var(--bg), var(--bg-strong));
  color: var(--text);
  font-family: "Aptos", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: var(--app-height, 100svh);
  height: var(--app-height, 100dvh);
  min-height: 0;
  width: min(100%, 1760px);
  margin: 0 auto;
  padding: clamp(12px, 1.6vw, 24px);
  overflow: hidden;
}

.ambient {
  position: absolute;
  border-radius: 999px;
  filter: blur(10px);
  opacity: 0.55;
  pointer-events: none;
  animation: float 16s ease-in-out infinite;
}

.ambient-a {
  width: 280px;
  height: 280px;
  top: -80px;
  right: 12%;
  background: radial-gradient(circle, rgba(255, 184, 128, 0.4), transparent 70%);
}

.ambient-b {
  width: 220px;
  height: 220px;
  bottom: -60px;
  left: 6%;
  background: radial-gradient(circle, rgba(120, 89, 55, 0.28), transparent 70%);
  animation-delay: -6s;
}

.topbar,
.layout,
.library-view {
  position: relative;
  z-index: 1;
}

.app-view {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 2vw, 20px);
  margin-bottom: clamp(12px, 1.8vw, 22px);
}

.topbar > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: clamp(14px, 2vw, 26px);
}

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

.topbar h1 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(2rem, 3.4vw, 3.3rem);
  line-height: 0.95;
  white-space: nowrap;
}

.topbar-library-stats {
  display: none;
  align-items: center;
  gap: 6px;
}

body:not(.reader-view-active) .topbar-library-stats {
  display: flex;
}

.topbar-library-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.38rem 0.58rem;
  background: color-mix(in srgb, var(--panel-strong) 72%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.topbar-library-stats strong {
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1rem, 1.3vw, 1.22rem);
  line-height: 1;
  color: var(--text);
}

.topbar-library-stats small {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 10px);
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-actions .button,
.topbar-actions .file-button {
  min-height: 34px;
  padding: 0.56rem 0.72rem;
  font-size: 0.86rem;
  white-space: nowrap;
}

.topbar-theme-button {
  display: none;
}

.topbar-icon-button {
  width: 36px;
  min-width: 36px;
  padding-inline: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.08rem;
}

body.reader-view-active .topbar-theme-button,
body.reader-view-active .file-button {
  display: none;
}

.topbar-label-short {
  display: none;
}

.import-status {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 8px;
  margin: -4px 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.import-status-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.import-status-copy strong {
  color: var(--text);
}

.import-status-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
}

.import-status-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #f0b08c);
  transition: width 180ms ease;
}

.layout {
  display: grid;
  grid-template-columns: clamp(280px, 23vw, 360px) minmax(0, 1fr);
  gap: clamp(12px, 1.4vw, 22px);
  align-items: stretch;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.library-view {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  align-self: stretch;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.library-home-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  gap: clamp(8px, 1vw, 12px);
  padding: clamp(10px, 1.5vw, 18px);
  overflow: hidden;
  background:
    radial-gradient(circle at 11% 8%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 28%),
    radial-gradient(circle at 92% 18%, color-mix(in srgb, var(--chapter-accent) 16%, transparent), transparent 24%),
    linear-gradient(145deg, color-mix(in srgb, var(--panel-strong) 84%, transparent), color-mix(in srgb, var(--panel) 90%, transparent));
}

.library-home-panel.has-current-shelf {
  grid-template-columns: clamp(220px, 18vw, 300px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
}

.library-home-panel.has-current-shelf .library-home-header {
  display: none;
}

.library-home-header {
  grid-row: 1;
  display: none;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(8px, 1.4vw, 16px);
  min-height: 0;
  padding: clamp(8px, 1vw, 12px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel-strong) 58%, transparent);
}

.library-home-header p:not(.eyebrow) {
  max-width: 58ch;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.96rem, 1.2vw, 1.08rem);
  line-height: 1.55;
}

.library-home-copy {
  display: grid;
  gap: 3px;
  align-content: center;
  min-width: 0;
}

.library-home-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, auto));
  align-items: center;
  justify-content: end;
  gap: 6px;
  min-width: 0;
}

.library-home-stats span {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.56rem;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--panel-strong) 88%, transparent), color-mix(in srgb, var(--panel) 70%, transparent)),
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent) 12%, transparent), transparent 44%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.library-home-stats strong {
  color: var(--text);
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1rem, 1.5vw, 1.3rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.library-home-stats small {
  margin: 0;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-shelf {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: relative;
  min-height: 0;
  overflow: hidden;
  padding: clamp(8px, 1vw, 12px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--panel-strong) 60%, transparent), color-mix(in srgb, var(--panel) 72%, transparent)),
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent) 10%, transparent), transparent 34%);
}

.current-shelf {
  grid-row: 2;
}

.library-browse-panel {
  grid-row: 1;
}

.library-home-panel.has-current-shelf .library-browse-panel {
  grid-column: 2;
  grid-row: 1;
  height: 100%;
}

.library-home-panel.has-current-shelf .current-shelf {
  grid-column: 1;
  grid-row: 1;
  height: 100%;
}

.library-shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  margin-bottom: 6px;
}

.library-shelf-header h3 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1rem, 1.25vw, 1.25rem);
}

.library-shelf-header .eyebrow {
  margin: 0;
}

.library-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.library-controls label {
  display: grid;
  grid-template-columns: auto minmax(112px, 1fr);
  align-items: center;
  gap: 6px;
  min-width: min(100%, 154px);
  color: var(--muted);
  font-size: 0.76rem;
}

.library-controls select {
  padding: 0.42rem 0.62rem;
  font-size: 0.78rem;
}

.current-shelf-list,
.library-home-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 176px));
  grid-auto-flow: row;
  align-content: start;
  align-items: start;
  min-height: 0;
  gap: 9px;
  padding: 2px;
}

.current-shelf-list {
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
}

.library-home-list {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.current-shelf-list .library-item,
.library-home-list .library-item {
  height: auto;
  min-height: 0;
  align-items: stretch;
  overflow: hidden;
}

.current-shelf-list .library-open,
.library-home-list .library-open {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 5px;
  align-content: stretch;
  min-height: 0;
  height: auto;
}

.current-shelf-list .library-cover-card,
.library-home-list .library-cover-card {
  height: auto;
  min-height: 0;
  align-self: start;
  grid-template-rows: auto;
  padding: 8px;
  border-radius: 18px;
  gap: 0;
}

.current-shelf-list .library-cover-card-featured {
  height: 100%;
  align-self: stretch;
}

.current-shelf-list .library-cover-card-featured .library-open {
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
}

.current-shelf-list .library-cover-card-featured .library-card-copy {
  align-content: start;
  gap: 6px;
  min-height: 0;
}

.current-shelf-list .library-cover-card-featured .library-card-description {
  -webkit-line-clamp: 8;
}

.current-shelf-list .library-cover,
.library-home-list .library-cover {
  height: auto;
  min-height: 0;
  aspect-ratio: 2 / 3;
  border-radius: 14px;
}

.current-shelf-list .stack-item,
.library-home-list .stack-item {
  width: min(420px, calc(100vw - 48px));
  align-self: start;
}

.sidebar,
.reader-panel {
  display: grid;
  gap: clamp(12px, 1.4vw, 18px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

@media (min-width: 1121px) {
  .sidebar {
    grid-template-rows: auto auto minmax(0, 1fr);
    align-content: stretch;
  }

  .hero-panel,
  .chapter-panel {
    align-self: start;
  }

  .bookmarks-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
  }

  .bookmarks-panel .stack-list {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }
}

.reader-panel:fullscreen,
body.theater-mode .reader-panel {
  background:
    radial-gradient(circle at top left, rgba(168, 93, 43, 0.12), transparent 28%),
    linear-gradient(160deg, var(--bg), var(--bg-strong));
  display: block;
  padding: 0;
  overflow: hidden;
}

.reader-panel:fullscreen .reader-stage,
body.theater-mode .reader-stage {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.reader-panel:fullscreen .progress-row,
body.theater-mode .progress-row,
.reader-panel:fullscreen .chapter-nav,
body.theater-mode .chapter-nav {
  display: none;
}

.reader-panel:fullscreen .reader-window,
body.theater-mode .reader-window {
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: clamp(24px, 4vw, 52px) clamp(14px, 2vw, 24px);
}

body.fullscreen-mode #readerView .reader-panel:fullscreen .reader-stage,
body.fullscreen-mode #readerView .reader-panel:fullscreen .reader-window {
  height: 100svh;
  height: 100dvh;
}

body.theater-mode {
  overflow: hidden;
}

body.theater-mode .app-shell {
  width: 100%;
  max-width: none;
  height: 100svh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body.theater-mode .topbar,
body.theater-mode .sidebar {
  display: none;
}

body.theater-mode .layout {
  grid-template-columns: 1fr;
  gap: 0;
  height: 100svh;
}

body.theater-mode .reader-panel {
  height: 100%;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  border-radius: var(--radius-xl);
}

.hero-panel {
  display: grid;
  grid-template-columns: clamp(76px, 7vw, 92px) minmax(0, 1fr);
  gap: clamp(12px, 1.2vw, 16px);
  padding: clamp(14px, 1.4vw, 18px);
  align-items: center;
}

.hero-cover {
  width: clamp(76px, 7vw, 92px);
  height: auto;
  aspect-ratio: 0.74;
  border-radius: 20px;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: #fff8f1;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.16), transparent 45%),
    linear-gradient(145deg, #9d5630, #4b2311);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.hero-cover.has-cover {
  background: var(--panel-strong);
  color: transparent;
  box-shadow: 0 14px 30px rgba(61, 34, 15, 0.18);
}

.hero-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.hero-copy h2,
.panel-title h3,
.progress-row h3 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
}

.hero-copy {
  min-width: 0;
}

.hero-copy h2 {
  overflow-wrap: anywhere;
}

.hero-copy p,
.panel-title span {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.hero-library-button {
  margin-top: 12px;
}

.controls-panel {
  position: fixed;
  top: var(--settings-popover-top, 88px);
  right: var(--settings-popover-right, 24px);
  z-index: 35;
  width: min(var(--settings-popover-width, 380px), calc(100vw - 32px));
  max-height: min(74vh, 620px);
  overflow: visible;
  padding: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px) scale(0.985);
  transform-origin: top right;
  transition:
    opacity 160ms ease,
    transform 180ms cubic-bezier(0.2, 0.82, 0.22, 1);
}

.controls-panel:not([open]) {
  display: none;
}

.controls-panel[open] {
  display: block;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.controls-panel::before {
  content: "";
  position: absolute;
  top: -7px;
  right: 34px;
  width: 14px;
  height: 14px;
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  background: var(--panel);
  transform: rotate(45deg);
  backdrop-filter: blur(18px);
}

.chapter-panel {
  display: grid;
  gap: 10px;
  padding: 18px;
  min-width: 0;
}

.bookmarks-panel {
  padding: 18px;
  min-width: 0;
}

.settings-summary {
  display: none;
}

.settings-summary::-webkit-details-marker {
  display: none;
}

.settings-summary::after {
  content: none;
}

.controls-panel[open] .settings-summary::after {
  content: none;
}

.settings-controls {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 13px;
  max-height: min(74vh, 620px);
  overflow: auto;
  padding: 18px;
}

.settings-popover-title {
  margin-bottom: 0;
}

.settings-popover-title h3 {
  font-size: 1.05rem;
}

.settings-popover-title .button {
  padding: 0.46rem 0.72rem;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group label,
.panel-title span {
  font-size: 0.9rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.8rem 1rem;
  line-height: 1;
  transition:
    transform 180ms ease,
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.button-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: white;
}

.button-ghost,
.button-mini {
  background: rgba(255, 255, 255, 0.4);
  border-color: var(--line);
  color: var(--text);
}

.button-mini {
  padding: 0.52rem 0.8rem;
}

.button-full {
  width: 100%;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.library-list,
.stack-list {
  display: grid;
  gap: 10px;
}

.library-item,
.stack-item {
  width: 100%;
  border: 1px solid var(--line);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--panel-strong) 88%, transparent), color-mix(in srgb, var(--panel) 76%, transparent));
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  text-align: left;
}

.library-open,
.library-delete,
.bookmark-open,
.bookmark-delete {
  border: 0;
  background: transparent;
  color: inherit;
}

.library-open,
.bookmark-open {
  min-width: 0;
  padding: 0;
  text-align: left;
}

.library-cover-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 10px;
  border-radius: 24px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel-strong) 74%, transparent), color-mix(in srgb, var(--panel) 56%, transparent));
  box-shadow: 0 16px 34px rgba(61, 34, 15, 0.08);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.library-cover-card.active {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
}

.library-cover-card.active .library-cover {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 3px;
}

.library-cover-card .library-open {
  display: grid;
  gap: 12px;
  color: inherit;
}

.library-cover-card:hover {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow: 0 22px 48px rgba(61, 34, 15, 0.14);
  transform: translateY(-2px);
}

.library-cover {
  aspect-ratio: 2 / 3;
  width: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.16), transparent 46%),
    linear-gradient(145deg, #9d5630, #4b2311);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 18px 38px rgba(61, 34, 15, 0.16);
  color: #fff8f1;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
}

.library-cover-card .library-cover,
.library-cover-card .library-cover span {
  color: #fff8f1;
}

.library-cover-card .library-open:hover .library-cover {
  transform: translateY(-4px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 24px 48px rgba(61, 34, 15, 0.22);
}

.library-cover.has-cover {
  background: var(--panel-strong);
}

.library-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.library-card-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.library-card-copy strong {
  margin: 0;
  line-height: 1.18;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-card-copy span,
.library-card-copy small {
  color: var(--muted);
}

.library-card-copy small {
  font-size: 0.72rem;
}

.library-card-description {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-style: normal;
  font-size: 0.76rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
}

.library-card-progress {
  position: relative;
  height: 5px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
}

.library-card-progress span {
  position: absolute;
  inset-block: 0;
  left: 0;
  width: var(--book-progress, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #f0b08c);
}

.library-cover-card .library-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  justify-self: end;
  background: color-mix(in srgb, var(--panel-strong) 88%, transparent);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateY(-4px);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.library-cover-card:hover .library-delete,
.library-cover-card:focus-within .library-delete {
  opacity: 1;
  transform: translateY(0);
}

.library-delete,
.bookmark-delete {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.48rem 0.72rem;
  color: var(--muted);
}

.library-delete:hover,
.bookmark-delete:hover {
  border-color: rgba(168, 93, 43, 0.34);
  color: var(--accent-strong);
}

.bookmark-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.library-item strong,
.stack-item strong {
  display: block;
  margin-bottom: 4px;
}

.library-item span,
.stack-item span,
.stack-item small {
  color: var(--muted);
}

.select-label {
  color: var(--muted);
  font-size: 0.88rem;
}

#chapterSelect,
#pageColumns,
#themePreset,
#librarySort,
#libraryFilter {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 0.72rem 1rem;
}

.reader-stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: clamp(10px, 1.2vw, 16px);
  overflow: hidden;
}

.progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 12px;
  margin-bottom: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--panel-strong) 90%, transparent), color-mix(in srgb, var(--panel) 76%, transparent)),
    radial-gradient(circle at top right, rgba(168, 93, 43, 0.08), transparent 34%);
}

.progress-heading {
  display: contents;
}

.progress-heading > div {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}

.progress-row .eyebrow {
  margin-bottom: 2px;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
}

.progress-row h3 {
  font-size: 0.98rem;
  line-height: 1.05;
}

.progress-metrics {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.progress-metric {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 28px;
  padding: 0.28rem 0.46rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-strong) 82%, transparent);
  color: var(--muted);
  font-size: 0.72rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.progress-metric strong {
  color: var(--text);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.progress-metric small {
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-swatch {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent);
}

.progress-swatch-book {
  background: linear-gradient(135deg, var(--accent), #f0b08c);
  color: var(--accent);
}

.progress-swatch-chapter {
  background: linear-gradient(135deg, var(--chapter-accent), color-mix(in srgb, var(--chapter-accent) 55%, white));
  color: var(--chapter-accent);
}

.progress-track {
  grid-column: 1 / -1;
  grid-row: 2;
  position: relative;
  width: 100%;
  height: 18px;
  border: 1px solid color-mix(in srgb, var(--line) 78%, rgba(255, 255, 255, 0.4));
  border-radius: 11px;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent) 14%, var(--panel-strong)) 0 50%,
      color-mix(in srgb, var(--chapter-accent) 14%, var(--panel-strong)) 50% 100%
    );
  box-shadow:
    inset 0 1px 2px rgba(36, 28, 21, 0.12),
    0 8px 20px rgba(61, 34, 15, 0.08);
  overflow: hidden;
}

.progress-track::before {
  content: "";
  position: absolute;
  inset-inline: 8px;
  top: 50%;
  z-index: 4;
  height: 1px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--reader-bg) 74%, transparent);
  transform: translateY(-50%);
  pointer-events: none;
}

.progress-track::after {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: 3;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 42%, rgba(0, 0, 0, 0.05) 50%, transparent 58%);
  pointer-events: none;
}

.progress-fill {
  position: absolute;
  left: 0;
  width: 0;
  transition: width 260ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

.progress-fill-book {
  top: 2px;
  height: calc(50% - 3px);
  z-index: 1;
  border-radius: 999px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 78%, #3b2112), var(--accent), #f0b08c),
    var(--accent);
  box-shadow: inset -10px 0 18px rgba(255, 255, 255, 0.2);
}

.progress-fill-chapter {
  bottom: 2px;
  height: calc(50% - 3px);
  z-index: 2;
  border-radius: 999px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--chapter-accent) 82%, #12312c), var(--chapter-accent), color-mix(in srgb, var(--chapter-accent) 52%, white));
  box-shadow: inset -10px 0 18px rgba(255, 255, 255, 0.18);
}

.progress-fill-chapter::after {
  content: none;
}

.reading-stats {
  grid-column: 1 / -1;
  grid-row: 3;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.chapter-nav {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
}

.reader-window {
  position: relative;
  isolation: isolate;
  perspective: 1800px;
  border-radius: calc(var(--radius-xl) - 4px);
  background:
    radial-gradient(circle at top right, rgba(168, 93, 43, 0.08), transparent 24%),
    var(--reader-bg);
  color: var(--reader-fg);
  border: 1px solid var(--line);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: clamp(30px, 3.2vw, 46px) clamp(18px, 2.1vw, 32px);
  display: flex;
  justify-content: center;
}

.reader-window::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: rgba(0, 0, 0, var(--reader-dim));
  transition: background-color 160ms ease;
}

.page-turn-layer {
  position: absolute;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  background: var(--reader-bg);
  color: var(--reader-fg);
  transform: translateX(0);
  will-change: transform, opacity, filter;
}

.page-turn-layer::after {
  content: "";
  position: absolute;
  inset-block: 0;
  z-index: 3;
  width: clamp(42px, 10%, 84px);
  opacity: 0;
  filter: blur(1px);
  pointer-events: none;
}

.page-turn-page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--reader-bg);
}

.page-turn-content {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  pointer-events: none;
  will-change: transform;
}

.page-turn-layer.turn-forward::after {
  right: -30px;
  background: linear-gradient(90deg, rgba(25, 15, 8, 0.28), rgba(25, 15, 8, 0.12), transparent);
}

.page-turn-layer.turn-back::after {
  left: -30px;
  background: linear-gradient(270deg, rgba(25, 15, 8, 0.28), rgba(25, 15, 8, 0.12), transparent);
}

.page-turn-layer.is-turning.turn-forward {
  animation: kindlePageOutForward 340ms cubic-bezier(0.23, 0.82, 0.24, 1) both;
}

.page-turn-layer.is-turning.turn-back {
  animation: kindlePageOutBack 340ms cubic-bezier(0.23, 0.82, 0.24, 1) both;
}

.page-turn-layer.is-turning.turn-forward::after {
  animation: kindlePageShadow 340ms ease-in-out both;
}

.page-turn-layer.is-turning.turn-back::after {
  animation: kindlePageShadow 340ms ease-in-out both;
}

.reader-fullscreen-toggle,
.reader-theater-toggle {
  position: absolute;
  z-index: 5;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-strong) 84%, transparent);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0;
  box-shadow: 0 10px 24px rgba(61, 34, 15, 0.12);
  transform: translateY(0);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.reader-fullscreen-toggle {
  top: 14px;
  right: 14px;
}

.reader-theater-toggle {
  top: 14px;
  right: 62px;
  width: auto;
  min-width: 76px;
  padding: 0 0.82rem;
  font-size: 0.82rem;
  font-weight: 700;
}

.reader-fullscreen-toggle:hover,
.reader-theater-toggle:hover {
  border-color: rgba(168, 93, 43, 0.34);
  color: var(--accent-strong);
}

.reader-panel:fullscreen .reader-fullscreen-toggle,
.reader-panel:fullscreen .reader-theater-toggle,
body.fullscreen-mode .reader-panel .reader-fullscreen-toggle,
body.fullscreen-mode .reader-panel .reader-theater-toggle {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}

.reader-panel:fullscreen .reader-window.immersive-controls-visible .reader-fullscreen-toggle,
.reader-panel:fullscreen .reader-window.immersive-controls-visible .reader-theater-toggle,
body.fullscreen-mode .reader-window.immersive-controls-visible .reader-fullscreen-toggle,
body.fullscreen-mode .reader-window.immersive-controls-visible .reader-theater-toggle,
.reader-panel:fullscreen .reader-fullscreen-toggle:focus-visible,
.reader-panel:fullscreen .reader-theater-toggle:focus-visible,
body.fullscreen-mode .reader-panel .reader-fullscreen-toggle:focus-visible,
body.fullscreen-mode .reader-panel .reader-theater-toggle:focus-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.reader-panel:fullscreen .reader-theater-toggle,
body.fullscreen-mode .reader-panel .reader-theater-toggle {
  display: none !important;
}

body.fullscreen-mode .mobile-reader-toolbar,
body.fullscreen-mode .mobile-progress-rail,
body.fullscreen-mode .mobile-sheet-backdrop {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.reader-edge {
  position: absolute;
  top: 50%;
  z-index: 4;
  width: 46px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-strong) 86%, transparent);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 2rem;
  line-height: 1;
  transform: translateY(-50%);
  box-shadow: 0 14px 34px rgba(61, 34, 15, 0.14);
}

.reader-edge-left {
  left: 14px;
}

.reader-edge-right {
  right: 14px;
}

.reader-edge:hover:not(:disabled) {
  border-color: rgba(168, 93, 43, 0.34);
  color: var(--accent-strong);
}

.reader-edge:disabled {
  opacity: 0.18;
  cursor: not-allowed;
}

.reader-content {
  position: relative;
  z-index: 1;
  width: min(100%, var(--reader-width));
  max-width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  column-gap: 0;
  column-fill: auto;
  font-size: var(--reader-font);
  line-height: var(--reader-line);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

.reader-panel:fullscreen .reader-content,
body.theater-mode .reader-content {
  max-width: none;
}

.reader-content.page-turn-enter.enter-forward {
  animation: kindlePageInForward 340ms cubic-bezier(0.23, 0.82, 0.24, 1) both;
}

.reader-content.page-turn-enter.enter-back {
  animation: kindlePageInBack 340ms cubic-bezier(0.23, 0.82, 0.24, 1) both;
}

.page-turn-content.reader-content {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  max-width: none;
  pointer-events: none;
}

.fullscreen-progress {
  display: none;
}

.reader-panel:fullscreen .fullscreen-progress,
body.theater-mode .fullscreen-progress {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 4;
  display: block;
  padding: 8px clamp(18px, 6vw, 72px) 10px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.16));
  opacity: 0;
  transform: translateY(calc(100% - 6px));
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.reader-panel:fullscreen .fullscreen-progress:hover,
body.theater-mode .fullscreen-progress:hover {
  opacity: 1;
  transform: translateY(0);
}

.fullscreen-progress-track {
  position: relative;
  height: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent) 28%, rgba(255, 255, 255, 0.2)) 0 50%,
      color-mix(in srgb, var(--chapter-accent) 28%, rgba(255, 255, 255, 0.2)) 50% 100%
    );
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.28),
    0 8px 22px rgba(0, 0, 0, 0.24);
}

.fullscreen-progress-track::before {
  content: "";
  position: absolute;
  inset-inline: 8px;
  top: 50%;
  z-index: 4;
  height: 1px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  transform: translateY(-50%);
  pointer-events: none;
}

.fullscreen-progress-track::after {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: 3;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 42%, rgba(0, 0, 0, 0.08) 50%, transparent 58%);
  pointer-events: none;
}

.fullscreen-progress-fill {
  position: absolute;
  left: 0;
  width: 0;
  transition: width 260ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

.fullscreen-progress-fill.progress-fill-book {
  top: 2px;
  height: calc(50% - 3px);
}

.fullscreen-progress-fill.progress-fill-chapter {
  top: auto;
  bottom: 2px;
  height: calc(50% - 3px);
}

.fullscreen-progress-fill.progress-fill-chapter::after {
  content: none;
}

.reader-content h1,
.reader-content h2,
.reader-content h3 {
  font-family: "Georgia", "Times New Roman", serif;
  line-height: 1.15;
  margin: 1.8em 0 0.5em;
}

.reader-content p,
.reader-content blockquote,
.reader-content ul,
.reader-content ol,
.reader-content pre {
  margin: 0 0 1em;
}

.reader-content blockquote {
  border-left: 4px solid rgba(168, 93, 43, 0.5);
  padding: 0.2rem 0 0.2rem 1rem;
  color: rgba(34, 27, 20, 0.82);
}

.reader-content pre {
  overflow: auto;
  padding: 1rem;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.05);
}

.reader-content img,
.reader-content svg {
  display: block;
  max-width: 100%;
  max-height: calc(100% - 2rem);
  height: auto;
  margin: 1.4rem auto;
  break-inside: avoid;
  object-fit: contain;
}

.reader-content mark {
  background: rgba(255, 208, 105, 0.65);
  color: inherit;
  padding: 0 0.1em;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 52vh;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0 0 10px;
  color: var(--text);
}

.mobile-reader-toolbar,
.mobile-progress-rail,
.mobile-sheet-backdrop,
.mobile-sheet-close {
  display: none;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  min-width: 240px;
  max-width: min(92vw, 360px);
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 220ms ease,
    opacity 220ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.hidden {
  display: none;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(18px);
  }
}

@keyframes kindlePageOutForward {
  0% {
    opacity: 1;
    transform: translateX(0);
    filter: brightness(1);
  }
  58% {
    opacity: 1;
    transform: translateX(-62%);
    filter: brightness(0.985);
  }
  100% {
    opacity: 0;
    transform: translateX(-106%);
    filter: brightness(0.97);
  }
}

@keyframes kindlePageOutBack {
  0% {
    opacity: 1;
    transform: translateX(0);
    filter: brightness(1);
  }
  58% {
    opacity: 1;
    transform: translateX(62%);
    filter: brightness(0.985);
  }
  100% {
    opacity: 0;
    transform: translateX(106%);
    filter: brightness(0.97);
  }
}

@keyframes kindlePageInForward {
  0% {
    opacity: 0.88;
    transform: translateX(18px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes kindlePageInBack {
  0% {
    opacity: 0.88;
    transform: translateX(-18px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes kindlePageShadow {
  0% {
    opacity: 0;
    transform: scaleX(0.45);
  }
  34% {
    opacity: 0.42;
    transform: scaleX(0.86);
  }
  70% {
    opacity: 0.24;
    transform: scaleX(1);
  }
  100% {
    opacity: 0;
    transform: scaleX(0.7);
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-turn-layer,
  .page-turn-layer::after,
  .reader-content.page-turn-enter {
    animation: none !important;
  }
}

@media (max-width: 1280px) {
  .layout {
    grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  }
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .reader-panel {
    order: -1;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .reader-window {
    height: 100%;
    min-height: 0;
  }
}

@media (max-width: 860px) {
  .library-home-header {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .library-home-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-content: stretch;
  }

  .library-home-stats span {
    justify-content: center;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body.reader-view-active:not(.theater-mode) {
    overflow: hidden;
  }

  .topbar-library-stats {
    display: none !important;
  }

  .app-shell {
    height: 100svh;
    height: 100dvh;
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .ambient {
    display: none;
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .topbar h1 {
    font-size: clamp(1.55rem, 7vw, 2.1rem);
  }

  .topbar-actions {
    display: flex;
    gap: 6px;
    flex: 0 1 auto;
    justify-content: flex-end;
  }

  .topbar-actions .button,
  .file-button {
    width: auto;
    min-height: 30px;
    padding: 0.48rem 0.58rem;
    font-size: 0.76rem;
    justify-content: center;
  }

  .layout,
  .library-view,
  .sidebar,
  .reader-panel {
    gap: 12px;
  }

  body:not(.reader-view-active) .library-view {
    height: 100%;
    min-height: 0;
  }

  body:not(.reader-view-active) .library-home-panel {
    height: 100%;
    min-height: 0;
    max-height: 100%;
  }

  body.reader-view-active:not(.theater-mode) .app-shell {
    min-height: 100svh;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      calc(78px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  body.mobile-reader-chrome-hidden:not(.theater-mode) .app-shell {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  body.reader-view-active:not(.theater-mode) .topbar {
    display: none;
  }

  #readerView {
    align-items: start;
  }

  body:not(.theater-mode) #readerView .sidebar {
    display: contents;
  }

  body:not(.theater-mode) #readerView .hero-panel {
    position: sticky;
    top: 10px;
    z-index: 6;
    order: 1;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    min-height: 64px;
    padding: 8px 10px;
    border-radius: 16px;
    transition:
      opacity 180ms ease,
      transform 180ms ease,
      max-height 180ms ease,
      padding 180ms ease,
      border-width 180ms ease;
  }

  body.mobile-reader-chrome-hidden:not(.theater-mode) #readerView .hero-panel {
    max-height: 0;
    min-height: 0;
    padding-block: 0;
    border-width: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transform: translateY(-120%);
  }

  body:not(.theater-mode) #readerView .reader-panel {
    order: 2;
  }

  body:not(.theater-mode) #readerView .hero-cover {
    width: 44px;
    height: 58px;
    border-radius: 10px;
    font-size: 0.72rem;
  }

  body:not(.theater-mode) #readerView .hero-copy {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 8px;
  }

  body:not(.theater-mode) #readerView .hero-copy .eyebrow {
    grid-column: 1;
    margin: 0 0 2px;
    font-size: 0.62rem;
    letter-spacing: 0.14em;
  }

  body:not(.theater-mode) #readerView .hero-copy h2 {
    grid-column: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body:not(.theater-mode) #readerView .hero-copy p:not(.eyebrow) {
    display: none;
  }

  body:not(.theater-mode) #readerView .hero-library-button {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: auto;
    margin: 0;
    padding: 0.52rem 0.68rem;
    font-size: 0.78rem;
  }

  body:not(.theater-mode) #readerView .reader-panel:not(:fullscreen) .reader-stage {
    display: grid;
    gap: 10px;
    padding: 8px;
  }

  body:not(.theater-mode) #readerView .reader-panel:not(:fullscreen) .reader-window {
    order: 1;
  }

  body.reader-view-active:not(.theater-mode) #readerView .chapter-panel,
  body.reader-view-active:not(.theater-mode) #readerView .controls-panel,
  body.reader-view-active:not(.theater-mode) #readerView .bookmarks-panel,
  body.reader-view-active:not(.theater-mode) #readerView .progress-row {
    position: fixed;
    top: auto;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    width: auto;
    bottom: calc(72px + env(safe-area-inset-bottom));
    z-index: 45;
    max-height: min(74svh, 620px);
    overflow: auto;
    overscroll-behavior: contain;
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(100% + 26px));
    transition:
      opacity 200ms ease,
      transform 220ms cubic-bezier(0.2, 0.82, 0.22, 1);
  }

  body.reader-view-active:not(.theater-mode) #readerView .controls-panel {
    transform-origin: bottom center;
  }

  body.reader-view-active:not(.theater-mode) #readerView .controls-panel .settings-controls {
    max-height: none;
    overflow: visible;
  }

  body.reader-view-active:not(.theater-mode) #readerView .controls-panel::before {
    content: none;
  }

  body.reader-view-active:not(.theater-mode) #readerView .chapter-panel.mobile-sheet-active,
  body.reader-view-active:not(.theater-mode) #readerView .controls-panel.mobile-sheet-active,
  body.reader-view-active:not(.theater-mode) #readerView .bookmarks-panel.mobile-sheet-active,
  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 14px;
    border-radius: 20px;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .progress-heading > div {
    grid-column: 1;
    grid-row: 1;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .eyebrow {
    display: block;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .mobile-sheet-close {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .progress-metrics {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .progress-track {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  body.reader-view-active:not(.theater-mode) #readerView .progress-row.mobile-sheet-active .reading-stats {
    grid-column: 1 / -1;
    grid-row: 4;
  }

  body.reader-view-active:not(.theater-mode) #readerView .bookmarks-panel .panel-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

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

  .mobile-sheet-backdrop:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    background: rgba(24, 18, 12, 0.28);
    backdrop-filter: blur(2px);
  }

  .mobile-reader-toolbar:not([hidden]) {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 32;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: color-mix(in srgb, var(--panel-strong) 88%, transparent);
    box-shadow: 0 16px 44px rgba(35, 24, 14, 0.22);
    backdrop-filter: blur(18px);
    transition:
      opacity 180ms ease,
      transform 180ms ease;
  }

  .mobile-reader-toolbar button {
    display: grid;
    gap: 2px;
    place-items: center;
    min-height: 46px;
    border: 0;
    border-radius: 16px;
    background: transparent;
    color: var(--muted);
  }

  .mobile-reader-toolbar button:hover,
  .mobile-reader-toolbar button:focus-visible,
  .mobile-reader-toolbar button.is-active {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent-strong);
  }

  .mobile-reader-toolbar span {
    font-weight: 800;
    font-size: 1rem;
    line-height: 1;
  }

  .mobile-reader-toolbar small {
    font-size: 0.68rem;
  }

  .mobile-progress-rail:not([hidden]) {
    position: fixed;
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(74px + env(safe-area-inset-bottom));
    z-index: 33;
    display: block;
    height: 14px;
    border: 0;
    border-radius: 999px;
    padding: 0;
    background: transparent;
    transition:
      bottom 180ms ease,
      opacity 180ms ease,
      transform 180ms ease;
  }

  .mobile-progress-track {
    position: relative;
    display: block;
    height: 100%;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.34);
    border-radius: inherit;
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb, var(--accent) 22%, rgba(255, 255, 255, 0.28)) 0 50%,
        color-mix(in srgb, var(--chapter-accent) 22%, rgba(255, 255, 255, 0.28)) 50% 100%
      );
    box-shadow:
      inset 0 1px 2px rgba(0, 0, 0, 0.22),
      0 8px 24px rgba(35, 24, 14, 0.16);
  }

  .mobile-progress-track::after {
    content: "";
    position: absolute;
    inset-inline: 8px;
    top: 50%;
    z-index: 4;
    height: 1px;
    background: rgba(255, 255, 255, 0.48);
    transform: translateY(-50%);
  }

  .mobile-progress-fill {
    position: absolute;
    left: 0;
    width: 0;
    border-radius: 999px;
    transition: width 260ms cubic-bezier(0.2, 0.72, 0.18, 1);
  }

  .mobile-progress-fill-book {
    top: 2px;
    height: calc(50% - 3px);
    background: linear-gradient(90deg, var(--accent), #f0b08c);
  }

  .mobile-progress-fill-chapter {
    bottom: 2px;
    height: calc(50% - 3px);
    background: linear-gradient(90deg, var(--chapter-accent), color-mix(in srgb, var(--chapter-accent) 55%, white));
  }

  body.mobile-reader-chrome-hidden .mobile-reader-toolbar:not([hidden]) {
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(100% + 18px));
  }

  body.mobile-reader-chrome-hidden .mobile-progress-rail:not([hidden]) {
    bottom: max(8px, env(safe-area-inset-bottom));
    opacity: 0.78;
  }

  body.mobile-sheet-open .mobile-progress-rail:not([hidden]) {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
  }

  body:not(.reader-view-active) .app-shell {
    grid-template-rows: auto auto minmax(0, 1fr);
    height: var(--app-height, 100svh);
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100svh);
    min-height: var(--app-height, 100dvh);
  }

  body:not(.reader-view-active) .topbar {
    margin-bottom: 6px;
  }

  body:not(.reader-view-active) .library-view {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .library-home-panel {
    display: flex;
    flex-direction: column;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    height: 100%;
    max-height: 100%;
    gap: 6px;
    padding: 6px;
    border-radius: 15px;
  }

  .library-home-panel.has-current-shelf {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(104px, 30vw, 128px);
    grid-template-rows: auto minmax(0, 1fr);
    align-items: stretch;
  }

  .library-home-panel.has-current-shelf .library-home-header {
    display: grid;
    grid-column: 1;
    grid-row: 1;
  }

  .library-home-panel.has-current-shelf .library-home-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .library-home-panel.has-current-shelf .library-home-stats span {
    justify-content: center;
  }

  .library-home-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
    padding: 7px;
    border-radius: 13px;
  }

  .library-home-header p:not(.eyebrow) {
    display: none;
  }

  .library-home-copy .eyebrow {
    margin: 0;
    font-size: 0.6rem;
    letter-spacing: 0.12em;
  }

  .library-home-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
  }

  .library-home-stats span {
    gap: 3px;
    min-height: 0;
    border-radius: 11px;
    padding: 0.34rem 0.28rem;
  }

  .library-home-stats strong {
    font-size: 0.94rem;
  }

  .library-home-stats small {
    font-size: 0.46rem;
    letter-spacing: 0.07em;
  }

  .library-shelf {
    padding: 6px;
    border-radius: 13px;
  }

  .library-home-header {
    flex: 0 0 auto;
  }

  .library-shelf-header {
    gap: 5px;
    margin-bottom: 5px;
  }

  .library-browse-header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .library-shelf-header h3 {
    font-size: 0.9rem;
    line-height: 1;
  }

  .library-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
  }

  .library-controls label {
    grid-template-columns: 1fr;
    gap: 0;
    min-width: 0;
  }

  .library-controls label > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .library-controls select {
    padding: 0.42rem 0.56rem;
    font-size: 0.76rem;
  }

  .library-home-panel.has-current-shelf .current-shelf {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    min-height: 0;
  }

  .library-home-panel.has-current-shelf .library-browse-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    flex: 1 1 auto;
    min-height: 0;
  }

  .current-shelf .eyebrow {
    margin-bottom: 0;
    font-size: 0.54rem;
    letter-spacing: 0.1em;
  }

  .current-shelf-list,
  .library-home-list {
    gap: 6px;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    grid-auto-flow: row;
    align-content: start;
    align-items: start;
    padding: 1px;
  }

  .current-shelf-list {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow: hidden;
  }

  .library-home-list {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 10px;
  }

  .library-cover-card {
    padding: 5px;
    border-radius: 11px;
  }

  .library-cover-card .library-delete {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    top: 5px;
    right: 5px;
    padding: 0;
    font-size: 0;
    opacity: 1;
    transform: none;
  }

  .library-cover-card .library-delete::before {
    content: "\00d7";
    font-size: 1.08rem;
    line-height: 1;
  }

  .current-shelf-list .library-cover-card .library-open,
  .library-home-list .library-cover-card .library-open {
    gap: 4px;
  }

  .current-shelf-list .library-cover,
  .library-home-list .library-cover {
    height: auto;
    aspect-ratio: 2 / 3;
    border-radius: 11px;
  }

  .current-shelf-list .library-card-copy span,
  .library-home-list .library-card-copy span {
    display: none;
  }

  .current-shelf-list .library-card-copy strong,
  .library-home-list .library-card-copy strong {
    font-size: 0.68rem;
    line-height: 1.05;
    -webkit-line-clamp: 1;
  }

  .current-shelf-list .library-card-copy small,
  .library-home-list .library-card-copy small {
    display: none;
  }

  .library-card-description {
    display: none;
  }

  .current-shelf-list .library-card-progress,
  .library-home-list .library-card-progress {
    height: 5px;
    margin-top: 3px;
  }

  .panel {
    border-radius: 18px;
  }

  .hero-panel {
    grid-template-columns: 72px minmax(0, 1fr);
    padding: 12px;
    text-align: left;
  }

  .hero-cover {
    width: 72px;
    height: 98px;
    border-radius: 14px;
    font-size: 1rem;
  }

  .hero-copy h2 {
    font-size: 1.08rem;
  }

  .hero-copy p {
    font-size: 0.9rem;
  }

  .settings-summary,
  .settings-controls {
    padding-inline: 14px;
  }

  .library-item:not(.library-cover-card),
  .bookmark-item {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 10px;
  }

  .library-delete,
  .bookmark-delete {
    padding: 0.5rem 0.62rem;
    font-size: 0.85rem;
  }

  .reader-stage {
    padding: 10px;
  }

  .progress-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 8px;
    margin-bottom: 8px;
    padding: 8px;
  }

  .progress-heading {
    display: contents;
  }

  .progress-heading > div {
    grid-column: 1;
  }

  .progress-row .eyebrow {
    display: none;
  }

  .progress-row h3 {
    font-size: 0.9rem;
  }

  .progress-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .progress-metrics {
    grid-column: 2;
    justify-content: flex-end;
  }

  .progress-metric {
    flex: 0 0 auto;
    justify-content: center;
  }

  .progress-metric small {
    display: none;
  }

  .reading-stats {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .chapter-nav {
    margin-bottom: 10px;
  }

  .reader-window {
    height: 100%;
    min-height: 0;
    padding: 24px 12px;
    border-radius: 16px;
  }

  body.reader-view-active:not(.theater-mode) #readerView .chapter-nav {
    display: none;
  }

  body.reader-view-active:not(.theater-mode) #readerView .reader-window {
    height: calc(100svh - 184px - env(safe-area-inset-bottom));
    min-height: 0;
    padding: 22px 12px;
  }

  body.mobile-reader-chrome-hidden:not(.theater-mode) #readerView .reader-window {
    height: calc(100svh - 48px - env(safe-area-inset-bottom));
  }

  .reader-edge {
    display: none;
  }

  .reader-theater-toggle,
  .reader-panel:fullscreen .reader-theater-toggle,
  body.theater-mode .reader-theater-toggle {
    display: none;
  }

  .reader-content {
    font-size: min(var(--reader-font), 20px);
  }

  .reader-content img,
  .reader-content svg {
    max-height: calc(100% - 2rem);
  }

  .reader-panel:fullscreen,
  body.theater-mode .reader-panel {
    padding: 0;
  }

  .reader-panel:fullscreen .reader-window,
  body.theater-mode .reader-window {
    height: 100svh;
    height: 100dvh;
    min-height: 0;
    padding: 18px 10px 16px;
  }

  body.fullscreen-mode.reader-view-active:not(.theater-mode) #readerView .reader-panel:fullscreen .reader-stage,
  body.fullscreen-mode.reader-view-active:not(.theater-mode) #readerView .reader-panel:fullscreen .reader-window {
    height: 100svh;
    height: 100dvh;
    min-height: 0;
  }

  body.fullscreen-mode.reader-view-active:not(.theater-mode) #readerView .reader-panel:fullscreen .reader-window {
    padding: 18px 10px 16px;
  }

  .reader-panel:fullscreen .fullscreen-progress,
  body.theater-mode .fullscreen-progress {
    opacity: 1;
    transform: translateY(0);
    padding: 6px 14px 8px;
  }

  .reader-panel:fullscreen .fullscreen-progress {
    padding-inline:
      max(22px, env(safe-area-inset-left))
      max(22px, env(safe-area-inset-right));
  }

  .reader-panel:fullscreen .reader-fullscreen-toggle,
  body.theater-mode .reader-fullscreen-toggle {
    top: 8px;
    right: 10px;
  }

  .reader-panel:fullscreen .reader-theater-toggle,
  body.theater-mode .reader-theater-toggle {
    top: 8px;
    right: 58px;
  }
}

@media (max-width: 430px) {
  .eyebrow {
    letter-spacing: 0.12em;
  }

  .library-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .hero-cover {
    width: 64px;
    height: 86px;
  }

  body:not(.theater-mode) #readerView .hero-panel {
    top: 8px;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 8px;
    min-height: 58px;
    padding: 7px 8px;
  }

  body:not(.theater-mode) #readerView .hero-cover {
    width: 40px;
    height: 54px;
  }

  body:not(.theater-mode) #readerView .hero-copy h2 {
    font-size: 0.94rem;
  }

  body:not(.theater-mode) #readerView .hero-library-button {
    padding: 0.48rem 0.56rem;
    font-size: 0.72rem;
  }

  .topbar-label-full {
    display: none;
  }

  .topbar-label-short {
    display: inline;
  }

  body:not(.theater-mode) #readerView .reader-panel:not(:fullscreen) .reader-stage {
    padding: 6px;
  }

  .reader-window {
    height: 100%;
    min-height: 0;
  }

  .reader-panel:fullscreen .reader-window,
  body.theater-mode .reader-window {
    height: 100svh;
    height: 100dvh;
    padding: 16px 8px 14px;
  }

  body.fullscreen-mode.reader-view-active:not(.theater-mode) #readerView .reader-panel:fullscreen .reader-window {
    padding: 16px 8px 14px;
  }
}
