/* ENCENDIDO — sistema de diseño. Tokens de docs/IDENTIDAD.md (el CSS no inventa colores).
   Modo oscuro héroe «Grafito + Naranja de Escape»; espejo claro «Smiths 1962». */

:root {
  --font-display: 'Space Grotesk', system-ui, -apple-system, 'SF Pro Display', sans-serif;
  --font-mono: 'Space Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* OSCURO (héroe) */
  --bg: #0e0f12;
  --panel: #16181d;
  --inset: #20242b;
  --line: #2c313a;
  --ink: #e8e6e1;
  --dim: #8a9099;
  --live: #ff6a1a;
  --heat: #ffb23e;
  --redline: #ff3b2f;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Modo CLARO: forzado con data-theme="light", o por preferencia del sistema si no hay override.
   (Sin data-theme = sigue al sistema; data-theme="dark" = fuerza el oscuro héroe.) */
:root[data-theme='light'] {
  --bg: #f3ecdd;
  --panel: #ede4d0;
  --inset: #e7dcc4;
  --line: #c9b89a;
  --ink: #211c17;
  --dim: #6b5e48;
  --live: #c24a12;
  --heat: #d98a2b;
  --redline: #8c2a22;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f3ecdd;
    --panel: #ede4d0;
    --inset: #e7dcc4;
    --line: #c9b89a;
    --ink: #211c17;
    --dim: #6b5e48;
    --live: #c24a12;
    --heat: #d98a2b;
    --redline: #8c2a22;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 800px at 50% -10%, color-mix(in srgb, var(--live) 6%, transparent), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 40px);
}

/* --- Barra superior / wordmark --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: clamp(20px, 4vw, 44px);
}
.wordmark {
  font-size: clamp(20px, 3.2vw, 30px);
  font-weight: 600;
  letter-spacing: 0.08em;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.06em;
}
.wordmark .spark {
  width: 0.34em;
  height: 0.34em;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 10px var(--heat), 0 0 22px color-mix(in srgb, var(--live) 60%, transparent);
  margin-left: 0.12em;
  animation: idle-pulse 1.1s var(--ease) infinite;
}
@keyframes idle-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.tagline { color: var(--dim); font-size: 13px; letter-spacing: 0.04em; display: inline-flex; align-items: center; gap: 14px; }
.tagline #version { font-family: var(--font-mono); }
.tagline-text, .site-actions { display: inline-flex; align-items: center; gap: 14px; }
.theme-toggle {
  appearance: none; background: transparent; border: 1px solid var(--line); color: var(--ink);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1;
  transition: border-color 120ms var(--ease), color 120ms var(--ease);
}
.theme-toggle:hover { border-color: var(--live); color: var(--live); }
.theme-toggle:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }

/* Llave de contacto (encender/apagar el motor) */
.ignition {
  appearance: none; background: transparent; border: 1px solid var(--line);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color 180ms var(--ease), box-shadow 250ms var(--ease);
}
.ignition .ign-key {
  width: 19px; height: 19px;
  transition: transform 250ms var(--ease);
  transform: rotate(-32deg); transform-origin: 9px 9px; /* OFF: llave sin girar */
}
.ignition .ign-bow, .ignition .ign-stem, .ignition .ign-teeth {
  fill: none; stroke: var(--dim); stroke-width: 2; stroke-linecap: round;
  transition: stroke 180ms var(--ease);
}
.ignition .ign-hole { fill: var(--bg); stroke: var(--dim); stroke-width: 1.5; }
.ignition:hover { border-color: var(--live); }
.ignition:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }
.ignition.is-on { border-color: var(--live); box-shadow: 0 0 12px color-mix(in srgb, var(--live) 45%, transparent); }
.ignition.is-on .ign-key { transform: rotate(28deg); } /* ON: llave girada */
.ignition.is-on .ign-bow, .ignition.is-on .ign-stem, .ignition.is-on .ign-teeth { stroke: var(--live); }
.ignition.is-on .ign-hole { stroke: var(--live); }

/* Motor apagado (llave en OFF tras haber arrancado): atenúa la placa */
#app.engine-off .tach-wrap, #app.engine-off .panels { opacity: 0.5; transition: opacity 250ms var(--ease); }

