:root {
  --bg: #0e131a;
  --panel: #151c26;
  --panel2: #1b2431;
  --panel3: #222d3d;
  --line: #2a3546;
  --fg: #e7ecf3;
  --muted: #8d99ab;
  --accent: #2fd27a;
  --accent-ink: #062614;
  --blue: #4aa8ff;
  --danger: #ff6b6b;
  --warn: #ffd60a;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 13.5px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
svg { width: 18px; height: 18px; flex: none; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--panel3); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 10px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
button:hover { background: #2a374b; border-color: #3a485e; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--panel3); }
button.danger { color: var(--danger); }
button.small { padding: 4px 8px; }
button.icon { padding: 6px; }
button.round { border-radius: 50%; width: 38px; height: 38px; padding: 0; }
button.toggle.on, .seg button.on { background: #1f4d36; border-color: var(--accent); color: #c9ffe2; }
select, input:not([type=checkbox]):not([type=radio]):not([type=range]), textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; width: 100%; min-width: 0;
}
select:focus, input:focus, textarea:focus { outline: 2px solid #2fd27a55; border-color: var(--accent); }
textarea { resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 18px 0 8px; font-weight: 700; }
.spacer { flex: 1; }
.help { color: var(--muted); font-size: 12px; margin: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ---------- barra superior ---------- */
.topbar {
  height: 54px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: .01em; margin-right: 6px; white-space: nowrap; }
.brand b { color: var(--accent); }
.logo { width: 28px; height: 28px; }
.pb-name { max-width: 260px; font-weight: 650; background: transparent !important; border-color: transparent !important; }
.pb-name:hover { border-color: var(--line) !important; }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }

/* ---------- distribución ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr) 330px; }
.left, .right { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.left { border-right: 1px solid var(--line); }
.right { border-left: 1px solid var(--line); }
.center { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ---------- lista de jugadas ---------- */
.left-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.play-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.left-foot { padding: 8px 12px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.card {
  display: grid; grid-template-columns: 84px 1fr; gap: 8px; padding: 6px; border-radius: var(--radius);
  background: var(--panel2); border: 1px solid transparent; cursor: pointer; position: relative;
}
.card:hover { border-color: var(--line); }
.card.on { border-color: var(--accent); background: #18301f; }
.card.drag-over { border-color: var(--blue); border-style: dashed; }
.card canvas { width: 84px; height: 66px; border-radius: 5px; display: block; background: #1e5a2e; }
.card .meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card .num { font-weight: 800; font-size: 12px; color: var(--accent); }
.card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.tag { font-size: 10px; background: #263246; color: #b9c6d8; border-radius: 4px; padding: 0 5px; }

/* ---------- barra de herramientas ---------- */
.toolbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg.small button { padding: 4px 8px; font-size: 12px; flex: 1; }
.seg.small { display: flex; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.mini { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

/* ---------- escenario ---------- */
.stage { flex: 1; min-height: 0; position: relative; background: #173f22; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.depth-ctl {
  position: absolute; right: 10px; top: 10px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: #cfd8e3;
  background: #0e131acc; border: 1px solid var(--line); border-radius: 8px; padding: 4px 4px 4px 10px;
}
.depth-ctl select { width: auto; padding: 3px 6px; }
.hint {
  position: absolute; left: 12px; bottom: 10px; max-width: calc(100% - 24px); pointer-events: none;
  background: #0e131acc; border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; font-size: 12px; color: #cfd8e3;
}
.hint:empty { display: none; }
.banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); pointer-events: none;
  background: #0e131aee; border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 24px #0007; white-space: nowrap;
}
.banner.good { border-color: var(--accent); color: #b8ffd6; }
.banner.bad { border-color: var(--danger); color: #ffc9c9; }
.banner.td { border-color: var(--warn); color: #fff3b0; }

/* ---------- reproducción ---------- */
.playbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.playbar select { width: auto; max-width: 230px; }
.timeline-wrap { flex: 1; min-width: 160px; position: relative; }
.marks { position: absolute; left: 0; right: 0; top: -6px; height: 6px; pointer-events: none; }
.marks i { position: absolute; top: 0; width: 2px; height: 7px; border-radius: 1px; background: var(--muted); transform: translateX(-1px); }
.marks i.snap { background: var(--blue); }
.marks i.throw { background: var(--warn); }
.marks i.catch, .marks i.handoff { background: var(--accent); }
.marks i.end { background: var(--danger); }
.time { font-variant-numeric: tabular-nums; color: var(--muted); width: 54px; text-align: right; }
.opts { display: flex; gap: 10px; color: var(--muted); font-size: 12px; }
.opts label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---------- panel derecho ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 11px 0; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
.panel { flex: 1; overflow-y: auto; padding: 12px 14px 24px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.field > input, .field > select, .field > textarea { color: var(--fg); font-size: 13.5px; }
.field small { font-size: 11px; opacity: .8; }
.field output { color: var(--accent); font-variant-numeric: tabular-nums; margin-left: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.btnrow.end { justify-content: flex-end; margin-top: 16px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid #0006; }
.swatches button.on { outline: 2px solid var(--fg); outline-offset: 2px; }
.route-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.route-grid button { padding: 6px 4px; font-size: 12px; white-space: normal; line-height: 1.15; min-height: 34px; }
.route-grid button.on { border-color: var(--accent); background: #1f4d36; }
.def-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.def-item { display: grid; grid-template-columns: 30px 1fr; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 7px; background: var(--panel2); cursor: pointer; border: 1px solid transparent; }
.def-item:hover { border-color: var(--line); }
.def-item.on { border-color: var(--accent); }
.def-item .tri { width: 26px; height: 22px; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; background: #20242e; clip-path: polygon(0 0, 100% 0, 50% 100%); padding-bottom: 6px; }
.def-item .txt { font-size: 12px; }
.def-item .txt small { display: block; color: var(--muted); }

/* ---------- diálogos ---------- */
.dlg { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); padding: 0; width: min(560px, 94vw); box-shadow: 0 20px 60px #000a; }
.dlg::backdrop { background: #05080ccc; }
.dlg.wide { width: min(1180px, 96vw); height: min(820px, 94vh); }
.dlg-body { padding: 18px 20px; }
.export { display: grid; grid-template-columns: 340px 1fr; gap: 0; padding: 0; height: 100%; }
.ex-opts { padding: 18px 18px 24px; overflow-y: auto; border-right: 1px solid var(--line); }
.ex-section { margin-bottom: 6px; }
.ex-preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #0b0f14; }
.ex-canvas { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.ex-canvas canvas { background: #fff; box-shadow: 0 8px 30px #000a; }
.ex-nav { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.ex-nav span { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 90px; text-align: center; }
.radio, .check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.radio select { width: auto; flex: 1; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.pick-list { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; margin-top: 4px; background: var(--panel2); }
.pick-list label { display: flex; gap: 8px; align-items: center; padding: 2px 0; cursor: pointer; }
.books-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.book { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel2); border: 1px solid transparent; }
.book.on { border-color: var(--accent); }
.book .t { flex: 1; min-width: 0; }
.book .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book .t small { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: #0e131af2; border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 16px; box-shadow: 0 10px 30px #000a; z-index: 50; font-weight: 600;
}

@media (max-width: 1600px) {
  .toolbar .toggle span { display: none; }
  .toolbar { gap: 5px; }
  .playbar select#selDefSim { max-width: 180px; }
  .opts { gap: 8px; }
}
@media (max-width: 1250px) {
  .topbar button span { display: none; }
  .toolbar button span { display: none; }
  .layout { grid-template-columns: 210px minmax(0, 1fr) 300px; }
}
@media (max-width: 900px) {
  /* en celular la página crece y se desplaza; cada sección tiene su propia altura */
  html, body { height: auto; }
  body { overflow-x: hidden; overflow-y: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 10px; row-gap: 6px; }
  .pb-name { flex: 1 1 120px; min-width: 120px; max-width: none; width: auto; }
  .topbar .spacer { display: none; }
  .layout { flex: none; grid-template-columns: 1fr; grid-template-rows: 240px 75vh auto; }
  .left { border-right: 0; border-bottom: 1px solid var(--line); }
  .right { border-left: 0; border-top: 1px solid var(--line); }
  .right .panel { overflow: visible; }
  .banner { white-space: normal; text-align: center; width: max-content; max-width: calc(100% - 24px); }
  .export { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(240px, 45%); }
  .ex-opts { border-right: 0; border-bottom: 1px solid var(--line); }
  .ex-nav { flex-wrap: wrap; padding: 8px 10px; }
  .ex-nav span { min-width: 0; }
  .dlg.wide { height: 94vh; }
}
