/* =====================================================================
   base.css — reset, layout, cabeçalho, sidebar, preferências, rodapé
   Mobile-first. Cores temáticas vêm de themes.css (variáveis CSS).
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .25s ease, color .25s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Barra de progresso ---------- */
#reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  z-index: 60;
  transition: width .1s linear;
}

/* ---------- Cabeçalho retrátil ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  transition: transform .3s ease, background .25s ease;
}
.app-header.header-hidden { transform: translateY(-100%); }

.brand {
  display: flex; align-items: center; gap: .5rem;
  margin: 0 auto 0 .25rem;
  font-weight: 600; color: var(--header-text);
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--gold); font-size: 1.25rem; line-height: 1; }
.brand-text { font-size: 1rem; letter-spacing: .2px; }

.header-actions { display: flex; gap: .25rem; margin-left: auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--header-text);
  cursor: pointer;
  transition: background .15s ease;
}
.icon-btn:hover { background: var(--hover); }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 55; opacity: 0;
  animation: fade .2s ease forwards;
}
@keyframes fade { to { opacity: 1; } }

/* ---------- Sidebar (sumário) ---------- */
.sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(86vw, 340px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 58;
  transform: translateX(-100%);
  transition: transform .28s ease;
  display: flex; flex-direction: column;
}
.sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.18); }

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--accent); color: #fff;
}
.sidebar-head .icon-btn { color: #fff; font-size: 1.4rem; }

.toc { overflow-y: auto; padding: .5rem .5rem 2rem; flex: 1; }
.toc-part { margin-bottom: .25rem; }
.toc-part > summary {
  cursor: pointer; list-style: none;
  padding: .6rem .75rem;
  font-weight: 600; font-size: .82rem;
  color: var(--accent);
  border-radius: 8px;
  text-transform: uppercase; letter-spacing: .4px;
}
.toc-part > summary::-webkit-details-marker { display: none; }
.toc-part > summary:hover { background: var(--hover); }
.toc-part ul { list-style: none; margin: 0 0 .5rem; padding: 0; }
.toc-part li a {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .5rem .75rem; border-radius: 8px;
  color: var(--text); font-size: .92rem;
}
.toc-part li a:hover { background: var(--hover); text-decoration: none; }
.toc-part li a.active { background: var(--accent); color: #fff; }
.toc-part li a.active .toc-num { color: var(--gold-on-dark); }
.toc-num {
  flex: 0 0 1.8rem; text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: .8rem; color: var(--muted); font-weight: 600;
}
.toc-title { flex: 1; }

/* Rodapé da sidebar — voltar ao site principal */
.sidebar-foot { padding: .75rem; border-top: 1px solid var(--border); }
.back-main {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem; border-radius: 10px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.back-main:hover { background: var(--accent); color: #fff; text-decoration: none; }

/* Link de volta no cabeçalho (oculto no mobile) */
.header-back {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .7rem; margin-right: .15rem; border-radius: 9px;
  font-size: .82rem; font-weight: 600;
  color: var(--header-text); border: 1px solid var(--border);
  white-space: nowrap;
}
.header-back:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); text-decoration: none; }
@media (max-width: 768px) { .header-back { display: none; } }

/* ---------- Painel de preferências ---------- */
.prefs-panel {
  position: fixed;
  top: 64px; right: .75rem;
  width: min(92vw, 320px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  z-index: 59;
  padding: .5rem .75rem 1rem;
}
.prefs-panel[hidden] { display: none; }
.prefs-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .35rem .25rem .6rem;
  border-bottom: 1px solid var(--border);
}
.pref-group { margin-top: 1rem; }
.pref-group > label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  margin-bottom: .5rem;
}
.seg { display: flex; gap: .35rem; }
.seg button {
  flex: 1; padding: .55rem .4rem;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text);
  cursor: pointer; font-size: .9rem;
  transition: all .15s ease;
}
.seg button:hover { border-color: var(--accent); }
.seg button.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.size-control {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
}
.size-control button {
  width: 52px; height: 44px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.size-control button:hover { border-color: var(--accent); }
#sizeLabel { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }

/* ---------- Toasts ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem;
  transform: translateX(-50%) translateY(1rem);
  background: var(--accent); color: #fff;
  padding: .7rem 1.2rem; border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.25);
  z-index: 70; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  font-size: .9rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.resume-toast {
  position: fixed; left: 50%; bottom: 1.5rem;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  padding: .65rem .75rem .65rem 1rem;
  border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.2);
  z-index: 65; font-size: .9rem;
}
.resume-toast[hidden] { display: none; }
.resume-toast button {
  border: 0; border-radius: 8px; cursor: pointer;
  padding: .45rem .8rem; font-weight: 600;
  background: var(--gold); color: #2a2000;
}
.resume-toast button.ghost { background: transparent; color: var(--muted); padding: .2rem .5rem; font-size: 1.2rem; }

/* ---------- Rodapé ---------- */
.app-footer {
  text-align: center; padding: 2.5rem 1rem 4rem;
  color: var(--muted); font-size: .85rem;
}

/* ---------- Desktop ---------- */
@media (min-width: 1024px) {
  .brand-text { font-size: 1.05rem; }
}

/* =====================================================================
   Mobile — melhorias gerais de UX
   ===================================================================== */
@media (max-width: 600px) {

  /* Painel de Preferências vira bottom-sheet em telas pequenas */
  .prefs-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: none;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 40px rgba(0,0,0,.22);
  }

  /* Botões de segmento maiores para toque */
  .seg button {
    padding: .7rem .5rem;
    font-size: .95rem;
    min-height: 44px;
  }

  /* Controles de tamanho de fonte maiores */
  .size-control button {
    width: 58px;
    height: 48px;
  }

  /* Resume toast acima da área de navegação segura */
  .resume-toast {
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Toast central */
  .toast {
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    max-width: 90vw;
    text-align: center;
  }

  /* Navegação de documento mais acessível */
  .doc-nav-link {
    padding: .9rem .75rem;
  }

  /* Rodapé com folga da safe area */
  .app-footer {
    padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
  }
}
