:root {
  color-scheme: dark;
  --bg: #181410;
  --surface: #241f19;
  --ink: #eadfcd;
  --muted: #aa9a83;
  --line: #3a3026;
  --accent: #c49a63;
  --accent-soft: #796547;
  --shadow: 0 24px 80px rgba(11, 8, 5, 0.5);
  --reader-font-size: clamp(1.35rem, 7vw, 2.42rem);
  --reader-font-family: Georgia, "Times New Roman", serif;
  --reader-ink: #eadfcd;
  --reader-bg-top: #1d1711;
  --reader-bg-bottom: #15120f;
  --reader-bg-halo: rgba(196, 154, 99, 0.11);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  min-height: 44px;
  padding: 0 1rem;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.reader-shell {
  background:
    radial-gradient(circle at 50% 12%, var(--reader-bg-halo), transparent 24rem),
    linear-gradient(180deg, var(--reader-bg-top) 0%, var(--reader-bg-bottom) 100%),
    var(--bg);
  min-height: 100dvh;
  position: relative;
}

.is-hidden {
  display: none;
}

.library-screen {
  background:
    radial-gradient(circle at 50% 0%, rgba(196, 154, 99, 0.12), transparent 24rem),
    linear-gradient(180deg, #1d1711 0%, #15120f 100%),
    var(--bg);
  min-height: 100dvh;
  overflow: auto;
  padding: max(1rem, env(safe-area-inset-top)) clamp(1rem, 5vw, 2rem) max(1.2rem, env(safe-area-inset-bottom));
}

.library-header,
.book-list,
.library-section {
  margin-left: auto;
  margin-right: auto;
  max-width: 34rem;
}

.library-header {
  padding: 0.65rem 0 0.85rem;
}

.library-topline,
.section-heading,
.heading-action {
  align-items: center;
  display: flex;
}

.library-topline,
.section-heading {
  justify-content: space-between;
}

.heading-action {
  gap: 0.48rem;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 0.45rem;
}

.library-topline .eyebrow {
  margin: 0;
}

.settings-button {
  aspect-ratio: 1;
  border-color: rgba(234, 223, 205, 0.1);
  color: var(--muted);
  display: grid;
  font-size: 1rem;
  min-height: 0;
  padding: 0;
  place-items: center;
  width: 40px;
}

.library-header h1 {
  font-size: clamp(1.8rem, 8vw, 3rem);
  max-width: 8ch;
  margin-top: 0.2rem;
}

.library-copy {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  margin: 0.45rem 0 0;
}

.install-card {
  align-items: center;
  background: rgba(36, 31, 25, 0.72);
  border: 1px solid rgba(196, 154, 99, 0.18);
  border-radius: 8px;
  display: flex;
  gap: 0.85rem;
  justify-content: space-between;
  margin: 0 auto 0.72rem;
  max-width: 34rem;
  padding: 0.72rem 0.78rem;
}

.install-card.is-hidden {
  display: none;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
  .install-card {
    display: none;
  }
}

.install-card div {
  display: grid;
  gap: 0.16rem;
  min-width: 0;
}

.install-card strong {
  font-size: 0.9rem;
}

.install-card span {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.install-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #201811;
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 800;
  min-height: 2rem;
  padding: 0 0.7rem;
}

.install-actions {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 0.35rem;
}

.library-section {
  margin-top: 0.75rem;
}

.library-section h2 {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 0.55rem;
  text-transform: uppercase;
}

.section-toggle {
  border: 0;
  color: var(--muted);
  display: flex;
  gap: 0.35rem;
  min-height: 1.72rem;
  padding: 0;
}

.section-toggle span:first-child {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toggle-mark {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 800;
}

.section-toggle[aria-expanded="true"] .toggle-mark {
  transform: rotate(45deg);
}

.section-toggle.locked .toggle-mark {
  transform: none;
}

.premium-pill {
  background: rgba(196, 154, 99, 0.08);
  border: 1px solid rgba(196, 154, 99, 0.22);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  min-height: 1.72rem;
  padding: 0.2rem 0.5rem;
  text-transform: uppercase;
}

.section-actions {
  align-items: center;
  display: flex;
  gap: 0.45rem;
}

.premium-note {
  color: rgba(170, 154, 131, 0.82);
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 0.42rem 0 0.6rem;
}

.empty-books-message {
  border: 1px dashed rgba(234, 223, 205, 0.12);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  margin: 0 0 0.55rem;
  padding: 0.62rem 0.68rem;
}

.import-row {
  background: rgba(196, 154, 99, 0.12);
  border-color: rgba(196, 154, 99, 0.34);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 0.18rem;
  justify-items: start;
  margin-top: 0.55rem;
  min-height: 0;
  padding: 0.56rem 0.68rem;
  text-align: left;
  width: 100%;
}

.import-row strong {
  font-size: 0.86rem;
  font-weight: 800;
}

.import-row span {
  color: var(--muted);
  font-size: 0.72rem;
}

.book-list {
  display: grid;
  gap: 0.48rem;
}

.compact-list {
  max-height: clamp(12rem, 33dvh, 19rem);
  overflow: auto;
  padding-right: 0.15rem;
}

.my-books-list {
  max-height: clamp(9rem, 26dvh, 15rem);
}

.library-screen.my-books-collapsed .available-books-list {
  max-height: clamp(18rem, 58dvh, 34rem);
}

.library-screen.available-books-collapsed .my-books-list {
  max-height: clamp(18rem, 58dvh, 34rem);
}

.compact-list,
.orientation-chapters {
  scrollbar-color: rgba(196, 154, 99, 0.28) transparent;
  scrollbar-width: thin;
}

.compact-list::-webkit-scrollbar,
.orientation-chapters::-webkit-scrollbar {
  width: 0.35rem;
}

.compact-list::-webkit-scrollbar-track,
.orientation-chapters::-webkit-scrollbar-track {
  background: transparent;
}

.compact-list::-webkit-scrollbar-thumb,
.orientation-chapters::-webkit-scrollbar-thumb {
  background: rgba(196, 154, 99, 0.24);
  border-radius: 999px;
}

.compact-list::-webkit-scrollbar-thumb:hover,
.orientation-chapters::-webkit-scrollbar-thumb:hover {
  background: rgba(196, 154, 99, 0.38);
}

.book-row {
  background: rgba(36, 31, 25, 0.72);
  border: 1px solid rgba(234, 223, 205, 0.08);
  border-radius: 8px;
}

.book-row {
  color: var(--ink);
  display: grid;
  gap: 0.2rem;
  min-height: 2.78rem;
  padding: 0.52rem 0.68rem;
  text-align: left;
  width: 100%;
}

.book-row strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.94rem;
  font-weight: 650;
  line-height: 1.15;
}

.book-row span,
.book-row small {
  color: var(--muted);
}

.book-row span {
  font-size: 0.74rem;
}

.book-row small {
  font-size: 0.64rem;
  font-weight: 700;
}

.imported-book-row {
  align-items: center;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 0;
}

.imported-open-button {
  background: transparent;
  border: 0;
  border-radius: 8px 0 0 8px;
  min-height: 2.78rem;
  padding: 0.52rem 0.68rem;
}

.remove-book-button {
  border-color: rgba(234, 223, 205, 0.1);
  color: var(--muted);
  font-size: 0.68rem;
  margin-right: 0.48rem;
  min-height: 2rem;
  padding: 0 0.58rem;
}

.menu-button,
.reader-settings-button {
  aspect-ratio: 1;
  align-items: center;
  background: rgba(24, 20, 16, 0.5);
  border-color: rgba(234, 223, 205, 0.1);
  display: grid;
  gap: 0.24rem;
  height: 44px;
  padding: 0;
  place-content: center;
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  width: 44px;
  z-index: 5;
}

.menu-button {
  left: max(1rem, env(safe-area-inset-left));
}

.reader-settings-button {
  color: #b8a78f;
  font-size: 1.05rem;
  right: max(1rem, env(safe-area-inset-right));
}

.menu-button span {
  background: #b8a78f;
  border-radius: 999px;
  display: block;
  height: 2px;
  width: 16px;
}

.progress-stack {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  left: 50%;
  min-height: 44px;
  max-width: 12rem;
  padding: 0.5rem 0.25rem;
  position: fixed;
  top: max(1.1rem, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: 38vw;
  z-index: 4;
}

.progress-stack:focus-visible {
  outline: 1px solid rgba(196, 154, 99, 0.45);
  outline-offset: 0.2rem;
}

.progress-row {
  background: rgba(234, 223, 205, 0.09);
  border-radius: 999px;
  height: 3px;
  overflow: hidden;
}

.progress-row + .progress-row {
  margin-top: 0.35rem;
}

.progress-row span {
  background: var(--accent);
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 0%;
}

.chapter-row {
  height: 2px;
  opacity: 0.52;
}

.reader-viewport {
  align-items: center;
  display: grid;
  min-height: 100dvh;
  outline: none;
  overflow: hidden;
  padding: max(4.6rem, env(safe-area-inset-top)) clamp(1.6rem, 8vw, 5rem) max(3.8rem, env(safe-area-inset-bottom));
  position: relative;
  touch-action: pan-y;
}

.sentence-text {
  color: var(--reader-ink);
  font-family: var(--reader-font-family);
  font-size: var(--reader-font-size);
  line-height: 1.42;
  margin: 0 auto;
  max-width: 27ch;
  text-wrap: pretty;
  z-index: 1;
}

.sentence-text.dense {
  line-height: 1.34;
  max-width: 30ch;
}

.sentence-text.forward {
  animation: slideNext 220ms ease both;
}

.sentence-text.back {
  animation: slidePrevious 220ms ease both;
}

.tap-zone {
  background: transparent;
  border: 0;
  border-radius: 0;
  height: 50%;
  left: 0;
  min-height: 0;
  opacity: 0;
  padding: 0;
  position: absolute;
  width: 100%;
  z-index: 2;
}

.tap-zone:focus-visible {
  opacity: 1;
  outline: 1px solid rgba(196, 154, 99, 0.45);
  outline-offset: -0.65rem;
}

.tap-zone-previous {
  top: 0;
}

.tap-zone-next {
  bottom: 0;
}

.menu-panel,
.orientation-panel,
.settings-panel,
.premium-panel {
  background: rgba(11, 8, 5, 0.54);
  display: none;
  inset: 0;
  padding: 1rem;
  position: fixed;
  z-index: 10;
}

.menu-panel.open,
.orientation-panel.open,
.settings-panel.open,
.premium-panel.open {
  align-items: end;
  display: flex;
}

.menu-surface,
.orientation-surface,
.settings-surface {
  background: rgba(36, 31, 25, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 32rem;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.2rem;
  position: relative;
  width: 100%;
}

.orientation-surface h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  line-height: 1.15;
  margin: 0;
}

.settings-surface h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  line-height: 1.15;
  margin: 0;
}

.settings-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.settings-list p,
.settings-block {
  border-top: 1px solid rgba(234, 223, 205, 0.08);
  display: grid;
  gap: 0.28rem;
  margin: 0;
  padding-top: 0.7rem;
}

.settings-list strong,
.settings-field > span {
  font-size: 0.95rem;
}

.settings-block-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}


.settings-list span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.settings-field {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.settings-field input,
.settings-field select {
  appearance: none;
  background: rgba(24, 20, 16, 0.72);
  border: 1px solid rgba(234, 223, 205, 0.12);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 42px;
  padding: 0 0.75rem;
}

.settings-field input[readonly] {
  color: var(--muted);
}

.auth-button {
  border-color: rgba(234, 223, 205, 0.14);
  color: var(--ink);
  justify-self: start;
  margin-top: 0.45rem;
}

.settings-action-row {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 0.45rem;
}

.settings-action-row .auth-button {
  justify-self: stretch;
  margin-top: 0;
  padding-left: 0.6rem;
  padding-right: 0.6rem;
}

.text-link-button {
  border: 0;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
  justify-self: start;
  min-height: 0;
  padding: 0;
}

.danger-link {
  color: #d8a19b;
}

.toast {
  background: rgba(36, 31, 25, 0.96);
  border: 1px solid rgba(196, 154, 99, 0.22);
  border-radius: 999px;
  bottom: max(1rem, env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 750;
  left: 50%;
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 0.62rem 0.9rem;
  position: fixed;
  transform: translateX(-50%);
  z-index: 20;
}

.close-button {
  margin-bottom: 1.4rem;
}

.panel-icon-button {
  aspect-ratio: 1;
  border-color: rgba(234, 223, 205, 0.1);
  color: var(--muted);
  display: grid;
  margin-bottom: 1rem;
  min-height: 0;
  padding: 0;
  place-items: center;
  width: 40px;
}

.settings-close-button {
  margin-bottom: 0;
  position: absolute;
  right: 1.2rem;
  top: 1.2rem;
}

.settings-surface h2 {
  padding-right: 3.1rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 0.35rem;
  text-transform: uppercase;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.65rem;
  line-height: 1.1;
  margin: 0;
}

.book-meta,
.progress-label {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0.75rem 0 0;
}

.quiet-button {
  margin-top: 1.25rem;
  width: 100%;
}

.quiet-button + .quiet-button {
  margin-top: 0.65rem;
}

.danger-button {
  border-color: rgba(196, 99, 99, 0.32);
  color: #d8a19b;
}

.orientation-context-toggle {
  margin-top: 1rem;
}

.orientation-context {
  display: none;
}

.orientation-context.open {
  display: grid;
  gap: 0.62rem;
  margin-top: 0.72rem;
}

.orientation-context-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.35;
  margin: 0;
}

.orientation-page-controls {
  display: grid;
  gap: 0.45rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.orientation-page-controls button {
  border-color: rgba(234, 223, 205, 0.1);
  color: var(--muted);
  font-size: 0.75rem;
  min-height: 2.35rem;
  padding: 0 0.5rem;
}

.orientation-sentence-list {
  background: rgba(24, 20, 16, 0.3);
  border: 1px solid rgba(234, 223, 205, 0.08);
  border-radius: 8px;
  display: block;
  max-height: min(62dvh, 34rem);
  overflow: auto;
  padding: 0.75rem;
}

.orientation-sentence {
  background: transparent;
  border-color: transparent;
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--reader-font-family);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  min-height: 0;
  padding: 0.2rem 0.24rem;
  text-align: left;
  width: 100%;
}

.orientation-sentence.current {
  background: rgba(196, 154, 99, 0.13);
  border-color: rgba(196, 154, 99, 0.34);
  color: var(--ink);
}

.orientation-chapters {
  border-top: 1px solid rgba(234, 223, 205, 0.08);
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
  max-height: 12.65rem;
  overflow: auto;
  padding-top: 1rem;
  padding-right: 0.1rem;
}

.orientation-chapter {
  border-color: rgba(234, 223, 205, 0.07);
  border-radius: 8px;
  display: grid;
  gap: 0.25rem;
  justify-items: start;
  min-height: 3.6rem;
  padding: 0.75rem;
  text-align: left;
}

.orientation-chapter.current {
  background: rgba(196, 154, 99, 0.11);
  border-color: rgba(196, 154, 99, 0.28);
}

.orientation-chapter strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

.orientation-chapter span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
}

@keyframes slideNext {
  from {
    opacity: 0;
    transform: translateY(36px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slidePrevious {
  from {
    opacity: 0;
    transform: translateY(-36px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 520px) {
  .library-screen {
    padding-top: max(0.72rem, env(safe-area-inset-top));
  }

  .library-header {
    padding: 0.35rem 0 0.62rem;
  }

  .library-header h1 {
    font-size: 1.72rem;
  }

  .library-copy {
    font-size: 0.9rem;
    margin-top: 0.28rem;
  }

  .library-section {
    margin-top: 0.58rem;
  }

  .install-card {
    margin-bottom: 0.58rem;
    padding: 0.62rem 0.68rem;
  }

  .compact-list {
    max-height: clamp(10.5rem, 31dvh, 17rem);
  }

  .my-books-list {
    max-height: clamp(8rem, 24dvh, 13rem);
  }

  .library-screen.my-books-collapsed .available-books-list,
  .library-screen.available-books-collapsed .my-books-list {
    max-height: clamp(17rem, 56dvh, 31rem);
  }

  .book-row {
    min-height: 2.62rem;
    padding: 0.48rem 0.62rem;
  }

  .menu-panel,
  .orientation-panel,
  .settings-panel,
  .premium-panel {
    padding: 0.72rem;
  }

  .menu-surface,
  .orientation-surface,
  .settings-surface {
    max-height: calc(100dvh - 1.44rem);
    padding: 1rem;
  }

  .progress-stack {
    max-width: 10rem;
    width: 34vw;
  }

  .sentence-text {
    max-width: 25ch;
  }
}
