/*
 * mm-reader F5 — Reader CSS
 * Reflow puro estilo Kindle, sem paginacao fixa.
 */

/* ============ TOKENS ============ */
:root {
  --color-bg: #fafaf7;
  --color-bg-sepia: #f3ead7;
  --color-bg-dark: #131211;
  --color-surface: #ffffff;
  --color-surface-dark: #1c1b19;
  --color-text: #0a0a0a;
  --color-text-dim: #666666;
  --color-text-on-dark: #f4f1ea;
  --color-accent: #7a1818;
  --color-accent-hover: #5e1212;
  --color-accent-soft: #f3eceb;
  --color-border: #e6e2db;
  --color-border-dark: rgba(244, 241, 234, 0.10);

  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --touch: 44px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;

  --duration-fast: 120ms;
  --duration-normal: 220ms;
  --ease-out-soft: cubic-bezier(0.22, 0.61, 0.36, 1);

  --shadow-sm: 0 1px 2px rgba(10,10,10,0.06);
  --shadow-md: 0 8px 24px rgba(10,10,10,0.08), 0 2px 6px rgba(10,10,10,0.04);

  /* Reader-specific: ajustados via JS e persistidos em localStorage */
  --reader-font-size: 1.05rem;
  --reader-line-height: 1.75;
  --reader-col-width: 680px;

  /* Topbar height — usado para scroll-padding-top (bugfix F5) */
  --topbar-height: 52px;

  /* Watermark */
  --watermark-opacity: 0.04;
  --watermark-text: "Marcio Marcal — Manual do Marketing";
}

/* ============ BUGFIX: scroll-padding-top ============ */
/* Garante que heading de capitulo nao fica escondido atras do topbar sticky */
html {
  scroll-padding-top: var(--topbar-height);
}

/* ============ BASE ============ */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }

/* ============ TEMAS ============ */
body.theme-light {
  background: var(--color-bg);
  color: var(--color-text);
}
body.theme-sepia {
  background: var(--color-bg-sepia);
  color: var(--color-text);
  --color-surface: #f9efd9;
  --color-border: #e2d4af;
}
body.theme-dark {
  background: var(--color-bg-dark);
  color: var(--color-text-on-dark);
  --color-surface: var(--color-surface-dark);
  --color-text: var(--color-text-on-dark);
  --color-border: rgba(244, 241, 234, 0.10);
  --color-text-dim: rgba(244, 241, 234, 0.50);
  --color-accent-soft: rgba(122, 24, 24, 0.18);
}

/* ============ LAYOUT PRINCIPAL ============ */
.reader-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ============ TOPBAR ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  height: var(--topbar-height);
}

.topbar-logo {
  display: block;
  height: 32px;
  width: auto;
  flex-shrink: 0;
}
.topbar-brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-text);
  flex-shrink: 0;
  white-space: nowrap;
}

.topbar-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}
.topbar-progress-label {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  letter-spacing: 0.05em;
  color: var(--color-text-dim);
  white-space: nowrap;
}
.topbar-progress-bar {
  width: 100%;
  max-width: 260px;
  height: 2px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}
.topbar-progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width var(--duration-normal) var(--ease-out-soft);
  width: 0%;
}
body.theme-dark .topbar-progress-fill { background: var(--color-text-on-dark); }

.icon-btn {
  width: var(--touch);
  height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text);
  flex-shrink: 0;
  transition: background var(--duration-fast);
}
.icon-btn:hover { background: rgba(10,10,10,0.06); }
body.theme-dark .icon-btn { color: var(--color-text-on-dark); }
body.theme-dark .icon-btn:hover { background: rgba(244,241,234,0.08); }

/* ============ SIDEBAR (sumario) ============ */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,0.38);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal);
}
.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 320px;
  max-width: 88vw;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--duration-normal) var(--ease-out-soft);
  will-change: transform;
}
.sidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 32px rgba(10,10,10,0.12);
}
body.theme-dark .sidebar {
  background: #1c1b19;
  border-right-color: rgba(244,241,234,0.08);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
body.theme-dark .sidebar-header { border-bottom-color: rgba(244,241,234,0.08); }
.sidebar-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
  -webkit-overflow-scrolling: touch;
}

