:root {
  color-scheme: light;
  --ui-font: "Noto Sans SC", "PingFang SC", "Helvetica Neue", sans-serif;
  --text-font: "Noto Serif SC", "Songti SC", "Source Han Serif SC", serif;
  --display-font: "Noto Serif SC", "Songti SC", "Source Han Serif SC", serif;
  --surface: rgba(255, 255, 255, 0.8);
  --paper: #fbfaf7;
  --paper-strong: #ffffff;
  --ink: #181818;
  --muted: #6d6862;
  --line: rgba(24, 24, 24, 0.075);
  --accent: #b25b33;
  --shadow: 0 14px 44px rgba(24, 24, 24, 0.055);
  --content-width: 47rem;
  --font-size: 1.1875rem;
  --line-height: 2.06;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body[data-theme="mist"] {
  --surface: rgba(248, 242, 232, 0.84);
  --paper: #f3ece2;
  --paper-strong: #fbf6ef;
  --ink: #211c18;
  --muted: #756b63;
  --line: rgba(33, 28, 24, 0.09);
  --accent: #9d5b36;
}

body[data-theme="night"] {
  color-scheme: dark;
  --surface: rgba(24, 24, 24, 0.82);
  --paper: #151414;
  --paper-strong: #1f1d1c;
  --ink: #dfd9d2;
  --muted: #aaa39b;
  --line: rgba(224, 224, 224, 0.12);
  --accent: #d3a07b;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
}

body[data-width="narrow"] {
  --content-width: 40rem;
}

body[data-width="wide"] {
  --content-width: 52rem;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--ui-font);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(178, 91, 51, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(178, 91, 51, 0.04), transparent 24%),
    var(--paper);
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  min-height: 100vh;
}

.progress-bar {
  position: fixed;
  inset: 0 0 auto;
  height: 2px;
  z-index: 40;
  background: transparent;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 24px rgba(17, 17, 17, 0.03);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.topbar-leading {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 0.18rem;
  text-align: center;
}

.topbar-title strong,
.topbar-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title strong {
  font-family: var(--display-font);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-title span {
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.topbar-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.ghost-button,
.ghost-link-button,
.ghost-icon-button,
.segmented-control button,
.chapter-link,
.bottom-nav button,
.secondary-button {
  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease,
    opacity 140ms ease;
}

.ghost-button {
  min-width: 3rem;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
}

.ghost-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}

.author-x-short {
  display: none;
}

.ghost-button:hover,
.ghost-link-button:hover,
.ghost-icon-button:hover,
.segmented-control button:hover,
.chapter-link:hover,
.bottom-nav button:hover,
.secondary-button:hover {
  border-color: color-mix(in srgb, var(--ink) 10%, var(--line));
  background: color-mix(in srgb, var(--paper-strong) 70%, transparent);
}

.ghost-button:focus-visible,
.ghost-link-button:focus-visible,
.ghost-icon-button:focus-visible,
.segmented-control button:focus-visible,
.chapter-link:focus-visible,
.bottom-nav button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page {
  padding: 1.2rem 1rem calc(7rem + var(--safe-bottom));
}

.settings-panel {
  position: fixed;
  top: calc(4.85rem + env(safe-area-inset-top, 0px));
  right: 1rem;
  z-index: 34;
  display: grid;
  gap: 0.8rem;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(calc(100vh - 7rem), 30rem);
  overflow: auto;
  padding: 0.9rem;
  border-radius: 1.25rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-strong) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

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

.settings-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.settings-panel-title {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.ghost-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  line-height: 1;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.settings-row span {
  font-size: 0.88rem;
  color: var(--muted);
  flex: 0 0 2.7rem;
}

.segmented-control {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1 1 auto;
}

.segmented-control button {
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.48rem 0.8rem;
}

.segmented-control button.is-active {
  background: var(--ink);
  color: var(--paper-strong);
  border-color: transparent;
}

.reader {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  transform: translateX(0);
  transform-origin: center center;
  transform-style: preserve-3d;
  transition:
    opacity 0.17s ease-in-out,
    transform 0.24s ease,
    filter 0.2s ease;
  will-change: opacity;
}

.reader.is-transitioning {
  opacity: 0;
  filter: blur(1px);
}

.reader[data-motion="forward"].is-transitioning {
  transform: translateX(-18px) rotateY(-3.4deg);
  transform-origin: right center;
}

.reader[data-motion="backward"].is-transitioning {
  transform: translateX(18px) rotateY(3.4deg);
  transform-origin: left center;
}

.intro,
.chapter-shell {
  display: grid;
  gap: 1.4rem;
}

.landing-frame,
.landing-track,
.landing-footer,
.book-card,
.chapter-hero,
.chapter-body,
.intro-hero {
  border: 1px solid var(--line);
  border-radius: 1.6rem;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--paper-strong) 97%, transparent), color-mix(in srgb, var(--paper-strong) 90%, transparent));
  box-shadow: var(--shadow);
}

