/* ============================================================
   Fuente y filtro — las vocales del español
   Sistema de diseño: papel cálido, tinta, acentos semánticos
   (terracota = fuente glotal · teal = filtro vocal)
   ============================================================ */

:root {
  /* Tipografía */
  --font-display: 'Zodiak', Georgia, serif;
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  /* Espaciado (base 4px) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;

  /* Superficies */
  --bg: #f5f1e8;
  --surface: #fbf8f1;
  --surface-2: #efe9dc;
  --border: #ddd5c3;
  --divider: #e7e0d0;

  /* Texto */
  --ink: #2b2620;
  --muted: #6e685a;
  --faint: #a49d8c;

  /* Acentos semánticos */
  --fuente: #b04a26;          /* terracota: fuente glotal */
  --fuente-suave: #f4e3d9;
  --filtro: #0d6b6b;          /* teal: filtro vocal */
  --filtro-suave: #dcebe8;

  --radius: 14px;
  --radius-sm: 9px;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(ellipse 90% 60% at 50% -10%, #faf6ec 0%, transparent 60%);
}

p { text-wrap: pretty; }

a { color: var(--filtro); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #0a5a5a; }

:focus-visible {
  outline: 2px solid var(--filtro);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Cabecera ---------- */
.cabecera {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-6);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
}

.cabecera h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-xl);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.subtitulo {
  color: var(--muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

.formula {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--text-lg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: var(--space-2) var(--space-5);
  background: var(--surface);
}

/* ---------- Disposición principal ---------- */
.disposicion {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-6) var(--space-8);
  display: grid;
  grid-template-columns: minmax(340px, 460px) 1fr;
  gap: var(--space-6);
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: 0 1px 2px rgb(43 38 32 / 0.04);
}

/* ---------- Aviso figura demo ---------- */
.aviso {
  display: grid;
  gap: var(--space-3);
  background: var(--fuente-suave);
  border: 1px solid #e3c9b8;
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
}

.aviso p { max-width: none; }

.aviso code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.9em;
  background: #fbf8f1;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 4px;
}

#btn-cargar-svg {
  justify-self: start;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fuente);
  background: #fbf8f1;
  border: 1.5px solid var(--fuente);
  border-radius: 999px;
  padding: var(--space-2) var(--space-5);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

#btn-cargar-svg:hover { background: var(--fuente); color: #fbf8f1; }

/* ---------- Figura ---------- */
.figura-marco {
  position: relative;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(var(--surface) 0 0) padding-box,
    var(--surface);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}

.figura-marco:active { cursor: grabbing; }

#figura-host {
  aspect-ratio: 400 / 480;
  position: relative;
}

#figura-host svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
}

#filtro-movil { will-change: transform; }

.figura-pista {
  margin-top: var(--space-2);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--muted);
}

/* Piezas de la figura de demostración */
#figura-host .cabeza   { fill: #ece5d8; stroke: #2b2620; stroke-width: 2; }
#figura-host .cavidad  { fill: #8b8171; }
#figura-host .lengua   { fill: #d4836f; stroke: #2b2620; stroke-width: 1.5; }
#figura-host .cuello   { fill: #ece5d8; stroke: #2b2620; stroke-width: 2; }
#figura-host .laringe-caja { fill: #ddd5c5; stroke: #2b2620; stroke-width: 1.5; }
#figura-host .pliegue  { fill: #2b2620; }
#figura-host .traquea  { fill: #cfc7b6; stroke: #2b2620; stroke-width: 1.5; }
#figura-host .anillo   { stroke: #a89f8c; stroke-width: 1.5; }
#figura-host .etiqueta {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
#figura-host .etiqueta-filtro { fill: var(--filtro); }
#figura-host .etiqueta-fuente { fill: var(--fuente); }

/* ---------- Controles ---------- */
.controles {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.grupo { display: grid; gap: var(--space-2); min-width: 0; }

.grupo-titulo {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.segmentos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.segmentos button {
  font: inherit;
  display: grid;
  gap: 1px;
  padding: var(--space-2) var(--space-2);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
}

.segmentos button:hover { border-color: var(--faint); }

.segmentos button[aria-pressed='true'] {
  background: #fbf8f1;
  border-color: var(--fuente);
  box-shadow: inset 0 0 0 1px var(--fuente);
}

.seg-nombre { font-size: var(--text-sm); font-weight: 600; }
.seg-valor  { font-size: var(--text-xs); color: var(--muted); }

.vocales {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
}

.vocales button {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1;
  padding: var(--space-2) 0 var(--space-3);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.vocales button:hover { border-color: var(--faint); transform: translateY(-1px); }

.vocales button[aria-pressed='true'] {
  background: var(--filtro-suave);
  border-color: var(--filtro);
  box-shadow: inset 0 0 0 1px var(--filtro);
  color: #0a4a4a;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--fuente);
  cursor: pointer;
}

.btn-sonido {
  font: inherit;
  font-weight: 600;
  font-size: var(--text-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--ink);
  color: #f5f1e8;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.btn-sonido:hover { background: #443d33; }
.btn-sonido[aria-pressed='true'] { background: var(--fuente); }
.btn-sonido[aria-pressed='true']:hover { background: #963e1f; }

/* ---------- Estado ---------- */
.estado {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid var(--filtro);
  min-height: 3.2em;
}

.estado[data-modo='separada'] { border-left-color: var(--fuente); }
.estado[data-modo='transicion'] { border-left-color: var(--faint); }

/* ---------- Gráficos ---------- */
.panel-graficos { display: grid; gap: var(--space-6); }

.grafico { display: grid; gap: var(--space-2); min-width: 0; }

.grafico h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  line-height: 1.2;
}

.sim {
  font-family: var(--font-body);
  font-size: 0.72em;
  font-weight: 500;
  color: var(--muted);
  vertical-align: baseline;
}

.grafico-sub {
  font-size: var(--text-sm);
  color: var(--muted);
  max-width: 60ch;
}

.canvas-marco {
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: #fdfbf5;
  overflow: hidden;
}

.marco-espectro { height: 260px; }
.marco-lpc { height: 220px; }

canvas { display: block; width: 100%; height: 100%; }

/* ---------- Ayuda ---------- */
.ayuda {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-6) var(--space-8);
}

.ayuda details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
}

.ayuda summary {
  font-weight: 600;
  cursor: pointer;
  font-size: var(--text-base);
}

.ayuda ol {
  margin: var(--space-4) 0 var(--space-1) var(--space-6);
  display: grid;
  gap: var(--space-2);
  color: var(--muted);
  max-width: 72ch;
}

.ayuda strong { color: var(--ink); }

/* ---------- Pie ---------- */
.pie {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6) var(--space-10);
  display: grid;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--muted);
  border-top: 1px solid var(--divider);
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .disposicion { grid-template-columns: 1fr; }
  .panel-figura { max-width: 560px; margin: 0 auto; width: 100%; }
  .cabecera { padding-top: var(--space-6); }
}

@media (max-width: 480px) {
  .formula { display: none; }
  .marco-espectro { height: 220px; }
  .marco-lpc { height: 190px; }
}
