/* ==========================================================================
   LIVROS — leitor de webnovels
   Tokens por tema em [data-theme]; fonte do texto em [data-font].
   Espaçamento sempre pela escala --space-*; empilhamento por flex/grid + gap.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Noite (padrão): tinta azul-petróleo + dourado velho */
  --bg: #0f1417;
  --surface: #151c20;
  --raised: #1e272c;
  --line: rgba(233, 228, 216, 0.1);
  --line-strong: rgba(233, 228, 216, 0.2);
  --text: #e9e4d8;
  --text-2: #b8b4a9;
  --muted: #8b9591;
  --accent: #d6a84f;
  --accent-strong: #e5bb66;
  --accent-ink: #1a1408;
  --accent-soft: rgba(214, 168, 79, 0.14);
  --read: #86ad91;
  --overlay: rgba(4, 7, 9, 0.68);
  --shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.75);

  --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Literata', Georgia, 'Times New Roman', serif;
  --font-read: 'Literata', Georgia, 'Times New Roman', serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --page-max: 1180px;
  --gutter: clamp(16px, 4vw, 32px);
  --header-h: 60px;
  --tabbar-h: 58px;
  --reader-bar-h: 56px;
  --reader-bottom-h: 60px;

  /* Controlados pelos ajustes de leitura (js/app.js → applySettings) */
  --reader-width: 42rem;
  --reader-size: 19px;
  --reader-leading: 1.8;
}

[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f3e9d2;
  --surface: #ece0c5;
  --raised: #e2d4b4;
  --line: rgba(58, 46, 32, 0.13);
  --line-strong: rgba(58, 46, 32, 0.24);
  --text: #33291d;
  --text-2: #5a4a37;
  --muted: #72604a;
  --accent: #8f5f14;
  --accent-strong: #7a500f;
  --accent-ink: #fff8ea;
  --accent-soft: rgba(143, 95, 20, 0.12);
  --read: #3f6f4b;
  --overlay: rgba(40, 30, 15, 0.45);
  --shadow: 0 16px 32px -20px rgba(60, 40, 10, 0.5);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #faf8f3;
  --surface: #ffffff;
  --raised: #efebe2;
  --line: rgba(28, 27, 24, 0.1);
  --line-strong: rgba(28, 27, 24, 0.2);
  --text: #1d1c19;
  --text-2: #4a473f;
  --muted: #6b675d;
  --accent: #8a5a12;
  --accent-strong: #744b0e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(138, 90, 18, 0.1);
  --read: #3a6b48;
  --overlay: rgba(20, 18, 12, 0.4);
  --shadow: 0 16px 32px -20px rgba(20, 18, 12, 0.35);
}

[data-theme="oled"] {
  --bg: #000000;
  --surface: #0c0c0c;
  --raised: #181818;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --text: #dcdcdc;
  --text-2: #a9a9a9;
  --muted: #858585;
  --overlay: rgba(0, 0, 0, 0.75);
}

[data-font="lora"] { --font-read: 'Lora', Georgia, serif; }
[data-font="atkinson"] { --font-read: 'Atkinson Hyperlegible', system-ui, -apple-system, sans-serif; }

/* ==========================================================================
   BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  scrollbar-gutter: stable; /* scroll-lock dos diálogos não desloca a página */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  background-color: var(--bg);
  color: var(--text);
  overflow-x: clip; /* clip não cria contêiner de rolagem: sticky continua funcionando */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.scroll-locked { overflow: hidden; }

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
ul[role="list"] { list-style: none; padding: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon { width: 20px; height: 20px; flex: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  transform: translateY(-160%);
}
.skip-link:focus { transform: none; }

#app { flex: 1; }

/* ==========================================================================
   CABEÇALHO, ABAS (MOBILE) E RODAPÉ
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  max-width: var(--page-max);
  height: var(--header-h);
  margin-inline: auto;
  padding-inline: var(--gutter);
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  margin-right: auto;
}

.brand-mark { width: 22px; height: 22px; color: var(--accent); }

.brand-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.brand-domain {
  margin-left: var(--space-1);
  padding-left: var(--space-3);
  border-left: 1px solid var(--line-strong);
  font-size: 0.82rem;
  color: var(--muted);
}

.main-nav { display: flex; gap: var(--space-1); }

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding-inline: var(--space-4);
  border-radius: var(--radius-full);
  color: var(--text-2);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link[aria-current="page"] { color: var(--text); background: var(--raised); }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-full);
  color: var(--text-2);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn--text { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }

.tabbar { display: none; }

.site-footer { border-top: 1px solid var(--line); }

.site-footer__inner {
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
  font-size: 0.88rem;
  color: var(--muted);
}
.site-footer strong { color: var(--text-2); font-weight: 600; letter-spacing: 0.06em; }

body[data-view="read"] .site-header,
body[data-view="read"] .tabbar,
body[data-view="read"] .site-footer { display: none; }

/* ==========================================================================
   PÁGINA, TIPOGRAFIA E BOTÕES
   ========================================================================== */
.page {
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}
.page--narrow { --page-max: 860px; }

.eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-5);
}

