/* ============================================================
   ESPACIO ESCÉNICO · blanco topográfico · bambalinas anidadas
   ============================================================ */
:root {
  --bg: #ffffff;
  --ink: #101010;
  --ink-2: #5d5d5d;
  --ink-3: #9a9a9a;
  --ink-4: #c9c9c9;
  --hair: #e8e8e8;
  --stage-hair: #dedede;
  --stage-bg: #f7f7f6;
  --ambient: rgba(0,0,0,.035);
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 14px 44px -20px rgba(0,0,0,.16);
  --mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Inter", system-ui, "Segoe UI", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--hair); border-radius: 8px;
  padding: 7px 10px; outline: none; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-3); }
::selection { background: #101010; color: #fff; }

/* ---------- botón editor ---------- */
.editor-btn {
  position: fixed; top: 16px; left: 16px; z-index: 40;
  display: flex; align-items: center; gap: 7px;
  padding: 8px 14px 8px 11px; border-radius: 999px;
  background: #fff; border: 1px solid var(--hair);
  font-size: 12px; font-weight: 550; box-shadow: var(--shadow);
  transition: transform .18s, background .18s;
}
.editor-btn:hover { transform: translateY(-1px); }
.editor-open .editor-btn .lbl { display: none; }
.editor-open .editor-btn {
  top: 18px; left: 18px;
  background: var(--ink); color: #fff;
  width: 34px; height: 34px; padding: 0; justify-content: center;
  border-color: var(--ink);
}

/* ---------- layout ---------- */
main { display: grid; height: 100dvh; grid-template-columns: 1.55fr 1fr; }

/* ============ PLANO (look topográfico) ============ */
.theater {
  position: relative;
  display: grid; place-items: center;
  padding: 40px 20% 16px; /* espacio para las bambalinas anidadas */
  min-width: 0; min-height: 0; overflow: hidden;
}
/* retícula topográfica sutil de fondo */
.theater::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--ambient) 1px, transparent 1px),
    linear-gradient(90deg, var(--ambient) 1px, transparent 1px);
  background-size: 56px 56px; background-position: center;
  opacity: .55;
}
/* reglas con ticks y números tipo mapa */
.theater::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(var(--hair) 6px, transparent 6px) top left/6px 100% no-repeat,
    linear-gradient(var(--hair) 6px, transparent 6px) bottom left/100% 6px no-repeat;
  opacity: .9;
}
.ruler-ticks {
  position: absolute; inset: 8px; pointer-events: none; z-index: 1;
}
.ruler-ticks span {
  position: absolute; font: 9px/1 var(--mono); letter-spacing: .1em;
  color: var(--ink-3); text-transform: uppercase;
}
.ruler-ticks span.v { left: 8px; }
.ruler-ticks span.h { bottom: 4px; }

.scene { width: min(100%, 760px); position: relative; z-index: 2; }

.scene-head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px;
  padding: 0 4px 12px;
  padding-right: 260px;
}
.head-kicker {
  font: 10px/1 var(--mono); letter-spacing: .22em; color: var(--ink-3);
  text-transform: uppercase;
}
.scene-title { font-weight: 640; font-size: 15.5px; letter-spacing: -.01em; }
.scene-label { font-size: 11px; color: var(--ink-3); letter-spacing: .14em; text-transform: uppercase; }
.scene-head[hidden] { display: none; }

/* --- wrapper: offbox sobresale arriba-derecha, slots anidados --- */
.stage-wrap { position: relative; }

/* --- fuera de escena: arriba a la derecha, fuera del escenario --- */
.offbox {
  position: absolute; top: -52px; right: 0; width: 240px; z-index: 7;
  min-height: 42px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center;
  border: 1px dashed var(--stage-hair); border-radius: 8px;
  background: #fafafa; padding: 16px 12px 4px;
  transition: border-color .15s, background .15s;
}
.offbox-label {
  position: absolute; top: 3px; left: 10px;
  font: 8.5px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3);
  pointer-events: none;
}
.offbox.drop-target { border-color: var(--ink-3); background: #f2f2f1; }
.offbox::after {
  content: ""; position: absolute; left: 44%; right: 0; top: 100%; height: 20px;
  border-left: 1px dashed var(--stage-hair);
}

/* --- escenario --- */
.stage {
  position: relative;
  aspect-ratio: var(--stage-aspect, 16/9);
  min-width: 0;
  touch-action: none; outline: none;
  border-radius: 8px;
  overflow: visible;
}
.wall {
  position: absolute; inset: 0; border-radius: 8px; overflow: hidden;
  background: var(--stage-bg);
  border: 1px solid var(--stage-hair);
  box-shadow: 0 18px 48px -26px rgba(0,0,0,.16);
}
#theater[data-tex="viñeta"] .wall { background: radial-gradient(90% 120% at 50% 20%, #fff 0%, #f4f4f3 55%, #e7e7e6 100%); }
#theater[data-tex="grano"] .wall::after {
  content: ""; position: absolute; inset: 0; opacity: .45;
  background-image: radial-gradient(rgba(0,0,0,.06) 1px, transparent 1.1px); background-size: 3px 3px;
}