/* --- Disposición principal --- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(20px, 4vw, 56px);
  align-items: center;
}
@media (max-width: 780px) { .main { grid-template-columns: 1fr; } }

.tach-wrap { width: 100%; max-width: 460px; margin: 0 auto; }
#tach { width: 100%; height: auto; display: block; }

/* --- Tacómetro (clases que emite views/tachometer.js) --- */
.tac-track { fill: none; stroke: var(--line); stroke-width: 10; stroke-linecap: round; }
.tac-warn { fill: none; stroke: color-mix(in srgb, var(--heat) 45%, var(--line)); stroke-width: 10; stroke-linecap: round; }
.tac-redline { fill: none; stroke: var(--redline); stroke-width: 10; stroke-linecap: round; }
.tac-heat {
  fill: none; stroke: var(--live); stroke-width: 10; stroke-linecap: round;
  opacity: 0; filter: drop-shadow(0 0 6px var(--live));
  transition: opacity 90ms var(--ease);
}
.tac-tick { stroke: var(--dim); stroke-width: 2; }
.tac-tick-red { stroke: var(--redline); stroke-width: 2.5; }
.tac-num { fill: var(--dim); font-family: var(--font-mono); font-size: 15px; }
.tac-num-red { fill: var(--redline); font-family: var(--font-mono); font-size: 15px; }
.tac-well { fill: var(--inset); stroke: var(--line); stroke-width: 1; }
.tac-digital {
  fill: var(--ink); font-family: var(--font-mono); font-weight: 700;
  font-size: 58px; font-variant-numeric: tabular-nums;
}
.tac-unit { fill: var(--dim); font-family: var(--font-mono); font-size: 14px; letter-spacing: 0.2em; }
.tac-label { fill: var(--dim); font-family: var(--font-display); font-size: 13px; }
.tac-needle {
  stroke: var(--ink); stroke-width: 3; stroke-linecap: round;
  transition: transform 85ms var(--ease);
  transform-box: view-box;
}
.tac-hub { fill: var(--ink); }
#tach.is-hot .tac-needle { stroke: var(--live); filter: drop-shadow(0 0 4px var(--live)); }
#tach.is-hot .tac-digital { fill: var(--live); }
#tach.is-cutting .tac-digital { fill: var(--redline); }
#tach.is-cutting .tac-needle { stroke: var(--redline); }

/* --- Configurador / ficha --- */
.config { display: flex; flex-direction: column; gap: 18px; }
.field-label { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin-bottom: 7px; }
select#engine-select {
  width: 100%; appearance: none; background: var(--inset); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
  font-family: var(--font-display); font-size: 16px; cursor: pointer;
}
select#engine-select:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }

#engine-crank { color: var(--dim); font-size: 13px; font-style: italic; margin: 2px 0 0; }
#engine-character { font-size: 15px; line-height: 1.5; margin: 0; color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-mono); font-size: 12px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; white-space: nowrap;
}

/* --- La ficha (reseña histórica + curiosidades) --- */
.lore {
  margin-top: clamp(22px, 4vw, 40px);
  border-top: 1px solid var(--line);
  padding-top: 22px;
}
.lore[hidden] { display: none; }
.lore-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.lore-head h2 { font-size: clamp(18px, 2.6vw, 24px); margin: 0; font-weight: 600; letter-spacing: 0.01em; }
.lore-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(248px, 1fr));
  gap: 20px 30px;
}
.lore-item .lore-label {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px;
}
.lore-item p { margin: 0; font-size: 14.5px; line-height: 1.58; color: var(--ink); }
.lore-pro .lore-label::before { content: '+ '; color: var(--live); font-weight: 700; }
.lore-con .lore-label::before { content: '− '; color: var(--dim); font-weight: 700; }
.lore-curio .lore-label::before { content: '✦ '; color: var(--heat); }

/* --- Paneles (despiece + osciloscopio) --- */
.panels {
  margin-top: clamp(22px, 4vw, 40px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(18px, 3vw, 36px);
}
@media (max-width: 780px) { .panels { grid-template-columns: 1fr; } }
.panel { display: flex; flex-direction: column; gap: 10px; }

/* mecanismo biela-manivela (canvas animado) */
#mechanism {
  width: 100%; height: 240px; display: block;
  background: var(--inset); border: 1px solid var(--line); border-radius: 8px;
}

