:root {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Poppins", sans-serif;
  background: #f4f1ea;
  color: #222;
}

[hidden] {
  display: none !important;
}

.reader-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
}

.reader-topbar,
.reader-toolbar,
.reader-notice,
.reader-content {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 20px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
}

.reader-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
}

.reader-heading {
  min-width: 0;
  text-align: center;
}

.reader-book-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b5523f;
}

.reader-heading h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.15;
}

.reader-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: #f6f0ee;
  color: #6b4d4d;
  font-size: 12px;
  font-weight: 700;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  flex-wrap: wrap;
}

.reader-chapter-controls,
.reader-page-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.reader-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reader-select-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
}

.reader-select {
  min-width: min(420px, 72vw);
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  font: inherit;
  background: #fff;
}

.reader-btn {
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: #fff;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

.reader-btn:hover {
  transform: translateY(-1px);
  background: #f7f7f7;
}

.reader-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.reader-page-indicator {
  font-size: 13px;
  font-weight: 600;
  color: #555;
}

.reader-notice {
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  background: #fff8e6;
  color: #8a6d3b;
}

.reader-state {
  min-height: 42vh;
  display: grid;
  place-items: center;
  gap: 12px;
  text-align: center;
  color: #666;
}

.reader-state-error h2 {
  margin: 0;
  font-size: 28px;
  color: #222;
}

.reader-state-error p {
  margin: 0;
}

.reader-spinner {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-top-color: #b5523f;
  animation: reader-spin 0.8s linear infinite;
}

@keyframes reader-spin {
  to {
    transform: rotate(360deg);
  }
}

.reader-content {
  padding: 22px;
}

.reader-spread {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}

.reader-page {
  min-height: 68vh;
  background: #fffdf8;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  padding: 28px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.9;
  font-size: 16px;
  color: #2b2b2b;
}

.reader-divider {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
}

@media (max-width: 980px) {
  .reader-topbar {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .reader-topbar-left,
  .reader-topbar-right {
    justify-self: center;
  }

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

  .reader-chapter-controls,
  .reader-page-controls {
    justify-content: center;
  }

  .reader-select {
    min-width: 100%;
  }

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

  .reader-divider,
  .reader-page:last-child {
    display: none;
  }

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

@media (max-width: 640px) {
  .reader-shell {
    padding: 14px;
  }

  .reader-content,
  .reader-topbar,
  .reader-toolbar,
  .reader-notice {
    padding: 14px;
    border-radius: 16px;
  }

  .reader-btn {
    width: 100%;
  }

  .reader-chapter-controls,
  .reader-page-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .reader-page {
    padding: 20px;
    font-size: 15px;
  }
}