:root {
  --noche: #0D1B2E;      /* el mapa de noche */
  --panel: #12233A;
  --panel-2: #1A2E4A;
  --raya: #24395A;
  --tinta: #EEF1F6;
  --tinta-2: #A3B3CA;
  --tinta-3: #6F82A0;
  --sodio: #F3B341;      /* farolas de andén: vías y acento */
  --paleta: #15181D;
  --paleta-luz: #232830;
  --paleta-txt: #F6F1E4;
  --bien: #3CC489;
  --regular: #F3B341;
  --mal: #F2545B;
  --neutro: #8A9BB5;

  --f-cartel: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  --f-texto: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --gutter: 16px;
  --panel-corto: 232px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--noche);
  color: var(--tinta);
  font-family: var(--f-texto);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sodio); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Mapa ─────────────────────────────────────────── */
.mapa { position: fixed; inset: 0; background: var(--noche); }
.maplibregl-ctrl-attrib { background: rgba(13, 27, 46, .7) !important; color: var(--tinta-3); font-size: 11px; }
.maplibregl-ctrl-attrib a { color: var(--tinta-2) !important; }
.maplibregl-ctrl-attrib-inner { color: var(--tinta-2); }
.maplibregl-ctrl-attrib-button { filter: invert(1); opacity: .6; }
.maplibregl-ctrl-top-right { top: calc(env(safe-area-inset-top) + 62px); }
.maplibregl-ctrl-bottom-right { display: none; }
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--raya); box-shadow: none !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--raya) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(.85); }

/* ── Cabecera ─────────────────────────────────────── */
.barra {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 18px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 22px;
  background: linear-gradient(var(--noche) 30%, rgba(13, 27, 46, 0));
  pointer-events: none;
}
.barra > * { pointer-events: auto; }
.cabecera {
  font-family: var(--f-cartel); font-weight: 700; font-size: 30px; line-height: 1;
  letter-spacing: -.01em; color: var(--tinta); text-decoration: none;
}
.secciones { display: flex; gap: 4px; font-size: 14px; overflow-x: auto; scrollbar-width: none; }
.secciones a, .secciones .pronto { padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.secciones a { color: var(--noche); background: var(--sodio); font-weight: 700; text-decoration: none; }
.secciones .pronto { color: var(--tinta-3); border: 1px dashed var(--raya); }

/* ── Panel (hoja inferior en móvil, columna en escritorio) ── */
.panel {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 0;
  max-height: calc(100dvh - 76px);
  height: calc(var(--panel-corto) + env(safe-area-inset-bottom));
  background: var(--panel);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--raya);
  box-shadow: 0 -18px 40px rgba(5, 10, 20, .45);
  display: flex; flex-direction: column;
  transition: height .32s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.panel[data-estado="largo"] { height: calc(100dvh - 76px); }
.asa {
  display: grid; place-items: center; width: 100%; height: 22px; flex: none;
  background: none; border: 0; cursor: grab; touch-action: none;
}
.asa-raya { width: 44px; height: 5px; border-radius: 3px; background: var(--raya); }

.panel-cab {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 var(--gutter) 10px;
}
.nucleo {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  font-family: var(--f-cartel); font-weight: 600; font-size: 22px; letter-spacing: .01em;
}
.nucleo svg { color: var(--tinta-2); }
.vivo { margin: 0; display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--tinta-2); }
.vivo-punto { width: 8px; height: 8px; border-radius: 50%; background: var(--neutro); }
.vivo[data-tono="ok"] .vivo-punto { background: var(--bien); box-shadow: 0 0 0 3px rgba(60, 196, 137, .18); }
.vivo[data-tono="viejo"] .vivo-punto { background: var(--regular); }
.vivo[data-tono="demo"] .vivo-punto { background: var(--sodio); }

/* Portada: la línea que sigues, en paletas */
.portada { padding: 0 var(--gutter) 14px; }
.portada-fila { display: flex; align-items: stretch; gap: 10px; }
.titular {
  margin: 12px 0 0; font-size: 17px; line-height: 1.42; color: var(--tinta);
  max-width: 34em; text-wrap: pretty;
}