.toc-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  text-align: left;
  color: var(--color-text);
  width: 100%;
  border: none;
  border-left: 3px solid transparent;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  cursor: pointer;
}
.toc-item:hover {
  background: var(--color-accent-soft);
}
.toc-item.active {
  border-left-color: var(--color-accent);
  background: var(--color-accent-soft);
}
.toc-item .toc-label {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  line-height: 1.4;
  flex: 1;
}
body.theme-dark .toc-item {
  color: var(--color-text-on-dark);
}
body.theme-dark .toc-item:hover,
body.theme-dark .toc-item.active {
  background: rgba(244,241,234,0.06);
}
body.theme-dark .toc-item.active {
  border-left-color: var(--color-text-on-dark);
}

/* ============ PAINEL Aa ============ */
.aa-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 28px rgba(10,10,10,0.14);
  padding: var(--space-4);
  z-index: 200;
  display: none;
}
.aa-panel.open { display: block; }
body.theme-dark .aa-panel {
  background: #1c1b19;
  border-color: rgba(244,241,234,0.12);
}

.aa-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.aa-row:last-child { margin-bottom: 0; }

.aa-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-text-dim);
  width: 70px;
  flex-shrink: 0;
}

.aa-opts {
  display: flex;
  gap: 4px;
  flex: 1;
}
.aa-opt {
  flex: 1;
  padding: 8px 4px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-align: center;
  color: var(--color-text);
  transition: border-color var(--duration-fast), background var(--duration-fast);
  min-height: 36px;
}
.aa-opt:hover { border-color: var(--color-text); }
.aa-opt.active {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--color-accent);
}
body.theme-dark .aa-opt {
  color: var(--color-text-on-dark);
  border-color: rgba(244,241,234,0.14);
}
body.theme-dark .aa-opt.active {
  border-color: var(--color-text-on-dark);
  background: rgba(244,241,234,0.08);
  color: var(--color-text-on-dark);
  box-shadow: 0 0 0 1px rgba(244,241,234,0.5);
}

/* temas dentro do painel Aa */
.aa-themes {
  display: flex;
  gap: 8px;
  flex: 1;
}
.aa-theme-btn {
  flex: 1;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.aa-theme-btn.light  { background: #fafaf7; color: #0a0a0a; border-color: #e6e2db; }
.aa-theme-btn.sepia  { background: #f3ead7; color: #3d2e1a; border-color: #d4c49a; }
.aa-theme-btn.dark   { background: #131211; color: #f4f1ea; border-color: #333; }
.aa-theme-btn.active { border-color: var(--color-accent) !important; box-shadow: 0 0 0 1px var(--color-accent); }
body.theme-dark .aa-theme-btn.dark.active { border-color: #f4f1ea !important; box-shadow: 0 0 0 1px #f4f1ea; }

/* ============ AREA DE CONTEUDO ============ */
.content-area {
  position: relative;
  display: flex;
  justify-content: center;
}

/* watermark diagonal repetida */
.content-area::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 120px,
    rgba(0,0,0,0.01) 120px,
    rgba(0,0,0,0.01) 121px
  );
  opacity: var(--watermark-opacity);
}

.watermark-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
  opacity: var(--watermark-opacity);
  user-select: none;
  -webkit-user-select: none;
}
.watermark-layer svg {
  width: 100%;
  height: 100%;
}

.chapter-scroll {
  width: 100%;
  max-width: var(--reader-col-width);
  padding: var(--space-8) var(--space-5);
  position: relative;
  z-index: 2;
}

/* estado vazio / loading */
.chapter-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--color-text-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
}

.chapter-heading {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-6);
  line-height: 1.2;
  color: var(--color-text);
  /* garante que heading nao fica atras do topbar ao usar scrollIntoView */
  scroll-margin-top: calc(var(--topbar-height) + var(--space-4));
}