/* osciloscopio + espectro */
.scope-stack { display: flex; flex-direction: column; gap: 8px; }
#scope-wave, #scope-spectrum {
  width: 100%; display: block; background: var(--inset);
  border: 1px solid var(--line); border-radius: 8px;
}
#scope-wave { height: 96px; }
#scope-spectrum { height: 64px; }

/* --- Acelerador --- */
.throttle-bar {
  margin-top: clamp(24px, 4vw, 44px);
  border-top: 1px solid var(--line);
  padding-top: 22px;
  display: grid; grid-template-columns: 1fr auto; gap: 16px 24px; align-items: center;
}
.throttle-head { display: flex; justify-content: space-between; align-items: baseline; grid-column: 1 / -1; }
.throttle-head .field-label { margin: 0; } /* antes style= en el HTML: la CSP publicada no admite estilos inline */
.throttle-head .hint { color: var(--dim); font-size: 12.5px; }
#throttle-val { font-family: var(--font-mono); font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--live); }
input#throttle {
  grid-column: 1 / -1; width: 100%; height: 28px; appearance: none; background: transparent; cursor: pointer;
}
input#throttle::-webkit-slider-runnable-track { height: 12px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); }
input#throttle::-moz-range-track { height: 12px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); }
input#throttle::-webkit-slider-thumb {
  appearance: none; width: 26px; height: 26px; margin-top: -8px; border-radius: 50%;
  background: var(--live); border: 2px solid var(--bg); box-shadow: 0 0 12px color-mix(in srgb, var(--live) 70%, transparent);
}
input#throttle::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--live); border: 2px solid var(--bg); }
input#throttle:focus-visible { outline: 2px solid var(--live); outline-offset: 6px; border-radius: 999px; }

/* --- Overlay de arranque --- */
#start-overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(6px); z-index: 10;
}
#start-overlay.hidden { display: none; }
.start-card { text-align: center; max-width: 420px; padding: 28px; }
.start-card h2 { font-size: clamp(28px, 5vw, 40px); margin: 0 0 8px; letter-spacing: 0.04em; }
.start-card .spark { display: inline-block; } /* antes style= en el HTML (CSP) */
.start-card p { color: var(--dim); margin: 0 0 24px; line-height: 1.5; }
#start-btn {
  font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: 0.06em;
  color: var(--bg); background: var(--live); border: none; border-radius: 10px;
  padding: 14px 38px; cursor: pointer; box-shadow: 0 0 24px color-mix(in srgb, var(--live) 50%, transparent);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
#start-btn:hover { transform: translateY(-1px); box-shadow: 0 0 34px color-mix(in srgb, var(--live) 70%, transparent); }
#start-btn:active { transform: translateY(0); }

#app.inert { opacity: 0.45; pointer-events: none; filter: saturate(0.6); }

footer { margin-top: 40px; color: var(--dim); font-size: 12px; text-align: center; border-top: 1px solid var(--line); padding-top: 16px; }

/* --- Web pública: «Acerca de», «♥ Apoya» y aviso legal (ADR-0005). Filetes y aire, sin sombras (IDENTIDAD §2). --- */
.site-btn {
  appearance: none; background: transparent; border: 1px solid var(--line); border-radius: 999px;
  color: var(--dim); font-family: var(--font-display); font-size: 13px; letter-spacing: 0.04em; line-height: 1;
  padding: 7px 12px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: border-color 120ms var(--ease), color 120ms var(--ease);
}
.site-btn[hidden] { display: none; }
.site-btn:hover { border-color: var(--live); color: var(--live); }
.link-btn {
  appearance: none; background: none; border: none; padding: 0; cursor: pointer;
  color: inherit; font: inherit; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--live); }
.site-btn:focus-visible, .link-btn:focus-visible, .about a:focus-visible, .start-links a:focus-visible, footer a:focus-visible, .legal a:focus-visible {
  outline: 2px solid var(--live); outline-offset: 2px;
}
.start-card .start-links { margin: 20px 0 0; font-size: 13px; }
.start-links a, footer a { color: inherit; text-underline-offset: 3px; }
.start-links a:hover, footer a:hover { color: var(--live); }