.pastilla {
  display: inline-grid; place-items: center; min-width: 40px; height: 26px; padding: 0 8px;
  border-radius: 7px; background: var(--c, var(--neutro)); color: var(--c-txt, #fff);
  font-family: var(--f-cartel); font-weight: 700; font-size: 17px; line-height: 1; letter-spacing: .02em;
}
.pastilla-grande { min-width: 64px; height: auto; font-size: 26px; border-radius: 9px; }
.pastilla-grande:not([style*="--c"]) { background: none; color: var(--tinta-2); box-shadow: inset 0 0 0 1.5px var(--raya); font-size: 22px; }

/* ── Paletas ─────────────────────────────────────── */
.paletas { display: flex; gap: 3px; flex: 1; min-width: 0; }
.paleta {
  position: relative; flex: 1 1 0; min-width: 0; height: 50px; max-width: 32px;
  border-radius: 4px; background: linear-gradient(var(--paleta-luz) 50%, var(--paleta) 50%);
  display: grid; place-items: center; overflow: hidden;
  font-family: var(--f-cartel); font-weight: 600; font-size: 34px; line-height: 1;
  color: var(--paleta-txt);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, .04), 0 1px 0 rgba(0, 0, 0, .5);
}
.paleta::after { /* el eje de la paleta */
  content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(0, 0, 0, .65);
}
.paleta.gira .paleta-t { animation: gira .12s ease-in; }
@keyframes gira {
  0% { transform: perspective(120px) rotateX(-70deg); opacity: .4; }
  100% { transform: none; opacity: 1; }
}
.paletas[data-tono="bien"] .paleta { color: #7FE6B5; }
.paletas[data-tono="regular"] .paleta { color: #FFD36E; }
.paletas[data-tono="mal"] .paleta { color: #FF8A8F; }
.paletas[data-tono="neutro"] .paleta { color: var(--paleta-txt); }

.paletas-mini { flex: none; width: 152px; }
.paletas-mini .paleta { height: 28px; font-size: 19px; border-radius: 3px; max-width: 18px; }

/* ── Cuerpo del panel ─────────────────────────────── */
.panel-cuerpo { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px var(--gutter) 24px; }
.panel[data-estado="corto"] .panel-cuerpo { visibility: hidden; }
.bloque { margin-top: 10px; }
.bloque + .bloque { margin-top: 26px; }
.bloque-tit { font-family: var(--f-cartel); font-weight: 600; font-size: 21px; margin: 0; letter-spacing: .01em; }
.bloque-ayuda { margin: 2px 0 10px; font-size: 14px; color: var(--tinta-2); }

.lineas { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.linea {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px;
  padding: 8px 10px; background: var(--panel-2); border: 1px solid transparent; border-radius: 12px;
  cursor: pointer; text-align: left;
}
.linea:hover { border-color: var(--raya); }
.linea[aria-pressed="true"] { border-color: var(--sodio); background: #20375A; }
.linea-num { font-size: 14px; color: var(--tinta-2); white-space: nowrap; }
.linea-marca { width: 18px; height: 18px; color: var(--tinta-3); }
.linea[aria-pressed="true"] .linea-marca { color: var(--sodio); }
.linea .paletas { justify-content: flex-start; }

.avisos { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.aviso { padding: 12px 14px; border-radius: 12px; background: var(--panel-2); border-left: 3px solid var(--sodio); }
.aviso-lineas { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.aviso-lineas .pastilla { min-width: 34px; height: 22px; font-size: 15px; }
.aviso p { margin: 0; font-size: 15px; color: var(--tinta); }
.aviso-vacio { color: var(--tinta-2); font-size: 15px; border-left-color: var(--bien); }

.creditos { margin-top: 28px; font-size: 13px; color: var(--tinta-3); }
.creditos p { margin: 0; max-width: 46em; }

/* ── Ficha del tren ──────────────────────────────── */
.ficha {
  position: fixed; z-index: 4; left: var(--gutter); right: var(--gutter);
  top: calc(env(safe-area-inset-top) + 64px);
  padding: 14px 16px 16px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--raya);
  box-shadow: 0 14px 40px rgba(5, 10, 20, .5);
  max-width: 380px; margin: 0 auto;
}
.ficha[hidden] { display: none; }
.ficha-cab { display: flex; align-items: center; gap: 10px; }
.ficha-tren { font-family: var(--f-cartel); font-weight: 700; font-size: 26px; line-height: 1; }
.ficha-cerrar {
  margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--raya); background: none; cursor: pointer; color: var(--tinta-2);
}
.ficha-donde { margin: 10px 0 12px; font-size: 16px; }
.ficha-datos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 14px; }
.ficha-datos div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.ficha-datos dt { font-size: 13px; color: var(--tinta-2); }
.ficha-datos dd { margin: 2px 0 0; font-family: var(--f-cartel); font-weight: 600; font-size: 22px; line-height: 1.1; }
.ficha-datos dd[data-tono="bien"] { color: var(--bien); }
.ficha-datos dd[data-tono="regular"] { color: var(--regular); }
.ficha-datos dd[data-tono="mal"] { color: var(--mal); }

.boton {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--sodio); color: var(--noche); font-weight: 700; font-size: 16px;
}
.boton[aria-pressed="true"] { background: var(--panel-2); color: var(--sodio); box-shadow: inset 0 0 0 1.5px var(--sodio); }
.boton-sec { background: var(--panel-2); color: var(--tinta); margin-top: 14px; }

/* ── Diálogo de núcleos ──────────────────────────── */
.dialogo {
  width: min(420px, calc(100vw - 32px)); max-height: 80dvh; padding: 18px; border-radius: 18px;
  background: var(--panel); color: var(--tinta); border: 1px solid var(--raya);
}
.dialogo::backdrop { background: rgba(5, 10, 20, .6); }
.dialogo h2 { font-family: var(--f-cartel); font-weight: 600; font-size: 26px; margin: 0 0 12px; }
.nucleos { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nucleos button {
  width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--panel-2); font-size: 16px;
}
.nucleos button[aria-current="true"] { box-shadow: inset 0 0 0 1.5px var(--sodio); }

/* ── Escritorio: columna a la izquierda ──────────── */
@media (min-width: 900px) {
  .barra { right: auto; width: 440px; padding-left: 24px; background: none; }
  .panel, .panel[data-estado="largo"] {
    top: 76px; left: 16px; bottom: 16px; right: auto; width: 424px; height: auto; max-height: none;
    border-radius: 20px; border: 1px solid var(--raya);
  }
  .panel[data-estado] .panel-cuerpo { visibility: visible; }
  .asa { display: none; }
  .maplibregl-ctrl-top-right { top: 8px; }
  .maplibregl-ctrl-bottom-right { display: block; }
  .panel-cab { padding-top: 16px; }
  .ficha { left: auto; right: 24px; top: 24px; width: 360px; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}

/* Número de tren en paletas dentro de la ficha */
.ficha-tren { display: inline-flex; align-items: center; gap: 8px; }
.ficha-tren .paletas { display: inline-flex; flex: none; gap: 2px; }
.ficha-tren .paleta { flex: none; width: 20px; height: 32px; font-size: 24px; border-radius: 3px; }
