:root {
  --bg: #070a0e;
  --panel: rgba(16, 22, 30, 0.92);
  --panel-solid: #10161e;
  --card: #151d27;
  --card-2: #1b2531;
  --line: #243142;
  --text: #e7edf4;
  --muted: #8d9bad;
  --accent: #38bdf8;
  --accent-2: #7dd3fc;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #ff4d6d;
  --hot: #ff7a2f;
  --radius: 12px;
  --hud-inset: 12px;
  --srow-label: 30px;
  --srow-gap: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0.35em 0; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: #0b1016;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { font-size: 1.02rem; letter-spacing: 0.01em; }
.mov-picker { display: flex; align-items: center; gap: 8px; }
.mov-picker select { min-width: 240px; font-weight: 600; }
select {
  background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px;
}
.icon-btn { width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); font-size: 1.1rem; line-height: 1; }
.icon-btn:hover, .btn:hover { border-color: var(--accent); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--card); padding: 6px 12px; border-radius: 9px; font-size: 0.84rem; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 2px 8px; font-size: 0.76rem; border-radius: 7px; }

/* ---------- distribución ---------- */
.shell { flex: 1; display: grid; grid-template-columns: 320px minmax(0, 1fr) 380px; min-height: 0; }
.panel { background: var(--panel-solid); overflow-y: auto; min-height: 0; }
.panel.left { border-right: 1px solid var(--line); padding: 12px; }
.panel.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.disclaimer { margin: 0; padding: 8px 16px; font-size: 0.72rem; color: var(--muted); border-top: 1px solid var(--line); background: #0b1016; }
/* ---------- escenario 3D ---------- */
.stage { position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 35%, #1a2532 0%, #0d131b 55%, #06090d 100%); min-height: 0; }
.viewer { position: absolute; inset: 0; cursor: grab; }
.viewer:active { cursor: grabbing; }
.hud { position: absolute; z-index: 3; }
.hud-tl { top: var(--hud-inset); left: var(--hud-inset); max-width: min(380px, 60%); pointer-events: none; }
.hud-tr { top: var(--hud-inset); right: var(--hud-inset); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.hud-bottom {
  left: 50%; bottom: var(--hud-inset); transform: translateX(-50%); width: min(640px, calc(100% - 2 * var(--hud-inset)));
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 14px;
  background: rgba(10, 15, 21, 0.72); border: 1px solid var(--line); backdrop-filter: blur(8px);
}
.hud-bottom input[type="range"] { flex: 1; accent-color: var(--accent); }
.hud-legend { left: var(--hud-inset); bottom: 76px; display: flex; flex-direction: column; gap: 4px; font-size: 0.74rem; color: var(--muted); pointer-events: none; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.lg.bone { background: #e2d3b4; }
.lg.ghost { background: transparent; border: 2px solid #4fb3ff; }
.lg.hot { background: var(--hot); }
.lg.arc { background: var(--warn); border-radius: 2px; }
.lg.arcn { background: transparent; border: 2px solid #9fd8ff; border-radius: 2px; margin-left: 2px; }
.play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #04131d; font-weight: 600; font-size: 0.8rem; }
.phase { min-width: 120px; font-size: 0.82rem; color: var(--accent-2); font-weight: 600; text-align: right; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: rgba(10, 15, 21, 0.72); border: 1px solid var(--line); backdrop-filter: blur(8px); }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.seg button.on { background: var(--card-2); color: var(--text); }
.seg.small button { padding: 4px 8px; font-size: 0.74rem; }
.toggles { display: flex; gap: 10px; padding: 6px 10px; border-radius: 10px; background: rgba(10, 15, 21, 0.72); border: 1px solid var(--line); font-size: 0.8rem; }
.toggles label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; color: var(--muted); }
.toggles input { accent-color: var(--accent); }

.score-card { padding: 12px 16px; border-radius: 14px; background: rgba(10, 15, 21, 0.72); border: 1px solid var(--line); backdrop-filter: blur(8px); }
.score-card h2 { font-size: 1.15rem; }
.score-row { display: flex; align-items: baseline; gap: 12px; margin-top: 4px; }
.big { font-size: 2.3rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.score-card .top-issue { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }

.hud-spine { right: var(--hud-inset); top: 50%; transform: translateY(-50%); width: 132px; padding: 8px; border-radius: 12px; background: rgba(10, 15, 21, 0.72); border: 1px solid var(--line); backdrop-filter: blur(8px); font-size: 0.66rem; }
.hud-spine h4 { font-size: 0.7rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; letter-spacing: 0.03em; text-transform: uppercase; }
.sp-row { display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 4px; height: 9px; }
.sp-row b { font-weight: 600; color: var(--muted); text-align: right; font-size: 0.6rem; }
.sp-bar { position: relative; height: 5px; background: #1a2430; border-radius: 3px; }
.sp-bar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: #3a4a5c; }
.sp-bar span { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.sp-row.gap { height: 4px; }
.sp-legend { display: flex; justify-content: space-between; color: var(--muted); margin-top: 4px; }

.tooltip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 260px;
  padding: 8px 10px; border-radius: 10px; background: rgba(6, 10, 14, 0.92); border: 1px solid var(--line);
  font-size: 0.8rem; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.tooltip b { display: block; font-size: 0.86rem; }
.loading[hidden] { display: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 4; pointer-events: none; }

/* ---------- panel de movilidad ---------- */
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 4px 0 12px; }
.panel-head h2 { font-size: 1rem; }
.group { margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.group > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; font-weight: 700; font-size: 0.88rem; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: "▾"; color: var(--muted); transition: transform 150ms ease-out; }
.group:not([open]) > summary::after { transform: rotate(-90deg); }
.dots { display: inline-flex; gap: 4px; margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.joint { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.joint.active { background: #18222e; box-shadow: inset 3px 0 0 var(--accent); }
.j-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.j-head h4 { font-size: 0.84rem; font-weight: 600; }
.j-ref { font-size: 0.72rem; color: var(--muted); }
.srow { display: grid; grid-template-columns: var(--srow-label) minmax(0, 1fr) 44px; align-items: center; gap: var(--srow-gap); }
.srow .sd { font-size: 0.7rem; color: var(--muted); font-weight: 700; }
.srow output { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.86rem; }
.srow input { width: 100%; accent-color: var(--accent); }
.j-tools { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 0.72rem; color: var(--muted); }
.j-tools label { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.j-tools button { border: 0; background: none; color: var(--accent); padding: 0; font-size: 0.72rem; }
.j-test { font-size: 0.76rem; color: var(--muted); margin-top: 8px; }
.j-extra { font-size: 0.7rem; color: var(--muted); margin-left: calc(var(--srow-label) + var(--srow-gap)); }
.badge { font-size: 0.66rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: rgba(52, 211, 153, 0.14); color: var(--ok); }
.badge.warn { background: rgba(251, 191, 36, 0.14); color: var(--warn); }
.badge.bad { background: rgba(255, 77, 109, 0.14); color: var(--bad); }

/* ---------- panel derecho ---------- */
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel-solid); z-index: 2; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 4px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; font-size: 0.84rem; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { padding: 12px; display: grid; gap: 12px; align-content: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h3 { font-size: 0.95rem; }
.issue { cursor: pointer; transition: border-color 150ms ease-out; }
.issue:hover { border-color: #35506b; }
.issue.focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.issue-head { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 12px; align-items: center; }
.issue-head h4 { font-size: 0.88rem; }
.bar { height: 5px; background: #1a2430; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.bar.ok > span { background: var(--ok); } .bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); } .bar.accent > span { background: var(--accent); }
.det { font-size: 0.8rem; color: var(--muted); }
.tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); border: 0; }
button.tag:hover { color: var(--accent-2); }
.tag.cause { color: var(--accent-2); text-align: left; }
.scale { font-size: 0.8rem; margin-top: 8px; padding: 6px 10px; border-radius: 8px; background: rgba(56, 189, 248, 0.08); border: 1px solid rgba(56, 189, 248, 0.18); }
.scale b { color: var(--accent-2); }
.ok-note { padding: 12px; border-radius: 10px; background: rgba(52, 211, 153, 0.1); color: var(--ok); font-weight: 600; font-size: 0.86rem; }

.mov-grid { display: grid; gap: 8px; }
.mov-cat { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 8px 0 4px; }
.mrow { display: grid; grid-template-columns: 22px minmax(0, 1fr) 38px; gap: 8px; align-items: center; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); text-align: left; width: 100%; }
.mrow:hover { border-color: #35506b; }
.mrow.on { border-color: var(--accent); }
.mrow .nm { font-weight: 600; font-size: 0.86rem; }
.mrow .sc { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.star { border: 0; background: none; padding: 0; color: #3a4a5c; font-size: 1.05rem; line-height: 1; }
.star[aria-pressed="true"] { color: #f5a524; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 1px solid var(--line); background: var(--card-2); border-radius: 99px; padding: 4px 10px; font-size: 0.78rem; color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--bad); color: #ffd0d8; background: rgba(255, 77, 109, 0.16); }
.chip .heat { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--bad); vertical-align: 0; }
.cause-row { display: grid; grid-template-columns: minmax(0, 1fr) 80px; gap: 4px 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.cause-row:first-of-type { border-top: 0; }
.cause-row ul { grid-column: 1 / -1; margin: 0; padding-left: 16px; font-size: 0.78rem; color: var(--muted); }

.prio { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 4px 12px; }
.rank { font-size: 1.35rem; font-weight: 600; color: var(--accent); }
.gains { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.8rem; margin: 4px 0; }
.gains b { color: var(--text); }
.drills { margin: 8px 0 0; padding-left: 16px; font-size: 0.8rem; color: var(--muted); }
details summary { cursor: pointer; color: var(--accent-2); font-size: 0.78rem; font-weight: 600; margin-top: 8px; }

/* ---------- responsive (al final para que prevalezca sobre las reglas base) ---------- */
@media (max-width: 1150px) {
  .shell { flex: none; grid-template-columns: 290px minmax(0, 1fr); height: auto; }
  .panel.left { max-height: 640px; }
  .stage { height: 640px; }
  .panel.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  :root { --hud-inset: 8px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .mov-picker { order: 3; flex: 1 1 100%; }
  .mov-picker select { min-width: 0; flex: 1; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .stage { order: -1; height: 74vh; min-height: 440px; }
  .panel.left { border-right: 0; max-height: none; }
  .hud-spine, .hud-legend { display: none; }
  .hud-tl { max-width: calc(100% - 2 * var(--hud-inset)); }
  .score-card { padding: 8px 12px; }
  .score-card h2 { font-size: 0.95rem; }
  .big { font-size: 1.7rem; }
  .hud-tr { top: auto; bottom: 64px; left: var(--hud-inset); align-items: center; }
  .seg button { padding: 4px 8px; font-size: 0.74rem; }
  .toggles { font-size: 0.74rem; gap: 8px; }
  .hud-bottom { padding: 6px 8px; gap: 8px; }
  .phase { min-width: 0; font-size: 0.74rem; }
}
