:root {
  --bg: #000; --panel: #0a0d14; --panel2: #0f1420; --line: rgba(255,255,255,.08);
  --fg: #eef2ff; --mute: #8b95b3; --dim: #566080; --accent: #7aa2ff;
  --ok: #3ddc97; --mid: #ffb02e; --bad: #ff4d5e;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { height: 100%; display: grid; grid-template-rows: auto 1fr auto; padding-top: var(--safe-t); transition: filter .8s ease; }
#app[data-night="1"] { filter: brightness(.55) sepia(.35) saturate(.9); }

/* Header */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 22px 6px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .02em; }
.brand-name b { color: var(--accent); margin-left: 3px; font-weight: 700; }
.logo { width: 18px; height: 18px; border-radius: 5px; background: conic-gradient(from 200deg, #ff4d5e, #ffb02e, #3ddc97, #7aa2ff, #ff4d5e); box-shadow: 0 0 14px rgba(122,162,255,.5); }
.clock { text-align: center; line-height: 1; }
#time { font-size: clamp(2rem, 4.4vw, 3.4rem); font-weight: 200; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
#date { margin-top: 4px; font-size: .78rem; color: var(--mute); text-transform: capitalize; letter-spacing: .08em; }
.tools { display: flex; gap: 8px; justify-content: flex-end; }
.ico, select { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; min-width: 40px; height: 40px; padding: 0 12px; font-size: 1.05rem; }
select { font-size: .85rem; font-weight: 600; appearance: none; text-align: center; }

/* Layout principale */
main { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr); gap: 14px; padding: 8px 18px 14px; min-height: 0; }
.pane { position: relative; background: linear-gradient(180deg, var(--panel), #05070c); border: 1px solid var(--line); border-radius: 26px; overflow: hidden; min-height: 0; }
#mapPane { background: radial-gradient(120% 90% at 50% 30%, #0b1224 0%, #04060c 60%, #000 100%); }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.legend { position: absolute; left: 18px; top: 16px; display: flex; align-items: center; gap: 8px; font-size: .74rem; color: var(--mute); flex-wrap: wrap; max-width: calc(100% - 36px); }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 10px currentColor; margin-left: 8px; }
.legend .dot:first-child { margin-left: 0; }
.dot.ok { background: var(--ok); color: var(--ok); } .dot.mid { background: var(--mid); color: var(--mid); } .dot.bad { background: var(--bad); color: var(--bad); }
.legend .count { margin-left: 14px; padding-left: 14px; border-left: 1px solid var(--line); }
.legend .count b { color: var(--fg); font-variant-numeric: tabular-nums; }
.banner { position: absolute; left: 50%; transform: translateX(-50%); bottom: 64px; background: rgba(255,176,46,.12); color: var(--mid); border: 1px solid rgba(255,176,46,.35); padding: 6px 14px; border-radius: 999px; font-size: .75rem; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }

.rewind { position: absolute; left: 18px; right: 18px; bottom: 14px; display: flex; align-items: center; gap: 12px; }
.rewind input { flex: 1; accent-color: var(--accent); height: 28px; }
.live { border: 1px solid var(--line); background: var(--panel2); color: var(--mute); border-radius: 999px; padding: 5px 12px; font-size: .72rem; font-weight: 700; letter-spacing: .12em; }
.live.on { color: #fff; background: rgba(255,77,94,.18); border-color: rgba(255,77,94,.5); }
.live.on::before { content: "●"; color: var(--bad); margin-right: 6px; animation: pulse 1.6s infinite; }
.rlbl { min-width: 54px; text-align: right; font-size: .75rem; color: var(--mute); font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { opacity: .25; } }

.tip { position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, calc(-100% - 16px)); background: rgba(12,16,28,.92); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.14); border-radius: 14px; padding: 10px 14px; font-size: .8rem; min-width: 150px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.tip b { font-size: 1rem; } .tip .s { color: var(--mute); margin-top: 3px; }

/* Board */
#boardPane { display: flex; flex-direction: column; }
.bhead { padding: 20px 22px 8px; }
.kicker { font-size: .7rem; color: var(--mute); text-transform: uppercase; letter-spacing: .16em; }
.stationrow { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
h1 { margin: 4px 0 0; font-size: clamp(1.5rem, 2.6vw, 2.2rem); font-weight: 650; letter-spacing: -.01em; line-height: 1.1; }
.searchwrap { position: relative; display: flex; gap: 8px; margin-top: 14px; }
#q { flex: 1; min-width: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; height: 42px; padding: 0 14px; outline: none; }
#q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,162,255,.18); }
#results { position: absolute; z-index: 10; left: 0; right: 0; top: 48px; margin: 0; padding: 6px; list-style: none; background: #0d1220; border: 1px solid rgba(255,255,255,.14); border-radius: 16px; box-shadow: 0 18px 40px rgba(0,0,0,.7); }
#results li { padding: 11px 12px; border-radius: 10px; cursor: pointer; }
#results li:hover, #results li:focus { background: rgba(122,162,255,.14); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 13px; font-size: .78rem; color: var(--mute); white-space: nowrap; }
.chip.on { color: #fff; border-color: rgba(122,162,255,.6); background: rgba(122,162,255,.16); }
.upd { margin-left: auto; font-size: .7rem; color: var(--dim); }

.cols { display: grid; grid-template-columns: 4.1rem 3.9rem 1fr 2.8rem 3.2rem; gap: 10px; padding: 8px 22px 6px; font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); border-bottom: 1px solid var(--line); }
.cols span:nth-child(n+4) { text-align: right; }
#rows { list-style: none; margin: 0; padding: 0 12px 12px; overflow-y: auto; flex: 1; scrollbar-width: none; }
#rows::-webkit-scrollbar { display: none; }
#rows li { display: grid; grid-template-columns: 4.1rem 3.9rem 1fr 2.8rem 3.2rem; gap: 10px; align-items: center; padding: 11px 10px; border-radius: 14px; }
#rows li.enter { animation: in .5s ease both; }
#rows li:nth-child(odd) { background: rgba(255,255,255,.025); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.t { font-variant-numeric: tabular-nums; font-size: 1.12rem; font-weight: 600; line-height: 1.1; }
.t small { display: block; font-size: .68rem; font-weight: 700; margin-top: 2px; }
.t small.mid { color: var(--mid); } .t small.bad { color: var(--bad); }
.badge { display: inline-block; text-align: center; padding: 4px 8px; border-radius: 8px; font-size: .78rem; font-weight: 800; letter-spacing: .02em; color: #fff; background: #333; min-width: 3.1rem; }
.badge.ic { background: #e5002b; box-shadow: 0 0 14px rgba(229,0,43,.35); }
.badge.ir { background: #7a0f21; border: 1px solid #e5002b; }
.badge.re { background: #14181f; border: 1px solid #aeb7cc; color: #e5eaf7; }
.badge.s { background: #1d4ed8; }
.badge.bus { background: #f5c518; color: #1a1500; }
.badge.tram { background: #16a34a; }
.badge.ship { background: #0ea5c4; }
.dest { font-weight: 560; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plat { text-align: right; color: var(--mute); font-weight: 600; font-variant-numeric: tabular-nums; }
.mins { text-align: right; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.mins.soon { color: var(--ok); animation: pulse 1.4s infinite; }
.empty { padding: 40px 22px; color: var(--mute); text-align: center; display: block !important; background: none !important; }

/* Tabs mobile */
.tabs { display: none; gap: 8px; padding: 6px 14px calc(10px + var(--safe-b)); }
.tabs button { flex: 1; height: 42px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); color: var(--mute); font-weight: 600; }
.tabs button.on { color: #fff; border-color: rgba(122,162,255,.6); background: rgba(122,162,255,.16); }

/* Portrait / telefono */
@media (max-width: 900px), (orientation: portrait) and (max-width: 1100px) {
  .top { grid-template-columns: auto 1fr auto; padding: 10px 14px 4px; }
  .brand-name { display: none; }
  .clock { text-align: left; }
  main { grid-template-columns: 1fr; grid-template-rows: 1fr; padding: 6px 12px 8px; }
  .tabs { display: flex; }
  #app[data-view="map"] #boardPane, #app[data-view="board"] #mapPane { display: none; }
  #app[data-view="split"] main { grid-template-rows: minmax(0, 46%) minmax(0, 54%); }
  .legend { font-size: .66rem; top: 12px; left: 12px; }
  .legend .count { display: none; }
  .bhead { padding: 14px 16px 6px; }
  .cols, #rows li { grid-template-columns: 3.6rem 3.3rem 1fr 2.2rem 2.6rem; gap: 8px; }
  .cols { padding: 6px 16px 4px; }
  .t { font-size: 1rem; } .dest { font-size: .95rem; }
}
@media (max-width: 900px) and (orientation: portrait) { #app[data-view="split"] main { grid-template-rows: 40% 60%; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

.credit { padding: 6px 22px 12px; font-size: .64rem; color: var(--dim); text-align: center; }

.mapctl { position: absolute; right: 14px; top: 12px; z-index: 4; }
.mapctl select { height: 36px; max-width: 46vw; font-size: .8rem; padding: 0 12px; background: rgba(15,20,32,.85); backdrop-filter: blur(6px); }
.maploading { position: absolute; right: 16px; top: 54px; font-size: .7rem; color: var(--mute); animation: pulse 1.4s infinite; }
@media (max-width: 900px) { .legend { max-width: calc(100% - 150px); } }
@media (max-width: 900px) {
  .mapctl { left: 12px; right: 12px; top: 10px; }
  .mapctl select { width: 100%; max-width: none; }
  .legend { top: 54px; left: 12px; max-width: calc(100% - 24px); }
  .maploading { top: 58px; right: 14px; }
}

.about { margin-top: 6px; text-align: left; max-width: 640px; margin-inline: auto; }
.about summary { cursor: pointer; color: var(--mute); text-align: center; list-style: none; }
.about summary::-webkit-details-marker { display: none; }
.about p { margin: 6px 0; line-height: 1.4; }
.about[open] { max-height: 30vh; overflow-y: auto; }
