/* base.css — reset, tokens, tema, layout del shell y menú.
   Enfoque mobile-first: los estilos base son para móvil; cada @media (min-width)
   mejora progresivamente en pantallas mayores.
   Los estilos propios de cada apartado van en apartados/<id>/<id>.css */

/* ---------- Tokens (tema claro por defecto) ---------- */
:root {
  --bg:            #f4f6f8;
  --surface:       #ffffff;
  --surface-2:     #eef2f5;
  --border:        #d8dee4;
  --text:          #16232b;
  --text-muted:    #5c6b75;

  --accent:        #0f766e;   /* teal petróleo */
  --accent-strong: #0b5c55;
  --accent-soft:   #d7efec;
  --on-accent:     #ffffff;

  --ok:            #15803d;
  --ok-bg:         #e7f6ec;
  --err:           #b91c1c;
  --err-bg:        #fdeaea;

  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 2px rgba(16,35,43,.06), 0 6px 20px rgba(16,35,43,.06);

  --font-ui:   system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-math: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", "Roboto Mono", monospace;

  --header-h: 60px;   /* altura de cabecera en escritorio */
  --tap:      44px;   /* zona táctil mínima en móvil */
}

/* ---------- Tema oscuro ---------- */
[data-theme="dark"] {
  --bg:         #0e171d;
  --surface:    #16232b;
  --surface-2:  #1d2c34;
  --border:     #2a3b45;
  --text:       #e7eef2;
  --text-muted: #9db0bb;

  --accent:        #2dd4bf;
  --accent-strong: #5eead4;
  --accent-soft:   #123531;
  --on-accent:     #06231f;

  --ok:     #4ade80;
  --ok-bg:  #143024;
  --err:    #f87171;
  --err-bg: #3a1a1a;

  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

/* ---------- Reset mínimo ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }

/* Accesibilidad: foco visible y coherente en todo el shell */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Header / menú (MÓVIL primero) ----------
   Fila 1: marca + hamburguesa + toggle. El menú es un panel desplegable. */
.shell-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding: .5rem clamp(.75rem, 3vw, 1.5rem);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.05rem;
}

/* --- Botón hamburguesa --- */
.menu-toggle {
  margin-left: auto;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.menu-toggle__bars,
.menu-toggle__bars::before,
.menu-toggle__bars::after {
  content: "";
  display: block;
  width: 20px; height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.menu-toggle__bars::before { transform: translateY(-6px); }
.menu-toggle__bars::after  { transform: translateY(4px); }
/* Estado abierto: hamburguesa → X */
.menu-toggle[aria-expanded="true"] .menu-toggle__bars { background: transparent; }
.menu-toggle[aria-expanded="true"] .menu-toggle__bars::before { transform: translateY(0) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-toggle__bars::after  { transform: translateY(-2px) rotate(-45deg); }

.theme-toggle {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.1rem;
  transition: background .15s, transform .15s;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle:active { transform: scale(.94); }

/* --- Menú: panel desplegable en móvil (oculto por defecto) --- */
.menu {
  flex-basis: 100%;
  display: none;               /* cerrado */
  flex-direction: column;
  gap: .15rem;
  padding: .5rem 0 .25rem;
  max-height: 70vh;            /* con muchas secciones, el panel hace scroll */
  overflow-y: auto;
}
.menu.is-open { display: flex; } /* abierto por JS */
.menu a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-size: .95rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}

/* --- Secciones del menú --- */
.menu-group + .menu-group {
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
}
.menu-group__title {
  margin: 0 0 .4rem;
  padding: 0 .75rem;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent-strong);   /* acento → manda sobre los enlaces */
}
/* Los enlaces "cuelgan" del título: sangría + línea guía vertical */
.menu-group__items {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  margin-left: 1.1rem;           /* sangría del contenido */
  padding-left: .5rem;
  border-left: 2px solid var(--border);
}

.menu a:hover { background: var(--surface-2); color: var(--text); }
.menu a.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
[data-theme="dark"] .menu a.is-active { color: var(--accent-strong); }
.menu a.is-soon { opacity: .55; }
.menu a.is-soon::after { content: " ·"; }

/* ---------- Área de contenido ---------- */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2.5rem) clamp(.9rem, 3vw, 1.5rem) 4rem;
  outline: none;
}

/* ---------- Placeholder / error (apartados no listos) ---------- */
.placeholder {
  margin-top: 3rem;
  text-align: center;
  color: var(--text-muted);
}
.placeholder h1 { margin: 0 0 .5rem; color: var(--text); font-size: 1.6rem; }
.placeholder--error h1 { color: var(--err); }

/* ---------- Borrador / scratchpad (compartido por todos los apartados) ---------- */
[data-scratch-slot] { margin: 0 0 1.25rem; }

.scratchpad-label {
  display: block;
  margin: 0 0 .35rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.scratchpad-input {
  width: 100%;
  min-height: 4.5rem;
  padding: .6rem .75rem;
  font-family: var(--font-math);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color .15s;
}
.scratchpad-input:focus { border-color: var(--accent); outline: none; }
.scratchpad-input::placeholder { color: var(--text-muted); opacity: .7; }

/* ---------- Enlace "Ver teoría" (compartido por todos los apartados) ---------- */
.btn-teoria {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin-top: .75rem;
  padding: .4rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn-teoria:hover { background: var(--surface-2); border-color: var(--accent); }

/* ---------- ≥ 720px: menú como DROPDOWN flotante (escala mejor que una barra
   horizontal con 15+ apartados). La hamburguesa SIGUE visible y es quien lo abre;
   el menú permanece oculto (display:none base) hasta recibir .is-open por JS. ---------- */
@media (min-width: 720px) {
  .shell-header { flex-wrap: nowrap; gap: 1rem; padding-block: 0; height: var(--header-h); }
  .theme-toggle { width: 38px; height: 38px; }

  /* Dropdown anclado bajo la cabecera y alineado a la derecha.
     .shell-header es sticky (elemento posicionado) → sirve de contexto para el absolute. */
  .menu {
    position: absolute;
    top: 100%;
    right: clamp(.75rem, 3vw, 1.5rem);
    width: min(340px, 92vw);
    max-height: 70vh;
    margin: .3rem 0 0;
    padding: .5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
  }

  .menu a { min-height: 40px; padding: .45rem .7rem; font-size: .92rem; }
}