/* ============ TIPOGRAFIA DO CORPO ============ */
.chapter-body {
  font-family: var(--font-serif);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  color: var(--color-text);
  /* highlights precisam de user-select ativo */
  user-select: text;
  -webkit-user-select: text;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chapter-body p {
  margin: 0 0 1.1em;
}
.chapter-body h2, .chapter-body h3, .chapter-body h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  margin: 1.6em 0 0.6em;
  line-height: 1.2;
}
.chapter-body h2 { font-size: 1.3em; }
.chapter-body h3 { font-size: 1.1em; }
.chapter-body blockquote {
  margin: 1.2em 0;
  padding: 0.8em 1.2em;
  border-left: 3px solid var(--color-accent);
  background: var(--color-accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
}
body.theme-dark .chapter-body blockquote {
  background: rgba(122,24,24,0.12);
}
.chapter-body ul, .chapter-body ol {
  padding-left: 1.4em;
  margin: 0 0 1em;
}
.chapter-body li { margin-bottom: 0.4em; }
.chapter-body strong { font-weight: 700; }
.chapter-body em { font-style: italic; }

/* ============ HIGHLIGHTS ============ */
mark.hl {
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
  position: relative;
}
mark.hl-yellow { background: rgba(255, 230, 0, 0.45); color: inherit; }
mark.hl-green  { background: rgba(72, 199, 116, 0.40); color: inherit; }
mark.hl-blue   { background: rgba(79, 148, 230, 0.40); color: inherit; }
mark.hl-pink   { background: rgba(240, 98, 146, 0.38); color: inherit; }

body.theme-dark mark.hl-yellow { background: rgba(255, 230, 0, 0.28); }
body.theme-dark mark.hl-green  { background: rgba(72, 199, 116, 0.28); }
body.theme-dark mark.hl-blue   { background: rgba(79, 148, 230, 0.28); }
body.theme-dark mark.hl-pink   { background: rgba(240, 98, 146, 0.25); }

/* icone de nota no highlight */
mark.hl .hl-note-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
  vertical-align: super;
  margin-left: 1px;
  font-size: 0;
}

/* ============ POPOVER DE HIGHLIGHT ============ */
#hlPopover {
  position: fixed;
  z-index: 300;
  display: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(10,10,10,0.16);
  padding: 6px 8px;
  gap: 6px;
  align-items: center;
}
#hlPopover.visible {
  display: flex;
}
body.theme-dark #hlPopover {
  background: #1c1b19;
  border-color: rgba(244,241,234,0.12);
}

.hl-color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--duration-fast), border-color var(--duration-fast);
  flex-shrink: 0;
}
.hl-color-btn:hover { transform: scale(1.18); border-color: rgba(10,10,10,0.3); }
.hl-color-btn[data-color="yellow"] { background: rgba(255, 230, 0, 0.85); }
.hl-color-btn[data-color="green"]  { background: rgba(72, 199, 116, 0.85); }
.hl-color-btn[data-color="blue"]   { background: rgba(79, 148, 230, 0.85); }
.hl-color-btn[data-color="pink"]   { background: rgba(240, 98, 146, 0.85); }

/* ============ MODAL DE NOTA ============ */
#noteModal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,10,0.45);
  padding: var(--space-4);
}
#noteModal.visible {
  display: flex;
}

.note-modal-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
body.theme-dark .note-modal-box {
  background: #1c1b19;
  border-color: rgba(244,241,234,0.12);
}

.note-modal-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}

#noteTextarea {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  transition: border-color var(--duration-fast);
}
#noteTextarea:focus { border-color: var(--color-accent); }
body.theme-dark #noteTextarea {
  background: #0d0c0b;
  color: var(--color-text-on-dark);
  border-color: rgba(244,241,234,0.14);
}