.about {
  width: min(540px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
/* ::backdrop no hereda las variables en navegadores viejos: el respaldo es el --bg oscuro de IDENTIDAD. */
.about::backdrop { background: color-mix(in srgb, var(--bg, #0e0f12) 70%, transparent); backdrop-filter: blur(4px); }
.about-body { position: relative; padding: 22px 24px 20px; }
.about-close { position: absolute; top: 12px; right: 14px; margin: 0; }
.about-close .link-btn { text-decoration: none; color: var(--dim); font-size: 16px; }
.about h2 { font-size: 22px; font-weight: 600; letter-spacing: 0.02em; margin: 0 1.6em 4px 0; }
.about-meta { margin: 0 0 14px; font-family: var(--font-mono); font-size: 12px; color: var(--dim); }
.about p { margin: 10px 0 0; font-size: 15px; line-height: 1.5; }
.about .micro { font-size: 13px; color: var(--dim); }
.about a { color: var(--ink); text-underline-offset: 3px; }
.about a:hover { color: var(--live); }
.about .about-links { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; }

/* aviso legal (public/legal.html): un documento que desplaza con normalidad */
.legal { max-width: 760px; margin: 0 auto; padding: 24px 20px 48px; font-size: 15px; line-height: 1.55; }
.legal h1 { font-size: clamp(26px, 5vw, 34px); font-weight: 600; letter-spacing: 0.02em; margin: 0.4em 0 0.1em; line-height: 1.15; }
.legal h2 { font-size: 17px; font-weight: 600; margin: 1.6em 0 0.4em; padding-top: 0.7em; border-top: 1px solid var(--line); }
.legal p, .legal li { margin: 0.5em 0 0; }
.legal ul { padding-left: 1.2em; }
.legal a { color: var(--ink); text-underline-offset: 3px; }
.legal a:hover { color: var(--live); }
.legal-date { font-family: var(--font-mono); font-size: 12px; color: var(--dim); }
.legal-owner { margin-top: 0.7em; padding: 10px 12px; font-family: var(--font-mono); font-size: 13px; background: var(--inset); border: 1px solid var(--line); border-radius: 8px; }

/* --- Móvil y táctil, sin rediseñar (rebanada 2 de la web pública). Va DESPUÉS de las reglas base: a igual
   especificidad gana la última. El escritorio no cambia. --- */
@media (max-width: 780px) {
  /* el acelerador se queda pegado abajo: se da gas viendo el tacómetro y el mecanismo */
  .throttle-bar { position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding: 10px 0 12px; row-gap: 4px; }
  #throttle-val { font-size: 22px; }
}
@media (max-width: 560px) {
  /* cabecera en dos filas: marca + llave + tema arriba; lema + «Acerca de» + «♥ Apoya» debajo */
  .topbar { flex-wrap: wrap; align-items: center; row-gap: 6px; column-gap: 10px; }
  .topbar::after { content: ''; order: 2; flex-basis: 100%; }
  .tagline { display: contents; }
  .wordmark { order: 0; flex: 1 1 auto; }
  .ignition, .theme-toggle { order: 1; }
  .tagline-text { order: 3; flex: 1 1 0; min-width: 0; flex-wrap: wrap; gap: 2px 8px; } /* el lema cede y se parte */
  .site-actions { order: 4; gap: 8px; }
}
.start-note { display: none; }
@media (pointer: coarse) {
  .ignition, .theme-toggle { width: 44px; height: 44px; }
  .site-btn { min-height: 44px; display: inline-flex; align-items: center; }
  .link-btn, .start-links a, footer a { display: inline-block; min-height: 44px; padding: 12px 6px; }
  .about-close { top: 4px; right: 6px; }
  .about-close .link-btn { min-width: 44px; }
  input#throttle { height: 44px; }
  .hint-keys { display: none; }
  .start-card .start-note { display: block; margin: 16px 0 0; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .wordmark .spark { animation: none; }
  .tac-needle, .tac-heat, #start-btn { transition: none; }
}
