/* #lab — "Armá tu idea en cubos" · prefijo lab- */
.lab { padding-block: var(--space-xl) var(--space-l); }
.lab__head { position: relative; isolation: isolate; display: grid; gap: clamp(14px, 2vw, 24px); max-width: 780px; margin-bottom: clamp(1.5rem, 4vw, 3.5rem); }
.lab__title { font-size: clamp(2.7rem, 1.3rem + 5.4vw, 7rem); }
.lab__lead { max-width: 44ch; }

.lab__stage { display: none; }
.lab__body { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: clamp(12px, 2vw, 28px); }
/* zona de la figura (desktop): arrastrar para girar, doble click = armalo de nuevo */
.lab__orbit { grid-column: 7 / -1; grid-row: 1; min-height: 60vh; touch-action: none; cursor: grab; border-radius: var(--radius-l); }
.lab__orbit.is-drag { cursor: grabbing; }

.lab-panel {
  grid-column: 1 / span 6; grid-row: 1; position: relative; display: grid; gap: clamp(12px, 1.4vw, 18px);
  padding: clamp(14px, 1.8vw, 24px); border-radius: var(--radius-l);
  background: linear-gradient(180deg, rgba(21,21,26,.86), rgba(13,13,16,.82));
  border: 1px solid var(--line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.8), inset 0 1px 0 rgba(241,238,230,.06);
}
.lab-panel::before { /* esquinas tipo "marco de lienzo" */
  content: ''; position: absolute; inset: 8px; border-radius: calc(var(--radius-l) - 6px); pointer-events: none;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 10px 2px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 0 0 / 2px 10px no-repeat,
    linear-gradient(var(--cobalt), var(--cobalt)) 100% 100% / 10px 2px no-repeat,
    linear-gradient(var(--cobalt), var(--cobalt)) 100% 100% / 2px 10px no-repeat;
}

/* barra de herramientas */
.lab-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.lab-tools { display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px; background: var(--ink-3); border: 1px solid var(--line); }
.lab-tool {
  display: inline-flex; align-items: center; gap: .55em; min-height: 44px; padding: 0 1.05em; border-radius: 999px;
  font-family: var(--font-mono); font-size: var(--step--1); text-transform: uppercase; letter-spacing: .05em; color: var(--paper-2);
  transition: background .35s var(--ease-out), color .35s var(--ease-out), transform .35s var(--ease-out);
}
.lab-tool:hover { color: var(--paper); }
.lab-tool:active { transform: scale(.95); }
.lab-tool[aria-checked="true"] { background: var(--paper); color: var(--ink); }
.lab-actions-mini { display: inline-flex; gap: 6px; }
.lab-icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line-strong); color: var(--paper);
  transition: background .35s var(--ease-out), color .35s var(--ease-out), transform .35s var(--ease-out), opacity .3s;
}
.lab-icon-btn:hover:not(:disabled) { background: var(--accent); color: var(--ink); border-color: var(--accent); transform: rotate(-8deg); }
.lab-icon-btn:active:not(:disabled) { transform: scale(.9); }
.lab-icon-btn[aria-pressed="true"] { background: var(--lime); color: var(--ink); border-color: var(--lime); }
.lab-icon-btn:disabled { opacity: .3; cursor: not-allowed; }

/* paleta */
.lab-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.lab-swatch {
  position: relative; width: 44px; height: 44px; border-radius: 10px; background: var(--c);
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.22), inset 0 0 0 1px rgba(255,255,255,.12);
  transition: transform .4s var(--ease-out), box-shadow .4s var(--ease-out);
}
.lab-swatch::after { content: attr(data-n); position: absolute; right: 5px; bottom: 3px; font-family: var(--font-pixel); font-size: 10px; color: rgba(13,13,16,.65); }
.lab-swatch:hover { transform: translateY(-3px); }
.lab-swatch[aria-checked="true"] { transform: translateY(-3px); box-shadow: inset 0 -5px 0 rgba(0,0,0,.22), 0 0 0 2px var(--ink), 0 0 0 4px var(--paper); }