.note-modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.note-btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.note-btn-cancel {
  border: 1.5px solid var(--color-border);
  color: var(--color-text-dim);
}
.note-btn-cancel:hover { border-color: var(--color-text); }
.note-btn-save {
  background: var(--color-accent);
  color: #fff;
  border: 1.5px solid var(--color-accent);
}
.note-btn-save:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
body.theme-dark .note-btn-cancel { color: rgba(244,241,234,0.5); border-color: rgba(244,241,234,0.14); }

/* tooltip de nota (hover no highlight com nota) */
.hl-note-tooltip {
  position: fixed;
  z-index: 350;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--color-text);
  max-width: 260px;
  pointer-events: none;
  display: none;
}
.hl-note-tooltip.visible { display: block; }
body.theme-dark .hl-note-tooltip {
  background: #1c1b19;
  border-color: rgba(244,241,234,0.12);
  color: var(--color-text-on-dark);
}

/* ============ NAVEGACAO ENTRE CAPITULOS ============ */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5) 0 var(--space-8);
  margin-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}
body.theme-dark .chapter-nav { border-top-color: rgba(244,241,234,0.08); }

.chapter-nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: border-color var(--duration-fast), background var(--duration-fast);
  max-width: 48%;
}
.chapter-nav-btn:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}
.chapter-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
body.theme-dark .chapter-nav-btn {
  color: var(--color-text-on-dark);
  border-color: rgba(244,241,234,0.14);
}
body.theme-dark .chapter-nav-btn:hover {
  background: rgba(244,241,234,0.06);
  border-color: rgba(244,241,234,0.4);
}
.chapter-nav-label {
  font-size: 0.82rem;
  font-family: var(--font-serif);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

/* ============ FOOTER ============ */
.bottombar {
  position: sticky;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -1px 8px rgba(10,10,10,0.04);
}
body.theme-dark .bottombar { border-top-color: rgba(244,241,234,0.08); }

.bottombar-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}
.bottombar-pct-book {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
  white-space: nowrap;
}
.bottombar-pct-chapter {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--color-text-dim);
  opacity: 0.7;
  white-space: nowrap;
}
.bottombar-bar {
  width: 100%;
  height: 2px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 3px;
}
.bottombar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width var(--duration-normal) var(--ease-out-soft);
  width: 0%;
}
body.theme-dark .bottombar-fill { background: rgba(244,241,234,0.6); }

/* ============ BOTAO Aa (posicionamento relativo) ============ */
.aa-wrapper {
  position: relative;
  flex-shrink: 0;
}

/* ============ ANTI-PRINT ============ */
@media print {
  body * { visibility: hidden !important; }
  body::after {
    content: "Impressao bloqueada. Conteudo licenciado.";
    visibility: visible !important;
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #0a0a0a;
  }
}

/* ============ MOBILE ============ */
@media (max-width: 767px) {
  :root {
    --reader-col-width: 100%;
  }
  .chapter-scroll {
    padding: var(--space-5) var(--space-4);
  }
  .sidebar {
    width: 100%;
    max-width: 100%;
  }
  .topbar {
    padding: var(--space-2) var(--space-3);
  }
  .chapter-nav-label { max-width: 90px; }
}

/* ============ MOBILE PEQUENO (< 600px): padding 15px fixo ============ */
/* Garante 15px de respiro lateral em qualquer tela estreita (ate iPhone SE 320px).
   Override do var(--space-4) do bloco mobile acima para valor exato pedido pelo Marcio. */
@media (max-width: 599px) {
  .chapter-scroll {
    padding-inline: 15px;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  :root { --reader-col-width: 640px; }
}
@media (min-width: 1024px) {
  :root { --reader-col-width: 680px; }
}

/* Botao Capitulos na topbar */
.topbar-chapters-btn {
  width: auto;
  padding: 0 10px;
  gap: 6px;
}
.topbar-btn-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* ============ PAINEL MINHAS NOTAS (F6) ============ */

/* botao Notas na topbar */
.topbar-notes-btn {
  width: auto;
  padding: 0 10px;
  gap: 6px;
}

/* painel lateral direito — espelha .sidebar mas slide da direita */
.notes-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 92vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-normal) var(--ease-out-soft);
  will-change: transform;
}
.notes-panel.open {
  transform: translateX(0);
  box-shadow: -4px 0 32px rgba(10,10,10,0.12);
}
body.theme-dark .notes-panel {
  background: #1c1b19;
  border-left-color: rgba(244,241,234,0.08);
}

