/* ==========================================================================
   NEXA CODE — lab.css
   Playground: dither, ASCII, flow field, type tester, kinetic type
   ========================================================================== */

.lab-page {
  background: var(--bg);
}

/* --------------------------------------------------------------------------
   HERO
   -------------------------------------------------------------------------- */
.lab-hero {
  position: relative;
  padding-top: calc(var(--header-h) + clamp(36px, 7vw, 88px));
  padding-bottom: clamp(30px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  isolation: isolate;
}
.lab-hero__grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(to right, var(--line-soft) 1px, transparent 1px) 0 0 / calc(100% / 8) 100%,
    radial-gradient(70% 90% at 85% 10%, rgba(233, 229, 218, 0.07), transparent 65%);
  mask-image: linear-gradient(to bottom, #000, transparent 92%);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 92%);
}
html[data-theme='bone'] .lab-hero__grid {
  background:
    linear-gradient(to right, var(--line-soft) 1px, transparent 1px) 0 0 / calc(100% / 8) 100%,
    radial-gradient(70% 90% at 85% 10%, rgba(8, 8, 8, 0.06), transparent 65%);
}
.lab-hero__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.lab-hero__title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(46px, 12.5vw, 176px);
  line-height: 0.82;
  letter-spacing: -0.06em;
  text-transform: uppercase;
  margin-top: clamp(18px, 3vw, 30px);
}
.lab-hero__title .serif {
  text-transform: none;
  letter-spacing: -0.03em;
}
.lab-hero__lead {
  margin-top: clamp(18px, 3vw, 28px);
  max-width: 60ch;
  font-size: clamp(14px, 1.2vw, 17px);
  line-height: 1.65;
  color: var(--fg-muted);
}
.lab-hero__meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-top: clamp(30px, 5vw, 52px);
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.lab-hero__meta div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.lab-hero__meta b {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(18px, 2vw, 26px);
  letter-spacing: -0.02em;
  color: var(--fg);
  text-transform: none;
}

/* --------------------------------------------------------------------------
   SUB NAV
   -------------------------------------------------------------------------- */
.lab-nav {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.lab-nav__inner {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-block: 10px;
}
.lab-nav__inner::-webkit-scrollbar {
  display: none;
}
.lab-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-faint);
  white-space: nowrap;
  transition: color 220ms linear, border-color 220ms linear, background-color 220ms linear;
}
.lab-nav a:hover {
  color: var(--fg);
}
.lab-nav a.is-active {
  color: var(--fg);
  border-color: var(--line-strong);
  background: var(--surface);
}
.lab-nav a span {
  font-size: 8px;
  opacity: 0.6;
}
.lab-nav__spacer {
  flex: 1;
}
.lab-nav__note {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-faint);
  white-space: nowrap;
  padding-left: 12px;
}

/* --------------------------------------------------------------------------
   EXPERIMENT SHELL
   -------------------------------------------------------------------------- */
.exp {
  padding-block: clamp(42px, 6vw, 84px);
  border-bottom: 1px solid var(--line);
  scroll-margin-top: calc(var(--header-h) + 58px);
  position: relative;
}
.exp__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr);
  gap: clamp(20px, 4vw, 64px);
  align-items: end;
  margin-bottom: clamp(22px, 3vw, 36px);
}
.exp__index {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.exp__index b {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(26px, 3.4vw, 42px);
  letter-spacing: -0.04em;
  color: var(--fg);
  line-height: 1;
}
.exp__title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(26px, 3.6vw, 46px);
  line-height: 1;
  letter-spacing: -0.045em;
  margin-top: 12px;
}
.exp__desc {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--fg-muted);
  max-width: 52ch;
}
.exp__hint {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(0, 0.78fr);
  gap: clamp(12px, 1.6vw, 20px);
  align-items: stretch;
}

