:root {
  --bg: #141a22; --bg2: #1b232e; --bg3: #232d3a; --line: #2e3a4a; --tx: #e6edf5; --tx2: #9aabbf;
  --ac: #ff7a1a; --ac2: #23c4e8; --ok: #2ecc71; --warn: #f1c40f; --err: #ff4d4d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--tx); font: 13px/1.35 "Segoe UI", system-ui, sans-serif; overflow: hidden; }
button, select, input { font: inherit; color: var(--tx); }
button { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--ac2); }
button:disabled { opacity: .45; cursor: default; }
select, input { background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
code { background: #0e1319; padding: 1px 4px; border-radius: 3px; color: #ffd28a; }

#top { height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 12px; background: #0f141b; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand .logo { font-size: 20px; color: var(--ac); }
.brand b { letter-spacing: 1.5px; font-size: 15px; }
.brand .sub { color: var(--tx2); font-size: 12px; }
.modes { display: flex; background: var(--bg3); border-radius: 8px; padding: 2px; border: 1px solid var(--line); }
.modes button { border: 0; background: transparent; padding: 5px 12px; }
.modes button.on { background: var(--ac); color: #111; font-weight: 600; }
.grp { display: flex; gap: 6px; align-items: center; }
.grp.right { margin-left: auto; }
button.run { background: #1d7a3c; border-color: #2a9a50; font-weight: 600; }
button.run.active { background: #0f4d24; }
button.stop { background: #7a1d1d; border-color: #9a2a2a; }

main { position: absolute; top: 48px; bottom: 26px; left: 0; right: 0; display: flex; }
#palette { width: 200px; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.ptitle { padding: 8px 10px; font-weight: 600; border-bottom: 1px solid var(--line); }
.ptitle small { display: block; font-weight: 400; color: var(--tx2); font-size: 11px; }
#plist { flex: 1; overflow-y: auto; padding: 4px 6px; }
.pcat { color: var(--ac); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 10px 4px 4px; }
.pitem { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.pitem:hover { background: var(--bg3); border-color: var(--line); }
.pitem.sel { border-color: var(--ac); background: #2b2218; }
.pitem .ic { width: 22px; text-align: center; font-size: 15px; }
.pfoot { padding: 8px 10px; font-size: 11px; color: var(--tx2); border-top: 1px solid var(--line); display: grid; gap: 4px; }

#stage { flex: 1; position: relative; overflow: hidden; background: #10161d; }
#cv { width: 100%; height: 100%; display: block; cursor: default; user-select: none; }
#cv.panning { cursor: grabbing; }
#cv.placing, #cv.wiring { cursor: crosshair; }
.part { cursor: move; }
.part.sel > .selbox { display: block; }
.selbox { display: none; fill: none; stroke: var(--ac2); stroke-width: 1.5; stroke-dasharray: 5 3; pointer-events: none; }
.part.err > .errbox { display: block; }
.errbox { display: none; fill: none; stroke: var(--err); stroke-width: 2; pointer-events: none; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.pin { fill: #d4a017; stroke: #6b5000; stroke-width: .6; cursor: crosshair; }
.pin:hover, .pin.hl { fill: #36f27a; stroke: #0a5; }
.hole { fill: #3c3c3c; cursor: crosshair; }
.hole:hover, .hole.hl { fill: #36f27a; }
.wire { fill: none; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; cursor: pointer; }
.wire.sel { stroke-dasharray: 6 4; }
.wirehit { fill: none; stroke: transparent; stroke-width: 10; cursor: pointer; }
.wend { pointer-events: none; }
.ghost { opacity: .55; pointer-events: none; }
.netdot { fill: none; stroke: #36f27a; stroke-width: 1.5; pointer-events: none; }

#tip { position: absolute; pointer-events: none; background: #0b0f14ee; border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; font-size: 12px; display: none; white-space: nowrap; z-index: 5; }
#tip b { color: var(--ac2); }
#hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: #2b2218ee; border: 1px solid var(--ac); color: #ffd8b5; padding: 5px 12px; border-radius: 16px; display: none; }
#zoom { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
#zoom button { width: 32px; height: 32px; padding: 0; font-size: 16px; }
#wcolors { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; background: #0b0f14cc; padding: 5px; border-radius: 8px; }
#wcolors span { width: 18px; height: 18px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
#wcolors span.on { border-color: #fff; }

#side { width: 430px; background: var(--bg2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: #10161d; }
.tabs button { border: 0; border-radius: 0; background: transparent; padding: 7px 12px; color: var(--tx2); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--tx); border-bottom-color: var(--ac); }
#wcount { background: var(--err); color: #fff; border-radius: 8px; padding: 0 6px; font-size: 11px; display: none; }
.pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.pane.on { display: flex; }
.pane2 { display: none; height: 210px; flex-direction: column; }
.pane2.on { display: flex; }
.ftabs { display: flex; gap: 2px; padding: 4px 6px 0; background: #10161d; }
.ftabs button { border-radius: 6px 6px 0 0; border-bottom: 0; padding: 4px 10px; font-size: 12px; background: #161d26; color: var(--tx2); }
.ftabs button.on { background: #0d1117; color: var(--tx); }
#codeErr { display: none; background: #4a1414; color: #ffd0d0; padding: 6px 10px; border-left: 4px solid var(--err); font-size: 12.5px; }
#codeErr.on { display: block; }

/* editor de código */
#editor { flex: 1; position: relative; min-height: 0; background: #0d1117; overflow: hidden; }
.ce { position: absolute; inset: 0; overflow: auto; font: 13px/19px Consolas, "Cascadia Code", monospace; }
.ce-inner { position: relative; min-height: 100%; }
.ce-gutter { position: absolute; left: 0; top: 0; width: 40px; padding: 6px 6px 40px 0; text-align: right; color: #4b5a6d; background: #0d1117; border-right: 1px solid #1d2632; user-select: none; }
.ce-gutter div.err { background: #6b1a1a; color: #fff; }
.ce-pre, .ce-ta { margin: 0; padding: 6px 10px 40px 50px; font: inherit; white-space: pre; tab-size: 2; border: 0; outline: 0; }
.ce-pre { position: absolute; inset: 0 auto auto 0; min-width: 100%; color: #d4d4d4; pointer-events: none; }
.ce-ta { position: relative; display: block; width: 100%; min-height: 100%; background: transparent; color: transparent; caret-color: #fff; resize: none; overflow: hidden; }
.ce-ta::selection { background: #264f78; color: transparent; }
.ce-ta[readonly] { caret-color: transparent; }
.ce-pre .errline { background: #4a141480; display: inline-block; width: 100%; }
.tk-k { color: #569cd6; } .tk-t { color: #4ec9b0; } .tk-s { color: #ce9178; } .tk-n { color: #b5cea8; } .tk-c { color: #6a9955; font-style: italic; }
.tk-p { color: #c586c0; } .tk-f { color: #dcdcaa; } .tk-x { color: #9cdcfe; }

/* inspector */
#inspector { padding: 12px; overflow-y: auto; }
#inspector.empty { color: var(--tx2); }
.ihead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ihead .ic { font-size: 26px; }
.ihead h3 { margin: 0; font-size: 16px; }
.ihead small { color: var(--tx2); }
.info { background: #18222e; border-left: 3px solid var(--ac2); padding: 8px 10px; border-radius: 4px; margin: 8px 0; }
body.mode-aula .info { font-size: 14.5px; line-height: 1.5; border-left-color: var(--ac); }
.prop { margin: 10px 0; display: grid; gap: 4px; }
.prop label { color: var(--tx2); font-size: 12px; }
.prop input[type=range] { width: 100%; accent-color: var(--ac); }
.prop.bool { display: flex; align-items: center; gap: 8px; }
.prop.bool label { color: var(--tx); font-size: 13px; }
table.meas { width: 100%; border-collapse: collapse; margin-top: 8px; font-family: Consolas, monospace; font-size: 12px; }
table.meas td { padding: 3px 6px; border-bottom: 1px solid #243041; }
table.meas td:first-child { color: var(--tx2); width: 38%; }
.ibtns { display: flex; gap: 6px; margin-top: 12px; }
.pinlist { margin-top: 10px; font-size: 12px; color: var(--tx2); columns: 2; }
h4 { margin: 14px 0 4px; font-size: 12px; color: var(--ac); text-transform: uppercase; letter-spacing: 1px; }

/* avisos */
#warnList { padding: 8px; overflow-y: auto; display: grid; gap: 6px; }
.wi { padding: 8px 10px; border-radius: 6px; background: #1d2633; border-left: 4px solid var(--warn); cursor: pointer; }
.wi.err { border-left-color: var(--err); background: #2a1a1d; }
.wi.info { border-left-color: var(--ac2); }
body.mode-aula .wi { font-size: 14px; }
.wnone { color: var(--ok); padding: 10px; }

/* serial / BT */
#serialOut, #btOut { flex: 1; margin: 0; padding: 6px 10px; background: #0a0e13; color: #b8f5c8; font: 12px/1.4 Consolas, monospace; overflow-y: auto; white-space: pre-wrap; }
#serialOut .sys { color: #ffcf6b; }
.sin { display: flex; gap: 4px; padding: 4px; }
.sin input { flex: 1; }
#btState { padding: 6px 10px; font-size: 12px; color: var(--tx2); }
#btState.on { color: var(--ok); }
.pad { display: grid; grid-template-columns: repeat(3, 52px); gap: 4px; justify-content: center; padding: 4px; }
.pad button { height: 36px; font-size: 16px; padding: 0; line-height: 1; }
.pad button small { display: block; font-size: 9px; color: var(--tx2); }
.padx { display: flex; gap: 6px; padding: 4px 10px; }
.padx input { flex: 1; }
#btOut { max-height: 50px; }

#status { position: absolute; bottom: 0; left: 0; right: 0; height: 26px; background: #0f141b; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; font-size: 12px; color: var(--tx2); }
#status .err { color: var(--err); }
#status .ok { color: var(--ok); }

/* modo aula: letras un poco más grandes */
body.mode-aula #plist { font-size: 14px; }
body.mode-taller .modes button[data-mode=taller] { background: var(--ac2); }

#top button, .tabs button, #viewSwitch button, .ibtns button, .padx button { display: inline-flex; align-items: center; white-space: nowrap; }
#selEx { max-width: 200px; }
#top { overflow: hidden; }
/* humo de piezas quemadas */
.part.boom { animation: boom .9s ease-out; }
@keyframes boom { 0%, 40% { filter: drop-shadow(0 0 14px #ff6b2a) brightness(1.8); } 100% { filter: none; } }
.smk { opacity: 0; transform-box: fill-box; transform-origin: center; animation: smoke 1.8s ease-out infinite; pointer-events: none; }
@keyframes smoke { 0% { opacity: .8; transform: translate(0, 0) scale(.6); } 100% { opacity: 0; transform: translate(6px, -34px) scale(2.2); } }
/* soltar una pieza en el lienzo: la pieza aparece y un anillo se expande */
.part.dropin { animation: dropIn .32s ease-out; }
@keyframes dropIn { from { opacity: 0; } to { opacity: 1; } }
.part.dragging { filter: drop-shadow(0 3px 7px #000a); }
.dropflash { fill: none; stroke: #2fd36b; stroke-width: 2.5; transform-box: fill-box; transform-origin: center; animation: dropFlash .45s ease-out forwards; pointer-events: none; }
@keyframes dropFlash { 0% { transform: scale(.5); opacity: .85; } 100% { transform: scale(3.6); opacity: 0; } }
/* marquesina: seleccionar varias piezas arrastrando el cursor */
#marqbox { position: absolute; display: none; z-index: 7; border: 1.5px solid #23c4e8; background: #23c4e833; border-radius: 3px; pointer-events: none; }
/* selección bien visible */
.selbox { stroke: #23c4e8; stroke-width: 2.5; stroke-dasharray: 7 4; filter: drop-shadow(0 0 4px #23c4e8); animation: selDash 0.8s linear infinite; }
.part.sel > .selbox { display: block; }
@keyframes selDash { to { stroke-dashoffset: -22; } }
/* modo Interactuar */
#viewSwitch #bMode.on { background: #2fd36b; color: #062a12; font-weight: 600; }
body.interact #cv .part { cursor: pointer; }
body.interact #cv .pin { cursor: pointer; }
/* Selector grande de modo: Editar / Interactuar (arriba al centro del lienzo) */
#modeSw { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; gap: 4px; z-index: 6; background: #0b0f14ee; border: 2px solid #3a4656; border-radius: 14px; padding: 4px; box-shadow: 0 6px 22px #0009; }
#modeSw button { display: flex; align-items: center; gap: 9px; border: 0; border-radius: 10px; padding: 7px 16px 7px 12px; background: transparent; color: #8b98a8; cursor: pointer; transition: background .2s, color .2s, transform .15s; }
#modeSw button i svg { width: 22px; height: 22px; }
#modeSw button span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
#modeSw button b { font-size: 14px; letter-spacing: .8px; }
#modeSw button small { font-size: 10.5px; opacity: .8; }
#modeSw button:hover { background: #1c2430; color: #dfe7f0; }
#modeSw button[data-m="edit"].on { background: #ff8a1f; color: #1d0e00; box-shadow: 0 0 0 2px #ffb46b inset, 0 0 18px #ff8a1f88; }
#modeSw button[data-m="int"].on { background: #2fd36b; color: #052a12; box-shadow: 0 0 0 2px #8ff0b2 inset, 0 0 18px #2fd36b88; animation: modePulse 1.8s ease-in-out infinite; }
@keyframes modePulse { 50% { box-shadow: 0 0 0 2px #8ff0b2 inset, 0 0 30px #2fd36bcc; } }
/* Marco de color alrededor del lienzo según el modo */
#stage::before { content: ''; position: absolute; inset: 0; border: 4px solid #ff8a1f55; pointer-events: none; z-index: 5; transition: border-color .3s; }
body.interact #stage::before { border-color: #2fd36b; box-shadow: inset 0 0 26px #2fd36b66; }
body.interact #stage::after { content: 'MODO INTERACTUAR · toca los sensores, botones y perillas'; position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; font-size: 13px; font-weight: 700; letter-spacing: .6px; color: #052a12; background: #2fd36b; padding: 6px 16px; border-radius: 14px; pointer-events: none; z-index: 6; box-shadow: 0 4px 16px #0008; }
body:not(.interact) #stage::after { content: 'MODO EDITAR · arrastra el fondo para seleccionar · barra espaciadora = mover la vista'; position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; font-size: 12px; font-weight: 700; letter-spacing: .6px; color: #1d0e00; background: #ff8a1fdd; padding: 5px 14px; border-radius: 14px; pointer-events: none; z-index: 6; }
/* Globo sobre una pieza dañada */
.dmgPop { position: absolute; z-index: 25; background: #fffdf6; color: #1b2430; border-radius: 12px; padding: 8px 10px; box-shadow: 0 8px 26px #000a; border: 2px solid #e5484d; text-align: center; animation: tIn .3s cubic-bezier(.2,.9,.3,1.3); white-space: nowrap; }
.dmgPop::after { content: ''; position: absolute; left: 50%; bottom: -9px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: #e5484d; }
.dmgPop .dp-t { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #c0262c; margin-bottom: 6px; justify-content: center; }
.dmgPop .dp-t svg { width: 16px; height: 16px; }
.dmgPop button { background: #2fd36b; color: #052a12; border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 700; cursor: pointer; font-size: 12.5px; }
.dmgPop button:hover { background: #4be285; }
#ctrlPop { position: absolute; z-index: 30; width: 270px; background: #fffdf6; color: #1b2430; border-radius: 14px; padding: 10px 12px 12px; box-shadow: 0 10px 34px #000b; display: none; animation: tIn .25s cubic-bezier(.2,.9,.3,1.3); }
#ctrlPop .cp-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#ctrlPop .cp-h .ic .ico { width: 20px; height: 20px; color: var(--ac); }
#ctrlPop .cp-h b { flex: 1; font-size: 13px; }
#ctrlPop .cp-x { background: #eef1f5; color: #333; border: 0; border-radius: 50%; width: 24px; height: 24px; padding: 0; font-size: 16px; line-height: 1; }
#ctrlPop .cp-r { display: grid; gap: 4px; margin: 8px 0; font-size: 12.5px; }
#ctrlPop .cp-r b { color: var(--ac); }
#ctrlPop input[type=range] { width: 100%; accent-color: var(--ac); }
#ctrlPop .cp-b { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 8px 0; }
#ctrlPop .cp-btn { width: 100%; background: var(--ac); color: #fff; border: 0; border-radius: 10px; padding: 10px; font-weight: 700; font-size: 14px; user-select: none; }
#ctrlPop .cp-i { font-size: 12.5px; color: #4a5563; }
.wi .wfix { margin-left: 8px; background: var(--ac); color: #111; border: 0; border-radius: 8px; padding: 3px 8px; font-size: 12px; font-weight: 700; }
/* globos: mensajes flotantes y tutorial */
#toasts { position: absolute; top: 54px; right: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; width: min(360px, 46%); z-index: 20; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 8px; max-width: 100%; background: #fffdf6; color: #222; border-radius: 18px; padding: 8px 14px; font-size: 13px; box-shadow: 0 6px 20px #0008; animation: tIn .35s cubic-bezier(.2,.9,.3,1.3); transition: opacity .5s, transform .5s; }
.toast .tico { color: var(--ac2); display: inline-flex; }
.toast.warn .tico { color: #d79b00; } .toast.err { background: #fff1f0; } .toast.err .tico { color: #e03030; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes tIn { from { opacity: 0; transform: translateY(-14px) scale(.92); } }
.balloon { position: fixed; z-index: 200; width: 300px; background: #fffdf6; color: #1b2430; border-radius: 16px; padding: 14px 16px 10px; box-shadow: 0 10px 40px #000a; animation: tIn .35s cubic-bezier(.2,.9,.3,1.3); }
.balloon .bt { font-weight: 800; color: var(--ac); font-size: 15px; margin-bottom: 4px; }
.balloon .bx { font-size: 13.5px; line-height: 1.45; }
.balloon .bf { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.balloon .bf span { color: #8a94a3; font-size: 11px; margin-right: auto; }
.balloon button { color: #1b2430; background: #eef1f5; border: 0; border-radius: 10px; }
.balloon button.next { background: var(--ac); color: #fff; font-weight: 700; }
.balloon::before { content: ''; position: absolute; width: 14px; height: 14px; background: #fffdf6; transform: rotate(45deg); }
.balloon.bottom::before { top: -7px; left: calc(50% - 7px); }
.balloon.right::before { left: -7px; top: 22px; }
.balloon.left::before { right: -7px; top: 22px; }
.balloon.center::before { display: none; }
.tour-dim { position: fixed; z-index: 190; border: 2px solid var(--ac); border-radius: 10px; box-shadow: 0 0 0 9999px #0009; pointer-events: none; animation: tIn .3s; }
#bHelp { position: absolute; left: 10px; bottom: 44px; width: 32px; height: 32px; border-radius: 50%; padding: 0; font-weight: 800; font-size: 16px; background: var(--ac); color: #111; border: 0; box-shadow: 0 2px 10px #0006; z-index: 4; }
#info3d:empty { display: none; }
#info3d .hint3 { color: #6c7a8c; font-size: 11px; }
body.v3d #bHelp { bottom: 10px; }
/* paleta con miniaturas */
#palette { width: 236px; }
.ptitle { padding: 8px 10px 4px; border-bottom: 0; }
.psearch { margin: 0 8px 6px; display: flex; align-items: center; background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; }
.psearch i[data-ico] { margin-right: 4px; color: var(--tx2); }
.psearch input { border: 0; background: transparent; flex: 1; padding: 6px 2px; outline: 0; }
#pcats { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 8px 6px; border-bottom: 1px solid var(--line); }
#pcats button { padding: 2px 8px; font-size: 11px; border-radius: 10px; }
#pcats button.on { background: var(--ac); color: #111; border-color: var(--ac); }
.ptiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 2px 4px; }
.ptiles .pitem { flex-direction: column; gap: 3px; padding: 6px 4px; background: #18202b; border: 1px solid #243041; text-align: center; font-size: 11px; line-height: 1.2; }
.ptiles .pitem:hover { border-color: var(--ac2); background: #1d2734; transform: translateY(-1px); }
.ptiles .pitem.sel { border-color: var(--ac); background: #2b2218; }
.ptiles .pitem .th { width: 100%; height: 54px; display: flex; align-items: center; justify-content: center; background: radial-gradient(#253142, #161d27); border-radius: 6px; }
.ptiles .pitem .th svg { width: 92%; height: 92%; }
body.mode-aula #plist { font-size: 11px; }
/* íconos */
.ico { width: 16px; height: 16px; display: block; }
i[data-ico] { display: inline-flex; vertical-align: -3px; margin-right: 6px; font-style: normal; }
button i[data-ico]:only-child { margin-right: 0; }
.pitem .ic .ico { width: 20px; height: 20px; color: #c9d6e6; }
.pitem.sel .ic .ico, .pitem:hover .ic .ico { color: var(--ac); }
.ihead .ic .ico { width: 30px; height: 30px; color: var(--ac); }
.wi .wico { display: inline-flex; vertical-align: -3px; margin-right: 6px; }
.wi.err .wico { color: var(--err); } .wi.warn .wico { color: var(--warn); } .wi.info .wico { color: var(--ac2); }
.wnone .ico { display: inline-block; vertical-align: -3px; margin-right: 6px; }
.pfoot i[data-ico] .ico { width: 13px; height: 13px; }
#zoom .ico { margin: auto; }

/* marca */
.brand { align-items: center; }
.brand-logo { height: 18px; display: block; }
.brand-lab { color: var(--ac); font-weight: 800; letter-spacing: 3px; font-size: 16px; margin-left: -2px; }
#status .copy { color: #5d6b7d; margin-left: 14px; }
#status .copy a { color: #7d8a9d; text-decoration: none; }
#status .copy a:hover { color: var(--ac); text-decoration: underline; }

/* pantalla de carga */
#splash { position: fixed; inset: 0; z-index: 100; background: radial-gradient(ellipse at center, #1b2430 0%, #0a0d12 70%); display: flex; align-items: center; justify-content: center; transition: opacity .6s ease; }
#splash.out { opacity: 0; pointer-events: none; }
.sp-center { display: flex; flex-direction: column; align-items: center; }
.sp-logo { display: flex; align-items: center; gap: 18px; height: 90px; }
.sp-sx { height: 70px; opacity: 0; transform: scale(.85); filter: drop-shadow(0 0 18px rgba(255,122,26,.35)); animation: spIn .9s .2s cubic-bezier(.2,.8,.2,1) forwards; }
.sp-lab { font: 800 64px/1 "Segoe UI", system-ui, sans-serif; letter-spacing: 10px; color: var(--ac); opacity: 0; transform: translateX(-30px); text-shadow: 0 0 24px rgba(255,122,26,.5); animation: spLab .7s 1.15s cubic-bezier(.2,.8,.2,1) forwards; }
.sp-bar { width: 340px; height: 3px; background: #222b36; border-radius: 3px; margin: 34px 0 22px; overflow: hidden; opacity: 0; animation: spFade .4s 1.5s forwards; }
.sp-bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ac), #ffb46b); animation: spLoad 1.3s 1.6s ease-in-out forwards; }
.sp-power { font-size: 13px; color: #a9b6c6; letter-spacing: .5px; opacity: 0; animation: spFade .6s 1.9s forwards; }
.sp-power b { color: #fff; }
.sp-copy { font-size: 11px; color: #5d6b7d; margin-top: 8px; letter-spacing: 1px; opacity: 0; animation: spFade .6s 2.2s forwards; }
@keyframes spIn { to { opacity: 1; transform: scale(1); } }
@keyframes spLab { to { opacity: 1; transform: translateX(0); } }
@keyframes spFade { to { opacity: 1; } }
@keyframes spLoad { to { width: 100%; } }

/* vista 3D */
#view3d { position: absolute; inset: 0; display: none; background: linear-gradient(#1a2330, #0d1218); }
#view3d.on { display: block; }
#cv3d { width: 100%; height: 100%; display: block; }
#info3d { position: absolute; left: 12px; top: 74px; z-index: 6; max-width: 360px; background: #0b0f14e6; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; color: var(--tx2); display: grid; gap: 4px; }
#info3d b { color: var(--ac); font-size: 13px; }
#info3d { max-height: calc(100% - 130px); overflow-y: auto; }
#info3d .net { color: var(--tx); line-height: 1.45; padding: 3px 0; border-top: 1px solid #1f2935; }
#info3d .net b { color: #fff; font-size: 12.5px; }
#info3d .net i.v { color: var(--ac2); font-style: normal; font-weight: 600; }
#info3d ul { margin: 2px 0 0; padding-left: 16px; color: var(--tx); }
#info3d li { margin: 2px 0; }
#info3d .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
#viewSwitch { position: absolute; right: 10px; top: 10px; display: flex; background: #0b0f14cc; border: 1px solid var(--line); border-radius: 8px; padding: 2px; z-index: 4; }
#viewSwitch button { border: 0; background: transparent; padding: 5px 12px; }
#viewSwitch button.on { background: var(--ac2); color: #06141a; font-weight: 600; }
body.v3d #zoom, body.v3d #wcolors { display: none; }
#viewSwitch .sep { width: 1px; background: var(--line); margin: 3px 4px; }
#viewSwitch #bFlow.on { background: #ffd23a; color: #1a1400; font-weight: 600; }
#flowLegend { position: absolute; left: 50%; transform: translateX(-50%); bottom: 54px; white-space: nowrap; background: #0b0f14e6; border: 1px solid #5a4a10; color: #ffe9a8; font-size: 12px; padding: 5px 10px; border-radius: 8px; display: none; z-index: 4; }
body.flow #flowLegend { display: block; }
#flowLegend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #ffd23a; box-shadow: 0 0 6px #ffd23a; margin-right: 6px; }
#flowLegend b { color: #fff; margin-left: 6px; }
.flowp { fill: none; stroke: #ffd23a; stroke-linecap: round; pointer-events: none; filter: drop-shadow(0 0 2px #ffb000); }
body.flow .wire { opacity: .75; }

.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal > div { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; max-width: 560px; }
.modal h2 { margin: 0 0 8px; color: var(--ac); }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* Tanda 4: panel Radio y panel Cámara */
#radioOut { flex: 1; margin: 0; padding: 6px 10px; background: #0a0e13; color: #9fd8ff; font: 12px/1.4 Consolas, monospace; overflow-y: auto; white-space: pre-wrap; }
#radioState, #camState { padding: 6px 10px; font-size: 12px; color: var(--tx2); }
#radioState.on, #camState.on { color: var(--ok); }
.padx.rq button { padding: 4px 12px; font-weight: 700; }
#pCam { overflow: hidden; }
.camBox { flex: 1; display: flex; align-items: center; justify-content: center; background: #05070a; min-height: 0; }
#camCanvas { max-height: 100%; max-width: 100%; image-rendering: auto; border: 1px solid #222; background: #111; }
.camBar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 10px; font-size: 12px; color: var(--tx2); }
.camBar button { padding: 3px 10px; }
#tabsBot button.ping { position: relative; }
#tabsBot button.ping::after { content: ''; position: absolute; top: 5px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #2fd36b; box-shadow: 0 0 6px #2fd36b; }
#ctrlPop .cp-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
#ctrlPop .cp-acts .cp-btn { padding: 12px 6px; font-size: 15px; }

/* globo de controles: título para arrastrar y versión compacta (control de TV) */
#ctrlPop .cp-h { cursor: move; user-select: none; }
#ctrlPop.compact { width: 210px; }
#ctrlPop.compact .cp-acts { gap: 4px; }
#ctrlPop.compact .cp-acts .cp-btn { padding: 6px 2px; font-size: 13px; border-radius: 8px; }

/* Acerca de */
#brand { cursor: pointer; }
#about { position: fixed; inset: 0; z-index: 200; background: rgba(5,8,12,.72); display: none; align-items: center; justify-content: center; backdrop-filter: blur(3px); }
#about.on { display: flex; animation: tIn .25s ease-out; }
#about .ab-card { position: relative; width: min(560px, 92vw); max-height: 90vh; overflow: auto; background: linear-gradient(160deg, #141b24, #0d1219); border: 1px solid #2a3442; border-radius: 18px; padding: 26px 30px 20px; color: #dfe7f0; box-shadow: 0 20px 60px #000c; }
#about .ab-x { position: absolute; right: 12px; top: 10px; background: transparent; border: 0; color: #9aa7b6; font-size: 24px; cursor: pointer; }
#about .ab-logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
#about .ab-logo img { height: 46px; }
#about .ab-logo span { font-weight: 800; font-size: 34px; letter-spacing: 6px; color: #ff8a1f; }
#about .ab-sub { text-align: center; color: #9aa7b6; margin-top: 6px; font-size: 13px; }
#about .ab-power { text-align: center; margin-top: 4px; font-size: 13px; color: #cfd8e3; }
#about .ab-txt { font-size: 13.5px; line-height: 1.5; color: #c4cfdb; margin: 14px 0; }
#about .ab-stats { display: flex; gap: 10px; justify-content: center; margin: 8px 0 14px; }
#about .ab-stats div { flex: 1; background: #1a2330; border: 1px solid #2a3442; border-radius: 12px; padding: 10px; text-align: center; }
#about .ab-stats b { display: block; font-size: 26px; color: #2fd36b; }
#about .ab-stats span { font-size: 12px; color: #9aa7b6; }
#about h4 { margin: 12px 0 6px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: #ff8a1f; }
#about .ab-keys { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12.5px; color: #c4cfdb; }
#about kbd { background: #263142; border: 1px solid #3a4656; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11.5px; color: #fff; }
#about .ab-cred { margin: 0; padding-left: 18px; font-size: 12px; line-height: 1.55; color: #aab6c4; }
#about .ab-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
#about .ab-btns button { border-radius: 10px; padding: 8px 16px; cursor: pointer; border: 1px solid #3a4656; background: #1a2330; color: #dfe7f0; }
#about .ab-btns .ab-ok { background: #ff8a1f; border-color: #ff8a1f; color: #1d0e00; font-weight: 700; }
#about .ab-btns .ab-terms { display: inline-flex; align-items: center; border-radius: 10px; padding: 8px 16px; border: 1px solid #3a4656; background: #1a2330; color: #dfe7f0; text-decoration: none; margin-right: auto; }
#about .ab-btns .ab-terms:hover { border-color: var(--ac); color: var(--ac); }
#about .ab-copy { text-align: center; margin-top: 14px; font-size: 11px; color: #6f7c8b; }

/* ------------------------------------------------------------ BETA y opinión */
.beta { align-self: center; font-size: 10px; font-weight: 800; letter-spacing: 1.2px; color: #1d0e00; background: linear-gradient(135deg, #ffd23a, #ff8a1f); padding: 2px 7px; border-radius: 6px; margin-left: -2px; box-shadow: 0 0 10px #ff8a1f55; }
a.opinion { display: inline-flex; align-items: center; white-space: nowrap; text-decoration: none; color: #062a14; background: #2fd36b; border-radius: 16px; padding: 5px 12px 5px 10px; font-weight: 700; font-size: 12.5px; box-shadow: 0 2px 10px #2fd36b40; transition: transform .15s, background .2s; }
a.opinion:hover { background: #45e07d; transform: translateY(-1px); }

/* ------------------------------------------------------------ celular y tablet */
#mNav, #mSel, .mBack { display: none; }
#cv { touch-action: none; -webkit-tap-highlight-color: transparent; }
@media (max-width: 820px) {
  html, body { height: 100dvh; }
  #top { overflow-x: auto; overflow-y: hidden; gap: 8px; padding: 0 8px; scrollbar-width: none; }
  #top::-webkit-scrollbar { display: none; }
  #top > * { flex-shrink: 0; }
  #top .grp.right { margin-left: 0; }
  .brand .sub { display: none; }
  #bRun, #bStop { display: none; }
  a.opinion span { display: none; }
  a.opinion { padding: 6px 8px; }
  a.opinion i[data-ico] { margin-right: 0; }
  main { bottom: 58px; }
  #status { display: none; }
  #palette, #side { position: absolute; inset: 0; width: auto; z-index: 40; display: none; border: 0; }
  body.m-piezas #palette, body.m-codigo #side { display: flex; }
  .mBack { display: flex; align-items: center; justify-content: center; margin: 8px; padding: 9px; border-radius: 10px; background: #2b2218; border-color: var(--ac); color: #ffd8b5; font-weight: 600; }
  #plist .ptiles { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)) !important; }
  .pane2 { height: 38%; }
  #mNav { display: flex; position: absolute; left: 0; right: 0; bottom: 0; height: 58px; background: #0f141b; border-top: 1px solid var(--line); z-index: 50; padding-bottom: env(safe-area-inset-bottom); }
  #mNav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; border-radius: 0; background: transparent; color: var(--tx2); font-size: 11.5px; }
  #mNav button i[data-ico] { margin: 0; }
  #mNav button .ico { width: 20px; height: 20px; }
  #mNav button.on { color: var(--ac); }
  #mNav .mrun { background: #1d7a3c; color: #fff; font-weight: 700; margin: 6px; border-radius: 12px; flex: 1.2; }
  #mNav .mrun.active { background: #7a1d1d; }
  #mNav .mrun svg { width: 20px; height: 20px; }
  /* barra de la pieza seleccionada (no hay teclado para R / Supr) */
  body.has-sel:not(.interact) #mSel { display: flex; position: absolute; left: 50%; transform: translateX(-50%); bottom: 54px; gap: 6px; z-index: 8; background: #0b0f14ee; border: 1px solid var(--line); border-radius: 12px; padding: 5px; }
  body.sel-wire #mRot { display: none; }
  #mSel button { padding: 8px 12px; border-radius: 9px; }
  /* controles flotantes más compactos */
  #modeSw { top: 6px; padding: 3px; border-radius: 12px; }
  #modeSw button { padding: 6px 10px; gap: 6px; }
  #modeSw small { display: none; }
  #viewSwitch { top: auto; bottom: 10px; right: 52px; }
  #viewSwitch #bFlow, #viewSwitch .sep { display: none; }
  #wcolors { display: none; }
  body.has-sel:not(.interact) #wcolors { display: none; }
  #bHelp { display: none; }
  #stage::after { display: none; }
  #zoom button { width: 38px; height: 38px; }
  #toasts { top: 58px; left: 4%; right: 4%; width: auto; align-items: center; }
  .toast { max-width: 100%; }
  #info3d { top: 60px; max-width: calc(100% - 24px); }
  #ctrlPop { width: min(270px, calc(100% - 16px)); }
  .pin, .hole { stroke-width: 3px; stroke: transparent; paint-order: stroke; }
}

/* pantallas medianas (laptops chicas): botones secundarios solo con ícono */
@media (max-width: 1320px) and (min-width: 821px) {
  #bNew, #bOpen, #bSave, #bExport, #bRepair, #bAbout { font-size: 0; padding: 6px 8px; }
  #bNew i, #bOpen i, #bSave i, #bExport i, #bRepair i, #bAbout i { margin-right: 0; }
  #top { gap: 10px; }
}
@media (max-width: 1100px) and (min-width: 821px) {
  .brand .sub, a.opinion span { display: none; }
  a.opinion i[data-ico] { margin-right: 0; }
  #selEx { max-width: 130px; }
}
#ld3d { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: #141b24; color: var(--tx2); font-size: 14px; z-index: 3; }
#ld3d .sp-bar { width: 200px; margin: 0; opacity: 1; animation: none; }
#ld3d .sp-bar div { width: 40%; animation: ld3d 0.9s ease-in-out infinite alternate; }
@keyframes ld3d { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
#selEx2 { display: none; }
@media (max-width: 820px) {
  #selEx2 { display: block; margin: 0 8px 8px; padding: 9px; border-radius: 10px; border-color: var(--ac2); }
  #top #selEx { display: none; }
}