.notes-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
body.theme-dark .notes-panel-header { border-bottom-color: rgba(244,241,234,0.08); }

.notes-panel-title-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.notes-panel-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}
.notes-panel-count {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--color-text-dim);
  opacity: 0.7;
}

.notes-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
  -webkit-overflow-scrolling: touch;
}

.notes-panel-loading {
  padding: var(--space-5) var(--space-4);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  color: var(--color-text-dim);
}

.notes-panel-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--color-text-dim);
}

/* card de nota individual */
.note-card {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.note-card:hover {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
}
body.theme-dark .note-card {
  border-color: rgba(244,241,234,0.10);
}
body.theme-dark .note-card:hover {
  background: rgba(122,24,24,0.18);
  border-color: rgba(122,24,24,0.5);
}

.note-card-chapter {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-card-snippet {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}
.note-card-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.hl-dot-yellow { background: rgba(255, 230, 0, 0.85); border: 1.5px solid rgba(200,180,0,0.6); }
.hl-dot-green  { background: rgba(72, 199, 116, 0.85); border: 1.5px solid rgba(50,160,90,0.6); }
.hl-dot-blue   { background: rgba(79, 148, 230, 0.85); border: 1.5px solid rgba(50,110,200,0.6); }
.hl-dot-pink   { background: rgba(240, 98, 146, 0.85); border: 1.5px solid rgba(200,60,110,0.6); }

.note-card-snippet-text {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--color-text-dim);
  font-style: italic;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.note-card-text {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text);
}
body.theme-dark .note-card-text { color: var(--color-text-on-dark); }

.note-card-date {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--color-text-dim);
  opacity: 0.6;
  margin-top: var(--space-1);
}

/* animacao de flash no highlight navegado */
@keyframes hl-flash {
  0%   { outline: 3px solid rgba(122,24,24,0); }
  25%  { outline: 3px solid rgba(122,24,24,0.7); }
  75%  { outline: 3px solid rgba(122,24,24,0.7); }
  100% { outline: 3px solid rgba(122,24,24,0); }
}
mark.hl.hl-flash {
  animation: hl-flash 1.5s ease-in-out;
  border-radius: 3px;
}

/* mobile: notes panel ocupa 100% */
@media (max-width: 767px) {
  .notes-panel {
    width: 100%;
    max-width: 100%;
  }
}

/* ============ HARDFIX MOBILE 2026-05-13 (Maestro) ============ */
/* Causa: flex items com white-space: nowrap forçam intrinsic min-content
   maior que viewport, container expande e vaza. Fix: cravar overflow-x
   hidden na raiz + esconder labels textuais no topbar < 600px. */

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

.reader-shell {
  max-width: 100vw;
  overflow-x: hidden;
}

.topbar {
  min-width: 0;
  max-width: 100%;
}
.topbar > * { min-width: 0; }

@media (max-width: 599px) {
  .topbar {
    gap: 6px !important;
    padding: 8px 12px !important;
  }
  /* Esconde os labels textuais dos botões. Mantém só os ícones SVG */
  .topbar-chapters-btn .topbar-btn-label,
  .topbar-notes-btn .topbar-btn-label {
    display: none !important;
  }
  .topbar-chapters-btn,
  .topbar-notes-btn {
    padding: 0 8px !important;
  }
  /* Brand encolhe e trunca em ellipsis */
  .topbar-brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 0.95rem !important;
  }
  /* Barra de % com tamanho fixo pequeno */
  .topbar-progress { flex: 0 0 auto !important; }
  .topbar-progress-bar { width: 36px !important; }
  .topbar-progress-label { font-size: 0.7rem !important; }
  /* Chapter scroll/body explicit max-width */
  .chapter-scroll {
    padding-inline: 15px !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .chapter-body, .chapter-heading, .chapter-body p {
    max-width: 100% !important;
    word-wrap: break-word;
  }
}

