:root {
  --orange: #ff9100;
  --red: #ff0000;
  --bg: #000;
  --fg: #f2f2f2;
  --muted: #9a9a9a;
  --card: #151515;
  --line: #333;
  --accent: #ff8f2e;
  --hud-h: 64px;
  --ctl-h: 84px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- Panel de luces ---------- */

#signals {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--hud-h) + env(safe-area-inset-top)) 12px calc(var(--ctl-h) + 20px + env(safe-area-inset-bottom));
}

.panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4vmin;
  width: 100%;
  height: 100%;
}

.light {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  --i: 0.08;
  opacity: var(--i);
  overflow: visible;
}
.light.turn { fill: var(--orange); opacity: 1; }
.light.turn rect, .light.brake path { opacity: 0.08; }
.light.brake { opacity: 1; }
.light.brake { fill: var(--red); }
.light.on { filter: drop-shadow(0 0 5vmin currentColor); }
.light.turn.on { color: var(--orange); }
.light.brake.on { color: var(--red); }

/* Horizontal: ◀ ■ ▶ */
.panel { flex-direction: row; }
.panel .left { order: 1; }
.panel .brake { order: 2; }
.panel .right { order: 3; }

/* Vertical (como el boceto): ▶ arriba, ■ al centro, ◀ abajo */
body.layout-vertical .panel { flex-direction: column; }
body.layout-vertical .panel .right { order: 1; }
body.layout-vertical .panel .left { order: 3; }
@media (orientation: portrait) {
  body.layout-auto .panel { flex-direction: column; }
  body.layout-auto .panel .right { order: 1; }
  body.layout-auto .panel .left { order: 3; }
}
body.layout-horizontal .panel { flex-direction: row; }

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  z-index: 5;
}
#status { top: 0; padding-top: calc(8px + env(safe-area-inset-top)); height: calc(var(--hud-h) + env(safe-area-inset-top)); }
#controls { bottom: 0; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }

