* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1d2126;
  color: #e9e6dc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- Barra superior ---------- */
#barra {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 14px;
  background: #2a2f36;
  border-bottom: 1px solid #3a4049;
  flex: 0 0 auto;
}

.logo {
  font-size: 17px;
  letter-spacing: 0.5px;
  color: #cfc9b8;
}
.logo b { color: #f2b632; }

#herramientas {
  display: flex;
  gap: 6px;
}

.herr {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #353b44;
  color: #e9e6dc;
  border: 1px solid #454c57;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.herr:hover { background: #3e454f; }
.herr.activa {
  background: #f2b632;
  border-color: #f2b632;
  color: #1d2126;
  font-weight: 600;
}
.herr .tecla {
  font-size: 11px;
  opacity: 0.6;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
}

/* ---------- Mapa ---------- */
#juego {
  display: block;
  touch-action: none;
}

/* ---------- Barra inferior ---------- */
#estado {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 14px;
  background: #2a2f36;
  border-top: 1px solid #3a4049;
  font-size: 12px;
  color: #b9b4a6;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
#estado-ayuda { opacity: 0.8; }
#estado-credito { opacity: 0.55; font-size: 11px; }
#estado-credito:empty { display: none; }

/* ---------- Reloj y velocidades ---------- */
#reloj {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}
#reloj-fecha { color: #cfc9b8; }
#reloj-hora {
  font-size: 16px;
  font-weight: 600;
  color: #f3efe2;
  min-width: 46px;
}
#reloj-clima { font-size: 16px; }
#reloj-feriado {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #4a3d6b;
  color: #e6dcff;
}
body.pausado #reloj-hora { color: #f2b632; }

