:root {
  --bg: #000;
  --ink: #fff;
  --muted: #a8a8a8;
  --red: #cc0000;
  --red-hi: #ff3030;
  --panel: #121212;
  --line: #2e2e2e;
  --panel-w: 380px;
  --font: "Helvetica Neue", Helvetica, Arial, "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }

/* ---------- Barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 8px 16px; background: rgba(0, 0, 0, .82); backdrop-filter: blur(6px); }
.intro { margin: 0; font-size: 13px; line-height: 1.35; color: var(--muted); flex: 1 1 0; min-width: 0; }
.lang { display: flex; border: 1px solid #555; border-radius: 4px; overflow: hidden; flex: none; }
.lang button { appearance: none; border: 0; background: transparent; color: var(--muted); font: 600 12px var(--font); padding: 6px 10px; cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--ink); color: #000; }
.lang button:focus-visible { outline: 2px solid var(--red-hi); outline-offset: -2px; }

/* Indicador de lo que suena */
.now { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: auto; font-size: 13px; }
.now[hidden] { display: none; }
.now button { appearance: none; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; padding: 0; }
.now-toggle { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--red) !important; font-size: 11px !important; line-height: 28px; }
.now-toggle:hover { background: var(--red-hi) !important; }
.now-title { font-weight: 700 !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-title:hover { text-decoration: underline; }
.now-time { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.now button:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }

/* Herramientas: comparar y explorar */
.tools { flex: 0 0 100%; display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tools::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; appearance: none; cursor: pointer; white-space: nowrap;
  border: 1px solid #4a4a4a; border-radius: 999px; background: transparent; color: #d8d8d8; font: 12px var(--font); padding: 4px 10px 4px 8px; }
.chip:hover { border-color: #999; color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #000; }
.chip[aria-pressed="true"] .ic { filter: invert(1); }
.chip .ic { width: 14px; height: 16px; }
.chip .dash { width: 16px; border-top: 2px dashed currentColor; }
.chip:focus-visible { outline: 2px solid var(--red-hi); outline-offset: 1px; }
.tools-label { flex: none; font-size: 12px; color: var(--muted); margin-left: 10px; }
.tools-hint { flex: none; font-size: 12px; color: var(--muted); margin-left: 8px; }

/* Etiqueta flotante */
#tip { position: fixed; z-index: 20; max-width: 290px; padding: 8px 11px; border-radius: 6px; background: #1b1b1b; border: 1px solid #444;
  color: var(--ink); font-size: 13px; line-height: 1.4; pointer-events: none; box-shadow: 0 6px 24px rgba(0, 0, 0, .6); }
#tip[hidden] { display: none; }
#tip .ic { width: 14px; height: 16px; vertical-align: -3px; margin-right: 5px; }
.tip-title { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--red-hi); font-weight: 700; margin-bottom: 3px; }
.tip-sub { color: var(--muted); margin-left: 6px; }

/* ---------- Lienzo ---------- */
#stage { max-width: 1100px; margin: 0 auto; transition: margin .25s ease; }
#viz { display: block; width: 100%; height: auto; font-family: var(--font); }
#viz text { fill: var(--ink); }

.stats { font-size: 23.5px; text-anchor: middle; }
.interlude { font-size: 9px; }

.stem { fill: var(--red); cursor: pointer; transition: fill .15s; }
.stem:hover, .stem.active { fill: var(--red-hi); }

.stem-prog { fill: #fff; }
.stem-hit { fill: transparent; cursor: pointer; touch-action: pan-y; }
.ghost { stroke: #fff; stroke-opacity: .7; stroke-width: 1.5; stroke-dasharray: 3 2; pointer-events: none; }
.playhead { pointer-events: none; }
.playhead line { stroke: #fff; stroke-width: 3; stroke-linecap: round; }
.playhead text { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: #000; stroke-width: 4px; }
.shade { pointer-events: none; }
.shade-cell { transition: opacity .3s; }

.ring { fill: none; stroke: #fff; stroke-opacity: .8; stroke-width: 1; stroke-dasharray: 2 2; }
.axis { stroke: #fff; stroke-opacity: .8; stroke-width: 1; }
.blob { fill: #fff; fill-opacity: .86; transition: fill-opacity .15s; }
.legend .ring, .legend .axis { stroke: #ccc; stroke-opacity: 1; }

.track { cursor: pointer; outline: none; }
.track .hit { fill: transparent; }
.track .halo { fill: none; stroke: #fff; stroke-width: 2.5; opacity: 0; transition: opacity .15s; }
.track:hover .halo, .track:focus-visible .halo { opacity: .55; }
.track.active .halo { opacity: 1; }
.track .prog { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: butt; pointer-events: none; }
.track.current .halo { opacity: .45; }
.track.playing .blob { fill-opacity: 1; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { fill-opacity: .7; } }
.mean { display: none; fill: none; stroke: #000; stroke-width: 1.8; stroke-dasharray: 4 2.5; pointer-events: none; }
.show-mean .mean { display: block; }
.vdot { fill: var(--red-hi); stroke: #fff; stroke-width: 1.5; pointer-events: none; }
.badge { display: none; pointer-events: none; }
.exploring .badge { display: block; }
.badge rect { fill: #000; fill-opacity: .82; stroke: #fff; stroke-opacity: .5; }
.badge text { font-size: 13px; font-weight: 700; text-anchor: middle; font-variant-numeric: tabular-nums; }
.pin-hit { fill: transparent; stroke: transparent; stroke-width: 1.5; cursor: pointer; outline: none; }
.pin-hit:hover, .pin-hit:focus-visible { stroke: #fff; }
.track:hover .blob, .track.active .blob { fill-opacity: 1; }
.track:hover .name, .track:focus-visible .name { text-decoration: underline; }

.t-title { font-size: 22px; }
.t-title .name { font-weight: 700; }
.t-title.small { font-size: 18.5px; }
.t-meta { font-size: 21.5px; font-weight: 300; }
.t-meta.small { font-size: 17px; }
.m-label { font-size: 31px; }
.m-label .name { font-weight: 700; }
.m-label .m-meta { font-size: 24px; font-weight: 400; fill: #cfcfcf !important; }

.tick { font-size: 10.5px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: #000; stroke-width: 3px; }
.lg-label { font-size: 12px; text-anchor: middle; }
.key { font-size: 22px; font-weight: 300; }
.lg-desc { font-size: 19px; }
.cr { font-size: 21px; }
.cr.link:hover { text-decoration: underline; }

/* ---------- Panel de detalle ---------- */
#panel { position: fixed; top: 0; right: 0; z-index: 10; width: var(--panel-w); max-width: 100vw; height: 100vh; height: 100dvh; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line); padding: 20px 24px 28px;
  transform: translateX(100%); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; }
#panel[aria-hidden="false"] { transform: none; visibility: visible; transition: transform .25s ease; }
.p-head { display: flex; justify-content: space-between; align-items: center; }
.kicker { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--red-hi); font-weight: 700; }
.close { appearance: none; border: 0; background: none; color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer; padding: 4px 8px; margin-right: -8px; }
#panel h2 { margin: 6px 0 12px; font-size: 28px; line-height: 1.1; text-wrap: balance; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 16px; font-size: 14px; }
.meta i { font-style: normal; color: var(--muted); margin-right: 4px; }
.txt { font-size: 15.5px; line-height: 1.55; margin: 0 0 16px; color: #ececec; }
.hidden-track, .note { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.bars { list-style: none; margin: 0 0 20px; padding: 14px 0 0; border-top: 1px solid var(--line); }
.bars li { display: grid; grid-template-columns: 22px 118px 1fr 34px; align-items: center; gap: 8px; font-size: 13px; padding: 5px 0; }
.ic { width: 20px; height: 22px; }
.dist { position: relative; height: 22px; }
.dist > span { position: absolute; top: 50%; }
.d-axis { left: 0; right: 0; height: 1px; background: #2c2c2c; }
.d-range { height: 1px; background: #8a8a8a; }
.d-box { height: 12px; margin-top: -6px; background: #333; border: 1px solid #777; border-radius: 2px; box-sizing: border-box; }
.d-pt { width: 1px; height: 6px; margin-top: -3px; background: #9a9a9a; opacity: .55; }
.d-mean { width: 2px; height: 18px; margin: -9px 0 0 -1px; background: #fff; }
.d-val { width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; background: var(--red-hi); border: 1.5px solid #fff; box-sizing: border-box; }
.dist-legend { margin: -10px 0 20px; font-size: 11.5px; line-height: 1.45; color: #8a8a8a; }
.fv { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.btn { display: inline-block; padding: 10px 16px; border-radius: 999px; background: var(--ink); color: #000; font-weight: 700; font-size: 14px; text-decoration: none; }
.btn:hover { background: #ddd; }
.player { display: flex; align-items: center; gap: 16px; margin: 0 0 16px; }
.play-btn { appearance: none; border: 0; cursor: pointer; font-family: var(--font); min-width: 132px; background: var(--red); color: #fff; }
.play-btn:hover, .play-btn.on { background: var(--red-hi); }
.ext { font-size: 13px; color: var(--muted); }
.ext:hover { color: var(--ink); }
#player-slot { margin: 0 0 18px; }
#player-slot[hidden] { display: none; }
#embed-wrap { height: 80px; border-radius: 12px; overflow: hidden; background: #1c1c1c; }
#embed-wrap iframe { display: block; border: 0; }
.player-note { margin: 8px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.player-note:empty { display: none; }
.keys { margin: 14px 0 0; font-size: 11.5px; color: #777; }
.nav { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.nav button { appearance: none; border: 0; background: none; color: var(--muted); font: 13px var(--font); cursor: pointer; padding: 6px 0; text-align: left; }
.nav button:last-child { text-align: right; }
.nav button:hover { color: var(--ink); }
#panel :focus-visible { outline: 2px solid var(--red-hi); outline-offset: 2px; }

@media (min-width: 1000px) {
  body.panel-open .topbar { padding-right: calc(var(--panel-w) + 16px); }
  body.panel-open #stage { margin-right: var(--panel-w); margin-left: auto; max-width: min(1100px, calc(100vw - var(--panel-w))); }
}

#foot { text-align: center; padding: 18px 16px 40px; font-size: 13px; color: var(--muted); }
#foot .lic { display: block; margin-top: 8px; font-size: 12px; }
.lic { color: var(--muted); }
.intro-more, .intro-keys { color: #8a8a8a; }

/* ---------- Móvil ---------- */
.m-only { display: none; }
@media (max-width: 720px) {
  .d-only { display: none; }
  .is-mobile .stats { font-size: 22px; text-anchor: end; }
  .intro { font-size: 12px; flex: 1 1 0; min-width: 0; }
  .topbar { padding: 8px 12px; }
  .topbar:has(.now:not([hidden])) .intro { display: none; }
  .now { margin-left: 0; flex: 1; }
  .tools-hint { display: none; }
  .intro-keys { display: none; }
  body.scrolled .intro { display: none; }
  body.scrolled .topbar { justify-content: flex-end; }
  .m-only { display: block; padding: 8px 16px 20px; border-top: 1px solid var(--line); }
  .m-only h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--red-hi); margin: 16px 0 10px; }
  .m-only p { font-size: 14px; line-height: 1.5; margin: 0 0 8px; }
  .m-only .note { color: var(--muted); font-size: 13px; }
  .lg { list-style: none; margin: 0; padding: 0; }
  .lg li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; font-size: 14px; line-height: 1.45; padding: 6px 0; }
  .tl { list-style: none; margin: 0; padding: 0; }
  .tl button { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; width: 100%; padding: 11px 0; border: 0; border-bottom: 1px solid var(--line);
    background: none; color: var(--ink); font: 15px var(--font); text-align: left; cursor: pointer; }
  .tl .n, .tl .du { color: var(--muted); font-variant-numeric: tabular-nums; }
  #m-credits { padding-bottom: 48px; }

  #panel { top: auto; bottom: 0; left: 0; width: 100%; height: auto; max-height: 72vh; max-height: 72dvh; border-left: 0; border-top: 1px solid #444;
    border-radius: 14px 14px 0 0; padding: 14px 16px 22px; transform: translateY(100%); box-shadow: 0 -12px 40px rgba(0, 0, 0, .7); }
  #panel h2 { font-size: 23px; }
  .bars li { grid-template-columns: 22px 112px 1fr 34px; }
  body.panel-open #m-credits { padding-bottom: 76vh; }
}

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