/* rejilla proyectada (picado): JS la dibuja */
.stage .grid {
  position: absolute; inset: 0; pointer-events: none;
  border-radius: 8px; overflow: hidden;
  opacity: 0; transition: opacity .3s;
}
.stage .grid svg { display: block; width: 100%; height: 100%; }
.stage .grid line { stroke: var(--stage-hair); stroke-width: 1; }
.stage.show-grid .grid { opacity: 1; }

/* --- bambalinas anidadas: 3 slots por lado, cada uno pegado al borde exterior anterior --- */
.wing-slot {
  position: absolute; top: -7px; bottom: -7px; width: 5.8%;
  border: 1px solid var(--stage-hair); border-radius: 6px;
  background: linear-gradient(0deg, rgba(255,255,255,.4), rgba(0,0,0,.045));
  transition: background .15s, box-shadow .15s, border-color .15s;
  z-index: 5;
}
.wing-slot.l0 { left: -6.6%;  }
.wing-slot.l1 { left: -13%;  }
.wing-slot.l2 { left: -19.4%; }
.wing-slot.r0 { right: -6.6%; }
.wing-slot.r1 { right: -13%; }
.wing-slot.r2 { right: -19.4%; }
.wing-slot.l0, .wing-slot.l1, .wing-slot.l2 { border-right-color: transparent; }
.wing-slot.r0, .wing-slot.r1, .wing-slot.r2 { border-left-color: transparent; }
/* profundidad: cuanto más lejos del escenario, más sutil */
.wing-slot.l2, .wing-slot.r2 { opacity: .55; }
.wing-slot.l1, .wing-slot.r1 { opacity: .8; }
.wing-slot.drop-target { background: rgba(0,0,0,.07); box-shadow: 0 0 0 1px var(--ink-3); }

.wing-slot .tag {
  position: absolute; top: 1px; left: 50%; transform: translateX(-50%);
  font: 7.5px/1 var(--mono); letter-spacing: .08em; color: var(--ink-3); white-space: nowrap;
}

.stage-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font: 10px/1.4 var(--mono); color: var(--ink-3); letter-spacing: .04em;
  opacity: 0; pointer-events: none; transition: opacity .3s; white-space: nowrap;
}
.stage.populated .stage-hint { display: none; }

/* --- público --- */
.pit {
  position: relative; width: calc(100% + 39.2%); margin-left: -19.6%;
  height: 30px; margin-top: 7px;
  border-top: 1px solid var(--stage-hair); border-radius: 0 0 10px 10px;
  background: repeating-linear-gradient(105deg, transparent 0 10px, rgba(0,0,0,.022) 10px 12px);
}
.pit-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 9px/1 var(--mono); letter-spacing: .32em; color: var(--ink-3);
}

/* ============ PUNTOS ============ */
.dot {
  position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 50%; cursor: grab; touch-action: none; z-index: 6;
  transition: left .5s cubic-bezier(.22,.9,.28,1), top .5s cubic-bezier(.22,.9,.28,1), opacity .4s;
}
.dot:active { cursor: grabbing; }
.dot .core { position: absolute; inset: 0; border-radius: 50%; background: var(--c, #999); box-shadow: 0 3px 10px -3px rgba(0,0,0,.35); border: 1.5px solid #fff; }
.dot .name {
  position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%);
  font: 9.5px/1.2 "Inter"; font-weight: 550; color: var(--ink); white-space: nowrap;
  background: rgba(255,255,255,.92); backdrop-filter: blur(3px);
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--hair);
  pointer-events: none;
}
.dot.speaking .name { border-color: var(--c); font-weight: 650; }
.dot.speaking::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 1.4px solid var(--c); animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(.65); opacity: 1; } 75%, 100% { transform: scale(1.25); opacity: 0; } }

/* puntos en bambalinas: centrados en su slot */
.dot.winged { left: 50%; top: 50%; margin: -14px 0 0 -14px; }
.wing-slot .dot { left: 50% !important; top: 50% !important; margin: -14px 0 0 -14px; }
.dot.offed { position: relative; left: auto !important; top: auto !important; transform: scale(.6); margin: 0; }

/* ============ TEXTO estilo letra ============ */
.text-col {
  position: relative; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--hair);
  padding: 56px 54px 24px 48px;
}
.scroller { flex: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; scrollbar-width: none; }
.scroller::-webkit-scrollbar { display: none; }

.lyr { display: block; width: 100%; text-align: left; padding: 0; }
.lyr-t {
  display: block;
  font-size: 16.5px; line-height: 1.5; letter-spacing: -.012em;
  color: var(--ink-4); opacity: .75;
  margin: 5px 0; white-space: pre-line;
  transition: all .34s cubic-bezier(.25,.8,.3,1);
}
.lyr.now .lyr-t { color: var(--ink); opacity: 1; font-weight: 620; font-size: 20.5px; margin: 10px 0; }
.lyr .who {
  display: inline-flex; align-items: center; gap: 7px;
  font: 10px/1.2 var(--mono); font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); margin-right: 8px; vertical-align: 2px;
}
.lyr.now .who { color: var(--ink); }
.lyr .who::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--wc, #999); }