/* ============ HARDFIX MOBILE Aa TEMA 2026-05-13 b ============ */
/* O painel Aa tem .aa-themes ou .aa-row--theme com flex-direction: row
   que estoura no mobile. Botão "Preto" sai do viewport. Fix: força wrap. */
@media (max-width: 599px) {
  .aa-panel {
    max-width: calc(100vw - 32px) !important;
  }
  .aa-themes, .aa-row--theme {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .aa-themes button, .aa-row--theme button[data-theme] {
    flex: 1 1 0 !important;
    min-width: 60px !important;
    padding: 0 8px !important;
    font-size: 0.78rem !important;
  }
  /* Mesma cura preventiva pras outras rows (fonte, linha, largura) */
  .aa-row, .aa-fonts, .aa-lines, .aa-widths {
    flex-wrap: wrap !important;
  }
}

/* ============ FIXES MAESTRO 2026-05-14 ============ */
/* 1. Brand expande pra empurrar Notas+Aa pra direita */
.topbar-brand {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 2. Painel Aa: wrap global (não só mobile) — botão Preto não corta em tablet/desktop */
.aa-themes, .aa-row--theme {
  flex-wrap: wrap !important;
  gap: 6px !important;
}
.aa-themes button[data-theme] {
  flex: 1 1 0 !important;
  min-width: 60px !important;
  max-width: 100% !important;
  padding: 0 8px !important;
}
.aa-row, .aa-opts {
  flex-wrap: wrap !important;
}
.aa-panel {
  max-width: min(360px, calc(100vw - 32px)) !important;
}



/* ============ PRINT MSG FIX (visibility heranca) ============ */
@media print {
  /* Override mais forte: body * fica hidden, mas .print-block-msg E descendentes ficam visiveis */
  .print-block-msg,
  .print-block-msg *,
  .print-block-msg::before,
  .print-block-msg::after {
    visibility: visible !important;
  }
  /* Garante que o pseudo body::after da regra antiga nao apareca */
  body::after { content: none !important; }
}

/* ============ MOBILE FIX 2026-05-14 b (Maestro) ============ */
/* No mobile: tira % do topo, brand centralizado, Sair só ícone */
@media (max-width: 599px) {
  #topbarProgress { display: none !important; }
  .topbar-brand {
    flex: 1 1 0 !important;
    text-align: center !important;
    font-size: 0.95rem !important;
  }
  #btnLogout span, .btn-logout-label { display: none !important; }
  #btnLogout { padding: 0 8px !important; }
}

/* Copyright sutil no final de cada capítulo */
.copyright-notice {
  margin: var(--space-7, 48px) auto var(--space-5, 24px);
  max-width: 540px;
  padding: 0 8px;
  text-align: center;
  opacity: 0.42;
  font-size: 0.74rem;
  line-height: 1.5;
  font-style: italic;
  font-family: Georgia, serif;
}
.copyright-notice p { margin: 0 0 6px; }
.copyright-notice p:last-child { margin-bottom: 0; font-weight: 600; }
@media (max-width: 599px) {
  .copyright-notice {
    font-size: 0.68rem;
    margin-top: 32px;
  }
}

/* Sair some no mobile (vai pra dentro do Aa) */
@media (max-width: 599px) {
  .btn-logout, #btnLogout { display: none !important; }
}

/* Sair dentro do painel Aa */
.aa-panel .aa-row-logout {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border, #eee);
  text-align: center;
}
.aa-panel .aa-logout-btn {
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px solid var(--color-border, #ccc);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--color-text-muted, #666);
  cursor: pointer;
  font-family: ui-monospace, monospace;
}
.aa-panel .aa-logout-btn:hover {
  color: var(--color-accent, #7a1818);
  border-color: var(--color-accent, #7a1818);
}
