/* ---------- Tipografías de Pizarrón (WOFF2 autoalojadas) ---------- */
@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/caveat-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/caveat-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/kalam-regular-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/kalam-regular-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/kalam-bold-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Kalam';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/kalam-bold-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Math for Caveat';
  font-style: normal;
  font-weight: 100 900;
  src: url("../fonts/math-subset.woff2") format("woff2"),
       local('STIX Two Math'),
       local('DejaVu Math TeX Gyre'),
       local('Cambria Math'),
       local('Latin Modern Math');
  size-adjust: 93%;
}

@font-face {
  font-family: 'Math for Kalam';
  font-style: normal;
  font-weight: 100 900;
  src: url("../fonts/math-subset.woff2") format("woff2"),
       local('STIX Two Math'),
       local('DejaVu Math TeX Gyre'),
       local('Cambria Math'),
       local('Latin Modern Math');
  size-adjust: 114%;
}

@font-face {
  font-family: 'Math fallback';
  font-style: normal;
  font-weight: 100 900;
  src: url("../fonts/math-subset.woff2") format("woff2"),
       local('STIX Two Math'),
       local('DejaVu Math TeX Gyre'),
       local('Cambria Math'),
       local('Latin Modern Math');
  size-adjust: 95%;
}

:root {
  color-scheme: dark;

  /* Superficie de pizarrón real */
  --bg: #26352d;          /* pizarrón verde pizarra */
  --card: #26352d;        /* igual que el pizarrón (usado en halos SVG) */
  --surface: #26352d;     /* igual que el pizarrón */
  --ink: #ece8dc;         /* blanco tiza: estructura y texto */
  --text: var(--ink);     /* alias de texto principal */
  --chalk: var(--ink);    /* alias de blanco tiza */
  --muted: #a9b3a6;       /* tiza gastada */
  --chalk-dim: var(--muted); /* alias de tiza gastada */
  --yellow: #e6d38a;     /* "mirá acá": respuesta, resultado, selección */
  --blue: #9bbfd9;       /* datos, entradas, lo que el usuario mueve */
  --teal: var(--blue);   /* alias de azul tiza / turquesa de entrada */
  --pink: #e3a1a1;       /* error, cuidado, tachado */
  --green: #aed1a2;      /* correcto, neutro multiplicativo, cancelación */

  /* Roles semánticos de tiza en pizarrón (7 tokens puros):
     --bg:     superficie de pizarra verde oscura
     --ink:    blanco tiza: texto principal, fórmulas, ejes, curvas base, catetos Δx y Δy, C⁻ (trazos), I↓ (trazos)
     --muted:  tiza gastada: guías secundarias, cuadrículas, asíntotas mudas, etiquetas sutiles
     --yellow: "mirá acá": resultados, respuestas, secante/TCP, raíces C₀, lámpara encendida
     --blue:   entradas, manijas interactivas (P₁, P₂), condiciones de entrada, C⁺, I↑
     --pink:   alerta estricta: error, trampa, "NO es función", quiz incorrecto
     --green:  éxito: correcto / acierto / confirmación, neutro multiplicativo, y NADA más */
  --border: color-mix(in srgb, var(--ink) 15%, transparent);
  --border-strong: color-mix(in srgb, var(--ink) 30%, transparent);

  /* Lámpara (circuito) */
  --lamp-fill: var(--yellow);
  --lamp-stroke: var(--yellow);
  --lamp-x: var(--bg);

  /* Geometría y tipografía manuscrita de pizarrón */
  --radius: 3px;
  --radius-lg: 4px;
  --font-sans: var(--font-hand);
  --font-math: "Math fallback", "DejaVu Math TeX Gyre", "Cambria Math", "STIX Two Math", "Latin Modern Math", "DejaVu Serif", Georgia, serif;
  --font-hand: 'Caveat', 'Math for Caveat', var(--font-math), cursive;
  --font-note: 'Kalam', 'Math for Kalam', var(--font-math), cursive;
  --font-mono: var(--font-hand);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 16px;
  font-size: clamp(1rem, 0.6vw + 0.5rem, 1.375rem);
}

