:root {
  color-scheme: light;
  --bg: #f8f8f4;
  --panel: #ffffff;
  --reader-bg: #fffdf7;
  --text: #181512;
  --muted: #6f6860;
  --border: #dedbd3;
  --accent: #b42d32;
  --accent-strong: #8d171e;
  --green: #23694c;
  --shadow: 0 18px 50px rgba(24, 21, 18, 0.11);
  --toolbar-h: 82px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11100f;
  --panel: #191715;
  --reader-bg: #11100f;
  --text: #f1eee8;
  --muted: #b7aea3;
  --border: #312d28;
  --accent: #ff6368;
  --accent-strong: #ff8387;
  --green: #63c695;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

:root[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f3efe3;
  --panel: #fbf7ea;
  --reader-bg: #fff7e6;
  --text: #2a2117;
  --muted: #766850;
  --border: #ded0b4;
  --accent: #a9312f;
  --accent-strong: #7f201f;
  --green: #356f4b;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
}

button,
select,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  transform: translateY(-160%);
  background: var(--text);
  color: var(--panel);
  padding: 10px 14px;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.book-panel {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 28px;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(180, 45, 50, 0.08), transparent 36%),
    var(--panel);
  border-right: 1px solid var(--border);
}

.identity {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  background: #151311;
}

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

.author,
.eyebrow,
.section-heading,
.rights {
  margin: 0;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 3.8vw, 3rem);
  line-height: 0.95;
}

.subtitle {
  margin: 0;
  color: var(--green);
  font-weight: 700;
}

.summary {
  margin: 18px 0 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.55;
}

.primary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition:
    transform 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.icon-button {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: var(--accent);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.toc-shell {
  min-height: 0;
}

.toc-list,
.toc-list ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.toc-list ol {
  margin: 4px 0 4px 14px;
  border-left: 1px solid var(--border);
}

.toc-list button {
  width: 100%;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 8px 9px;
  text-align: left;
}

.toc-list button:hover,
.toc-list button[aria-current="true"] {
  background: rgba(180, 45, 50, 0.11);
  color: var(--accent-strong);
}

.rights {
  margin-top: auto;
  text-transform: none;
}

.reader-shell {
  display: grid;
  grid-template-rows: var(--toolbar-h) minmax(0, 1fr) 40px;
  height: 100vh;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.reader-toolbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 248, 244, 0.92);
  backdrop-filter: blur(14px);
}

[data-theme="dark"] .reader-toolbar {
  background: rgba(17, 16, 15, 0.9);
}

[data-theme="sepia"] .reader-toolbar {
  background: rgba(243, 239, 227, 0.9);
}

.chapter-state {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.chapter-state strong {
  overflow: hidden;
  max-width: 48vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-controls {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.icon-button {
  min-width: 72px;
  padding: 0 13px;
}

.select-label,
.range-label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

select {
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
}

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

.reader-frame {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--reader-bg);
}

#viewer {
  width: 100%;
  max-width: 100%;
  height: 100%;
  padding: clamp(12px, 2vw, 26px) clamp(10px, 3.2vw, 48px);
  overflow: hidden;
}

#viewer iframe {
  border: 0 !important;
  background: var(--reader-bg);
  box-shadow: var(--shadow);
}

.loading-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: var(--reader-bg);
  color: var(--muted);
}

.loading-state.is-hidden {
  display: none;
}

.reader-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.progress-track {
  position: relative;
  flex: 1;
  height: 5px;
  overflow: hidden;
  background: var(--border);
}

.progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 180ms ease;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .book-panel {
    position: relative;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .reader-shell {
    height: 100dvh;
    min-height: 680px;
  }

  .chapter-state strong {
    max-width: 90vw;
  }
}

@media (max-width: 720px) {
  :root {
    --toolbar-h: 192px;
  }

  .book-panel {
    padding: 20px;
  }

  .identity {
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 14px;
  }

  .summary {
    font-size: 0.94rem;
  }

  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .reader-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
  }

  .select-label,
  .range-label,
  .icon-button {
    width: 100%;
  }

  .select-label span,
  .range-label span {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .icon-button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

@media (max-width: 460px) {
  .primary-actions {
    grid-template-columns: 1fr;
  }

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

  .cover {
    max-width: 150px;
  }

  .reader-shell {
    min-height: 700px;
  }
}