/* grilla */
.lab-grid-wrap { position: relative; display: grid; place-items: center; }
.lab-grid {
  --ghost: var(--accent);
  width: min(100%, 440px); aspect-ratio: 1; display: grid; grid-template-columns: repeat(16, 1fr); grid-template-rows: repeat(16, 1fr);
  background: var(--ink); border-radius: 10px; overflow: hidden; border: 1px solid var(--line-strong);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: calc(100% / 16) calc(100% / 16);
}
.lab-row { display: contents; }
.lab-cell { position: relative; padding: 0; min-width: 0; min-height: 0; border-radius: 0; background: transparent; cursor: crosshair; }
.lab-cell[data-c] { background: var(--c); box-shadow: inset -2px -2px 0 rgba(0,0,0,.2), inset 2px 2px 0 rgba(255,255,255,.14); }
.lab-cell:focus { outline: none; }
.lab-cell:focus-visible, .lab-cell.is-cursor { outline: 2px solid var(--lime); outline-offset: -2px; z-index: 2; border-radius: 0; }
.lab-grid:not(:focus-within) .lab-cell.is-cursor { outline-color: transparent; }
.lab-cell.is-pop { animation: lab-pop .45s var(--ease-out); }
@keyframes lab-pop { 0% { transform: scale(.4); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
/* "fantasma": la celda bajo el puntero muestra el color activo */
@media (hover: hover) {
  .lab-cell:hover::before { content: ''; position: absolute; inset: 0; background: var(--ghost); opacity: .45; pointer-events: none; }
  .lab-grid[data-tool="eraser"] .lab-cell:hover::before { background: transparent; box-shadow: inset 0 0 0 2px var(--paper); opacity: .8; }
}
.lab-empty { position: absolute; z-index: 3; pointer-events: none; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--paper-2); opacity: 0; transition: opacity .5s var(--ease-out); padding: .5em .9em; background: var(--ink); border: 1px dashed var(--line-strong); border-radius: 6px; }
.lab-empty.is-on { opacity: 1; animation: lab-blink 1.6s steps(2, jump-none) infinite; }
@keyframes lab-blink { 50% { color: var(--lime); } }

/* el cursor custom del chrome tapaba la grilla: acá manda la mira */
html.has-cursor .lab-grid, html.has-cursor .lab-cell { cursor: crosshair; }
html.has-cursor:has(.lab-grid:hover) .efx-cursor { opacity: 0; }

.lab-help { font-size: var(--step--1); color: var(--muted); line-height: 1.7; }
.lab-help .pixel { color: var(--paper-2); font-size: .82em; padding: .1em .45em; border: 1px solid var(--line-strong); border-radius: 4px; white-space: nowrap; }

/* presets */
.lab-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lab-chip {
  min-height: 44px; padding: 0 .9em; border-radius: 999px; border: 1px solid var(--line-strong);
  font-family: var(--font-mono); font-size: var(--step--1); text-transform: uppercase; letter-spacing: .04em;
  transition: background .35s var(--ease-out), color .35s var(--ease-out), transform .35s var(--ease-out), border-color .35s;
}
.lab-chip::before { content: ''; display: inline-block; width: .5em; height: .5em; margin-right: .55em; background: var(--accent); transition: transform .4s var(--ease-out), background .3s; }
.lab-chip:hover { background: var(--paper); color: var(--ink); border-color: var(--paper); transform: translateY(-2px); }
.lab-chip:hover::before { transform: rotate(90deg) scale(1.2); background: var(--cobalt); }
.lab-chip:active { transform: scale(.96); }

.lab-cta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 4px; }
.lab-cta-row .btn { min-height: 48px; }
.lab-count { margin-left: auto; color: var(--paper-2); font-size: var(--step--1); }
.lab-count span { color: var(--lime); }

/* cierre */
.lab__final { margin-top: clamp(3rem, 7vw, 7rem); padding-bottom: clamp(2rem, 6vh, 4rem); min-height: 66vh; }
.lab__final-in { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: clamp(12px, 2vw, 28px); padding-top: clamp(1.5rem, 3vw, 3rem); align-items: end; }
.lab__final-title { grid-column: 1 / span 7; font-size: clamp(2.3rem, 1.3rem + 4vw, 5.4rem); }
.lab__final-side { grid-column: 9 / span 4; display: grid; gap: 1.4rem; justify-items: start; }