@media (max-width: 820px) {
  html {
    font-size: 100%;
  }
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font: 1rem/1.6 var(--font-note);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    url("grain-tile.webp"),
    url("chalkboard-eraser.webp"),
    url("chalkboard-ghosts.svg"),
    radial-gradient(ellipse 120% 90% at 50% 25%, #2e3f36 0%, #26352d 65%, #1f2c25 100%);
  background-repeat: repeat, no-repeat, no-repeat, no-repeat;
  background-size: 256px 256px, cover, cover, cover;
  background-position: 0 0, center center, center center, center center;
}

h1 {
  font-family: var(--font-hand);
  font-size: clamp(2.125rem, 6vw, 3.25rem);
  line-height: 1.15;
  font-weight: 700;
  margin: 0 0 0.5rem;
  letter-spacing: 0.5px;
}

h2 {
  font-family: var(--font-hand);
  font-size: clamp(1.625rem, 4.5vw, 2.25rem);
  line-height: 1.2;
  font-weight: 700;
  margin: 1.75rem 0 0.5rem;
}

h3 {
  font-family: var(--font-hand);
  font-size: clamp(1.25rem, 3.5vw, 1.625rem);
  line-height: 1.25;
  font-weight: 700;
  margin: 1.125rem 0 0.375rem;
}

p {
  font-family: var(--font-note);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 0.75rem;
}

code {
  font: inherit;
  color: var(--yellow);
  background: none;
  padding: 0;
}

button,
select,
input {
  font-family: inherit;
  font-size: inherit;
  font-weight: 400;
}

a {
  color: var(--blue);
}

svg {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

.plot,
.seq-track,
.seq-chart,
#circuit,
#number-line {
  display: block;
  width: 100%;
}

svg text:not([fill]) {
  fill: var(--ink);
}

.intro,
.muted {
  color: var(--muted);
}

.muted {
  font-size: 1rem;
}

.intro {
  margin: 0 0 1.375rem;
  font-size: 1.0625rem;
  max-width: 36rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ---------- Utilidades de Pizarrón ---------- */
.encerrado {
  position: relative;
  display: inline-block;
  padding: 0 .35em;
}

.encerrado::after {
  content: "";
  position: absolute;
  inset: -.15em -.2em;
  pointer-events: none;
  border: 2px solid var(--yellow);
  border-radius: 58% 42% 55% 45% / 48% 56% 44% 52%;
  transform: rotate(-2deg);
}

.tachado {
  position: relative;
  display: inline-block;
}

.tachado::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cline x1='0' y1='82' x2='100' y2='18' stroke='%23e3a1a1' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}

.nota {
  font-family: var(--font-hand);
  font-size: 1.125rem;
  line-height: 1.4;
  transform: rotate(-.8deg);
  max-width: 36rem;
}

.nota:nth-of-type(even) {
  transform: rotate(.6deg);
}

.subrayado-ondulado {
  display: inline;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 4'%3E%3Cpath d='M0 3.5 Q 5 0.5, 10 3.5 T 20 3.5' fill='none' stroke='%23e6d38a' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") bottom left / 16px 4px repeat-x;
  padding-bottom: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.small {
  font-size: 1rem;
  max-width: 36rem;
}

.math {
  font-family: var(--font-hand);
  font-style: italic;
  font-size: 1.0625rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden],
.hidden {
  display: none !important;
}

/* Texto SVG: siempre via tokens para que el modo oscuro sea legible */
.svg-t {
  font-size: 1rem;
  fill: var(--ink);
}

.svg-ts {
  font-size: 1rem;
  fill: var(--muted);
}

.svg-th {
  font-size: 1.0625rem;
  font-weight: 600;
  fill: var(--ink);
}

/* Curvas matemáticas animadas: trazado progresivo (600ms ease-out) */
@keyframes curve-draw-write {
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.curve-anim {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: curve-draw-write 600ms ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .curve-anim {
    animation: none !important;
    stroke-dasharray: none !important;
    stroke-dashoffset: 0 !important;
  }
}