#velocidades { display: flex; gap: 3px; }
.vel {
  min-width: 34px;
  padding: 5px 7px;
  background: #353b44;
  color: #e9e6dc;
  border: 1px solid #454c57;
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.vel:hover { background: #3e454f; }
.vel.activa { background: #f2b632; border-color: #f2b632; color: #1d2126; font-weight: 600; }

/* ---------- Área de juego + panel ---------- */
#area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  position: relative;
}
#lienzo { flex: 1 1 auto; min-width: 0; position: relative; }
#lienzo #juego, #lienzo #mundo { position: absolute; inset: 0; width: 100%; height: 100%; }
#lienzo #mundo { pointer-events: none; }

#panel {
  flex: 0 0 290px;
  background: #262b31;
  border-left: 1px solid #3a4049;
  overflow-y: auto;
}
#panel[hidden] { display: none; }

.panel-cabeza, .ventana-cabeza {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 10px 10px 14px;
  background: #2f353d;
  border-bottom: 1px solid #3a4049;
  font-weight: 600;
  font-size: 15px;
}
#panel-titulo, .ventana-titulo { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icono {
  background: none;
  border: none;
  color: #b9b4a6;
  font-size: 13px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.icono:hover { background: #3e454f; color: #fff; }

#panel-cuerpo, .ventana-cuerpo { padding: 10px 14px 14px; }

.fila {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.fila span { color: #b9b4a6; }
.fila b { color: #f3efe2; font-weight: 600; text-align: right; }
.nota { font-size: 11px; color: #8f8a7d; margin: -1px 0 4px; }
hr { border: none; border-top: 1px solid #3a4049; margin: 8px 0; }
.sube { color: #6cc36a; }
.baja { color: #d9534f; }
.barra { height: 6px; background: #3a4049; border-radius: 3px; overflow: hidden; margin: 2px 0 4px; }
.barra i { display: block; height: 100%; border-radius: 3px; }

/* ---------- Ventanas fijadas ---------- */
.ventana {
  position: absolute;
  width: 270px;
  background: #262b31;
  border: 1px solid #454c57;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  z-index: 5;
}
.ventana-cabeza { cursor: move; font-size: 14px; padding: 7px 8px 7px 12px; }

/* ---------- Pantalla de inicio ---------- */
#inicio {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 23, 27, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 20;
}
#inicio[hidden] { display: none; }
.tarjeta {
  width: min(380px, calc(100vw - 32px));
  background: #262b31;
  border: 1px solid #454c57;
  border-radius: 12px;
  padding: 26px 28px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.tarjeta h1 { margin: 0; font-size: 26px; font-weight: 400; color: #cfc9b8; }
.tarjeta h1 b { color: #f2b632; }
.tarjeta .sub { margin: 4px 0 20px; color: #8f8a7d; }
.tarjeta label { display: block; margin-bottom: 18px; color: #b9b4a6; }
.tarjeta label b { float: right; color: #f3efe2; font-size: 18px; }
.tarjeta select, .tarjeta input[type=range] { display: block; width: 100%; margin-top: 8px; }
.tarjeta select {
  padding: 7px 8px;
  background: #353b44;
  color: #e9e6dc;
  border: 1px solid #454c57;
  border-radius: 6px;
  font: inherit;
}
.tarjeta input[type=range] { accent-color: #f2b632; }
.rango { display: flex; justify-content: space-between; font-size: 11px; color: #8f8a7d; }
#inicio-empezar {
  width: 100%;
  padding: 11px;
  background: #f2b632;
  color: #1d2126;
  border: none;
  border-radius: 7px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
#inicio-empezar:hover { background: #f5c252; }

/* ---------- Ventanas de la empresa ---------- */
#btn-lineas { margin-left: 6px; }
.titulo-sec { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #8f8a7d; margin: 6px 0 4px; }
.acciones { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.btn {
  padding: 6px 11px;
  background: #f2b632;
  color: #1d2126;
  border: 1px solid #f2b632;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #f5c252; }
.btn.sec { background: #353b44; color: #e9e6dc; border-color: #454c57; font-weight: 500; }
.btn.sec:hover { background: #3e454f; }
.btn.peligro { background: transparent; color: #e57373; border-color: #6b3a3a; font-weight: 500; }
.btn.peligro:hover { background: #3a2626; }
.btn:disabled { opacity: 0.45; cursor: default; }
.alerta {
  margin: 6px 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: rgba(217, 83, 79, 0.16);
  border: 1px solid rgba(217, 83, 79, 0.45);
  color: #f3c6c4;
  font-size: 12px;
}
.alerta.suave { background: rgba(242, 182, 50, 0.12); border-color: rgba(242, 182, 50, 0.4); color: #f3e2b8; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border: none;
  border-radius: 5px;
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.chip.grande { min-width: 34px; height: 28px; font-size: 15px; cursor: default; }
.linea-cab { display: flex; align-items: center; gap: 10px; margin: 2px 0 8px; font-weight: 600; }
.fila select, .acciones select, .flota select {
  background: #353b44;
  color: #e9e6dc;
  border: 1px solid #454c57;
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  padding: 3px 4px;
  max-width: 150px;
}
.acciones select { max-width: none; width: 100%; padding: 5px; }
.fila small { color: #8f8a7d; font-size: 10px; }
.check { display: flex; align-items: center; gap: 7px; margin: 8px 0 2px; cursor: pointer; }
.check input { accent-color: #f2b632; }
.modelo { background: #2f353d; border-radius: 7px; padding: 8px 10px; margin: 6px 0; }
.modelo-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modelo-cab .btn { padding: 3px 10px; font-size: 12px; }
.modelo-datos { font-size: 11px; color: #b9b4a6; line-height: 1.5; }
.flota { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.flota span { flex: 1; color: #b9b4a6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link { background: none; border: none; padding: 0; color: #f2b632; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.link:hover { text-decoration: underline; }
.recorrido { margin: 0; padding-left: 22px; font-size: 13px; }
.recorrido li { padding: 2px 0; }
.recorrido li > span:first-child { display: inline-block; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.recorrido li.paso { color: #8f8a7d; font-size: 12px; }
.recorrido em { font-style: normal; font-size: 10px; color: #f2b632; margin-left: 4px; }
.recorrido .mini { float: right; }
.recorrido .mini .icono { padding: 0 5px; }
.fila-linea {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 6px;
  background: none;
  border: none;
  border-bottom: 1px solid #333940;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.fila-linea:hover { background: #2f353d; }
.fl-nombre { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.fl-dato { font-size: 12px; color: #b9b4a6; }

/* ---------- Aviso flotante ---------- */
#aviso {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 9px 16px;
  background: #2f353d;
  border: 1px solid #f2b632;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  color: #f3efe2;
  font-size: 13px;
  z-index: 15;
}
#aviso[hidden] { display: none; }

/* ---------- Configuración y rendimiento ---------- */
#btn-config { font-size: 14px; }
#rendimiento {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 5px 9px;
  background: rgba(20, 23, 27, 0.8);
  border-radius: 6px;
  color: #b9f5a8;
  font: 12px ui-monospace, Menlo, monospace;
  pointer-events: none;
  white-space: pre;
  z-index: 4;
}
#rendimiento[hidden] { display: none; }
.opcion { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; cursor: pointer; }
.opcion small { display: block; color: #8f8a7d; font-size: 11px; }
.opcion input[type=checkbox] { accent-color: #f2b632; width: 16px; height: 16px; flex: none; }

/* ---------- Barra superior compacta (entra con 6 herramientas y 6 velocidades) ---------- */
#barra { gap: 14px; }
.logo, #reloj, #reloj-fecha { white-space: nowrap; }
#herramientas { gap: 4px; }
.herr { padding: 6px 9px; gap: 6px; white-space: nowrap; }
#btn-lineas { margin-left: 0; }
#reloj { gap: 8px; }
#velocidades { gap: 2px; }
.vel { min-width: 30px; padding: 5px 5px; }
@media (max-width: 1300px) {
  .herr .tecla { display: none; }   /* en pantallas angostas, sin el numerito */
}

/* ---------- Menús de herramientas (menu.js) ---------- */
#barra { position: relative; z-index: 25; }    /* el menú abierto queda encima del mapa y las ventanas */
.grupo-herr { position: relative; }
.grupo-btn .flecha { font-size: 10px; opacity: 0.7; }
.grupo-btn.abierto { background: #3e454f; border-color: #6b7380; }
.grupo-btn.activa.abierto { background: #f2b632; }
.grupo-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  display: flex; flex-direction: column; gap: 2px; min-width: 180px; padding: 5px;
  background: #2a2f36; border: 1px solid #454c57; border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}
.grupo-menu[hidden] { display: none; }
.grupo-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 10px; background: none; color: #e9e6dc; border: 1px solid transparent; border-radius: 5px;
  font: inherit; text-align: left; cursor: pointer; white-space: nowrap; margin: 0;
}
.grupo-item:hover { background: #3e454f; }
.grupo-item.activa { background: #f2b632; color: #1d2126; font-weight: 600; }
.grupo-item .tecla { font-size: 11px; opacity: 0.6; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; }

/* ---------- Carta de la ciudad (debajo de su cartel) ---------- */
#carta-ciudad {
  position: absolute;
  transform: translateX(-50%);
  z-index: 4;
  font-size: 12px;
  color: #f3efe2;
  pointer-events: auto;
}
#carta-ciudad[hidden] { display: none; }
#carta-ciudad::before {          /* puntita hacia el cartel */
  content: ''; position: absolute; top: -6px; left: 50%; margin-left: -6px;
  border: 6px solid transparent; border-top: 0; border-bottom-color: rgba(29, 33, 38, 0.78);
}
#carta-ciudad .carta-tira {
  display: flex; gap: 4px; align-items: center;
  background: rgba(29, 33, 38, 0.78);
  border-radius: 18px; padding: 5px 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}
#carta-ciudad .chip { background: rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 3px 8px; }
#carta-ciudad .chip b { color: #f2b632; }
#carta-ciudad button {
  background: none; border: 0; color: #b9b4a6; font: inherit; cursor: pointer;
  padding: 3px 6px; border-radius: 10px;
}
#carta-ciudad button:hover { color: #f3efe2; background: rgba(255, 255, 255, 0.08); }
#carta-ciudad .carta-mas {
  margin: 4px auto 0; width: 230px; box-sizing: border-box;
  background: rgba(29, 33, 38, 0.88);
  border-radius: 8px; padding: 8px 11px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
#carta-ciudad .f { display: flex; justify-content: space-between; padding: 2px 0; color: #d8d3c4; }
#carta-ciudad .f b { color: #f3efe2; }
#carta-ciudad .n { color: #8e897c; font-size: 10.5px; }
#carta-ciudad .barra { height: 5px; margin: 4px 0 2px; }
#carta-ciudad .carta-fijar { display: block; width: 100%; margin-top: 6px; text-align: center; background: rgba(255, 255, 255, 0.06); }

/* ---------- Cajón de Terreno (barrita flotante) ---------- */
.ventana.cajon-terreno { width: auto; }
.ventana.cajon-terreno[hidden] { display: none; }
.cajon-cuerpo { padding: 8px; }
.cajon-grilla { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; }
.cajon-herr {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #323840; color: #f3efe2; border: 1px solid #454c57; border-radius: 7px;
  padding: 6px 2px 5px; font: inherit; font-size: 11px; cursor: pointer;
}
.cajon-herr .ic { font-size: 18px; line-height: 1.1; }
.cajon-herr:hover { background: #3e454f; }
.cajon-herr.activa { background: #f2b632; border-color: #f2b632; color: #1d2126; font-weight: 600; }
.cajon-pincel { display: flex; align-items: center; gap: 4px; margin-top: 8px; font-size: 11px; color: #b9b4a6; }
.cajon-pincel span { margin-right: 4px; }
.cajon-pincel button {
  flex: 1; background: #323840; color: #f3efe2; border: 1px solid #454c57; border-radius: 6px;
  padding: 3px 0; font: inherit; font-size: 11px; cursor: pointer;
}
.cajon-pincel button.activa { background: #f2b632; border-color: #f2b632; color: #1d2126; font-weight: 600; }

/* Crédito de los datos del mapa (lo pide la licencia de OpenStreetMap) */
#credito-mapa {
  position: absolute; right: 8px; bottom: 6px; z-index: 3;
  font-size: 10.5px; color: rgba(255, 255, 255, 0.85);
  background: rgba(29, 33, 38, 0.45); padding: 2px 7px; border-radius: 4px;
  pointer-events: none;
}
#credito-mapa:empty { display: none; }
