/* ===== Design tokens ===== */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --muted2: #64748b;
  --border: #e2e8f0;
  --accent: #14b8a6;
  --accent2: #0ea5e9;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --shadow2: 0 8px 18px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

body:not(.reader-page) {
  background: var(--bg);
  color: var(--text);
}

body.reader-page .theme-dot {
  display: none;
}

body.dark-mode:not(.reader-page) {
  --bg: #0b1220;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #cbd5e1;
  --muted2: #9ca3af;
  --border: #263244;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --shadow2: 0 10px 22px rgba(0, 0, 0, 0.28);
  --accent: #34d399;
  --accent2: #38bdf8;
}

/* ===== Utilitários ===== */
.surface {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow2);
}

.muted { color: var(--muted); }
.muted2 { color: var(--muted2); }

/* ===== Botões ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 9999px;
  padding: 0.75rem 1.1rem;
  font-weight: 800;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 10px 20px rgba(2, 6, 23, 0.08);
  user-select: none;
}

.btn:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: 0 8px 16px rgba(2, 6, 23, 0.08);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { opacity: 0.95; }

.btn-secondary {
  background: #0f172a;
  color: #fff;
}

body.dark-mode .btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}

.btn-ghost:hover { background: rgba(15, 23, 42, 0.04); }
body.dark-mode .btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }

/* ===== Tema (botões de alternância) ===== */
.theme-dot {
  width: 24px;
  height: 24px;
  border-radius: 9999px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15) inset;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.theme-dot:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35) inset;
  opacity: 0.95;
}

#temaClaro,
#temaClaroM {
  background: linear-gradient(90deg, #ffffff 50%, #14b8a6 50%);
}

#temaEscuro,
#temaEscuroM {
  background: linear-gradient(90deg, #0b1220 50%, #38bdf8 50%);
}

/* ===== Responsividade global (páginas estáticas) ===== */
html {
  -webkit-text-size-adjust: 100%;
}

img,
video {
  max-width: 100%;
}

img.nav-logo {
  height: 2.25rem;
  width: auto;
  max-width: none;
  object-fit: contain;
}

@media (min-width: 640px) {
  img.nav-logo {
    height: 2.5rem;
  }
}

.mobile-nav-panel {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}

.mobile-nav-panel.open {
  max-height: 320px;
  opacity: 1;
}

@media (max-width: 767px) {
  .btn,
  .pill {
    min-height: 44px;
  }

  .theme-dot {
    min-width: 28px;
    min-height: 28px;
    width: 28px;
    height: 28px;
  }
}

.nav-shell {
  min-width: 0;
}

.nav-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Navbar ===== */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
}

.site-nav .nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .site-nav .nav-row {
    gap: 1rem;
  }
}

.glass {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
}

body.dark-mode .glass {
  background: rgba(11, 18, 32, 0.92);
}

@media (min-width: 768px) {
  .glass {
    backdrop-filter: blur(10px);
  }
  body.dark-mode .glass {
    background: rgba(11, 18, 32, 0.78);
  }
}

/* ===== Leitura (capítulos, contos, weblivros) ===== */
.reader-shell {
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

.leitura-prose {
  line-height: 1.8;
  font-size: 1rem;
  max-width: 65ch;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 640px) {
  .leitura-prose {
    font-size: 1.05rem;
  }
}

.leitura-prose h2,
.leitura-prose .chapter-title {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
  line-height: 1.3;
}

.leitura-prose p {
  margin-bottom: 1rem;
}

.leitura-prose p em,
.leitura-prose p.italic {
  font-style: italic;
}

.reader-page-title {
  font-size: clamp(1.75rem, 5vw, 3rem);
  line-height: 1.15;
}

.reader-back-only {
  padding: 0.5rem 0;
}

.reader-back-only .reader-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.progress-wrap .reader-toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
}

.progress-wrap .reader-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

@media (max-width: 639px) {
  .progress-wrap .reader-controls {
    display: none;
    flex-basis: 100%;
    margin-left: 0;
    padding-top: 0.25rem;
  }

  .progress-wrap .reader-controls.open {
    display: flex;
  }

  .reader-controls-toggle {
    display: inline-flex !important;
    margin-left: auto;
  }

  .progress-wrap .ctl-btn {
    font-size: 0.7rem;
    padding: 0.35rem 0.5rem;
    min-height: 36px;
  }
}

.reader-controls-toggle {
  display: none;
}

.sd-reader-grid,
.reader-layout-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}

@media (min-width: 768px) {
  .sd-reader-grid {
    grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) minmax(0, 14rem);
    gap: 1.5rem;
  }
}

.sd-reader-main {
  min-width: 0;
}

