:root {
  --blue: #0b5f8a;
  --blue-d: #084564;
  --orange: #d97a1a;
  --ink: #1d2733;
  --muted: #637083;
  --line: #dde3ea;
  --bg: #f3f6f9;
  --panel: #ffffff;
  --ok: #2bb673;
  --warn: #f0821a;
  --pos: #d9382f;
  --neg: #3d7bd9;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }

/* ───────── cabecera ───────── */
.top {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 17px; color: var(--blue-d); letter-spacing: .1px; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.joints { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.joints button {
  border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: 999px;
  color: var(--ink); font-weight: 600; transition: .15s;
}
.joints button:hover { border-color: var(--blue); }
.joints button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.top-actions { display: flex; gap: 6px; }
.ghost { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; color: var(--blue-d); font-weight: 600; }
.ghost:hover { border-color: var(--blue); }

/* ───────── layout ───────── */
.layout { flex: 1; align-items: start; display: grid; grid-template-columns: 340px minmax(0, 1fr) 340px; gap: 12px; padding: 12px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow: auto; max-height: calc(100vh - 128px); }
.stage {
  position: relative; border-radius: 12px; overflow: hidden; height: calc(100vh - 128px); min-height: 560px;
  background: radial-gradient(ellipse at 50% 35%, #ffffff 0%, #e8eef4 70%, #dbe4ec 100%);
  border: 1px solid var(--line);
}
#c { width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-size: 12px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,.88); border: 1px solid var(--line); color: var(--ink);
}
.lbl.deg { font-size: 15px; font-weight: 700; border-color: var(--blue); color: var(--blue-d); }
.lbl.deg.out { border-color: var(--warn); color: #b25a06; }
.lbl.axis { color: #b01f1f; border-color: #e7b3b3; }
.lbl.plane { color: #245fd0; border-color: #b9ccf3; }
.lbl.bone { font-weight: 500; color: #5b5545; background: rgba(250,246,236,.9); }

.views { position: absolute; top: 10px; left: 10px; display: flex; gap: 4px; }
.views button {
  border: 1px solid var(--line); background: rgba(255,255,255,.92); border-radius: 8px; padding: 4px 9px; font-size: 12px; color: var(--ink);
}
.views button:hover { border-color: var(--blue); }
.hud {
  position: absolute; top: 10px; right: 10px; text-align: right; background: rgba(255,255,255,.92); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; min-width: 160px;
}
.hud .big { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--blue-d); }
.hud .big.out { color: #b25a06; }
.hud .small { font-size: 12px; color: var(--muted); }
.hud .rhythm { margin-top: 4px; font-size: 12px; color: var(--ink); }
.toolbar {
  position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.toolbar .sep { width: 1px; height: 22px; background: var(--line); }
.toolbar label { display: flex; align-items: center; gap: 5px; font-size: 12.5px; user-select: none; cursor: pointer; }
.primary, .secondary { border-radius: 8px; padding: 7px 12px; font-weight: 600; border: 1px solid var(--blue); }
.primary { background: var(--blue); color: #fff; }
.primary:hover { background: var(--blue-d); }
.primary.on { background: var(--orange); border-color: var(--orange); }
.secondary { background: #fff; color: var(--blue-d); }
.secondary:hover { background: #eef5fa; }
.secondary.on { background: var(--orange); border-color: var(--orange); color: #fff; }

/* ───────── panel izquierdo ───────── */
.intro { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.intro b { color: var(--ink); }
.dof { display: inline-block; font-size: 11px; font-weight: 700; background: #e3f1fa; color: var(--blue-d); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.finger-bar { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.finger-bar span { font-size: 12px; color: var(--muted); align-self: center; margin-right: 2px; }
.finger-bar button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.finger-bar button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.presets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.presets .t { width: 100%; font-size: 12px; color: var(--muted); }
.presets button { border: 1px solid var(--orange); background: #fff; color: #9a5208; border-radius: 8px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; }
.presets button:hover { background: #fff5ea; }

.move { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; margin-bottom: 8px; cursor: pointer; background: #fff; transition: border-color .15s, box-shadow .15s; }
.move:hover { border-color: #9fc3d8; }
.move.sel { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11, 95, 138, .15); }
.move .mh { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.move .mn { font-weight: 650; font-size: 13.5px; }
.move .mv { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--blue-d); font-size: 13px; text-align: right; }
.move .mv.out { color: #b25a06; }
.move .mv small { font-weight: 500; color: var(--muted); }
.slidewrap { position: relative; margin-top: 8px; }
.slidewrap .track { position: absolute; left: 0; right: 0; top: 50%; height: 8px; margin-top: -4px; border-radius: 4px; pointer-events: none; }
.slidewrap .zero { position: absolute; top: 50%; width: 2px; height: 16px; margin-top: -8px; background: #35424f; pointer-events: none; opacity: .7; border-radius: 1px; }
.slidewrap input[type=range] { position: relative; width: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; height: 22px; }
.slidewrap input[type=range]::-webkit-slider-runnable-track { background: transparent; height: 22px; }
.slidewrap input[type=range]::-moz-range-track { background: transparent; height: 22px; }
.slidewrap input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: 2px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.slidewrap input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 1px; }
.legend { font-size: 11.5px; color: var(--muted); margin: 8px 2px 0; display: flex; gap: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ───────── panel derecho ───────── */
#info h2 { margin: 0 0 2px; font-size: 17px; color: var(--blue-d); }
#info .where { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; background: #f6f9fc; border-radius: 10px; padding: 9px 11px; margin-bottom: 10px; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }
#info h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 12px 0 5px; }
#info p { margin: 0 0 6px; }
.musc { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.chip { font-size: 12.5px; border-radius: 999px; padding: 2px 10px; border: 1px solid var(--line); background: #fff; cursor: default; }
.chip.pos { border-color: #efb6b2; background: #fdf1f0; }
.chip.neg { border-color: #b6cdf0; background: #eff5fd; }
.chip.nomesh { opacity: .75; border-style: dashed; }
.chip:hover { outline: 2px solid #ffc400; }
.mside { font-size: 12.5px; font-weight: 700; margin: 6px 0 3px; }
.mside.pos { color: var(--pos); }
.mside.neg { color: var(--neg); }
.phases { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.phases div { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.phases div:last-child { border-bottom: 0; }
.phases div.cur { background: #fff3e4; font-weight: 600; }
.note { font-size: 12px; color: var(--muted); background: #fafbfc; border-left: 3px solid #cfd8e1; padding: 6px 9px; border-radius: 4px; margin-top: 8px; }

.foot { padding: 8px 18px 14px; font-size: 11.5px; color: var(--muted); text-align: center; }

/* ───────── modal ───────── */
.modal { position: fixed; inset: 0; background: rgba(15, 25, 35, .5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 14px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; padding: 20px 22px; }
.modal-card h2 { margin: 0 0 8px; color: var(--blue-d); }
.modal-card .opts { display: grid; gap: 8px; margin: 12px 0; }
.modal-card .opts button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 12px; }
.modal-card .opts button:hover:not(:disabled) { border-color: var(--blue); background: #f2f8fc; }
.modal-card .opts button.right { background: #e4f6ec; border-color: var(--ok); }
.modal-card .opts button.wrong { background: #fdecea; border-color: #d9382f; }
.modal-card .why { background: #f6f9fc; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 10px; }
.modal-card .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-card .bar { height: 6px; background: #e8eef4; border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
.modal-card .bar i { display: block; height: 100%; background: var(--blue); }
.modal-card ul { padding-left: 18px; margin: 6px 0; }
.modal-card kbd { background: #eef2f6; border: 1px solid #d3dbe3; border-radius: 4px; padding: 0 5px; font-size: 12px; }

/* ───────── responsive ───────── */
@media (max-width: 1150px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .panel.right { grid-column: 1 / -1; max-height: none; }
}
.opts { display: contents; }
.opts-btn { display: none; }

@media (max-width: 760px) {
  .top { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { flex: 1; min-width: 0; }
  .brand h1 { font-size: 15px; }
  .brand p { display: none; }
  .top-actions { order: 2; }
  .joints { order: 3; margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .joints button { white-space: nowrap; padding: 6px 12px; font-size: 13px; }
  .layout { display: flex; flex-direction: column; flex: none; padding: 0 0 12px; }
  .stage {
    order: -1; position: sticky; top: 0; z-index: 10; height: 46vh; min-height: 270px; max-height: 430px;
    border-radius: 0 0 14px 14px; border-top: 0; box-shadow: 0 6px 16px rgba(20, 40, 60, .18);
  }
  .panel { max-height: none; margin: 12px 12px 0; flex-shrink: 0; overflow: visible; }
  .toolbar .lg { display: none; }
  .views { top: 6px; left: 6px; gap: 3px; }
  .views button { padding: 3px 7px; font-size: 11px; }
  .hud { top: 6px; right: 6px; min-width: 0; padding: 4px 9px; }
  .hud .big { font-size: 20px; }
  .hud .small { font-size: 11px; }
  .hud .rhythm { display: none; }
  .lbl { font-size: 11px; padding: 1px 5px; }
  .lbl.deg { font-size: 13px; }
  .toolbar { left: 6px; right: 6px; bottom: 6px; padding: 5px 6px; gap: 6px; flex-wrap: nowrap; }
  .toolbar .primary, .toolbar .secondary { padding: 6px 9px; font-size: 12px; white-space: nowrap; }
  .opts-btn { display: inline-block; margin-left: auto; }
  .opts {
    display: none; position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
    background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
    grid-template-columns: 1fr 1fr; gap: 8px 12px;
  }
  .toolbar.show-opts .opts { display: grid; }
  .opts .sep { display: none; }
  .move { padding: 11px 12px; }
  .slidewrap input[type=range] { height: 30px; }
  .slidewrap input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: 2px; }
  .slidewrap input[type=range]::-moz-range-thumb { width: 20px; height: 20px; }
  .foot { padding: 8px 12px 16px; }
}
