:root {
  color-scheme: light;
  --bg: #f3eee3;
  --bg-accent: #e0d4be;
  --panel: rgba(255, 250, 240, 0.88);
  --panel-border: rgba(88, 62, 38, 0.14);
  --ink: #23170d;
  --muted: #695848;
  --accent: #8a5a30;
  --accent-strong: #5d3514;
  --reader-width: min(100%, 1440px);
  --reader-padding: 30%;
  --reader-font-size: 100%;
  --reader-font-family: "Source Serif 4";
  font-family: "IBM Plex Sans", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 30%),
    linear-gradient(180deg, #f8f2e8 0%, var(--bg) 50%, #e7dcc9 100%);
  color: var(--ink);
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.page-shell {
  width: min(100%, 1720px);
  margin: 0 auto;
  padding: 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow,
.panel-label,
.status-label,
.empty-kicker {
  margin: 0 0 8px;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar h1,
.panel-card h2,
.empty-state h2 {
  margin: 0;
  font-family: "Source Serif 4", serif;
  font-weight: 600;
}

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

.reader-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.control-panel {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 24px;
}

.library-card {
  display: grid;
  gap: 14px;
}

.panel-card,
.reader-frame {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(51, 32, 15, 0.1);
  backdrop-filter: blur(14px);
}

.panel-card {
  padding: 20px;
}

.book-selector {
  display: grid;
  gap: 12px;
}

.book-option {
  border: 1px solid rgba(88, 62, 38, 0.12);
  border-radius: 20px;
  background: rgba(255, 252, 245, 0.88);
  padding: 10px;
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.book-option:hover {
  transform: translateY(-1px);
  border-color: rgba(88, 62, 38, 0.24);
  box-shadow: 0 18px 40px rgba(51, 32, 15, 0.08);
}

.book-option.is-active {
  border-color: rgba(93, 53, 20, 0.5);
  box-shadow: 0 0 0 1px rgba(93, 53, 20, 0.12);
}

.book-option-title {
  display: block;
  font-weight: 600;
  color: var(--ink);
}

.muted {
  color: var(--muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.upload-button,
.toc-button,
.reader-nav,
.toc-close {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: rgba(138, 90, 48, 0.12);
  color: var(--ink);
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.upload-button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-button:hover,
.toc-button:hover,
.reader-nav:hover,
.toc-close:hover {
  transform: translateY(-1px);
  background: rgba(138, 90, 48, 0.18);
}

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

.controls-card,
.nav-card {
  display: grid;
  gap: 16px;
}

.control-row {
  display: grid;
  gap: 10px;
}

.control-row label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 500;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  appearance: none;
  border: 1px solid rgba(88, 62, 38, 0.18);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fffaf2;
}

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

.status-block strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.reader-stage {
  min-width: 0;
}

.reader-frame {
  position: relative;
  height: calc(100vh - 112px);
  min-height: calc(100vh - 112px);
  overflow: hidden;
}

.reader-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 4;
  width: 52px;
  height: 52px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 18px 40px rgba(51, 32, 15, 0.12);
}

.reader-nav:hover {
  transform: translateY(calc(-50% - 1px));
}

.reader-nav svg {
  width: 22px;
  height: 22px;
}

.reader-nav-prev {
  left: 20px;
}

.reader-nav-next {
  right: 20px;
}

.viewer {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 112px);
  visibility: hidden;
}

.viewer.is-ready {
  visibility: visible;
}

.viewer iframe {
  background: #fffdf8;
}

.toc-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100% - 36px));
  z-index: 5;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 18px;
  background: rgba(255, 250, 240, 0.96);
  border: 1px solid rgba(88, 62, 38, 0.12);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(51, 32, 15, 0.16);
  backdrop-filter: blur(14px);
}

.toc-panel[hidden] {
  display: none;
}

.toc-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.toc-title {
  margin: 0;
}

.toc-close {
  padding: 10px 14px;
  font-weight: 600;
}

.toc-list {
  overflow: auto;
  padding-right: 6px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.toc-item {
  border: 0;
  border-radius: 14px;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.toc-item:hover {
  background: rgba(138, 90, 48, 0.1);
}

.toc-item-label {
  display: block;
  line-height: 1.35;
}

.toc-item-depth-1 {
  padding-left: 24px;
}

.toc-item-depth-2 {
  padding-left: 36px;
}

.toc-item-depth-3 {
  padding-left: 48px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: none;
}

.empty-state[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .page-shell {
    padding: 20px;
  }

  .reader-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .reader-frame,
  .viewer {
    height: 70vh;
    min-height: 70vh;
  }

  .reader-nav-prev {
    left: 14px;
  }

  .reader-nav-next {
    right: 14px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
  }

  .reader-nav {
    width: 44px;
    height: 44px;
  }

  .toc-panel {
    top: 12px;
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
  }

  .panel-card,
  .reader-frame {
    border-radius: 22px;
  }
}