.landing-frame,
.chapter-hero,
.chapter-body,
.intro-hero,
.landing-footer,
.book-card {
  padding: clamp(1.4rem, 3vw, 2.1rem);
}

.landing-copy {
  display: grid;
  gap: 0.8rem;
}

.landing-frame-library,
.landing-frame-book {
  display: grid;
  gap: 1rem;
}

.landing-aside {
  display: grid;
  gap: 0.9rem;
  align-content: start;
}

.landing-note-card,
.landing-focus-card {
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--paper-strong) 96%, transparent), color-mix(in srgb, var(--paper) 94%, transparent));
}

.landing-note-card {
  padding: 1rem 1.05rem;
}

.landing-note-kicker {
  display: inline-block;
  margin-bottom: 0.45rem;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.landing-note-card p,
.landing-focus-copy p {
  margin: 0;
  color: var(--ink);
  line-height: 1.78;
}

.landing-primer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.landing-primer-item {
  display: grid;
  gap: 0.28rem;
  padding: 0.9rem 0.92rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: color-mix(in srgb, var(--paper-strong) 92%, transparent);
}

.landing-primer-item span {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.landing-primer-item strong {
  font-family: var(--display-font);
  font-size: 0.96rem;
  line-height: 1.55;
  font-weight: 600;
}

.landing-kicker,
.book-card-kicker,
.chapter-hero .eyebrow,
.landing-track-header span {
  display: inline-block;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.landing-copy h1,
.chapter-hero h1,
.intro-hero h1,
.book-card h2 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: -0.02em;
  font-family: var(--display-font);
  font-weight: 600;
}

.landing-copy h1,
.chapter-hero h1,
.intro-hero h1 {
  font-size: clamp(2rem, 4vw, 3.1rem);
}

.book-card h2 {
  font-size: clamp(1.35rem, 2.8vw, 1.9rem);
}

.landing-deck,
.book-card-deck {
  margin: 0;
  max-width: 42rem;
  font-size: 1.03rem;
  line-height: 1.92;
  color: var(--ink);
}

.chapter-meta,
.intro-meta,
.landing-track-header p,
.landing-footer p {
  margin: 0;
  color: var(--muted);
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.4rem;
}

.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.72rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--paper-strong) 84%, transparent);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
}

.primary-button,
.secondary-button {
  width: fit-content;
  border-radius: 999px;
  padding: 0.82rem 1.18rem;
}

.primary-button {
  border: none;
  background: var(--ink);
  color: var(--paper-strong);
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
}

.library-shelf,
.landing-track-items {
  display: grid;
  gap: 1rem;
}

.book-card {
  display: grid;
  gap: 1.1rem;
}

.book-card-interactive {
  cursor: pointer;
}

.book-card-interactive:hover {
  transform: translateY(-1px);
}

.book-card-head {
  display: flex;
  align-items: flex-start;
  gap: 0.95rem;
}

.book-card-number {
  flex: 0 0 auto;
  min-width: 2.4rem;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  line-height: 1;
  letter-spacing: -0.05em;
  color: color-mix(in srgb, var(--accent) 65%, var(--ink));
}

.book-card-title-group {
  display: grid;
  gap: 0.3rem;
}

.book-card-copy {
  display: grid;
  gap: 0.6rem;
}

.book-card-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.7;
}

.book-card-actions {
  margin-top: 0;
}

.landing-track {
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.landing-focus-card {
  padding: 0.95rem 1.05rem;
}

.landing-focus-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.landing-focus-main {
  display: grid;
  gap: 0.22rem;
}

.landing-inline-action {
  flex: 0 0 auto;
  justify-self: start;
  white-space: nowrap;
}

.landing-track-header {
  display: grid;
  gap: 0.4rem;
}

.landing-jump {
  display: grid;
  gap: 0.28rem;
  width: 100%;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--line) 92%, transparent);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--paper-strong) 96%, transparent), color-mix(in srgb, var(--paper) 92%, transparent));
  border-radius: 1.15rem;
  padding: 1rem;
  min-height: 5.5rem;
}

