/* Quire — calm, minimal UI. Tokens first; light/sepia/dark themes; desktop sidebar, phone tab bar. */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efede8;
  --fg: #1f1f1d;
  --muted: #64625d; /* 5.6:1 on --bg */
  --line: #e2dfd8;
  --accent: #2f4f78; /* 7.7:1 on --bg */
  --accent-fg: #ffffff;
  --warn: #9a3a12; /* 6.6:1 on --bg */
  --focus: #2f6fd1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.05);
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-serif: Charter, 'Bitstream Charter', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --nav-w: 216px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='sepia']) {
    --bg: #141413;
    --surface: #1c1c1a;
    --surface-2: #252522;
    --fg: #e6e4df;
    --muted: #a19e97;
    --line: #2f2e2b;
    --accent: #9dbbe6;
    --accent-fg: #10161f;
    --warn: #f0a67e;
    --focus: #8fb4ef;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #141413;
  --surface: #1c1c1a;
  --surface-2: #252522;
  --fg: #e6e4df;
  --muted: #a19e97;
  --line: #2f2e2b;
  --accent: #9dbbe6;
  --accent-fg: #10161f;
  --warn: #f0a67e;
  --focus: #8fb4ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
:root[data-theme='sepia'] {
  --bg: #f4ecd8;
  --surface: #faf4e6;
  --surface-2: #ebe1c8;
  --fg: #3b3024;
  --muted: #6e5f4b;
  --line: #ddd0b3;
  --accent: #6b4420;
  --warn: #8a2f0e;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.reading {
  overflow: hidden;
}
h1,
h2,
h3 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em;
}
h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 500;
}
h2 {
  font-size: 1.05rem;
}
a {
  color: var(--accent);
}
p {
  margin: 0 0 0.75em;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.warn-text {
  color: var(--warn);
}
.icon {
  flex: none;
  vertical-align: -0.2em;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}
.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
}
.skip:focus {
  left: 8px;
}
.boot,
.fatal {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---- buttons & controls ------------------------------------------------------------- */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-decoration: none;
  color: var(--fg);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.btn:hover {
  border-color: var(--muted);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn.danger {
  color: var(--warn);
}
.btn.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.85rem;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s var(--ease);
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.small {
  width: 28px;
  height: 28px;
}
.link-btn {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.check {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  cursor: pointer;
}
.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
select,
input[type='text'],
input[type='search'] {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 10px;
}
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  flex-wrap: wrap;
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 34px;
}
.segmented button[aria-checked='true'],
.segmented button[aria-selected='true'] {
  background: var(--surface);
  box-shadow: var(--shadow);
}
.field {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}
.field-label {
  font-size: 0.85rem;
  color: var(--muted);
}
.notice {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
}

/* ---- shell -------------------------------------------------------------------------- */
.shell {
  min-height: 100dvh;
}
.nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav-w);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-right: 1px solid var(--line);
  background: var(--bg);
  z-index: 10;
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  padding: 4px 12px 18px;
}
.nav-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--fg);
}
.nav-link[aria-current='page'] {
  background: var(--surface-2);
  color: var(--fg);
  font-weight: 500;
}
.nav-foot {
  margin-top: auto;
}
.view {
  margin-left: var(--nav-w);
  padding: 32px clamp(16px, 4vw, 48px) 64px;
  max-width: calc(1180px + var(--nav-w));
  outline: none;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.head-actions {
  display: flex;
  gap: 4px;
}
.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin: 28px 0 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  max-width: 760px;
}
.empty {
  color: var(--muted);
  padding: 32px 0;
}
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 100%;
}
.sync-chip:hover {
  background: var(--surface-2);
}
.sync-chip.warn {
  color: var(--warn);
}
.spin .icon,
.icon-btn.spin .icon {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  .nav {
    inset: auto 0 0 0;
    width: auto;
    height: calc(60px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    flex-direction: row;
    align-items: stretch;
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .brand {
    display: none;
  }
  .nav-links {
    flex-direction: row;
    flex: 1;
  }
  .nav-link {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    font-size: 0.7rem;
    padding: 6px 0;
  }
  .nav-link[aria-current='page'] {
    background: transparent;
    color: var(--accent);
  }
  .nav-foot {
    margin: 0;
    display: flex;
    align-items: center;
  }
  .nav-foot .sync-chip span {
    display: none;
  }
  .view {
    margin-left: 0;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(88px + env(safe-area-inset-bottom));
  }
  h1 {
    font-size: 1.5rem;
  }
}

/* ---- covers ------------------------------------------------------------------------- */
.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: hsl(var(--cover-hue) 18% 86%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 6px 18px rgba(0, 0, 0, 0.06);
}
:root[data-theme='dark'] .cover {
  background: hsl(var(--cover-hue) 12% 24%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='sepia']) .cover {
    background: hsl(var(--cover-hue) 12% 24%);
  }
}
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 12% 10%;
  gap: 6px;
  font-family: var(--font-serif);
  color: var(--fg);
}
.cover-title {
  font-size: 0.95rem;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cover-author {
  font-size: 0.75rem;
  color: var(--muted);
}
.cover-format {
  margin-top: auto;
  font: 600 0.65rem/1 var(--font-ui);
  letter-spacing: 0.08em;
  color: var(--muted);
}
.cover-sm {
  width: 44px;
}
.cover-sm .cover-placeholder {
  padding: 4px;
}
.cover-sm .cover-title {
  font-size: 0.5rem;
  -webkit-line-clamp: 4;
}
.cover-sm .cover-author,
.cover-sm .cover-format {
  display: none;
}
.cover-lg {
  width: 120px;
}

/* ---- progress & badges -------------------------------------------------------------- */
.progress {
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s var(--ease);
}
.progress-empty {
  background: transparent;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge .icon {
  width: 13px;
  height: 13px;
}
.badge-warn {
  color: var(--warn);
}
.badge-quiet {
  background: transparent;
  padding: 2px 0;
}

/* ---- home --------------------------------------------------------------------------- */
.onboarding {
  max-width: 560px;
}
.continue-card {
  display: flex;
  gap: 20px;
  align-items: center;
  width: 100%;
  max-width: 560px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.continue-card:hover {
  box-shadow: var(--shadow);
}
.continue-meta {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.continue-meta .btn {
  justify-self: start;
  margin-top: 8px;
}
.continue-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
}
.shelf-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 112px;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
}
.shelf-item {
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
}
.shelf-title {
  display: block;
  font-size: 0.8rem;
  margin-top: 6px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- library ------------------------------------------------------------------------ */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.search-wrap {
  position: relative;
  flex: 1 1 260px;
  display: flex;
  align-items: center;
}
.search-wrap .icon {
  position: absolute;
  left: 10px;
  color: var(--muted);
}
.search {
  width: 100%;
  padding-left: 36px !important;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.chip {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  min-height: 32px;
}
.chip[aria-pressed='true'] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.scan-line {
  min-height: 1.5em;
  margin-bottom: 12px;
}
.book-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 24px 20px;
}
.book {
  position: relative;
  min-width: 0;
}
.book-open {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.book-open .cover {
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.book-open:hover .cover {
  transform: translateY(-2px);
}
.book-meta {
  display: grid;
  gap: 2px;
  margin-top: 6px;
  padding-right: 28px;
}
.book-title {
  font-size: 0.88rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-author {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-height: 0;
}
.book-more {
  position: absolute;
  right: -8px;
  bottom: -4px;
}
.book-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.book-list .book {
  display: grid;
  grid-template-columns: 44px 1fr 40px;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.book-list .book-open .progress {
  display: none;
}
.book-list .book-meta {
  margin: 0;
  padding: 0;
}
.book-list .book-more {
  position: static;
}
@media (max-width: 760px) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 18px 14px;
  }
}

/* ---- popover, modal, toast ---------------------------------------------------------- */
.popover {
  position: fixed;
  z-index: 60;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  padding: 6px;
  display: grid;
  animation: pop 0.12s var(--ease);
}
.popover button {
  text-align: left;
  border: 0;
  background: none;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.popover button:hover,
.popover button:focus-visible {
  background: var(--surface-2);
}
.popover button.danger {
  color: var(--warn);
}
.popover hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
.modal {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 20px 20px;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-wide {
  width: min(640px, calc(100vw - 32px));
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  padding: 14px 0 8px;
}
.modal-head h2 {
  margin: 0;
}
.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  margin: 12px 0 6px;
  font-size: 0.9rem;
}
.crumbs .sep {
  color: var(--muted);
}
.picker-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 46vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.picker-list li {
  border-bottom: 1px solid var(--line);
}
.picker-list li:last-child {
  border: 0;
}
.picker-list li.muted,
.picker-list li.notice {
  padding: 12px;
}
.picker-item {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 0;
  background: none;
  padding: 12px;
  cursor: pointer;
  text-align: left;
}
.picker-item:hover {
  background: var(--surface-2);
}
.picker-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.toasts {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(480px, calc(100vw - 24px));
}
.toast {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--fg);
  color: var(--bg);
  border-radius: 10px;
  padding: 8px 8px 8px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: pop 0.15s var(--ease);
}
.toast span {
  flex: 1;
}
.toast .link-btn {
  color: inherit;
}
.toast-error {
  background: var(--warn);
  color: #fff;
}
@media (min-width: 761px) {
  .toasts {
    bottom: 24px;
    left: calc(50% + var(--nav-w) / 2);
  }
}

/* ---- settings ----------------------------------------------------------------------- */
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0 0 12px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
}
.download-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}
.download-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.note-list {
  list-style: none;
  padding: 0;
}

/* ---- reader ------------------------------------------------------------------------- */
.reader-root:empty {
  display: none;
}
.reader {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--reader-bg, var(--bg));
  color: var(--reader-fg, var(--fg));
  display: grid;
  grid-template-rows: auto 1fr auto;
  outline: none;
  --line: color-mix(in srgb, var(--reader-fg, #000) 14%, transparent);
  --surface: var(--reader-bg);
  --surface-2: color-mix(in srgb, var(--reader-fg, #000) 8%, var(--reader-bg, #fff));
  --muted: var(--reader-muted);
  --fg: var(--reader-fg);
}
.reader[data-theme='dark'] {
  --accent: #9dbbe6;
  --accent-fg: #10161f;
  color-scheme: dark;
}
.reader-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px max(8px, env(safe-area-inset-left));
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 2;
  background: var(--reader-bg);
}
.reader-top {
  padding-top: max(6px, env(safe-area-inset-top));
}
.reader-bottom {
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.reader.chrome-hidden .reader-bar {
  opacity: 0;
  pointer-events: none;
}
.reader.chrome-hidden .reader-top {
  transform: translateY(-6px);
}
.reader.chrome-hidden .reader-bottom {
  transform: translateY(6px);
}
.reader-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--reader-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-stage {
  position: relative;
  min-height: 0;
}
.reader-stage foliate-view {
  display: block;
  position: absolute;
  inset: 0;
}
.reader-progress {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.reader-progress input[type='range'] {
  width: 100%;
  accent-color: var(--reader-fg);
  margin: 0;
}
.reader-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--reader-muted);
  font-variant-numeric: tabular-nums;
}
.reader-chapter {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-info-right {
  white-space: nowrap;
}
@media (max-width: 760px) {
  .reader-time {
    display: none;
  }
  .page-btn {
    display: none;
  }
}
.reader-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--reader-muted);
  pointer-events: none;
}
.reader-error {
  max-width: 520px;
  margin: 15vh auto 0;
  padding: 24px;
  text-align: center;
  display: grid;
  gap: 12px;
  justify-items: center;
}
.reader-banner {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px));
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--reader-bg);
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  font-size: 0.9rem;
}
.reader-banner span {
  flex: 1 1 240px;
}
.reader-panel {
  position: absolute;
  z-index: 4;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100vw);
  background: var(--reader-bg);
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.12);
  padding: max(8px, env(safe-area-inset-top)) 16px 24px;
  overflow: auto;
  animation: slide 0.2s var(--ease);
}
@keyframes slide {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--reader-bg);
  padding: 4px 0;
}
.panel-head h2 {
  margin: 0;
}
.toc {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc .toc {
  padding-left: 14px;
}
.toc-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 9px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--reader-fg);
}
.toc-item:hover {
  background: var(--surface-2);
}
.toc-item[aria-current='true'] {
  font-weight: 600;
  background: var(--surface-2);
}
.theme-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 8px 0 16px;
}
.theme-swatch {
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  font-size: 0.8rem;
}
.theme-swatch[aria-checked='true'] {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.theme-system {
  background: linear-gradient(135deg, #fcfcfa 50%, #161615 50%);
  color: #6b6a66;
}
.theme-light {
  background: #fcfcfa;
  color: #1f1f1d;
}
.theme-sepia {
  background: #f4ecd8;
  color: #3b3024;
}
.theme-dark {
  background: #161615;
  color: #dcdad5;
}
.stepper {
  display: grid;
  grid-template-columns: 1fr 40px 64px 40px;
  align-items: center;
  margin: 6px 0;
}
.stepper output {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.stepper-label {
  font-size: 0.9rem;
}