/* stage */
.stage {
  position: relative;
  border: 1px solid var(--line);
  background: #050505;
  overflow: hidden;
  min-height: 300px;
  isolation: isolate;
}
.stage--ratio {
  aspect-ratio: 4 / 3;
}
.stage--ratio > .stage__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.stage__canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.stage--contain {
  display: grid;
  place-items: center;
}
.stage__label {
  position: absolute;
  z-index: 3;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 242, 236, 0.5);
  pointer-events: none;
}
.stage__label--tl {
  top: 10px;
  left: 12px;
}
.stage__label--br {
  right: 12px;
  bottom: 10px;
  text-align: right;
}
.stage__corner {
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: rgba(244, 242, 236, 0.35);
  border-style: solid;
  pointer-events: none;
  z-index: 3;
}
.stage__corner--tl {
  top: 8px;
  left: 8px;
  border-width: 1px 0 0 1px;
}
.stage__corner--tr {
  top: 8px;
  right: 8px;
  border-width: 1px 1px 0 0;
}
.stage__corner--bl {
  bottom: 8px;
  left: 8px;
  border-width: 0 0 1px 1px;
}
.stage__corner--br {
  bottom: 8px;
  right: 8px;
  border-width: 0 1px 1px 0;
}

/* control panel */
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: clamp(14px, 1.6vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-faint);
}
.panel__head b {
  font-weight: 400;
  color: var(--fg);
}
.panel__group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel__divider {
  height: 1px;
  background: var(--line);
  margin: 2px 0;
}
.ctrl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  align-items: center;
}
.ctrl__label {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.ctrl__value {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--fg);
  background: var(--surface-2);
  padding: 3px 6px;
  border-radius: 2px;
  min-width: 38px;
  text-align: center;
}
.ctrl__input {
  grid-column: 1 / -1;
}
.ctrl select,
.ctrl input[type='text'] {
  grid-column: 1 / -1;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 8px 9px;
  font-size: 12px;
  color: var(--fg);
  transition: border-color 200ms linear;
}
.ctrl select:focus,
.ctrl input[type='text']:focus {
  outline: none;
  border-color: var(--line-strong);
}
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  grid-column: 1 / -1;
}
.seg button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  transition: background-color 180ms linear, color 180ms linear, border-color 180ms linear;
}
.seg button:hover {
  border-color: var(--line-strong);
  color: var(--fg);
}
.seg button[aria-pressed='true'] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}
.panel__actions .btn {
  flex: 1 1 auto;
  min-height: 38px;
  font-size: 8.5px;
  padding: 0 12px;
}
.panel__note {
  font-family: var(--font-mono);
  font-size: 8px;
  line-height: 1.6;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-faint);
}