.pill {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.pill.listening { color: #7dff9a; border-color: #2c7a41; }
.pill.error { color: #ff8080; border-color: #7a2c2c; }

.heard {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.ctl {
  flex: 1;
  height: var(--ctl-h);
  min-width: 0;
  background: #111;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 2px;
}
.ctl .ic { width: 40px; height: 40px; }
.ctl span { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.ctl:active { background: #222; }
.ctl-left .ic, .ctl-right .ic { color: var(--orange); }
.ctl-brake .ic { color: var(--red); }
.ctl-hazard .ic { color: var(--orange); }

.sos {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  width: clamp(84px, 22vmin, 120px);
  height: clamp(84px, 22vmin, 120px);
  border: 4px solid #fff;
  border-radius: 50%;
  background: #000;
  color: #fff;
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 0 0 6px #0006;
  transition: opacity .3s;
}
.sos-label { position: relative; display: flex; flex-direction: column; line-height: 1; align-items: center; gap: 2px; }
.sos-label .ic { width: 34px; height: 34px; }
.sos-label b { font-size: 30px; font-weight: 800; }
.sos-label small { font-size: 10px; font-weight: 600; letter-spacing: .02em; max-width: 80%; text-align: center; }
.sos-fill {
  position: absolute;
  inset: 0;
  background: #fff3;
  transform-origin: bottom;
  transform: scaleY(0);
}
.sos.holding .sos-fill { background: #c4001a; transform: scaleY(1); transition: transform var(--hold-ms, 1000ms) linear; }

/* Íconos */
.ic { width: 28px; height: 28px; flex: none; }
.ic-sm { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.ic-lg { width: 34px; height: 34px; flex: none; }
.icon-btn .ic { width: 26px; height: 26px; }
.pill { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000d;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}

.card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h1 { margin: 0; font-size: 26px; }
.card p { margin: 0; line-height: 1.4; }
.small { font-size: 13px; color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; }

.primary, .secondary {
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 650;
}
.primary { background: var(--accent); color: #000; border: 0; }
.secondary { background: transparent; border: 1px solid var(--line); }
.primary.wa { background: #25d366; }
.primary.call { background: #fff; color: #000; text-decoration: none; }
.primary.wa, .primary.call { display: flex; align-items: center; justify-content: center; gap: 10px; }

.em-card h1 { display: flex; align-items: center; gap: 10px; }
.em-icon { color: #ff3b4e; }
.em-loc { display: flex; align-items: center; gap: 8px; }

.support { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.support { list-style: none; padding-left: 0; }
.support li { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 4px; }
.support li .ic-sm { margin-top: 1px; }
.support li.warn { color: #ffb36b; }

.em-card { border-color: #c4001a; }
.em-calls { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Ajustes ---------- */

dialog#settings {
  width: min(560px, 100vw);
  max-height: 100dvh;
  margin: auto;
  padding: 0;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 18px;
  user-select: text;
  -webkit-user-select: text;
}
dialog::backdrop { background: #000c; }

#settings-form { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
#settings-form h2 { margin: 0; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}
legend { padding: 0 6px; font-weight: 700; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
label.row { flex-direction: row; align-items: center; gap: 8px; }

input, select, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: #0b0b0b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input[type="checkbox"] { width: 20px; height: 20px; }

.contact { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 6px; }
.contact button { background: none; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns > * { flex: 1; }

.dialog-actions { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
.dialog-actions > * { flex: 1; }

@media (max-width: 440px) {
  #controls { gap: 5px; padding-left: 8px; padding-right: 8px; }
  .ctl .ic { width: 34px; height: 34px; }
  .ctl span { font-size: 9.5px; }
}

/* ---------- Guía inicial ---------- */

.wizard {
  position: fixed;
  inset: 0;
  z-index: 20;
  /* Ilustración sin texto de fondo, oscurecida al centro para leer las indicaciones */
  background:
    radial-gradient(ellipse 75% 55% at 50% 52%, rgba(0,0,0,.78), rgba(0,0,0,.45) 70%, rgba(0,0,0,.25)),
    #000 url("img/guia.webp") center / cover no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(56px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
  overflow: auto;
}
.wizard h1 { margin: 0; font-size: 30px; text-shadow: 0 2px 12px #000; }
.wizard > p { margin: 0; max-width: 360px; font-size: 18px; line-height: 1.4; color: #e8e8e8; text-shadow: 0 1px 8px #000; }
.wz-skip {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  background: none;
  border: 0;
  color: #fff;
  text-shadow: 0 1px 6px #000;
  font-size: 16px;
  padding: 8px;
}
.wz-art { width: min(280px, 70vw); }
.wz-art svg { width: 100%; height: auto; overflow: visible; }
.wz-body { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 360px; }
.wz-body input { font-size: 18px; padding: 12px; }
.wz-nav { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.wz-nav > * { flex: 1; }
.wizard .secondary { background: rgba(0,0,0,.6); }
.wz-dots { display: flex; gap: 10px; }
.wz-dots span { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #555; }
.wz-dots span.done { background: #555; }
.wz-dots span.on { background: var(--orange); border-color: var(--orange); }
.wz-status { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; font-size: 16px; }
.wz-status.ok { color: #7dff9a; }
.wz-status.bad { color: #ffb36b; }

.a-orange { fill: var(--orange); }
.a-red { fill: var(--red); }
.a-white { fill: #fff; }
.a-green { fill: #2fbf5b; }
.a-ring { fill: none; stroke: #fff; stroke-width: 4; }
.a-rays line { stroke: #fff; stroke-width: 4; stroke-linecap: round; }
.a-check { fill: none; stroke: #000; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.a-text { fill: #fff; font: 800 34px system-ui, sans-serif; }
.a-dim { opacity: 0.18; transition: opacity .15s; }
.a-lit { opacity: 1; filter: drop-shadow(0 0 8px currentColor); transition: opacity .1s; }
.a-pulse1, .a-pulse2 { animation: wz-pulse 1.6s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.a-pulse2 { animation-delay: .3s; }
@keyframes wz-pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .a-pulse1, .a-pulse2 { animation: none; } }

/* ---------- Una señal grande a la vez ---------- */

body.display-una .light { display: none; }
body.display-una[data-show="brake"] .light.brake,
body.display-una[data-show="left"] .light.left,
body.display-una[data-show="right"] .light.right,
body.display-una[data-show="hazard"] .light.turn { display: block; }
body.display-una .panel { flex-direction: row; }
body.display-una .panel .left { order: 1; }
body.display-una .panel .right { order: 3; }
body.display-una[data-show="hazard"] .panel { flex-direction: row; }
@media (orientation: portrait) {
  body.display-una[data-show="hazard"] .panel { flex-direction: column; }
  body.display-una[data-show="hazard"] .panel .right { order: 1; }
  body.display-una[data-show="hazard"] .panel .left { order: 3; }
}

/* Controles escondidos mientras se pedalea; SOS siempre visible */
#status, #controls .ctl { transition: opacity .3s; }
body.hud-hidden #status,
body.hud-hidden #controls .ctl { opacity: 0; pointer-events: none; }
body.hud-hidden #signals { padding: env(safe-area-inset-top) 8px calc(var(--ctl-h) + 12px + env(safe-area-inset-bottom)); }
body.hud-hidden #controls { justify-content: flex-end; }
/* El cuadrado de freno ocupa toda la pantalla disponible para verse más */
body.display-una .light.brake { aspect-ratio: auto; width: 100%; height: 100%; }
body.display-tres .light.brake { aspect-ratio: 1; }
body.hud-hidden #btn-sos { opacity: 0.35; }

/* Una señal: la figura ocupa toda la pantalla y los controles quedan encima */
body.display-una #signals,
body.display-una.hud-hidden #signals { padding: 0; }
body.display-una .panel { gap: 0; }
body.display-una .light { aspect-ratio: auto; width: 100%; height: 100%; flex: 1 1 0; }
body.display-una .panel { flex-direction: row; }
#controls { background: linear-gradient(transparent, #000c 40%); }
#status { background: linear-gradient(#000c 60%, transparent); }
#controls { transition: opacity .3s; }
body.hud-hidden #controls { opacity: 0; pointer-events: none; }

.sos-hint {
  position: fixed;
  left: 50%;
  top: calc(50% + clamp(84px, 22vmin, 120px) / 2 + 14px);
  transform: translateX(-50%);
  z-index: 7;
  width: min(340px, calc(100vw - 32px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #000e;
  border: 1px solid #fff6;
  color: #fff;
  font-size: 17px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

/* Recorrido terminado: todas las luces apagadas */
body.ride-ended #signals, body.ride-ended #btn-sos, body.ride-ended #controls { visibility: hidden; }
/* El círculo SOS es chico para no tapar la señal; la explicación aparece al tocarlo */
.sos-label small { display: none; }
.sos-label b { font-size: 24px; }
.sos-label .ic { width: 26px; height: 26px; }

/* ---------- Pantalla de inicio: el afiche de Andrés con las señales animadas ---------- */

@font-face { font-family: "Knewave"; src: url("fonts/knewave.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Barlow Condensed"; font-style: italic; font-weight: 800; src: url("fonts/barlow-condensed-800-italic.woff2") format("woff2"); font-display: swap; }

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

.start {
  --brush: "Knewave", "Arial Black", Impact, sans-serif;
  --display: "Barlow Condensed", "Roboto Condensed", "Arial Narrow", Impact, system-ui, sans-serif;
  --paper: #f4efe6;
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-top) 0 calc(14px + env(safe-area-inset-bottom));
  background: #000;
  overflow: auto;
}

/* El afiche mantiene su proporción 2:3; todas las capas animadas van en % de la imagen */
.start-poster {
  position: relative;
  flex: none;
  width: min(100%, calc((100dvh - 190px) * 2 / 3));
  aspect-ratio: 1024 / 1536;
  background: url("img/afiche.webp") center / 100% 100% no-repeat;
  /* Funde los bordes con el fondo negro */
  -webkit-mask: linear-gradient(to bottom, #000 88%, transparent);
  mask: linear-gradient(to bottom, #000 88%, transparent);
}
.start-poster > * { position: absolute; }

/* Luz de la mochila: se enciende del centro hacia los lados, como el intermitente */
.fx-pack {
  inset: 0;
  clip-path: polygon(21.2% 40.5%, 29.1% 37.9%, 35.4% 40.7%, 26.1% 42.8%);
}
.fx-half { position: absolute; top: 37%; height: 7%; background: #050302; animation: fx-reveal 1.6s infinite; }
.fx-l { left: 20%; width: 8.3%; transform-origin: left center; }
.fx-r { left: 28.3%; width: 8%; transform-origin: right center; }
@keyframes fx-reveal {
  0%, 8% { transform: scaleX(1); opacity: .88; }
  40%, 72% { transform: scaleX(0); opacity: .88; }
  73%, 100% { transform: scaleX(1); opacity: .88; }
}
.fx-glow {
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(closest-side, #ff9100cc, #ff910033 55%, transparent);
  mix-blend-mode: screen;
  animation: fx-glow 1.6s infinite;
}
.fx-glow-pack { left: 14%; top: 33%; width: 28%; height: 14%; }
@keyframes fx-glow { 0%, 20% { opacity: 0; } 40%, 72% { opacity: 1; } 73%, 100% { opacity: 0; } }

/* Las tres señales de la derecha parpadean en secuencia: izquierda, derecha, freno */
.fx-ico {
  border-radius: 40%;
  background: radial-gradient(closest-side, #000e 60%, #0000);
  animation: fx-blink 1.8s steps(1) infinite;
}
.fx-ico-left { left: 74.5%; top: 40.6%; width: 6.5%; height: 5.6%; }
.fx-ico-right { left: 78.9%; top: 49.6%; width: 6.5%; height: 5.6%; animation-delay: .6s; }
.fx-ico-brake { left: 72.6%; top: 58.2%; width: 13.4%; height: 6%; animation-delay: 1.2s; }
@keyframes fx-blink { 0%, 33% { opacity: 0; } 34%, 100% { opacity: .85; } }

.start-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: -40px;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  z-index: 1;
}
.go {
  width: min(420px, 100%);
  height: 78px;
  border: 0;
  background: var(--orange);
  color: #000;
  font: 400 40px/1 var(--brush);
  text-transform: uppercase;
  letter-spacing: .02em;
  clip-path: polygon(4% 0, 100% 0, 96% 100%, 0 100%);
  box-shadow: inset 0 -6px 0 #0003;
  animation: go-pulse 1.8s ease-in-out infinite;
}
.go:active { background: var(--paper); }
@keyframes go-pulse { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 14px var(--orange)); } }
.link { background: none; border: 0; color: #d9d4cc; font: italic 800 15px var(--display); text-transform: uppercase; letter-spacing: .1em; text-decoration: underline; text-underline-offset: 4px; padding: 8px; }
.start .support { max-width: 420px; text-align: left; }
.get-android {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 22px;
  border: 2px solid var(--orange);
  border-radius: 999px;
  color: var(--orange);
  font: italic 800 16px var(--display);
  text-transform: uppercase;
  letter-spacing: .08em;
  text-decoration: none;
}
.get-android:active { background: var(--orange); color: #000; }

@media (prefers-reduced-motion: reduce) {
  .go, .fx-half, .fx-glow, .fx-ico { animation: none; }
  .fx-half, .fx-ico { opacity: 0; }
  .fx-glow { opacity: 1; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .start { flex-direction: row; justify-content: center; padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left)); }
  .start-poster { width: auto; height: 100dvh; -webkit-mask: none; mask: none; }
  .start-actions { margin-top: 0; width: min(380px, 45vw); padding: 0; }
}

/* ---------- Dibujos en canvas (giro, freno y peligro a elección) ---------- */
#art { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
body.display-una.art-on #art { display: block; }
body.display-una.art-on .panel { visibility: hidden; }

/* ---------- Botones redondos ---------- */
body.btn-circulos .ctl { background: none; border: 0; border-radius: 0; gap: 6px; }
body.btn-circulos .ctl .ic {
  box-sizing: content-box; width: 28px; height: 28px; padding: 14px;
  border-radius: 50%; background: #141210; border: 2px solid currentColor;
}
body.btn-circulos .ctl-stop .ic { color: var(--fg); }
body.btn-circulos .ctl:active { background: none; }
body.btn-circulos .ctl:active .ic { background: #2a2622; transform: scale(.94); }