.nav { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex: none; }
.nav-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--hair); display: grid; place-items: center;
  transition: border-color .15s;
}
.nav-btn:hover:not(:disabled) { border-color: var(--ink); }
.nav-btn:disabled { opacity: .25; }
.counter { font: 11px/1 var(--mono); color: var(--ink-3); font-variant-numeric: tabular-nums; letter-spacing: .06em; }

/* ============ EDITOR ============ */
.scrim { position: fixed; inset: 0; opacity: 0; pointer-events: none; z-index: 30; }
.editor-open .scrim { opacity: 1; pointer-events: none; }
.editor {
  position: fixed; top: 0; bottom: 0; right: 0; z-index: 35;
  width: min(390px, 92vw); background: #fff;
  border-left: 1px solid var(--hair); box-shadow: -24px 0 60px -30px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
}
.editor-open .editor { transform: none; }
.editor { transform: translateX(102%); transition: transform .32s cubic-bezier(.3,.8,.3,1); }
.e-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--hair); flex: none; }
.e-title { font-weight: 620; font-size: 14px; }
.e-sel { font: 10.5px/1.4 var(--mono); color: var(--ink-3); margin-top: 3px; }
.e-close { width: 28px; height: 28px; border-radius: 50%; color: var(--ink-3); font-size: 13px; }
.e-close:hover { background: #f5f5f5; color: var(--ink); }
.e-scroll { overflow-y: auto; padding: 4px 20px 34px; flex: 1; }
.e-sec { padding: 18px 0 6px; border-bottom: 1px solid var(--hair); }
.e-sec:last-child { border-bottom: none; }
.e-label { font: 10px/1.4 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 11px; }
.count { font-size: 10.5px; color: var(--ink-3); text-transform: none; letter-spacing: .02em; }
.e-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.e-row2 label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--ink-2); }
.e-toggles { display: flex; gap: 8px; margin-top: 2px; }
.toggle { flex: 1; text-align: center; padding: 7px 0; border-radius: 999px; border: 1px solid var(--hair); color: var(--ink-3); font-size: 12px; font-weight: 550; transition: all .18s; }
.toggle.on { border-color: var(--ink); color: var(--ink); }

.row-item { display: grid; grid-template-columns: 1fr 26px 24px; gap: 8px; align-items: center; padding: 4px 0; }
.row-item input[type="text"] { border-color: transparent; padding: 5px 8px; }
.row-item input[type="text"]:hover { border-color: var(--hair); }
.row-item input[type="color"] { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1px solid var(--hair); cursor: pointer; }
.arrow-btn { color: var(--ink-3); font-size: 11px; }
.icon-btn { color: var(--ink-3); width: 24px; height: 24px; font-size: 13px; border-radius: 6px; display: grid; place-items: center; justify-self: end; }
.icon-btn:hover { color: #d64541; background: #f7f7f7; }

.line-item { display: grid; grid-template-columns: 20px 1fr 24px; gap: 8px; align-items: start; padding: 9px; margin-bottom: 5px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.line-item:hover { background: #fafafa; }
.line-item.sel { border-color: var(--ink); }
.line-item .num { font: 10.5px/1.6 var(--mono); color: var(--ink-3); font-variant-numeric: tabular-nums; padding-top: 9px; }
.line-item textarea { border-color: transparent; background: none; resize: none; overflow: hidden; padding: 5px 8px; font-size: 13px; line-height: 1.5; }
.line-item textarea:focus { border-color: var(--hair); background: #fff; }
.line-item select { grid-column: 2; font-size: 11.5px; color: var(--ink-2); padding: 4px 8px; }

.e-add { width: 100%; padding: 9px 0; border: 1px dashed var(--hair); border-radius: 10px; color: var(--ink-2); font-size: 12.5px; margin-top: 4px; }
.e-add:hover { border-color: var(--ink-3); color: var(--ink); }
.e-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.e-mini { padding: 8px 10px; border: 1px solid var(--hair); border-radius: 9px; font-size: 11.5px; color: var(--ink-2); text-align: center; }
.e-mini:hover { border-color: var(--ink-3); color: var(--ink); }
.e-mini.warn { color: #d64541; border-color: #f1d5d4; }

@media (max-width: 1200px) {
  .scene { width: min(100%, 640px); }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  main { display: flex; flex-direction: column; height: auto; }
  .text-col { border-left: none; border-top: 1px solid var(--hair); padding: 40px 26px 48px; }
  .theater { padding: 60px 46px 22px; }
  .wing-slot { display: none; }
  .offbox { position: static; width: 100%; margin-bottom: 8px; }
  .offbox::after { display: none; }
  .pit { width: 100%; margin-left: 0; }
}
