:root {
  --bg: #15171a;
  --panel: rgba(24, 26, 29, 0.78);
  --panel-solid: #1c1f22;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #ece7de;
  --muted: #a39d93;
  --faint: #6f6a63;
  --accent: #f0b35a;
  --accent-ink: #2a1c06;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 14px/1.4 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; }
svg { stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }

.panel {
  position: fixed;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

/* capçalera */
.brand { top: var(--gutter); left: var(--gutter); display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; max-width: calc(100vw - 2 * var(--gutter)); }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.logo svg { width: 22px; height: 22px; stroke-width: 2.4; }
.title { min-width: 0; }
.title h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title p { margin: 1px 0 0; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.04); cursor: pointer; font-weight: 550; font-size: 13px; white-space: nowrap; margin-left: 6px; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.22); }
.btn svg { width: 17px; height: 17px; }
.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* panells laterals */
.side { width: 304px; padding: 14px; max-height: calc(100vh - 160px); overflow: auto; scrollbar-width: thin; }
.levels { top: 84px; left: var(--gutter); }
.trains { top: var(--gutter); right: var(--gutter); }
.head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.head h2 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.head-actions { display: flex; gap: 6px; align-items: center; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12.5px; font-weight: 550; padding: 4px 6px; border-radius: 6px; }
.link:hover { background: rgba(240, 179, 90, 0.1); }
.icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.04); cursor: pointer; padding: 0; font-size: 18px; line-height: 1; }
.icon:hover { background: rgba(255, 255, 255, 0.1); }
.icon svg { width: 16px; height: 16px; }
#play .i-play { display: none; }
#play.paused .i-play { display: block; fill: currentColor; }
#play.paused .i-pause { display: none; }
.close-mobile { display: none; }

.layer-list, .train-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 2px; }
.layer { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; padding: 6px 6px 6px 4px; border-radius: 9px; cursor: pointer; user-select: none; transition: background 0.12s; }
.layer:hover { background: rgba(255, 255, 255, 0.05); }
.layer .eye { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; border: 1.5px solid var(--sw); background: var(--sw); transition: background 0.12s, opacity 0.12s; }
.layer .eye svg { width: 13px; height: 13px; stroke: #111; stroke-width: 3; }
.layer.off .eye { background: transparent; }
.layer.off .eye svg { opacity: 0; }
.layer.off .name { color: var(--faint); }
.layer .name { font-weight: 520; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .z { color: var(--muted); font: 500 11.5px/1 "JetBrains Mono", ui-monospace, monospace; white-space: nowrap; }
.layer .solo { opacity: 0; font-size: 11.5px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 2px 4px; }
.layer:hover .solo { opacity: 1; }

.field { margin: 10px 0 12px; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.field label { font-size: 13px; color: var(--text); }
.field output { font: 500 12px "JetBrains Mono", ui-monospace, monospace; color: var(--accent); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--accent) var(--p, 0%), rgba(255, 255, 255, 0.14) var(--p, 0%)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; margin-top: -6px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.toggles { display: grid; gap: 4px; border-top: 1px solid var(--line); padding-top: 10px; }
.tg { display: flex; align-items: center; gap: 10px; padding: 5px 2px; cursor: pointer; font-size: 13px; user-select: none; }
.tg input { position: absolute; opacity: 0; pointer-events: none; }
.tg span { width: 30px; height: 18px; border-radius: 10px; background: rgba(255, 255, 255, 0.14); position: relative; flex: none; transition: background 0.15s; }
.tg span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform 0.18s cubic-bezier(.3, .7, .4, 1); }
.tg input:checked + span { background: var(--accent); }
.tg input:checked + span::after { transform: translateX(12px); }
.tg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.train { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; grid-template-areas: 'sw nm nm' 'sw ds act'; column-gap: 10px; row-gap: 4px; align-items: center; padding: 8px 4px 8px 6px; border-radius: 10px; }
.train:hover { background: rgba(255, 255, 255, 0.04); }
.train .sw { grid-area: sw; width: 4px; align-self: stretch; border-radius: 2px; }
.train .nm { grid-area: nm; min-width: 0; font-weight: 600; font-size: 13.5px; line-height: 1.3; text-wrap: balance; overflow-wrap: anywhere; }
.train .ds { grid-area: ds; min-width: 0; color: var(--muted); font-size: 12px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.train .act { grid-area: act; display: flex; gap: 3px; }
.train .act button { width: 28px; height: 28px; padding: 0; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.04); cursor: pointer; transition: background 0.15s, color 0.15s; }
.train .act button svg { width: 15px; height: 15px; }
.train .act button:hover { background: rgba(255, 255, 255, 0.1); }
.train .act button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.train .act button.honk { animation: honk 0.5s ease-out; }
@keyframes honk { 0% { background: var(--accent); color: var(--accent-ink); } 100% { background: rgba(255, 255, 255, 0.04); } }
.train.new { animation: fadein 0.6s ease-out; }
@keyframes fadein { from { background: rgba(240, 179, 90, 0.18); } to { background: transparent; } }
.spawn { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; }
.spawn .label { font-size: 13px; }
.seg3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.seg3 button { height: 32px; padding: 0 4px; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.04); cursor: pointer; font-size: 12px; font-weight: 550; white-space: nowrap; transition: background 0.15s, border-color 0.15s; }
.seg3 button:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.22); }
.seg3 button:active { transform: translateY(1px); }
.note { margin: 0; font-size: 12.5px; color: #ffcf8a; text-wrap: balance; }
.hint { margin: 0; font-size: 12px; color: var(--faint); text-wrap: balance; }
#mute .i-off { display: none; }
#mute.muted .i-off { display: block; }
#mute.muted .i-on { display: none; }
.empty { color: var(--muted); font-size: 13px; margin: 0 0 12px; text-wrap: balance; }

/* barra de vistes */
.views { bottom: var(--gutter); left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 5px; }
.views button { height: 34px; padding: 0 14px; border-radius: 9px; border: 0; background: transparent; cursor: pointer; font-weight: 550; font-size: 13px; color: var(--muted); white-space: nowrap; transition: background 0.15s, color 0.15s; }
.views button:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.views button.on { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.mobile-only { display: none; }

.stats { bottom: var(--gutter); left: var(--gutter); padding: 10px 14px; display: flex; gap: 18px; font-size: 12px; color: var(--muted); }
.stats b { display: block; color: var(--text); font: 500 14px "JetBrains Mono", ui-monospace, monospace; margin-top: 1px; }

.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; font-size: 12.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); max-width: 280px; }
.tip b { text-wrap: balance; display: block; font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.tip .row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; color: var(--muted); }
.tip .row span { min-width: 0; }
.tip .row span:last-child { text-align: right; flex: none; max-width: 60%; }
.tip .row span:last-child { color: var(--text); font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }

.cabbar { position: fixed; top: var(--gutter); left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 14px; backdrop-filter: blur(12px); font-weight: 560; z-index: 5; }
.cabbar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.cabbar button { white-space: nowrap; height: 30px; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.06); padding: 0 10px; cursor: pointer; font-size: 12.5px; }
kbd { font: 500 11px "JetBrains Mono", monospace; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--muted); margin-left: 4px; }
body.cab .side, body.cab .stats, body.cab .brand { opacity: 0; pointer-events: none; }
.side, .stats, .brand { transition: opacity 0.25s; }

.drop { position: fixed; inset: 0; z-index: 40; background: rgba(12, 13, 15, 0.7); display: grid; place-items: center; backdrop-filter: blur(4px); }
.drop div { border: 2px dashed var(--accent); border-radius: 18px; padding: 40px 56px; font-size: 18px; }

.loading { position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px; background: radial-gradient(ellipse at center, #22252a, #121315); transition: opacity 0.4s; }
.loading.hide { opacity: 0; pointer-events: none; }
.loading p { text-wrap: balance; margin: 0; color: var(--muted); max-width: 420px; text-align: center; padding: 0 var(--gutter); }
.loading.error p { color: #ffb4a8; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.12); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.loading.error .spinner { display: none; }
@keyframes spin { to { transform: rotate(1turn); } }

@media (max-width: 1180px) and (min-width: 861px) {
  .views { left: var(--gutter); transform: none; }
  .stats { left: auto; right: var(--gutter); }
}

@media (max-width: 860px) {
  .side { display: none; left: var(--gutter); right: var(--gutter); top: auto; bottom: 72px; width: auto; max-height: 55vh; }
  .side.open { display: block; z-index: 6; }
  .close-mobile { display: grid; }
  .mobile-only { display: inline-block; }
  .stats { display: none; }
  .views { left: var(--gutter); right: var(--gutter); transform: none; justify-content: space-between; overflow-x: auto; }
  .views button { padding: 0 9px; font-size: 12.5px; }
  .btn span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