.landing-jump-index {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.landing-jump strong {
  font-family: var(--display-font);
  font-size: 1rem;
  line-height: 1.55;
}

.landing-jump span:last-child {
  font-size: 0.8rem;
  color: var(--muted);
}

.landing-jump:hover {
  border-color: var(--line);
  transform: translateY(-1px);
}

.chapter-hero .eyebrow {
  margin-bottom: 0.5rem;
}

.reader-crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.crumb-link {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
}

.crumb-link:hover {
  color: var(--ink);
}

.crumb-separator {
  opacity: 0.48;
}

.crumb-current {
  color: var(--ink);
}

.chapter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

.chapter-body h2 {
  margin: 2rem 0 0.8rem;
  font-family: var(--display-font);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.chapter-body p {
  margin: 0 0 1.6em;
  font-family: var(--text-font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  text-wrap: pretty;
  text-align: justify;
  text-justify: inter-ideograph;
  hanging-punctuation: first allow-end last;
  color: var(--ink);
}

.chapter-body p:last-child {
  margin-bottom: 0;
}

.chapter-body h2 + p {
  margin-top: 0;
}

.chapter-body p + h2 {
  margin-top: 2.25rem;
}

.appendix-shell {
  gap: 1rem;
}

.appendix-intro {
  box-shadow: none;
}

.appendix-list {
  display: grid;
  gap: 1.35rem;
}

.appendix-group {
  display: grid;
  gap: 0.85rem;
}

.appendix-group-heading {
  font-family: var(--ui-font);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.appendix-group-list {
  display: grid;
  gap: 0.9rem;
}

.appendix-item {
  padding: 1.15rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: color-mix(in srgb, var(--paper-strong) 90%, transparent);
}

.appendix-item-head {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 0.85rem;
}

.appendix-item-number {
  flex: 0 0 auto;
  min-width: 2rem;
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--accent);
}

.appendix-item-copy {
  display: grid;
  gap: 0.22rem;
}

.appendix-item-copy h2 {
  margin: 0;
  font-family: var(--display-font);
  font-size: 1.03rem;
  line-height: 1.5;
}

.appendix-item-body p {
  margin: 0 0 1em;
  font-family: var(--text-font);
  font-size: calc(var(--font-size) * 0.94);
  line-height: 1.9;
  text-align: justify;
  text-justify: inter-ideograph;
}

.appendix-item-body p:last-child {
  margin-bottom: 0;
}

.appendix-subheading {
  margin-top: 0.25rem;
  color: var(--muted);
  font-family: var(--ui-font);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.appendix-notes {
  padding: 0.95rem 1.1rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: color-mix(in srgb, var(--paper-strong) 88%, transparent);
}

.appendix-notes summary {
  position: relative;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--ui-font);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  list-style: none;
  padding-right: 1.2rem;
}

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

.appendix-notes summary::after {
  content: "+";
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-52%);
  color: var(--accent);
  font-size: 0.92rem;
}

.appendix-notes[open] summary {
  margin-bottom: 0.85rem;
}

.appendix-notes[open] summary::after {
  content: "-";
}

.appendix-notes-list {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding-left: 1.25rem;
}

.appendix-notes-list li {
  color: var(--muted);
  font-size: calc(var(--font-size) * 0.8);
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.appendix-notes-list a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(23rem, 88vw);
  transform: translateX(-102%);
  transition: transform 180ms ease;
  z-index: 32;
}

.sidebar.is-open {
  transform: translateX(0);
}

.sidebar-inner {
  height: 100%;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 1.25rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-strong) 94%, transparent);
  backdrop-filter: blur(18px);
}

.sidebar-inner h1 {
  margin: 0.55rem 0 0.3rem;
  font-family: var(--display-font);
  font-size: 1.35rem;
}

.sidebar-inner p {
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.7;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.35rem;
}

.chapter-link {
  position: relative;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 1rem;
  padding: 0.8rem 0.9rem;
}

.chapter-link span {
  display: block;
}

.chapter-link .label {
  font-size: 0.92rem;
  line-height: 1.55;
}

.chapter-link .meta {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.chapter-link.is-active {
  border-color: var(--line);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 10%, transparent);
}

.chapter-link.is-active::before {
  content: "";
  position: absolute;
  left: 0.45rem;
  top: 50%;
  width: 0.22rem;
  height: 1.3rem;
  border-radius: 999px;
  transform: translateY(-50%);
  background: color-mix(in srgb, var(--accent) 86%, white);
}

.chapter-link.is-active .label {
  color: var(--ink);
}

.home-link,
.intro-link {
  margin: 0 0 0.55rem;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + var(--safe-bottom));
  transform: translate(-50%, 0);
  z-index: 28;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.8rem;
  width: min(calc(100% - 1.5rem), 34rem);
  padding: 0.78rem 0.82rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.bottom-nav button {
  display: grid;
  gap: 0.08rem;
  min-width: 0;
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0.45rem 0.5rem;
  border-radius: 999px;
}

