:root {
  --fondo: #0a0b0e;
  --panel: #14151a;
  --panel-2: #1c1d24;
  --borde: #2a2c35;
  --texto: #f4f4f6;
  --tenue: #8b8e9b;
  --rojo: #e10600;
  --rojo-vivo: #ff2a1f;
  --verde: #00d26a;
  --amarillo: #ffd400;
  --morado: #b46bff;
  --azul: #2f8bff;
  --fuente: "Titillium Web", "Segoe UI", system-ui, sans-serif;
  --fuente-digitos: "Orbitron", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--fondo); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--texto);
  font-family: var(--fuente);
  /* Fibra de carbono */
  background-color: #101114;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(225, 6, 0, .16), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, .9), transparent 70%),
    linear-gradient(27deg, #131418 5px, transparent 5px),
    linear-gradient(207deg, #131418 5px, transparent 5px),
    linear-gradient(27deg, #1c1d22 5px, transparent 5px),
    linear-gradient(207deg, #1c1d22 5px, transparent 5px),
    linear-gradient(90deg, #17181c 10px, transparent 10px),
    linear-gradient(#18191d 25%, #151619 25%, #151619 50%, transparent 50%, transparent 75%, #1e1f24 75%, #1e1f24);
  background-size: 100% 100%, 100% 100%, 20px 20px, 20px 20px, 20px 20px, 20px 20px, 20px 20px, 20px 20px;
  background-position: 0 0, 0 0, 0 5px, 10px 0, 0 10px, 10px 5px, 0 0, 0 0;
  background-attachment: fixed;
}

.contenedor {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.cuadros {
  height: 16px;
  margin: 0 -16px;
  background: repeating-conic-gradient(#f4f4f6 0 25%, #0a0b0e 0 50%) 0 0 / 16px 16px;
  opacity: .9;
}

/* ---------- Barra superior ---------- */

.barra {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px 0 24px;
}

.marca {
  display: flex;
  align-items: stretch;
  font-weight: 900;
  text-transform: uppercase;
  line-height: 1;
}
.marca-rsr {
  padding: 8px 14px 8px 12px;
  background: var(--rojo);
  font-style: italic;
  font-size: 1.3rem;
  letter-spacing: .04em;
  clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}
.marca-rc {
  display: flex;
  align-items: center;
  margin-left: -6px;
  padding: 8px 16px 8px 18px;
  background: var(--texto);
  color: var(--fondo);
  font-size: .95rem;
  letter-spacing: .12em;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}

.estado {
  --color: var(--verde);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, .5);
  border: 1px solid var(--borde);
  border-left: 4px solid var(--color);
  border-radius: 4px;
  font-weight: 700;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.estado[data-bandera="amarilla"] { --color: var(--amarillo); }
.estado[data-bandera="roja"] { --color: var(--rojo-vivo); }
.estado[data-bandera="morada"] { --color: var(--morado); }
.punto {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color);
  box-shadow: 0 0 10px var(--color);
  animation: latido 1.4s ease-in-out infinite;
}
@keyframes latido { 50% { opacity: .35; } }

/* ---------- Pantalla del volante ---------- */

.dash {
  position: relative;
  padding: 18px 20px 22px;
  background: linear-gradient(180deg, var(--panel-2), #0e0f13);
  border: 1px solid var(--borde);
  border-radius: 24px;
  box-shadow:
    0 30px 60px rgba(0, 0, 0, .6),
    inset 0 1px 0 rgba(255, 255, 255, .07);
}

.rev {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 6px;
  padding: 0 6px 16px;
}
.led {
  aspect-ratio: 1;
  border-radius: 50%;
  background: #1a1b21;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .8);
  transition: background .3s, box-shadow .3s;
}
.led.on.verde { background: var(--verde); box-shadow: 0 0 12px var(--verde), inset 0 -2px 3px rgba(0, 0, 0, .3); }
.led.on.roja  { background: var(--rojo-vivo); box-shadow: 0 0 12px var(--rojo-vivo), inset 0 -2px 3px rgba(0, 0, 0, .3); }
.led.on.azul  { background: var(--azul); box-shadow: 0 0 12px var(--azul), inset 0 -2px 3px rgba(0, 0, 0, .3); }
.rev.record .led { animation: limitador .25s steps(1) infinite; }
.rev.record .led.on { background: var(--morado); box-shadow: 0 0 14px var(--morado); }
@keyframes limitador { 50% { opacity: .2; } }

.pantalla {
  padding: 22px 16px 20px;
  text-align: center;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 40%, #0d1015, #030405 75%);
  border: 2px solid #000;
  border-radius: 14px;
  box-shadow: 0 0 0 1px #30323b, inset 0 0 50px rgba(0, 0, 0, .9);
}

.pantalla-sup,
.pantalla-inf {
  margin: 0;
  font-weight: 700;
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  text-transform: uppercase;
  letter-spacing: .3em;
  color: var(--tenue);
}
.pantalla-inf { color: var(--texto); letter-spacing: .22em; }

.numero {
  margin: 4px 0 8px;
  font-family: var(--fuente-digitos);
  font-weight: 900;
  font-size: clamp(5.5rem, 25vw, 12rem);
  line-height: 1.05;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.numero .apagado { color: #1a1c22; }
.numero .encendido {
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 255, 255, .28);
}
.numero.cero .encendido {
  color: var(--rojo-vivo);
  text-shadow: 0 0 26px rgba(255, 42, 31, .55);
}
.numero.record .encendido {
  color: var(--morado);
  text-shadow: 0 0 26px rgba(180, 107, 255, .55);
}

.objetivo {
  display: inline-block;
  margin: 14px 0 0;
  padding: 4px 14px;
  border: 1px solid var(--borde);
  border-radius: 999px;
  font-family: var(--fuente-digitos);
  font-weight: 700;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--tenue);
}
.objetivo.record {
  color: var(--morado);
  border-color: var(--morado);
  box-shadow: 0 0 14px rgba(180, 107, 255, .35);
}

/* ---------- Torre de tiempos ---------- */

.torre {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}
.casilla {
  --acento: var(--tenue);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 22px 12px 16px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .04), transparent), var(--panel);
  border-left: 4px solid var(--acento);
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
}
.casilla-morada { --acento: var(--morado); }
.casilla-roja   { --acento: var(--rojo-vivo); }
.casilla-verde  { --acento: var(--verde); }
.casilla-titulo {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--tenue);
}
.casilla-valor {
  font-family: var(--fuente-digitos);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.3;
}
.casilla-morada .casilla-valor { color: var(--morado); }
.casilla-fecha { font-family: var(--fuente); font-size: 1.15rem; }

/* ---------- Botón de bandera roja ---------- */

.boton-bandera {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 14px 28px;
  border: 0;
  color: #fff;
  background:
    repeating-linear-gradient(-60deg, transparent 0 18px, rgba(0, 0, 0, .12) 18px 36px),
    linear-gradient(180deg, var(--rojo-vivo), #b30500);
  font-family: var(--fuente);
  font-weight: 900;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
  clip-path: polygon(18px 0, 100% 0, calc(100% - 18px) 100%, 0 100%);
  filter: drop-shadow(0 10px 24px rgba(225, 6, 0, .35));
  transition: transform .1s, filter .2s;
}
.boton-bandera svg { width: 28px; height: 28px; flex: none; }
.boton-bandera:hover { filter: drop-shadow(0 10px 30px rgba(255, 42, 31, .6)) brightness(1.08); }
.boton-bandera:active { transform: scale(.985); }
.boton-bandera:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

/* ---------- Mensajes de dirección de carrera ---------- */

.feed { margin-top: 36px; }
.feed-cabecera {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--borde);
}
.feed h2 {
  margin: 0;
  font-weight: 900;
  font-style: italic;
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.feed h2::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: .9em;
  margin-right: 10px;
  background: var(--rojo);
  transform: skewX(-15deg);
  vertical-align: -1px;
}
.vacio { color: var(--tenue); font-style: italic; }

#lista-historial {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  display: grid;
  grid-template-columns: auto 1fr;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
  overflow: hidden;
}
.msg-fecha {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 72px;
  padding: 10px 12px;
  background: var(--amarillo);
  color: #111;
  font-weight: 900;
  line-height: 1.05;
  text-transform: uppercase;
}
.msg-dia { font-family: var(--fuente-digitos); font-size: 1.5rem; }
.msg-mes { font-size: .75rem; letter-spacing: .1em; }
.msg-cuerpo { padding: 10px 14px; min-width: 0; }
.msg-titulo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-weight: 700;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.etiqueta {
  padding: 1px 8px;
  border-radius: 3px;
  font-size: .7rem;
  letter-spacing: .1em;
  background: #2a2c35;
  color: var(--texto);
}
.etiqueta.nivel-1 { background: #3a3a1a; color: var(--amarillo); }
.etiqueta.nivel-2 { background: #3d2412; color: #ff9d3d; }
.etiqueta.nivel-3 { background: #3d1210; color: var(--rojo-vivo); }
.etiqueta.nivel-4 { background: var(--rojo); color: #fff; }
.msg-desc {
  margin: 4px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-pie {
  margin-top: 4px;
  font-size: .8rem;
  color: var(--tenue);
}

footer {
  margin-top: 32px;
  text-align: center;
}

.enlace {
  background: none;
  border: none;
  padding: 0;
  color: var(--tenue);
  text-decoration: underline;
  text-underline-offset: 3px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}
.enlace:hover { color: var(--texto); }

/* ---------- Diálogos ---------- */

dialog {
  width: min(500px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--borde);
  border-top: 4px solid var(--rojo);
  border-radius: 10px;
  background: var(--panel);
  color: var(--texto);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
}
dialog::backdrop {
  background: rgba(0, 0, 0, .75);
  backdrop-filter: blur(3px);
}
dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 22px 22px;
}
.dialogo-sup {
  margin: 0 0 -10px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .2em;
  color: var(--rojo-vivo);
}
dialog h2 {
  margin: 0;
  font-weight: 900;
  font-style: italic;
  font-size: 1.6rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--tenue);
}
dialog textarea,
dialog input,
dialog select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: #0c0d10;
  color: var(--texto);
  font: inherit;
  font-size: 1rem;
  text-transform: none;
  letter-spacing: normal;
  color-scheme: dark;
  resize: vertical;
}
dialog textarea:focus,
dialog input:focus,
dialog select:focus {
  outline: none;
  border-color: var(--rojo-vivo);
  box-shadow: 0 0 0 3px rgba(255, 42, 31, .2);
}
.ayuda { margin: 0; color: var(--tenue); }
dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 6px 0 0;
  padding: 0;
}
dialog menu button {
  padding: 10px 18px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--texto);
  font: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  cursor: pointer;
}
dialog menu button:hover { border-color: var(--tenue); }
dialog menu button.peligro,
dialog menu button.primario {
  border-color: transparent;
  background: var(--rojo);
  color: #fff;
}
dialog menu button.peligro:hover,
dialog menu button.primario:hover { background: var(--rojo-vivo); }

/* ---------- Bandera roja (al reiniciar) ---------- */

.bandera-roja {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(160, 0, 0, .95), rgba(40, 0, 0, .97));
  animation: aparecer .2s ease-out;
  cursor: pointer;
}
.bandera-roja[hidden] { display: none; }
.bandera-roja.saliendo { animation: desaparecer .4s ease-in forwards; }
@keyframes aparecer { from { opacity: 0; } }
@keyframes desaparecer { to { opacity: 0; } }

.semaforo {
  display: flex;
  gap: clamp(8px, 2.5vw, 16px);
  padding: 14px clamp(12px, 3vw, 20px);
  background: #0a0a0a;
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .6), inset 0 0 0 2px #222;
}
.semaforo span {
  width: clamp(36px, 11vw, 64px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #2a0605;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .8);
  transition: background .08s, box-shadow .08s;
}
.semaforo span.on {
  background: radial-gradient(circle at 40% 35%, #ff7a70, var(--rojo-vivo) 45%, #a00000);
  box-shadow: 0 0 28px var(--rojo-vivo), 0 0 60px rgba(255, 42, 31, .5);
}

.br-titulo {
  margin: 0;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(2.6rem, 11vw, 5.5rem);
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .02em;
  text-shadow: 0 6px 30px rgba(0, 0, 0, .5);
}
.br-sub {
  margin: 0;
  font-weight: 700;
  font-size: clamp(.9rem, 3.5vw, 1.2rem);
  text-transform: uppercase;
  letter-spacing: .16em;
  color: #ffd0cc;
}

@media (prefers-reduced-motion: reduce) {
  .punto, .rev.record .led { animation: none; }
}

@media (max-width: 560px) {
  .torre { grid-template-columns: 1fr; }
  .casilla { flex-direction: row; justify-content: space-between; align-items: center; }
  .rev { gap: 4px; padding: 0 2px 14px; }
  .dash { padding: 14px 12px 16px; border-radius: 18px; }
  .estado { font-size: .8rem; }
}
