:root {
  --bg: #0e1016;
  --panel: #161922;
  --panel2: #1d2130;
  --line: #2a2f40;
  --text: #e8eaf2;
  --muted: #9097ab;
  --accent: #ffb547;
  --lead: #4f8cff;
  --follow: #ff5c8a;
  --bad: #ff6b5b;
  --p-closed: #a78bfa;
  --p-open: #34d399;
  --p-two: #fbbf24;
  --p-cuddle: #f472b6;
  --p-shadow: #60a5fa;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; font-size: 14px; }
button { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: #444b63; background: #242a3b; }
button.primary { background: var(--accent); color: #1b1300; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
input[type=text], input[type=search], select {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus { outline: 2px solid #ffb54755; border-color: var(--accent); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }

/* Header */
.top { display: flex; align-items: center; gap: 18px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.logo { color: var(--accent); }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 5px 14px; }
.seg button.on { background: var(--accent); color: #1b1300; font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; border-color: transparent; color: var(--muted); }
.tabs button.on { color: var(--text); background: var(--panel2); border-color: var(--line); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #1b1300; font-size: 11px; font-weight: 700; }
.badge:empty { display: none; }
.spacer { flex: 1; }
.legend { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.dot.lead { background: var(--lead); }
.dot.follow { background: var(--follow); }

/* Layout */
main { flex: 1; display: flex; min-height: 0; }
#panel { width: 430px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 14px; }
#stageArea { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#stageBox { flex: 1; position: relative; min-height: 0; }
#stageBox canvas { display: block; width: 100%; height: 100%; }

/* Map mode: map fills the area, stage becomes picture-in-picture */
body.map-mode #map { display: block; }
#map { position: absolute; inset: 0 0 auto 0; bottom: var(--transport-h, 130px); overflow: auto; background: var(--bg); z-index: 1; }
body.map-mode #stageBox { position: absolute; right: 16px; bottom: calc(var(--transport-h, 130px) + 16px); width: 380px; height: 280px; z-index: 2; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 10px 40px #000a; flex: none; }
body.map-mode #stageBox .hud-counts, body.map-mode #viewBtns, body.map-mode .hud-pos, body.map-mode .hud-next { display: none; }
body.map-mode .hud-move { font-size: 18px; }
body.map-mode .hud-step { font-size: 10px; }
body.map-mode #transport { margin-top: auto; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hud-step { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.hud-move { font-size: 26px; font-weight: 700; text-shadow: 0 2px 10px #000; }
.hud-move.quiz { color: var(--accent); }
.hud-pos { margin-top: 4px; display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
.hud-next { text-align: right; color: var(--muted); font-size: 13px; background: #0e1016aa; padding: 6px 10px; border-radius: 8px; }
.hud-next:empty { display: none; }
.hud-next b { color: var(--text); display: block; font-size: 15px; }
.hud-bottom { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 44px; }
.hud-counts { display: flex; justify-content: center; gap: 8px; }
.hud-caption { background: #0e1016d9; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 13.5px; line-height: 1.5; max-width: 640px; }
.hud-caption:empty { display: none; }
.hud-caption b { display: inline-block; width: 72px; font-weight: 600; }
.hud-caption b.lead { color: var(--lead); } .hud-caption b.follow { color: var(--follow); }
.hud-caption .sig { color: var(--accent); margin-top: 2px; }
body.map-mode .hud-caption { display: none; }
.ttable { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.trow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px 10px; padding: 5px 6px; border-radius: 6px; background: var(--bg); line-height: 1.35; }
.trow.head { background: transparent; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.trow .tc { font-weight: 700; color: var(--muted); }
.trow .tl { color: #c9d7ff; } .trow .tf { color: #ffd0dc; }
.trow.head .tl, .trow.head .tf { color: var(--muted); }
.trow .ts { grid-column: 2 / -1; color: var(--accent); font-size: 12px; }
.trow.on { background: #ffb54722; outline: 1px solid var(--accent); }
.trow.on .tc { color: var(--accent); }
.vids { margin: 0; padding-left: 18px; line-height: 1.6; font-size: 13px; }
.vids a { color: #8fb4ff; }
.hud-counts span { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 17px; background: #0e1016bb; border: 2px solid var(--line); color: var(--muted); transition: transform .08s, background .08s; }
.hud-counts span.rest { font-size: 12px; font-weight: 500; }
.hud-counts span.on { background: var(--accent); color: #1b1300; border-color: var(--accent); transform: scale(1.12); }
.view-btns { position: absolute; right: 14px; bottom: 12px; display: flex; gap: 4px; }
.view-btns button { font-size: 12px; padding: 4px 9px; background: #161922cc; }

/* Transport */
#transport { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 14px 10px; display: flex; flex-direction: column; gap: 6px; position: relative; z-index: 3; }
#transport .row { display: flex; align-items: center; gap: 10px; }
#transport .opts { flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 13px; }
#scrub { flex: 1; accent-color: var(--accent); }
.icon { width: 36px; height: 34px; padding: 0; display: grid; place-items: center; }
.icon.play { width: 46px; background: var(--accent); color: #1b1300; border-color: var(--accent); font-size: 16px; }
.bpm { display: flex; align-items: center; gap: 8px; }
.bpm input { width: 140px; accent-color: var(--accent); }
.tog { display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.tog input { accent-color: var(--accent); }
.strip { display: flex; gap: 3px; min-height: 26px; }
.strip:empty { display: none; }
.strip button { flex: 1 1 0; min-width: 0; font-size: 11px; padding: 4px 6px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; background: var(--bg); position: relative; }
.strip button.on { border-color: var(--accent); color: var(--accent); }
.strip button.bad { border-color: var(--bad); }
.strip button .fill { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); }

/* Panel content */
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
h2:first-child { margin-top: 0; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.filters input { grid-column: 1 / -1; }
.move-list { display: flex; flex-direction: column; gap: 4px; }
.move-row { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 8px; border: 1px solid transparent; background: var(--panel2); cursor: pointer; }
.move-row:hover { border-color: var(--line); }
.move-row.sel { border-color: var(--accent); }
.move-row .name { flex: 1; min-width: 0; }
.move-row .name small { display: block; margin-top: 3px; }
.move-row .add { opacity: 0; }
.move-row:hover .add { opacity: 1; }
.lvl { display: inline-flex; gap: 2px; }
.lvl i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); display: inline-block; }
.lvl i.f { background: var(--accent); }
.pos { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; border: 1px solid currentColor; white-space: nowrap; }
.pos-closed { color: var(--p-closed); } .pos-open { color: var(--p-open); } .pos-two { color: var(--p-two); }
.pos.cuban { color: #fb923c; margin-left: 6px; vertical-align: middle; }
.pos-cuddle { color: var(--p-cuddle); } .pos-shadow { color: var(--p-shadow); }
.arrow { color: var(--muted); font-size: 11px; }
.flow { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.combo-steps .flow .arrow:last-child { margin-left: 4px; }

.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0; font-size: 19px; }
.card .aka { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card .meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; font-size: 12px; color: var(--muted); }
.card p { margin: 8px 0; line-height: 1.45; }
.card dl { margin: 10px 0; display: grid; grid-template-columns: 62px 1fr; gap: 6px 10px; line-height: 1.4; }
.card dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.card dt.lead { color: var(--lead); } .card dt.follow { color: var(--follow); } .card dt.tip { color: var(--accent); }
.card dd { margin: 0; }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.l2 { border-style: dashed; } .chip.l3 { border-style: dotted; }
.close-x { float: right; background: transparent; border: 0; color: var(--muted); font-size: 18px; padding: 0 4px; }

.combo-head { display: flex; gap: 6px; }
.combo-steps { list-style: none; padding: 0; margin: 10px 0; display: flex; flex-direction: column; gap: 4px; counter-reset: step; }
.combo-steps li { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; counter-increment: step; }
.combo-steps li::before { content: counter(step); width: 20px; color: var(--muted); font-size: 12px; text-align: right; }
.combo-steps li.on { border-color: var(--accent); }
.combo-steps li.bad { border-color: var(--bad); }
.combo-steps .name { flex: 1; min-width: 0; cursor: pointer; }
.combo-steps .name small { display: block; margin-top: 2px; }
.combo-steps .ctrl { display: flex; gap: 2px; }
.combo-steps .ctrl button { padding: 2px 6px; font-size: 11px; background: transparent; border-color: transparent; color: var(--muted); }
.combo-steps .ctrl button:hover { color: var(--text); border-color: var(--line); }
.warn { color: var(--bad); font-size: 12px; display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }
.ends { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.sugg-group { margin-bottom: 8px; }
.sugg-group > div:first-child { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-btns select { width: auto; }
.saved { display: flex; flex-direction: column; gap: 4px; }
.saved-item { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.saved-item .name { flex: 1; min-width: 0; cursor: pointer; }
.saved-item .name small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item.cur { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.kbd { font-family: ui-monospace, monospace; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* Map */
#map svg { display: block; margin: 0 auto; }
#map .pcard rect.box { fill: var(--panel); stroke: var(--line); stroke-width: 1.5; }
#map .pcard text.title { font-weight: 700; font-size: 15px; }
#map .pcard text.sub { fill: var(--muted); font-size: 11px; }
#map .mv { cursor: pointer; }
#map .mv rect { fill: transparent; rx: 6; }
#map .mv:hover rect { fill: #ffffff10; }
#map .mv text { fill: var(--text); font-size: 12.5px; }
#map .mv.l2 text { fill: #cfd3e0; }
#map .mv.l3 text { fill: #b5bbcc; font-style: italic; }
#map .mv.sel rect { fill: #ffb54733; }
#map .mv.sel text { fill: var(--accent); font-weight: 700; }
#map .mv.inc text { text-decoration: underline; text-decoration-color: var(--accent); }
#map .edge path { fill: none; stroke-width: 2; opacity: .75; }
#map .edge .lbl rect.bg { fill: var(--bg); stroke: var(--line); }
#map .help { fill: var(--muted); font-size: 12px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  main { flex-direction: column-reverse; }
  #panel { width: auto; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  .legend { display: none; }
}