@media (max-width: 900px) {
  .lab-panel { grid-column: 1 / -1; }
  .lab__orbit { display: none; }
  .lab__final-title { grid-column: 1 / -1; }
  .lab__final-side { grid-column: 1 / -1; }
}
/* mobile: la figura queda pinneada arriba (stage sticky) y el panel scrollea por debajo, recortado */
@media (max-width: 760px) {
  .lab__lead { margin-bottom: 1rem; }
  .lab__stage {
    display: grid; place-items: start start; position: sticky; top: 56px; height: 26vh; min-height: 180px; z-index: 0;
    touch-action: pan-y; margin-bottom: 8px;
  }
  .lab__stage-tag { font-size: 11px; color: var(--muted); }
  .lab-panel { background: var(--ink-2); -webkit-backdrop-filter: none; backdrop-filter: none; z-index: 1; }
  .lab-count { margin-left: 0; width: 100%; }
  .lab-tool span { display: none; }
  .lab-tool { padding: 0 .9em; }
  .lab-swatches { flex-wrap: nowrap; gap: 6px; }
  .lab-swatch { width: 40px; height: 40px; flex: 0 0 auto; }
  .lab-help { display: none; }
  .lab-cta-row .btn { flex: 1 1 auto; justify-content: center; }
  .lab__final { min-height: 0; }
}
/* velo ink tras el encabezado mientras llega el motor (entrada por ancla): solo en el estado de transición */
.lab__head::before { content: ''; position: absolute; inset: -14px -16px; z-index: -1; border-radius: 18px; background: var(--ink); opacity: 0; pointer-events: none; transition: opacity .7s var(--ease-out); -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px); }
.lab--arriving .lab__head::before { opacity: .72; }
.lab--arriving .lab__head { text-shadow: 0 1px 14px var(--ink); }
/* arrival banner, nudge de sonido, logros, toast */
.lab-banner { margin: 0; padding: .7em 1em; background: var(--ink-3); color: var(--lime); border: 1px solid var(--lime); font-size: var(--step--1); letter-spacing: .02em; }
.lab-banner[hidden], .lab-nudge[hidden], .lab-sign[hidden], .lab-sign-note[hidden], .lab-ach__list[hidden] { display: none; }
.lab-nudge { margin: 0; display: flex; align-items: center; gap: 12px; padding: 4px 6px 4px 14px; border: 1px dashed var(--lime); border-radius: 999px; color: var(--lime); font-size: var(--step--1); width: fit-content; }
.lab-nudge .lab-chip { min-height: 36px; background: var(--lime); color: var(--ink); border-color: var(--lime); }
.lab-nudge .lab-chip::before { display: none; }
.lab-sound { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; width: auto; padding: 0 .8em 0 .7em; gap: .45em; border-radius: 999px; font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.lab-sound[aria-pressed="true"] { background: var(--lime); color: var(--ink); border-color: var(--lime); }

.lab-ach__btn { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 1em; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--paper-2); font-size: var(--step--1); transition: border-color .3s, color .3s; }
.lab-ach__btn:hover, .lab-ach__btn[aria-expanded="true"] { border-color: var(--lime); color: var(--paper); }
.lab-ach__btn b { color: var(--lime); font-weight: 400; }
.lab-ach__pips { display: inline-flex; gap: 4px; }
.lab-ach__pips i { width: 8px; height: 8px; background: var(--ink-3); border: 1px solid var(--line-strong); }
.lab-ach__pips i.is-on { background: var(--lime); border-color: var(--lime); }
.lab-ach__list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.lab-ach__list li { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: var(--step--1); color: var(--muted); }
.lab-ach__list li.is-on { border-color: var(--lime); color: var(--paper); }
.lab-ach__list li strong { font-family: 'Silkscreen', var(--font-mono), monospace; font-weight: 400; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.lab-ach__list li.is-on strong { color: var(--lime); }
.lab-ach__list li small { font-size: 12px; opacity: .8; }

.lab-toast {
  position: fixed; right: 24px; top: 92px; z-index: 90; max-width: calc(100vw - 32px);
  padding: .8em 1.1em; background: var(--ink-2); color: var(--paper); border: 2px solid var(--lime);
  box-shadow: 4px 4px 0 var(--lime); font-family: 'Silkscreen', var(--font-mono), monospace; font-size: 12px; letter-spacing: .06em; text-transform: uppercase;
  transform: translateY(-14px); opacity: 0; pointer-events: none; transition: transform .35s steps(5), opacity .2s;
}
.lab-toast.is-on { transform: none; opacity: 1; }
.lab-toast b { color: var(--lime); font-weight: 400; }

/* controles de órbita (hint + girar con botones) y fallback sin WebGL */
.lab__orbit { position: relative; }
@media (min-width: 901px) { .lab__orbit { display: flex; align-items: flex-end; justify-content: center; } }
.lab--kbd .lab__orbit:focus-visible, .lab--kbd .lab__stage:focus-visible { outline: 2px dashed var(--lime); outline-offset: -6px; }
.lab-orbitctl { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; touch-action: manipulation; position: sticky; bottom: 14vh; }
.lab-hint { display: inline-flex; align-items: center; min-height: 36px; padding: 0 .9em; border: 1px dashed var(--line-strong); border-radius: 999px; background: rgba(13,13,16,.7); color: var(--paper-2); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; animation: lab-nudge 2.4s ease-in-out infinite; }
.lab-rot { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong); background: rgba(13,13,16,.7); color: var(--paper); font-size: 11px; transition: background .3s, color .3s; }
.lab-rot:hover { background: var(--lime); color: var(--ink); border-color: var(--lime); }
.lab.lab--orbited .lab-hint { display: none; }
.lab-fallback { display: none; max-width: 100%; height: auto; align-self: center; }
.lab--nogl .lab-fallback { display: block; position: sticky; top: 22vh; align-self: flex-start; margin-top: 4vh; }
.lab--nogl .lab-orbitctl, .lab--nogl .lab__stage-tag { display: none; }
@media (min-width: 901px) { .lab--nogl .lab__orbit { align-items: center; } }
@keyframes lab-nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }

/* firma en el CTA */
.lab-sign { width: 28px; height: 28px; image-rendering: pixelated; margin-right: .2em; border-radius: 4px; background: var(--ink); }
.lab-dock { display: grid; gap: clamp(12px, 1.4vw, 18px); }
.lab-sign-note { margin: 0; color: var(--paper-2); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }

/* desktop: la barra queda pegada bajo el header (no la pisa el nav) */
@media (min-width: 761px) {
  .lab-dock { position: sticky; top: 84px; z-index: 4; padding: 6px 4px 12px; margin: -6px -4px 0; background: var(--ink-2); border-radius: 18px; box-shadow: 0 12px 14px -8px var(--ink-2); }
  .lab-dock .lab-swatch { width: 40px; height: 40px; }
}
@media (max-width: 760px) {
  .lab-toast { right: auto; left: 50%; top: 104px; bottom: auto; white-space: nowrap; font-size: 11px; padding: .6em .9em; transform: translate(-50%, -14px); }   /* sobre el stage fijo: nunca pisa la grilla de dibujo */
  .lab-toast.is-on { transform: translate(-50%, 0); }
  .lab-sound__t { display: none; }
  .lab-sound { width: 40px; padding: 0; }
  .lab-icon-btn { width: 40px; height: 40px; }
  .lab-actions-mini { gap: 4px; }
  .lab-bar { gap: 6px; flex-wrap: nowrap; }
  .lab-tools { flex: 0 1 auto; min-width: 0; }
  .lab__stage { grid-template-rows: auto 1fr; }
  .lab-orbitctl { justify-self: center; align-self: end; margin: 0 0 6px; position: static; }
  .lab--nogl .lab__stage { height: auto; position: static; }
  .lab--nogl .lab-fallback { width: min(260px, 70vw); justify-self: center; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-hint { animation: none; }
  .lab-toast { transition: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-toast { transition: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lab-cell.is-pop, .lab-empty.is-on { animation: none; }
}