/* Painéis laterais (caps, partes, comentários) acompanham o conteúdo, não esticam na coluna */
.reader-panel {
  align-self: start;
  height: auto;
  width: 100%;
}

/* Leitores estilo diário / contos simples */
.book article,
.reading #texto,
#content.script,
#content.leitura-prose {
  max-width: 65ch;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.8;
  font-size: 1rem;
}

@media (min-width: 640px) {
  .book article,
  .reading #texto,
  #content.script,
  #content.leitura-prose {
    font-size: 1.05rem;
  }
}

.top-wrap .reader-toolbar-row,
.top-wrap > div:first-child {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 639px) {
  .top-wrap .ml-auto {
    display: none;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .top-wrap .ml-auto.open {
    display: flex;
  }

  .top-wrap .reader-controls-toggle {
    display: inline-flex !important;
    margin-left: auto;
  }
}

/* ===== Chips e pills ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.55rem 0.9rem;
  font-weight: 900;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  user-select: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.55rem 0.9rem;
  font-weight: 800;
  font-size: 0.875rem;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  transition: background 0.15s ease, transform 0.15s ease;
  user-select: none;
}

.pill:hover { background: rgba(15, 23, 42, 0.04); }
body.dark-mode .pill:hover { background: rgba(255, 255, 255, 0.06); }

.pill.active {
  background: rgba(20, 184, 166, 0.12);
  border-color: rgba(20, 184, 166, 0.35);
  color: var(--accent);
}

/* ===== Campos de formulário ===== */
.field {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 0.85rem 1.1rem;
  color: var(--text);
  outline: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.field:focus {
  border-color: rgba(20, 184, 166, 0.55);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.14);
}

/* ===== Fundos decorativos ===== */
.soft-grid {
  background:
    radial-gradient(circle at 25% 15%, rgba(14, 165, 233, 0.2), transparent 55%),
    radial-gradient(circle at 75% 75%, rgba(20, 184, 166, 0.2), transparent 55%);
}

body.dark-mode .soft-grid {
  background:
    radial-gradient(circle at 25% 15%, rgba(56, 189, 248, 0.22), transparent 55%),
    radial-gradient(circle at 75% 75%, rgba(52, 211, 153, 0.22), transparent 55%);
}

/* ===== Sacola (drawer) ===== */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 100%;
  max-width: 420px;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 60;
}

.drawer.open { transform: translateX(0); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  display: none;
  z-index: 50;
}

.overlay.show { display: block; }

/* ===== Modais ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(6px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.modal-card {
  width: min(720px, 100%);
  border-radius: 24px;
  overflow: hidden;
}

.modal-header {
  padding: 18px 18px 12px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle at 20% 0%, rgba(14, 165, 233, 0.14), transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(20, 184, 166, 0.14), transparent 55%);
}

body.dark-mode .modal-header {
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.16), transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(52, 211, 153, 0.16), transparent 55%);
}

.modal-kicker {
  font-weight: 900;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--accent2);
}

.modal-title {
  margin-top: 6px;
  font-weight: 900;
  font-size: 1.35rem;
  line-height: 1.15;
}

.modal-sub { margin-top: 6px; font-size: 0.95rem; }
.modal-body { padding: 16px 18px 18px 18px; }

.modal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 640px) {
  .modal-grid { grid-template-columns: 1fr 1fr; }
}

.modal-item {
  text-align: left;
  padding: 14px 14px;
  border-radius: 18px;
  box-shadow: none !important;
  transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease;
  position: relative;
  overflow: hidden;
}

.modal-item:hover {
  transform: translateY(-1px);
  background: rgba(15, 23, 42, 0.03);
}

body.dark-mode .modal-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.modal-item-title { font-weight: 900; }
.modal-item-sub { margin-top: 4px; font-size: 0.85rem; }

.modal-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.7rem;
  font-weight: 900;
  padding: 0.35rem 0.6rem;
  border-radius: 9999px;
  border: 1px solid;
}

.modal-badge.ok {
  background: rgba(20, 184, 166, 0.12);
  border-color: rgba(20, 184, 166, 0.3);
  color: var(--accent);
}

.modal-badge.soon {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.35);
  color: var(--muted2);
}

.modal-item.is-soon {
  opacity: 0.72;
  cursor: not-allowed;
}

.modal-item.is-soon:hover {
  transform: none;
  background: transparent;
}

.modal-hint {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px dashed var(--border);
  background: rgba(14, 165, 233, 0.06);
}

body.dark-mode .modal-hint {
  background: rgba(56, 189, 248, 0.1);
}

.hint-dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: var(--accent2);
  box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.14);
}

.modal-backdrop { background: rgba(2, 6, 23, 0.55); }

/* ===== Acessibilidade ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