.bottom-nav button[data-direction="prev"] {
  justify-items: start;
  text-align: left;
}

.bottom-nav button[data-direction="next"] {
  justify-items: end;
  text-align: right;
}

.nav-button-label {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.nav-button-title {
  max-width: 9.6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
}

.bottom-nav button:disabled .nav-button-title {
  opacity: 0.42;
}

.bottom-meta {
  display: grid;
  gap: 0.08rem;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: center;
  padding: 0.38rem 0.55rem;
  border-radius: 999px;
}

.bottom-meta:hover {
  background: color-mix(in srgb, var(--paper-strong) 70%, transparent);
}

.bottom-meta strong,
.bottom-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-meta strong {
  font-family: var(--display-font);
  font-size: 0.9rem;
}

.bottom-meta span {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.scrim {
  position: fixed;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.18);
  z-index: 31;
}

.only-mobile {
  display: inline-flex;
}

body[data-view="library"] .bottom-nav,
body[data-view="intro"] .bottom-nav {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(180% + var(--safe-bottom)));
}

body[data-chrome="hidden"] .topbar {
  transform: translateY(calc(-100% - 0.75rem));
}

body[data-chrome="hidden"][data-view="chapter"] .bottom-nav {
  transform: translate(-50%, calc(180% + var(--safe-bottom)));
}

@media (min-width: 768px) {
  .landing-frame {
    display: grid;
    gap: 1rem;
    align-items: end;
  }

  .landing-frame-library,
  .landing-frame-book {
    grid-template-columns: minmax(0, 1.25fr) minmax(17rem, 0.95fr);
    align-items: start;
  }

  .library-shelf,
  .landing-track-items {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .only-mobile {
    display: none;
  }

  .sidebar {
    transform: translateX(0);
    width: 21rem;
  }

  .page {
    padding-left: calc(21rem + 2rem);
    padding-right: 2rem;
  }

  .topbar {
    padding-left: calc(21rem + 2rem);
    padding-right: 2rem;
  }

  .settings-panel {
    right: 2rem;
    width: min(22rem, calc(100vw - 25rem));
  }

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

  .landing-track-items {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --font-size: 1.08rem;
    --line-height: 1.95;
  }

  .topbar {
    padding: 0.9rem 0.85rem;
  }

  .topbar-leading {
    gap: 0.4rem;
  }

  .topbar-actions {
    gap: 0.4rem;
  }

  .topbar-home-long {
    display: none;
  }

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

  .ghost-link-button {
    padding: 0.55rem 0.7rem;
  }

  .author-x-long {
    display: none;
  }

  .author-x-short {
    display: inline;
  }

  .page {
    padding: 1rem 0.8rem calc(7rem + var(--safe-bottom));
  }

  .landing-frame,
  .landing-track,
  .landing-footer,
  .book-card,
  .chapter-hero,
  .chapter-body,
  .intro-hero {
    border-radius: 1.25rem;
    padding: 1.15rem;
  }

  .landing-primer-grid {
    grid-template-columns: 1fr;
  }

  .landing-focus-copy {
    display: grid;
    gap: 0.35rem;
  }

  .landing-copy h1,
  .chapter-hero h1,
  .intro-hero h1 {
    font-size: clamp(1.72rem, 8vw, 2.5rem);
  }

  .landing-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
    text-align: center;
  }

  .settings-panel {
    top: calc(4.35rem + env(safe-area-inset-top, 0px));
    right: 0.8rem;
    width: calc(100vw - 1.6rem);
    max-height: min(calc(100vh - 6.5rem), 28rem);
    padding: 0.85rem;
  }

  .settings-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-row span {
    flex-basis: auto;
  }

  .segmented-control {
    justify-content: flex-start;
  }

  .bottom-nav {
    width: calc(100% - 1rem);
    gap: 0.55rem;
  }

  .nav-button-title {
    max-width: 5.5rem;
    font-size: 0.78rem;
  }

  .ghost-button,
  .ghost-link-button,
  .ghost-icon-button,
  .segmented-control button,
  .chapter-link,
  .bottom-nav button,
  .primary-button,
  .secondary-button,
  .landing-jump,
  .bottom-meta {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .topbar,
  .bottom-nav,
  .reader,
  .ghost-button,
  .ghost-link-button,
  .ghost-icon-button,
  .segmented-control button,
  .chapter-link,
  .bottom-nav button,
  .secondary-button,
  .primary-button,
  .landing-jump {
    transition: none;
  }

  .reader.is-transitioning {
    filter: none;
  }
}