.section-title {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.section-meta { color: var(--muted); font-size: 0.9rem; }

.page-head { display: flex; flex-direction: column; gap: var(--space-2); }

.page-title {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 1.4rem + 1.8vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.page-sub { color: var(--text-2); max-width: 60ch; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 46px;
  padding-inline: var(--space-5);
  border-radius: var(--radius-full);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn .icon { width: 18px; height: 18px; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); }

.btn-secondary { border: 1px solid var(--line-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface); }
.btn-secondary[aria-pressed="true"] { border-color: var(--accent); }

.btn-ghost { padding-inline: var(--space-3); color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--surface); }

.link-btn {
  align-self: flex-start;
  min-height: 44px;
  margin-top: calc(-1 * var(--space-3));
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }

.cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--raised);
  box-shadow: var(--shadow);
}

.progress {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--raised);
  overflow: hidden;
}
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.progress.is-thin { height: 3px; }

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.88rem;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  max-width: 760px;
  padding: var(--space-6);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
}
.empty-state h2 { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; line-height: 1.3; }
.empty-state p { color: var(--text-2); }
.empty-state .btn { margin-top: var(--space-2); }

/* ==========================================================================
   INÍCIO: CONTINUAR LENDO + ESTANTE
   ========================================================================== */
.continue {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  grid-template-areas:
    "cover head"
    "cover progress"
    "cover actions";
  align-content: center;
  gap: var(--space-4) var(--space-6);
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.continue__cover { grid-area: cover; align-self: center; }
.continue__head { grid-area: head; display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.continue__progress { grid-area: progress; display: flex; flex-direction: column; gap: var(--space-2); max-width: 520px; }
.continue__actions { grid-area: actions; margin-top: var(--space-2); }

.continue__title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.12;
}
.continue__title a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }

.continue__text {
  max-width: 62ch;
  color: var(--text-2);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-6) var(--space-5);
}

.book-tile { display: flex; flex-direction: column; gap: var(--space-2); }
.book-tile .cover { margin-bottom: var(--space-1); transition: transform 0.2s ease; }
.book-tile:hover .cover { transform: translateY(-3px); }
.book-tile__title { font-weight: 600; line-height: 1.3; }
.book-tile__meta { font-size: 0.82rem; color: var(--muted); }

/* ==========================================================================
   LIVRO: CABEÇALHO, PERSONAGENS, MAPA E LISTA DE CAPÍTULOS
   ========================================================================== */
.book-hero {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-areas:
    "cover head"
    "cover details";
  align-content: start;
  gap: var(--space-5) var(--space-7);
}

.book-hero__cover { grid-area: cover; }
.book-hero__head { grid-area: head; display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; align-self: end; }
.book-hero__details { grid-area: details; display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }

.book-title {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 1.3rem + 2.4vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.08;
}

.book-byline { color: var(--text-2); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  padding: 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-2);
}

.synopsis { max-width: 68ch; color: var(--text-2); line-height: 1.7; }
.synopsis.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-progress { display: flex; flex-direction: column; gap: var(--space-2); max-width: 420px; }
.book-hero .actions { margin-top: var(--space-2); }