/* file drop */
.drop {
  position: relative;
  border: 1px dashed var(--line-strong);
  border-radius: 2px;
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 220ms linear, background-color 220ms linear;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.drop:hover,
.drop.is-over {
  border-color: var(--fg);
  background: var(--surface-2);
  color: var(--fg);
}
.drop svg {
  width: 16px;
  height: 16px;
}
.drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop small {
  font-size: 7.5px;
  color: var(--fg-faint);
  letter-spacing: 0.08em;
}

/* --------------------------------------------------------------------------
   ASCII
   -------------------------------------------------------------------------- */
.ascii-stage {
  position: relative;
  background: #050505;
  border: 1px solid var(--line);
  min-height: 360px;
  display: flex;
  overflow: hidden;
}
.ascii-out {
  margin: 0;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 6px;
  line-height: 0.94;
  letter-spacing: 0;
  color: #f4f2ec;
  white-space: pre;
  overflow: auto;
  flex: 1;
  scrollbar-width: thin;
  user-select: text;
  tab-size: 1;
}
.ascii-out::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.ascii-out::-webkit-scrollbar-thumb {
  background: rgba(244, 242, 236, 0.3);
}

/* --------------------------------------------------------------------------
   FLOW
   -------------------------------------------------------------------------- */
.flow-stage {
  min-height: clamp(360px, 52vw, 560px);
}
.flow-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* --------------------------------------------------------------------------
   TYPE TESTER
   -------------------------------------------------------------------------- */
.type-stage {
  position: relative;
  border: 1px solid var(--line);
  background: var(--bone);
  color: var(--ink);
  min-height: clamp(300px, 38vw, 440px);
  display: flex;
  align-items: center;
  padding: clamp(18px, 3vw, 40px);
  overflow: hidden;
}
.type-stage__specimen {
  width: 100%;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(28px, 5vw, 72px);
  line-height: 1;
  letter-spacing: -0.03em;
  outline: none;
  word-break: break-word;
  white-space: pre-wrap;
  transition: font-family 120ms linear;
  max-height: 100%;
  overflow: hidden;
}
.type-stage__specimen:focus {
  outline: none;
}
.type-stage__meta {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(8, 8, 8, 0.45);
  pointer-events: none;
}
.type-controls {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: clamp(14px, 1.6vw, 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.type-controls textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 10px;
  font-size: 12.5px;
  line-height: 1.5;
}
.type-controls textarea:focus {
  outline: none;
  border-color: var(--line-strong);
}
.swatch-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.swatch {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  position: relative;
}
.swatch[aria-pressed='true'] {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   KINETIC TYPE
   -------------------------------------------------------------------------- */
.kinetic-stage {
  position: relative;
  border: 1px solid var(--line);
  background: var(--ink);
  color: #f4f2ec;
  min-height: clamp(260px, 32vw, 380px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  cursor: grab;
}
.kinetic-stage:active {
  cursor: grabbing;
}
.kinetic-line {
  display: flex;
  white-space: nowrap;
  will-change: transform;
  width: max-content;
}
.kinetic-line span {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(40px, 8.6vw, 116px);
  line-height: 0.9;
  letter-spacing: -0.05em;
  text-transform: uppercase;
  padding-right: 0.32em;
}
.kinetic-line--outline span {
  color: transparent;
  -webkit-text-stroke: 1px rgba(244, 242, 236, 0.7);
}
.kinetic-stage__hud {
  position: absolute;
  left: 12px;
  bottom: 10px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 242, 236, 0.4);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   CASE / NOTES
   -------------------------------------------------------------------------- */
.lab-note {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: clamp(20px, 4vw, 60px);
  padding-block: clamp(40px, 6vw, 80px);
}
.lab-note h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(26px, 3.4vw, 42px);
  line-height: 1;
  letter-spacing: -0.04em;
}
.lab-note p {
  font-size: 14px;
  line-height: 1.75;
  color: var(--fg-muted);
  max-width: 62ch;
}
.lab-note p + p {
  margin-top: 14px;
}
.lab-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  margin-bottom: clamp(48px, 7vw, 90px);
}
.lab-cta h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.lab-cta p {
  font-size: 13px;
  color: var(--fg-muted);
  margin-top: 8px;
  max-width: 46ch;
}
.lab-cta__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   RESPONSIVE
   -------------------------------------------------------------------------- */
@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 16px 20px;
  }
  .panel__head {
    grid-column: 1 / -1;
  }
  .panel__divider {
    grid-column: 1 / -1;
  }
  .panel__actions {
    grid-column: 1 / -1;
    margin-top: 0;
  }
  .panel__note {
    grid-column: 1 / -1;
  }
  .exp__head {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .exp__desc {
    max-width: 68ch;
  }
}

@media (max-width: 820px) {
  .lab-hero__meta {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  .lab-note {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .type-stage {
    min-height: 280px;
  }
  .lab-nav__note {
    display: none;
  }
}

@media (max-width: 620px) {
  .lab-hero__title {
    font-size: clamp(34px, 12vw, 60px);
    line-height: 0.9;
  }
  .lab-hero__meta {
    grid-template-columns: 1fr 1fr;
  }
  .panel {
    grid-template-columns: 1fr;
  }
  .stage--ratio {
    aspect-ratio: 1 / 1;
  }
  .ascii-out {
    font-size: 4.4px;
  }
  .ascii-stage {
    min-height: 280px;
  }
  .type-stage__specimen {
    font-size: clamp(22px, 8vw, 40px);
  }
  .exp {
    scroll-margin-top: calc(var(--header-h) + 46px);
  }
  .kinetic-line span {
    font-size: clamp(32px, 13vw, 64px);
  }
}

/* ==========================================================================
   EXTRA MODULES — halftone, easing, pixel canvas
   ========================================================================== */

/* --------------------------------------------------------------------------
   EASING LAB
   -------------------------------------------------------------------------- */
.ease-stage {
  background: var(--bone) !important;
  color: var(--ink);
  padding: clamp(12px, 1.8vw, 22px);
  min-height: 420px;
}
.ease-inner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  height: 100%;
  min-height: 0;
}
.ease-graph {
  display: block;
  width: min(100%, 320px);
  height: auto;
  max-height: 300px;
  margin-inline: auto;
  flex: none;
  touch-action: none;
  overflow: visible;
}
.ease-grid line {
  stroke: rgba(8, 8, 8, 0.11);
  stroke-width: 1;
}
.ease-diagonal {
  stroke: rgba(8, 8, 8, 0.28);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}
.ease-curve {
  fill: none;
  stroke: #080808;
  stroke-width: 2.4;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.ease-handle-line {
  stroke: rgba(8, 8, 8, 0.55);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.ease-anchor {
  fill: #080808;
}
.ease-handle {
  fill: var(--bone);
  stroke: #080808;
  stroke-width: 2;
  cursor: grab;
  transition: fill 160ms linear;
}
.ease-handle:hover,
.ease-handle:focus-visible {
  fill: #080808;
}
.ease-handle:active {
  cursor: grabbing;
}
.ease-graph text {
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.1em;
  fill: rgba(8, 8, 8, 0.45);
}
.ease-track {
  position: relative;
  height: 46px;
  border: 1px solid rgba(8, 8, 8, 0.22);
  background:
    repeating-linear-gradient(90deg, rgba(8, 8, 8, 0.07) 0 1px, transparent 1px 28px),
    rgba(8, 8, 8, 0.03);
  overflow: hidden;
}
.ease-ball {
  position: absolute;
  left: 8px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border-radius: 50%;
  background: #080808;
  will-change: transform;
}
.ease-ball::after {
  content: '';
  position: absolute;
  left: 4px;
  bottom: -9px;
  width: 8px;
  height: 2px;
  background: rgba(8, 8, 8, 0.18);
  border-radius: 50%;
}
.ease-mark {
  position: absolute;
  right: 8px;
  top: 50%;
  width: 1px;
  height: 20px;
  margin-top: -10px;
  background: rgba(8, 8, 8, 0.35);
}
.ease-readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(8, 8, 8, 0.16);
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(8, 8, 8, 0.5);
}
.ease-readout code {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  color: #080808;
  text-transform: none;
  word-break: break-all;
  text-align: right;
}

/* --------------------------------------------------------------------------
   PIXEL CANVAS
   -------------------------------------------------------------------------- */
.pixel-stage {
  aspect-ratio: 1 / 1;
  max-height: 72vh;
  cursor: crosshair;
  touch-action: none;
}
.pixel-stage > .stage__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.pixel-stage.is-erasing {
  cursor: cell;
}
.pixel-stage.is-erasing .stage__label--tl::after {
  content: ' · ERASE';
}

@media (max-width: 1080px) {
  .ease-stage {
    min-height: 360px;
  }
  .ease-graph {
    max-height: 260px;
  }
}

@media (max-width: 620px) {
  .ease-stage {
    min-height: 320px;
    padding: 12px;
  }
  .ease-graph {
    max-height: 220px;
  }
  .ease-readout {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .ease-readout code {
    text-align: left;
    font-size: 9px;
  }
  .pixel-stage {
    aspect-ratio: 1 / 1;
    max-height: 92vw;
  }
}