.cast {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 156px;
  gap: var(--space-4);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  padding-bottom: var(--space-3);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.cast-card { display: flex; flex-direction: column; gap: var(--space-1); scroll-snap-align: start; }
.cast-card img {
  width: 100%;
  aspect-ratio: 4 / 5;
  margin-bottom: var(--space-2);
  object-fit: cover;
  object-position: top;
  border-radius: var(--radius);
  background: var(--raised);
}
.cast-name { font-size: 1rem; font-weight: 600; line-height: 1.25; }
.cast-role { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.cast-desc { font-size: 0.82rem; line-height: 1.45; color: var(--muted); }

img.is-broken { visibility: hidden; }

.chapter-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.search-field { position: relative; display: block; flex: 1 1 260px; }
.search-field .icon {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}
.search-field input {
  width: 100%;
  min-height: 46px;
  padding: 0 var(--space-4) 0 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: 16px; /* evita o zoom automático do iOS */
}
.search-field input::placeholder { color: var(--muted); }
.search-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.map-caption { margin-bottom: var(--space-3); font-size: 0.85rem; color: var(--muted); }

.reading-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.map-block {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.map-block:hover { border-color: var(--line-strong); color: var(--text); }
.map-block[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.map-block.is-current::after {
  content: '';
  position: absolute;
  top: 9px;
  right: 9px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.map-block__bar { height: 3px; border-radius: var(--radius-full); background: var(--raised); overflow: hidden; }
.map-block__bar > span { display: block; height: 100%; background: var(--read); }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--space-2);
}

.chapter-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
  min-height: 48px;
  padding: var(--space-2) 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.chapter-cell:hover { border-color: var(--line-strong); background: var(--raised); }
.chapter-cell.is-read { color: var(--text-2); }
.chapter-cell.is-current { border-color: var(--accent); }
.chapter-cell .icon { width: 16px; height: 16px; color: var(--read); }
.chapter-cell__text { display: flex; flex-direction: column; min-width: 0; }
.chapter-cell__name { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-cell__badge {
  flex: none;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.list-empty { grid-column: 1 / -1; padding: var(--space-6); text-align: center; color: var(--muted); }

/* ==========================================================================
   LEITOR
   ========================================================================== */
.reader { min-height: 100dvh; }

.reader-progress {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  z-index: 45;
  height: 3px;
  pointer-events: none;
}
.reader-progress > span { display: block; width: 0; height: 100%; background: var(--accent); }

.reader-bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.25s ease;
}

.reader-top { top: 0; padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--line); }

.reader-top__inner {
  max-width: var(--page-max);
  height: var(--reader-bar-h);
  margin-inline: auto;
  padding-inline: max(var(--space-2), env(safe-area-inset-left)) max(var(--space-2), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.reader-top__title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-inline: var(--space-2);
  line-height: 1.25;
}
.reader-top__chapter,
.reader-top__book { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-top__chapter { font-size: 0.95rem; font-weight: 600; }
.reader-top__book { font-size: 0.78rem; color: var(--muted); }

.reader-bottom {
  bottom: 0;
  display: none;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--line);
}

.reader-bottom__inner {
  height: var(--reader-bottom-h);
  padding-inline: var(--space-2);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
}
.reader-bottom__inner > :first-child { justify-self: start; }
.reader-bottom__inner > :last-child { justify-self: end; }
.reader-bottom__pos { font-size: 0.85rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

.reader.bars-hidden .reader-top { transform: translateY(-100%); }
.reader.bars-hidden .reader-bottom { transform: translateY(100%); }

.reader-article {
  max-width: var(--reader-width);
  margin-inline: auto;
  padding: calc(var(--reader-bar-h) + env(safe-area-inset-top) + var(--space-7)) var(--gutter) var(--space-8);
}

.chapter-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-7);
  text-align: center;
}
.chapter-head .eyebrow a:hover { text-decoration: underline; }
.chapter-head::after {
  content: '';
  width: 40px;
  height: 2px;
  margin-top: var(--space-4);
  border-radius: 2px;
  background: var(--accent);
}

.chapter-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 1.5rem + 2vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
}
.chapter-name { font-family: var(--font-display); font-size: 1.15rem; font-style: italic; color: var(--text-2); }
.chapter-meta { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.prose {
  font-family: var(--font-read);
  font-size: var(--reader-size);
  line-height: var(--reader-leading);
  color: var(--text);
  overflow-wrap: break-word;
}
/* Justificado sem hifenização abre "rios" de espaço; à esquerda, hifenizar só atrapalha */
[data-align="justify"] .prose { text-align: justify; -webkit-hyphens: auto; hyphens: auto; }
.prose p { margin-bottom: 1.1em; }
.prose h2,
.prose h3 { margin: 1.8em 0 0.6em; font-family: var(--font-display); line-height: 1.25; }
.prose blockquote { margin: 1.5em 0; padding-left: 1em; border-left: 2px solid var(--accent); color: var(--text-2); }
.prose hr { margin: 2em 0; border: 0; text-align: center; }
.prose hr::before { content: '* * *'; letter-spacing: 0.5em; color: var(--muted); }
.prose img {
  width: 100%;
  height: auto;
  margin-block: 1.6em;
  border-radius: var(--radius);
  background: var(--raised);
  cursor: zoom-in;
}

.skeleton-lines { display: flex; flex-direction: column; gap: 1.1em; }
.skeleton-lines span {
  height: 0.9em;
  border-radius: 4px;
  background: var(--raised);
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
.skeleton-lines span:nth-child(3n) { width: 72%; }
@keyframes skeleton-pulse { 50% { opacity: 0.5; } }

.chapter-end {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.end-link {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 76px;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: background-color 0.15s ease;
}
.end-link:hover { background: var(--surface); }
.end-link__label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.end-link__label .icon { width: 16px; height: 16px; }
.end-link__title { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; }

.end-link--prev { grid-column: 1; }
.end-link--next {
  grid-column: 2;
  align-items: flex-end;
  text-align: right;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.end-link--next:hover { background: var(--accent-strong); }
.end-link--next .end-link__label { color: inherit; opacity: 0.8; }

.end-note { grid-column: 2; align-self: center; text-align: right; font-size: 0.9rem; color: var(--muted); }

.kbd-hint { margin-top: var(--space-6); text-align: center; font-size: 0.8rem; color: var(--muted); }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: 0.75rem;
}

/* ==========================================================================
   HISTÓRICO E MARCADORES
   ========================================================================== */
.entry-list { display: flex; flex-direction: column; gap: var(--space-3); }

.entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.entry--compact { grid-template-columns: minmax(0, 1fr) auto; padding-left: var(--space-5); }

.entry__cover { width: 56px; box-shadow: none; }
.entry__body { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.entry__title { font-size: 1.05rem; font-weight: 600; line-height: 1.3; }
.entry__title:hover { text-decoration: underline; }
.entry__meta { font-size: 0.85rem; color: var(--muted); }
.entry .progress { max-width: 280px; margin-block: var(--space-1); }
.entry__actions { display: flex; align-items: center; gap: var(--space-2); }

/* ==========================================================================
   DIÁLOGOS (<dialog> nativo com showModal)
   ========================================================================== */
.dialog {
  padding: 0;
  border: 0;
  max-width: none;
  max-height: none;
  background: var(--surface);
  color: var(--text);
  opacity: 0;
  transition:
    opacity 0.2s ease,
    transform 0.25s ease,
    overlay 0.25s ease allow-discrete,
    display 0.25s ease allow-discrete;
}
.dialog[open] { opacity: 1; transform: none; }
@starting-style { .dialog[open] { opacity: 0; } }

.dialog::backdrop {
  background: var(--overlay);
  opacity: 0;
  transition: opacity 0.2s ease, overlay 0.25s ease allow-discrete, display 0.25s ease allow-discrete;
}
.dialog[open]::backdrop { opacity: 1; }
@starting-style { .dialog[open]::backdrop { opacity: 0; } }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.dialog-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; }

/* Ajustes: centralizado no desktop, folha inferior no celular */
.dialog--sheet {
  width: min(460px, calc(100% - 32px));
  margin: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transform: translateY(12px);
}
.dialog--sheet[open] { display: flex; flex-direction: column; max-height: 90dvh; }
@starting-style { .dialog--sheet[open] { transform: translateY(12px); } }

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-5);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.setting { display: flex; flex-direction: column; gap: var(--space-2); }
.setting__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.setting__label { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.setting__value { font-size: 0.85rem; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }

.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.segmented--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segmented--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.setting__hint { font-size: 0.85rem; color: var(--muted); }
.data-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-2); margin-top: var(--space-1); }
.data-actions .btn { padding-inline: var(--space-3); }
.segmented button {
  min-height: 44px;
  padding-inline: var(--space-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
}
.segmented button:hover { background: var(--raised); }
.segmented button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }

/* Amostras de tema: cores fixas, iguais em qualquer tema ativo */
.segmented .swatch[data-value="dark"] { background: #0f1417; color: #e9e4d8; }
.segmented .swatch[data-value="sepia"] { background: #f3e9d2; color: #33291d; }
.segmented .swatch[data-value="light"] { background: #faf8f3; color: #1d1c19; }
.segmented .swatch[data-value="oled"] { background: #000000; color: #dcdcdc; }
.segmented .swatch:hover { filter: brightness(1.08); }
.segmented .swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }

.stepper { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: var(--space-3); }
.stepper button {
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 600;
}
.stepper button:hover { background: var(--raised); }

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

/* Resultado de ação que grava */
.dialog--alert {
  width: min(420px, calc(100% - 32px));
  margin: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transform: translateY(12px);
}
@starting-style { .dialog--alert[open] { transform: translateY(12px); } }
.alert-body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); }
.alert-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.alert-text { color: var(--text-2); }
.alert-body .actions { justify-content: flex-end; margin-top: var(--space-3); }

/* Capítulos: gaveta à direita */
.dialog--drawer {
  width: min(400px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  border-left: 1px solid var(--line);
  transform: translateX(32px);
}
.dialog--drawer[open] { display: flex; flex-direction: column; }
@starting-style { .dialog--drawer[open] { transform: translateX(32px); } }
.dialog--drawer .dialog-head { padding-top: calc(var(--space-3) + env(safe-area-inset-top)); }

.drawer-search { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); }

.drawer-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-3) calc(var(--space-5) + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.drawer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  padding-inline: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.drawer-item:hover { background: var(--raised); color: var(--text); }
.drawer-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.drawer-item .icon { width: 16px; height: 16px; color: var(--read); }

/* Ilustração ampliada */
.dialog--lightbox {
  margin: auto;
  background: transparent;
  overflow: visible;
}
.dialog--lightbox img {
  max-width: min(96vw, 1280px);
  max-height: 88dvh;
  object-fit: contain;
  border-radius: var(--radius);
  cursor: zoom-out;
}
.lightbox-close {
  position: fixed;
  top: calc(var(--space-3) + env(safe-area-inset-top));
  right: var(--space-3);
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
}
.lightbox-close:hover { background: rgba(0, 0, 0, 0.8); color: #ffffff; }

/* ==========================================================================
   AVISO (TOAST)
   ========================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: calc(100% - 32px);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  min-height: 48px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast:empty { display: none; }
.toast.is-visible { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast button {
  min-height: 36px;
  padding-inline: var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ==========================================================================
   RESPONSIVO
   ========================================================================== */
@media (max-width: 767px) {
  .main-nav,
  .brand-domain { display: none; }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }

  .tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-h);
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--muted);
  }
  .tab .icon { width: 22px; height: 22px; }
  .tab[aria-current="page"] { color: var(--accent); }

  body:not([data-view="read"]) { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  body:not([data-view="read"]) .toast { bottom: calc(var(--tabbar-h) + var(--space-3) + env(safe-area-inset-bottom)); }
  body[data-view="read"] .toast { bottom: calc(var(--reader-bottom-h) + var(--space-3) + env(safe-area-inset-bottom)); }

  .page { padding-top: var(--space-5); gap: var(--space-7); }

  .continue {
    grid-template-columns: 92px minmax(0, 1fr);
    grid-template-areas:
      "cover head"
      "progress progress"
      "actions actions";
    gap: var(--space-4);
    padding: var(--space-4);
  }
  .continue__cover { align-self: start; }
  .continue__actions .btn { flex: 1 1 auto; }

  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5) var(--space-4); }

  .book-hero {
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-areas:
      "cover head"
      "details details";
    gap: var(--space-5) var(--space-4);
  }
  .book-hero__head { align-self: center; }
  .book-hero .actions .btn { flex: 1 1 auto; }

  .cast {
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
    scroll-padding-inline: var(--gutter);
    grid-auto-columns: 136px;
  }

  .chapter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-map { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

  .reader-bottom { display: block; }
  .reader-article {
    padding-top: calc(var(--reader-bar-h) + env(safe-area-inset-top) + var(--space-6));
    padding-bottom: calc(var(--reader-bottom-h) + env(safe-area-inset-bottom) + var(--space-7));
  }
  .chapter-end { margin-top: var(--space-7); }
  .end-link { padding: var(--space-3) var(--space-4); }
  .kbd-hint { display: none; }

  .entry { grid-template-columns: auto minmax(0, 1fr); }
  .entry > .entry__actions { grid-column: 1 / -1; justify-content: flex-end; }
  .entry--compact { grid-template-columns: minmax(0, 1fr) auto; padding-left: var(--space-4); }
  .entry--compact > .entry__actions { grid-column: auto; }

  .dialog--sheet {
    width: 100%;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
  }
  @starting-style { .dialog--sheet[open] { transform: translateY(100%); } }
  .setting--width { display: none; }
}

@media (hover: none) {
  .kbd-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
