:root {
  color-scheme: light dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: light-dark(#f0ece1, #171b1a);
  color: var(--ink);
  --paper: light-dark(#faf8f0, #252c2a);
  --ink: light-dark(#282c28, #e8ede5);
  --quiet: light-dark(#555b53, #b7c4bb);
  --teal: light-dark(#245947, #a9d8c0);
  --path: light-dark(#537363, #8ba899);
  --edge: light-dark(#b4b5a8, #48564e);
  --button-top: light-dark(#fcfbf6, #303b35);
  --button-bottom: light-dark(#eeece3, #242d28);
  --button-fill: light-dark(#fffaf1, #2c3730);
  --primary-text: light-dark(#fff, #18261e);
  --amber: light-dark(#f0b676, #dcaa77);
  --ice: light-dark(#aacdd4, #91b7bd);
  --pulse: light-dark(#c4b5d5, #b5a6ca);
  --fade: light-dark(#b4c7a7, #a1b595);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--edge);
  border-radius: 12px; background: var(--button-fill); touch-action: manipulation; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

.play {
  width: min(100%, 530px);
  min-height: min(100dvh, 860px);
  margin: auto;
  padding: 12px max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.top, .actions, .tray-actions, .strip-piece, dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
}
.top { padding: 1px 2px; }
.wordmark {
  display: inline-flex; align-items: center; gap: .4em;
  color: var(--teal); font-weight: 680; font-size: .76rem; text-decoration: none;
}
.wordmark[href]:focus-visible, #scene-list a:focus-visible {
  outline: 3px solid var(--teal); outline-offset: 4px; border-radius: 4px;
}
.wordmark[href]:hover { text-decoration: underline; text-underline-offset: .25em; }
.schema-mark { width: 1.55em; height: 1.55em; flex: none; border-radius: .29em; }
.scene-picker {
  width: min(100%, 730px); min-height: 100dvh; margin: auto;
  display: grid; align-content: center; gap: 1rem; padding: 24px max(18px, env(safe-area-inset-right));
}
.scene-picker .wordmark { font-size: .9rem; }
#scene-picker-status { color: var(--quiet); }
#scene-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 10px; list-style: none; padding: 0; margin: 0;
}
#scene-list:empty { display: none; }
#scene-list a {
  display: grid; align-content: end; gap: 12px; min-height: 100px; padding: 16px;
  border-radius: 14px; border: 1px solid var(--edge);
  background: linear-gradient(var(--button-top), var(--button-bottom));
  color: var(--ink); text-decoration: none; font-size: 1.13rem; font-weight: 670;
  box-shadow: inset 0 1px #fff3, 0 3px 0 var(--edge);
}
#scene-list a:hover { border-color: var(--teal); }
#scene-list a:active { transform: translateY(2px); box-shadow: none; }
#scene-list img { width: 100%; aspect-ratio: 2; object-fit: cover; border-radius: 8px; }
h1 { font-size: clamp(1.65rem, 7vw, 2.1rem); letter-spacing: -.045em; line-height: 1.08; }
.actions button, .tray-actions button { font-size: .78rem; }
.actions #theme-toggle { width: 44px; padding: 0; font-size: 1.2rem; line-height: 1; }
#hint { min-height: 20px; padding: 0 3px; color: var(--quiet); font-size: .78rem; line-height: 1.2; }
#play-guide {
  padding: 10px 12px; border: 1px solid var(--edge); border-radius: 12px;
  background: var(--paper); font-size: .82rem;
}
.guide-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.guide-heading h2 { font-size: 1rem; }
#replay-hints { font-size: .76rem; }
#play-guide p { margin-block: 4px 8px; line-height: 1.35; }
#guide-examples h3 { font-size: .87rem; margin: 8px 0 0; }
#example-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 6px; }
#example-list button {
  display: grid; align-content: start; text-align: start; gap: 3px;
  min-height: 62px; padding: 8px; line-height: 1.25;
}
#example-list button span { font-size: .76rem; color: var(--quiet); }
@media (max-width: 420px) {
  .top, .actions { flex-wrap: wrap; }
}
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(var(--play-rows, 4), 144px);
  gap: 6px;
  padding: 9px 8px;
  border: 1px solid #c5ae8b;
  border-radius: 17px;
  background:
    radial-gradient(#aa94764d 1px, transparent 1.1px) 0 0 / 13px 13px,
    linear-gradient(150deg, #f7ebd9, var(--wood));
  box-shadow: inset 0 2px 5px #7f61472b;
}
#board[data-expanded] {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, 110px);
}
#board[data-expanded] .peg > .brick {
  grid-template-rows: 20px minmax(0, 1fr) 8px 14px / minmax(0, 1fr);
}
#board[data-expanded] .parameter-row label,
#board[data-expanded] .modulate-parameter {
  min-height: 17px;
}
#board[data-expanded] .modulate-parameter {
  min-width: 18px;
  padding: 0;
  font-size: .82rem;
}
#board[data-expanded] .params label span,
#board[data-expanded] .grip {
  font-size: .68rem;
  padding-inline: 2px;
  overflow: hidden;
}
.peg { position: relative; min-width: 0; display: grid; }
.peg::before {
  content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  place-self: center; background: #f6e7d1; box-shadow: 0 2px 3px #9a7d5645;
}
.peg[data-flow]::after {
  content: "↓"; position: absolute; z-index: 2; bottom: -13px; left: calc(50% - 7px);
  color: var(--teal); font-weight: 800; line-height: 1; pointer-events: none;
}
.peg[data-tail]::before {
  width: 2px; height: 100%; border-radius: 0; box-shadow: none;
  background: repeating-linear-gradient(var(--path) 0 4px, transparent 4px 8px);
}
.peg[data-join] .brick::after {
  content: ""; position: absolute; top: 42%; right: -8px; width: 8px; height: 15px;
  border-radius: 0 4px 4px 0; background: var(--teal); z-index: 3;
}
.slot {
  z-index: 1; padding: 0; border: 0; background: transparent;
  min-height: 44px;
}
.peg:has(.slot:focus-visible) { border-radius: 10px; box-shadow: inset 0 0 0 2px var(--teal); }
.brick {
  --brick-color: var(--amber);
  position: relative; z-index: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 6px 4px 4px; border: 1px solid #38524642; border-radius: 10px;
  background: linear-gradient(#ffffff55, transparent 50%), var(--brick-color);
  color: #202f2b; box-shadow: inset 0 -3px #3455442b, 0 2px 5px #5b493a32;
}
.brick[data-id="ice"] { --brick-color: var(--ice); }
.brick[data-id="pulse"] { --brick-color: var(--pulse); }
.brick[data-id="fade"] { --brick-color: var(--fade); }
.brick[data-id="fire"] { --brick-color: #e79b66; --control-ink: #74341c; --control-paper: #ffecd9; }
.brick[data-id="sparks"] { --brick-color: #d8b5e8; --control-ink: #58336a; --control-paper: #fbecff; }
.brick[data-id="dim"] { --brick-color: #b3c5ca; --control-ink: #344d56; --control-paper: #eaf6fa; }
.brick[data-id="hue_shift"] { --brick-color: #efbed2; --control-ink: #6e3150; --control-paper: #fff0f7; }
.brick > .grip {
  min-width: 0; min-height: 25px; padding: 0; border: 0; border-radius: 4px;
  background: transparent; font-size: .75rem; font-weight: 720; text-align: center;
  touch-action: none; overflow-wrap: anywhere;
}
.brick[data-selected] { outline: 2px solid var(--teal); }
.brick[data-ghost] {
  z-index: 3; position: absolute; inset: 0;
  outline: 2px dashed var(--teal); outline-offset: -2px; pointer-events: none; opacity: .86;
  font-weight: 720; font-size: .76rem;
}
.brick[data-ghost="blocked"] { outline-color: #902e2e; }
.row-lights, .pixels { display: grid; grid-auto-flow: column; gap: 2px; align-items: center; }
.row-lights { min-height: 8px; padding: 0 3px; pointer-events: none; }
.row-lights i, .pixels i {
  appearance: none; display: block; background: var(--light, #52635b);
  border-radius: 50%; width: 100%; max-width: 13px; aspect-ratio: 1;
  box-shadow: 0 0 5px var(--light, transparent);
}
.strip-piece {
  min-height: 48px; padding: 6px 8px; border: 2px solid #546459; border-radius: 10px;
  background: #233831; color: #f9f3e6; flex-wrap: wrap;
}
.strip-piece .pixels { flex: 1; min-width: 110px; }
.strip-label { font-weight: 650; font-size: .73rem; white-space: nowrap; }
#connection { font-size: .65rem; color: #e5eedf; }
#connection[data-draft] { color: #ead8ff; }
.tray { padding: 7px 8px 0; border-radius: 14px; background: #f8eddd; border: 1px solid #d4c3aa; }
#palette {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px; margin: 3px 0 2px;
}
#palette button {
  min-height: 47px; text-align: center; justify-content: flex-end; padding: 5px 1px;
  font-weight: 740; font-size: .76rem; touch-action: none;
}
#palette button::before {
  content: ""; position: absolute; top: -5px; left: calc(50% - 16px); width: 13px; height: 8px;
  border-radius: 4px 4px 1px 1px; background: var(--brick-color); box-shadow: 19px 0 var(--brick-color);
}
#palette button[aria-pressed="true"] { outline: 2px solid var(--teal); outline-offset: 1px; }
.tray-actions button { border: 0; background: transparent; padding: 0 4px; }
#trash {
  position: fixed; z-index: 20;
  display: grid; justify-items: center; align-content: center; gap: 5px;
  width: 76px; min-height: 72px; padding: 7px;
  border: 2px solid light-dark(#b44d47, #e8a49a);
  border-radius: 18px;
  background: light-dark(#fff1e8, #412e2d);
  color: light-dark(#852e29, #ffd6cd);
  box-shadow: 0 3px 0 light-dark(#93514a, #251817), 0 6px 16px #25181748;
  font-size: .78rem; font-weight: 750;
}
#trash[data-offscreen] { visibility: hidden; }
#trash[data-over] {
  background: light-dark(#a43c34, #f5a99c);
  border-color: light-dark(#812d27, #ffd4c7);
  color: light-dark(#fff, #461b18);
}
.bin-icon { display: grid; justify-items: center; width: 28px; gap: 3px; padding-top: 4px; }
.bin-lid {
  position: relative; width: 26px; height: 3px; border-radius: 3px; background: currentColor;
  transform-origin: 100% 50%;
}
.bin-lid::before {
  content: ""; position: absolute; left: 9px; top: -4px;
  width: 8px; height: 5px; border: 2px solid currentColor; border-radius: 3px 3px 0 0;
}
.bin-body {
  width: 20px; height: 20px; border: 2px solid currentColor; border-radius: 1px 1px 5px 5px;
  background: linear-gradient(90deg, transparent 35%, currentColor 35% 43%, transparent 43% 57%,
    currentColor 57% 65%, transparent 65%) center / 100% 10px no-repeat;
}
#trash[data-over] .bin-lid { transform: rotate(29deg); }
@media (prefers-reduced-motion: no-preference) {
  #trash { animation: bin-arrive 160ms ease-out both; transition: background-color 120ms, color 120ms; }
  .bin-lid { transition: transform 150ms cubic-bezier(.2, .8, .35, 1.3); }
  @keyframes bin-arrive {
    from { opacity: 0; transform: translateY(8px) scale(.92); }
    to { opacity: 1; transform: none; }
  }
}
#proposal-actions, #choices, #suggestions, #scopes { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
#apply-proposal, #speech-preview { background: var(--teal); color: var(--primary-text); }
dialog {
  width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 20px);
  padding: 14px; background: var(--paper); color: var(--ink); border: 1px solid var(--edge); border-radius: 16px;
}
dialog::backdrop { background: light-dark(#223a35a0, #070b08b8); }
dialog a { color: var(--teal); }
dialog h2 { font-size: 1.12rem; }
dialog input { width: 100%; min-height: 44px; margin: 5px 0; padding: 6px; }
dialog header { margin-bottom: 8px; }
dialog #slots { display: grid; gap: 5px; margin-top: 7px; }
dialog .idea-row { display: flex; align-items: center; gap: 5px; }
.idea-row span { flex: 1; }
@media (max-width: 350px) {
  .play { padding-inline: 7px; }
  #board { gap: 4px; padding-inline: 5px; }
  .brick { padding-inline: 2px; }
  .top { gap: 5px; padding-inline: 0; }
  .top h1, .actions button { white-space: nowrap; }
  .actions { gap: 4px; }
  .actions button { padding-inline: 6px; }
  .strip-piece .pixels i:nth-child(2n) { display: none; }
}

/* Same stud and socket contour as the Studio stack, fitted to each peg. */
.play { width: min(100%, 550px); gap: 10px; padding-top: 15px; }
.top { padding: 3px 4px 0; }
.wordmark { text-transform: uppercase; font-size: .69rem; letter-spacing: .09em; }
h1 { font-weight: 750; }
.actions button, .tray-actions button, #animation-drawer summary {
  background: linear-gradient(var(--button-top), var(--button-bottom));
  border: 1px solid var(--edge);
  box-shadow: 0 1px 1px #23342a18;
}
#hint { margin-inline: 4px; font-weight: 550; }
#board {
  gap: 10px 8px;
  padding: 12px 10px 8px;
  border-color: light-dark(#aaa99a, #4d5b51);
  border-radius: 19px;
  background:
    radial-gradient(circle, light-dark(#6e70591c, #b5ceaf2d) .8px, transparent 1px) 0 0 / 12px 12px,
    linear-gradient(145deg, light-dark(#f7f4e8, #29332e), light-dark(#e6e2d5, #222a26));
  box-shadow: inset 0 2px 6px #3c604721, 0 2px 3px #3c604715;
}
.peg::before { background: linear-gradient(150deg, light-dark(#efeee4, #354138), light-dark(#e1dfd3, #29362e)); border: 1px solid light-dark(#c9c8b9, #4a5a4f); box-shadow: inset 0 1px light-dark(#fff9, #a9c8ae2a), 0 1.5px 2px #12171454; }
.peg[data-tail]::before { border: 0; background: #6d9b86; }
.peg[data-flow]::after {
  bottom: -13px; left: calc(50% - 6px); color: #27644f; z-index: 4;
}
.peg[data-join] .brick::after {
  top: 43%; right: -10px; width: 10px; height: 3px;
  border-radius: 3px; background: var(--path);
}
.brick {
  --brick-gap: 5px;
  isolation: isolate; margin-top: var(--brick-gap); border: 0; background: transparent; box-shadow: none;
  padding: 4px 5px 6px; color: #172d27;
}
.peg > .brick[data-joined-inputs] { --join-inset: var(--brick-gap); }
.brick .studio-shell {
  position: absolute; pointer-events: none; z-index: -1; overflow: visible;
  top: calc(-11px - var(--join-inset, 0px)); left: -1px;
  width: calc(100% + 2px); height: calc(100% + 12px + var(--join-inset, 0px));
  filter: drop-shadow(0 2px 1px #223e3227);
}
.studio-shell path {
  fill: var(--brick-finish, var(--brick-color));
  stroke: color-mix(in srgb, var(--brick-color) 58%, #29433a);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}
.studio-shell .highlight { stop-color: color-mix(in srgb, var(--brick-color), #fff8e8 38%); }
.studio-shell .face { stop-color: var(--brick-color); }
.studio-shell .foot { stop-color: color-mix(in srgb, var(--brick-color), #322020 23%); }
.brick { user-select: none; }
.peg > .brick:not([data-ghost]) { touch-action: none; }
#board[aria-busy="false"] .peg > .brick:has(> .grip[data-move-ready]),
#board[aria-busy="false"] .grip[data-move-ready],
.tray button[data-palette]:enabled { cursor: grab; }
#board[aria-busy="false"] .peg > .brick:has(> .grip[data-move-ready]):active,
#board[aria-busy="false"] .grip[data-move-ready]:active,
.tray button[data-palette]:enabled:active { cursor: grabbing; }
.tray img { -webkit-user-drag: none; }
.brick[data-selected], #palette button[aria-pressed="true"], #presets button[aria-pressed="true"] { outline: 0; }
.brick[data-selected] .studio-shell path, .brick[aria-pressed="true"] .studio-shell path {
  stroke: var(--teal); stroke-width: 2.3;
}
.brick[data-ghost] { outline: 0; color: #183a30; opacity: .97; }
.brick[data-ghost] .studio-shell path {
  fill: color-mix(in srgb, var(--brick-color) 54%, #f9fbf3);
  stroke: light-dark(#17644e, #416e59); stroke-width: 2; stroke-dasharray: 4 3;
}
.brick[data-ghost="blocked"] .studio-shell path { stroke: #9a3933; }
.brick[data-ghost="snapping"] .studio-shell path { stroke-dasharray: none; fill: var(--brick-finish); }
#palette button::before { content: none; }
.brick > .grip { min-height: 24px; font-size: .8rem; }
#palette button { align-items: center; justify-content: center; gap: 2px; padding-bottom: 8px; min-height: 56px; }
#palette img { width: 19px; height: 19px; }
/* The label and its lettering share a positioning box so the two tones
   exchange places at the same pixel across the whole control. */
.brick[data-id="ice"] { --control-ink: #214d61; --control-paper: #e5f5fb; }
.brick[data-id="pulse"] { --control-ink: #503767; --control-paper: #f5edff; }
.brick[data-id="fade"] { --control-ink: #2f5036; --control-paper: #e9f5e7; }
.params { display: grid; align-content: center; gap: 2px; min-width: 0; }
.params label {
  --fader-light: var(--control-paper, #fff0da);
  --fader-dark: var(--control-ink, #613a19);
  position: relative;
  display: grid;
  min-height: 24px;
  border-radius: 5px;
  background: linear-gradient(to right,
    var(--fader-dark) var(--value), var(--fader-light) var(--value));
  box-shadow: inset 0 1px 2px #1a292633, 0 1px #fffa, 0 0 0 1px #1a292622;
}
.params label span {
  display: grid;
  align-items: center;
  padding-inline: 7px;
  font-size: .74rem;
  font-weight: 650;
  color: transparent;
  background: linear-gradient(to right,
    var(--fader-light) var(--value), var(--fader-dark) var(--value));
  background-clip: text;
  -webkit-background-clip: text;
  pointer-events: none;
}
.params input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  appearance: none; opacity: 0; cursor: ew-resize; touch-action: none;
}
.params input::-webkit-slider-thumb { appearance: none; width: 1px; height: 1px; }
.params input::-moz-range-thumb { width: 1px; height: 1px; border: 0; }
.params label:has(input:focus-visible) {
  outline: 2px solid #fff; outline-offset: 1px; z-index: 2;
  box-shadow: 0 0 0 4px var(--fader-dark);
}
.params label[data-moving]::after {
  content: ""; position: absolute; pointer-events: none;
  left: clamp(2px, var(--engine-value), calc(100% - 2px));
  bottom: 1px; width: 3px; height: 6px;
  transform: translateX(-50%); border-radius: 2px;
  background: #75ffe0; box-shadow: 0 0 0 1px #153e35;
}
#touch-fader {
  position: fixed; z-index: 19; pointer-events: none;
  padding: 9px 12px; border: 1px solid var(--edge); border-radius: 12px;
  background: var(--paper); box-shadow: 0 6px 20px #15191355;
  opacity: 0; visibility: hidden;
}
#touch-fader[data-open] { opacity: 1; visibility: visible; }
#touch-fader-track {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  min-height: 38px; gap: 8px; padding: 0 10px; border-radius: 7px;
  background: linear-gradient(90deg, var(--fader-dark) var(--value), var(--fader-light) var(--value));
  box-shadow: inset 0 1px 2px #1a292655;
}
#touch-fader-track > span {
  color: var(--fader-dark); background: var(--fader-light); border-radius: 4px; padding: 3px 5px;
  font-size: .83rem; font-weight: 700;
}
#touch-fader[data-tight] { padding-block: 3px; }
#touch-fader[data-tight] #touch-fader-track { min-height: 32px; }
#touch-fader-track[data-moving]::after {
  content: ""; position: absolute; left: clamp(3px, var(--engine-value), calc(100% - 3px));
  bottom: 2px; width: 4px; height: 8px; transform: translateX(-50%); border-radius: 2px;
  background: #75ffe0; box-shadow: 0 0 0 1px #153e35;
}
@media (prefers-reduced-motion: no-preference) {
  #touch-fader { transition: opacity 120ms ease, visibility 120ms; }
}
.params label:only-child { min-height: 38px; }
.parameter-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px;
}
.parameter-row label:only-child { min-height: 24px; }
.params > .parameter-row:only-child label { min-height: 36px; }
.modulate-parameter {
  min-width: 26px; min-height: 24px; padding: 0 3px;
  color: #26433a; background: #f8f5eb; border: 1px solid #52695c;
  border-radius: 4px; font-size: 1rem; line-height: 1;
}
.modulate-parameter[data-modulated] { color: #fff; background: #276454; }
dialog#modulation {
  position: fixed; inset: auto; margin: 0; padding: 10px;
  width: min(330px, calc(100vw - 16px)); overflow: auto;
  border-color: var(--path); border-radius: 14px;
}
dialog#modulation::backdrop { background: transparent; }
#modulation header { margin-block-end: 6px; }
#modulation header button { min-width: 44px; padding-inline: 0; font-size: 1.25rem; }
#modulation-brick { font-size: .72rem; font-weight: 670; color: var(--quiet); }
#modulation-form { display: grid; gap: 6px; }
#modulation-target { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: .8rem; }
#modulation-target select { min-height: 40px; font: inherit; color: inherit; }
.motion-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.motion-shapes {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  padding: 0; margin: 0; border: 0; min-width: 0;
}
.motion-shapes label { position: relative; }
.motion-shapes input {
  position: absolute; inset: 0; height: 100%; width: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1;
}
.motion-shapes span {
  display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 46px;
  border: 1px solid var(--edge); border-radius: 7px;
  background: linear-gradient(var(--button-top), var(--button-bottom));
  font-size: .69rem; font-weight: 670; box-shadow: inset 0 -2px #0002;
}
.motion-shapes svg { width: 29px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.motion-shapes input:checked + span {
  background: var(--control-paper, #e2efdf); color: var(--control-ink, #245947);
  border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor;
}
.motion-shapes input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 1px; }
.motion-faders { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.motion-cycle { grid-column: 1 / -1; }
#modulation .motion-faders label { min-height: 44px; }
#modulation .motion-faders label span { grid-template-columns: auto 1fr; gap: 2px; font-size: .82rem; }
.motion-readout { text-align: end; font-style: normal; font-variant-numeric: tabular-nums; }
#modulation .motion-faders input { min-height: 0; padding: 0; }
.motion-live { min-height: 20px; }
#modulation-feedback {
  display: grid; align-items: center; grid-template-columns: auto 1fr minmax(3em, auto);
  gap: 6px; color: var(--quiet); font-size: .73rem;
}
#modulation-meter { width: 100%; height: 14px; }
#modulation-value { font-variant-numeric: tabular-nums; text-align: end; }
.modulation-actions { display: flex; justify-content: flex-end; gap: 6px; }
.modulation-actions button { font-size: .79rem; }
#modulation-form [type="submit"] { background: var(--teal); color: var(--primary-text); }
#board .parameter-row[data-motion-target] > label { outline: 2px solid var(--teal); outline-offset: 1px; }
@media (max-width: 370px), (max-height: 520px) {
  dialog#modulation { padding: 7px; }
}
@media (forced-colors: active) {
  .params label { outline: 1px solid CanvasText; }
  .params label span { color: CanvasText; padding-bottom: 12px; }
  .params input { appearance: auto; opacity: 1; top: auto; height: 12px; }
  .params input::-webkit-slider-thumb { appearance: auto; width: auto; height: auto; }
  .params input::-moz-range-thumb { width: .7em; height: .7em; }
}
.row-lights { background: #20392f4a; padding: 2px 3px; border-radius: 3px; min-height: 8px; }
.row-lights i, .pixels i { border-radius: 2px; transition: background-color 140ms linear, box-shadow 140ms linear; }
#strip[data-drag-preview] i { transition-duration: 0ms; }
.strip-piece { border-color: #365247; background: #20362d; padding-inline: 10px; border-radius: 9px; }
.tray { position: relative; margin-top: 1px; padding: 6px 9px 1px; background: light-dark(#f4f1e7, #202925); border: 1px solid var(--edge); }
.tray-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
.tray-heading h2 { font-size: .8rem; }
#animation-drawer summary {
  display: grid; place-items: center; min-height: 44px; padding: 0 11px; border-radius: 9px;
  font-size: .74rem; color: var(--teal); cursor: pointer; list-style: none;
}
#animation-drawer summary::-webkit-details-marker { display: none; }
#animation-drawer .drawer-close, #animation-drawer[open] .drawer-open { display: none; }
#animation-drawer[open] .drawer-close { display: inline; }
.more-bricks {
  position: absolute; z-index: 8; inset: auto 0 calc(100% + 4px);
  background: var(--paper); border: 1px solid var(--edge); border-radius: 15px;
  padding: 12px; box-shadow: 0 8px 20px #1e3b3333;
}
#animation-drawer[data-dragging] .more-bricks { pointer-events: none; opacity: .2; }
#presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
#presets button { min-height: 48px; justify-content: center; align-items: flex-start; text-align: left; padding: 5px 9px 9px; touch-action: none; }
.tile-name { font-weight: 740; font-size: .77rem; }
.tile-note { font-size: .65rem; color: inherit; }
@media (max-width: 350px) {
  #board { gap: 8px 6px; padding-inline: 7px; }
  .brick { padding-inline: 3px; }

}
@media (prefers-reduced-motion: reduce) {
  .row-lights i, .pixels i { transition: none; }
}

/* Reserve room for all three faders so editing never changes snap geometry. */
.peg > .brick {
  display: grid;
  grid-template: 24px minmax(0, 1fr) 10px 24px / minmax(0, 1fr);
  justify-content: normal;
  gap: 1px;
  padding: 3px 3px 4px;
}
.peg .grip {
  display: flex;
  align-items: center;
  padding-inline: 4px;
  min-height: 0;
  text-align: left;
  font-weight: 690;
}
.peg .row-lights { margin-inline: 3px; }
.peg > .brick .row-lights i { max-height: 6px; }
.peg[data-drop="fits"] > .slot,
.peg[data-drop="target"] > .slot {
  border: 1.5px dashed var(--path);
  border-radius: 7px;
  background: light-dark(#f4f9ed77, #a9d8c01a);
}
.peg[data-drop="fits"] > .slot::after,
.peg[data-drop="target"] > .slot::after {
  content: "+";
  color: var(--teal);
  font-size: 1.25rem;
  font-weight: 600;
}
.peg[data-drop="target"] > .slot {
  border-style: solid; border-width: 2px; background: light-dark(#c7dfc1, #3b584c);
}
.peg[data-drop="blocked"] > .slot { background: #65776c13; border-radius: 7px; }
.peg[data-drop="blocked"]::before { opacity: .38; }
.flow-trace {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 4;
}
.flow-trace path {
  fill: none;
  stroke: var(--path);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
#board .peg[data-flow]::after,
#board .peg[data-join] .brick::after { content: none; }
#hint { min-height: 32px; padding: 4px 6px; border-radius: 5px; }
#hint[data-invalid] {
  color: light-dark(#692a23, #f4c2b7);
  background: light-dark(#f7e6db, #492e29);
  box-shadow: inset 3px 0 light-dark(#a55244, #d79483);
}

.play { width: min(100%, 740px); }
.instrument {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(69px, 18vw, 106px);
  align-items: start;
  gap: clamp(5px, 1.6vw, 12px);
  flex: 1;
}
.stack-workspace {
  display: flex; flex-direction: column;
  align-self: stretch; min-width: 0; gap: 3px;
}
#play-space { align-self: end; min-height: 38px; padding-inline: 10px; font-size: .76rem; }
.tray {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
  margin: 0;
  padding: 10px clamp(4px, 1vw, 9px) 6px;
}
.tray h2 { padding-inline: 2px; font-size: .82rem; }
#palette { grid-template-columns: minmax(0, 1fr); gap: 8px; margin: 0; }
#palette button { min-height: 54px; }
.custom-color-tile { position: relative; display: grid; min-width: 0; }
#palette .custom-color-tile > .brick { justify-content: end; min-height: 64px; padding-top: 30px; }
.custom-color-tile input {
  position: absolute; z-index: 2; top: 5px; left: 50%; translate: -50% 0;
  width: min(40px, calc(100% - 4px)); height: 30px; padding: 6px 8px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
}
.custom-color-tile input::-webkit-color-swatch-wrapper { padding: 0; }
.custom-color-tile input::-webkit-color-swatch { border: 1px solid #271d3c; border-radius: 4px; }
.custom-color-tile input::-moz-color-swatch { border: 1px solid #271d3c; border-radius: 4px; }
.custom-color-tile input:focus-visible {
  outline: 2px solid var(--teal); outline-offset: -3px;
}
@media (min-width: 375px) {
  .instrument { grid-template-columns: minmax(0, 1fr) 124px; }
  #palette { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 5px; }
  #palette .tile-name { font-size: .7rem; overflow-wrap: anywhere; }
  .more-bricks { width: min(294px, calc(100vw - 148px)); }
}
@media (min-width: 1200px) {
  .instrument { grid-template-columns: minmax(0, 1fr) 194px; }
  #palette, #presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .more-bricks { width: 386px; }
}
.tray-actions { display: grid; gap: 4px; align-items: stretch; justify-content: stretch; }
.tray-actions .speak-brick {
  --brick-color: #b2d5c7; min-height: 49px; justify-content: center;
  background: transparent; border: 0; box-shadow: none; color: #172d27;
}
#tray-shortcuts {
  position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px;
}
#tray-shortcuts > .brick {
  display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 46px; padding: 5px 3px; gap: 4px;
}
#tray-shortcuts > .brick[aria-expanded="true"] .studio-shell path { stroke: var(--teal); stroke-width: 2; }
.tray-actions .gift-menu-brick {
  --brick-color: #e4b6a4; color: #442e2a; font-weight: 750; box-shadow: none;
  border: 0; background: transparent;
}
.gift-menu-icon {
  position: relative; display: inline-block; flex: none;
  width: 14px; height: 11px; margin-top: 3px; border-radius: 2px;
  border: 1.5px solid currentColor;
  background: linear-gradient(90deg, transparent 43%, currentColor 43% 57%, transparent 57%),
    linear-gradient(transparent 27%, currentColor 27% 43%, transparent 43%);
}
.gift-menu-icon::before {
  content: ""; position: absolute; inset: -5px 1px auto; height: 4px;
  border: 1.5px solid currentColor; border-radius: 4px 4px 1px 1px;
}
#speech, #gift-shelf {
  position: absolute; inset: calc(100% + 5px) 0 auto auto; z-index: 15;
  width: min(332px, calc(100vw - 22px)); max-height: var(--tray-panel-height, 288px);
  padding: 8px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--edge); border-radius: 12px;
  color: var(--ink); background: var(--paper); box-shadow: 0 5px 20px #18131e40;
}
#speech { border-top: 2px solid light-dark(#89639c, #b88dd0); }
.imagine-prompt {
  position: sticky; z-index: 1; top: 0; background: var(--paper);
  display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-flow: column; grid-auto-columns: auto;
  gap: 5px; align-items: center;
}
.imagine-prompt-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
#speech input, #speech select {
  min-width: 0; min-height: 38px; padding: 5px 8px; font: inherit;
  color: var(--ink); background: var(--button-fill); border: 1px solid var(--edge); border-radius: 7px;
}
#speech #transcript { width: 100%; min-height: 42px; font-size: 16px; }
#speech button { min-height: 36px; padding: 4px 8px; }
#speech #kfir-dictate { min-height: 42px; padding-inline: 6px; }
#speech #kfir-dictate[data-listening] { border-color: var(--teal); }
#speech #speech-preview { min-height: 42px; padding-inline: 9px; }
#speech-status { margin: 5px 0; font-size: .76rem; line-height: 1.35; }
#speech-status:empty { display: none; }
#imagine-access { margin-top: 5px; font-size: .76rem; }
#imagine-access summary { min-height: 28px; padding: 5px 2px; cursor: pointer; }
#kfir-tester-fields, #kfir-invite-result { display: grid; gap: 4px; }
#kfir-tester-fields > button, #kfir-copy-invite { justify-self: start; }
#kfir-speech-notice p { margin-block: 6px; font-size: .74rem; }
#gift-shelf { margin: 0; }
#gift-shelf-title { flex: 1; }
#gift-shelf #close-gifts, #close-imagine { width: 36px; font-size: 1.15rem; }
@media (prefers-reduced-motion: no-preference) {
  #speech:not([hidden]), #gift-shelf:not([hidden]) { animation: tray-panel-in 140ms ease-out; }
  @keyframes tray-panel-in {
    from { opacity: .8; translate: 0 -3px; }
    to { opacity: 1; translate: 0 0; }
  }
}
#generated-brick:empty { display: none; }
#generated-brick button {
  width: 100%; padding: 6px; min-height: 48px; justify-content: center;
  background: transparent; border: 0; box-shadow: none; overflow-wrap: anywhere;
  touch-action: none; cursor: grab;
}
.gift-tools { display: flex; gap: 3px; min-width: 0; }
.gift-tools button, #generated-brick .gift-tools button {
  flex: 1; min-width: 0; min-height: 28px; padding: 2px 4px; cursor: pointer; touch-action: manipulation;
  color: var(--ink); background: var(--paper); border: 1px solid var(--edge); font-size: .7rem;
}
.saved-gift { display: grid; gap: 3px; align-content: start; max-width: 100%; }
#gift-workspace {
  position: fixed; inset: 0 auto auto 0; margin: 0; width: min(360px, calc(100vw - 18px));
  max-width: calc(100vw - 18px); padding: 10px; overflow: hidden;
}
#gift-workspace[open] { display: flex; flex-direction: column; gap: 6px; }
#gift-workspace::backdrop { background: #10181240; }
#gift-workspace header, .gift-workspace-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0;
}
#gift-workspace h2, #gift-workspace h3 { margin: 0; overflow-wrap: anywhere; }
#gift-workspace header button { min-height: 32px; white-space: nowrap; }
#gift-workspace header div { min-width: 0; }
#gift-breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 5px; font-size: .74rem; }
#gift-breadcrumb button { min-height: 28px; padding: 1px 4px; white-space: normal; }
#gift-breadcrumb span { overflow-wrap: anywhere; }
.gift-workspace-body { display: grid; gap: 8px; overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
#gift-graph { padding: 6px; background: var(--button-bottom); border-radius: 8px; overflow-x: auto; }
.native-branch { display: grid; gap: 4px; justify-items: stretch; }
.native-inputs { display: grid; gap: 5px; padding-inline-start: 7px; border-inline-start: 1px solid var(--edge); }
.native-lane { display: grid; gap: 2px; }
.native-lane > small, #gift-graph > small { justify-self: center; text-align: center; font-size: .68rem; }
.native-brick {
  display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; text-align: left; flex-wrap: wrap;
  min-width: 84px; min-height: 32px; padding: 4px 7px; overflow-wrap: anywhere;
  background: linear-gradient(var(--button-top), var(--button-bottom)); box-shadow: inset 0 -2px var(--edge);
}
.native-lane:has(> small) .native-brick { font-size: .78rem; }
.native-brick small { font-size: .67rem; opacity: .84; }
.native-brick[aria-pressed="true"], .native-gift { border-color: var(--teal); }
.native-brick[aria-pressed="true"] { outline: 1px solid var(--teal); outline-offset: -2px; }
#gift-block-settings { display: grid; gap: 4px; padding: 5px; align-content: start; }
#gift-block-settings h3 { font-size: .96rem; }
#gift-block-settings label { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
#gift-block-settings input { width: 90px; min-height: 34px; margin: 0; }
#gift-block-settings input[type="color"] { width: 46px; }
#gift-block-settings input[type="checkbox"] { width: 22px; }
#gift-block-settings dl { margin: 4px 0; font-size: .77rem; }
#gift-block-settings dd { margin: 0 0 5px; overflow-wrap: anywhere; }
#gift-preview-pixels { margin-block: 2px 4px; }
#gift-workspace-status { margin: 3px 0; font-size: .75rem; }
#gift-workspace-status:empty { display: none; }
.gift-workspace-actions button { min-height: 36px; }
#save-gift-workspace:enabled { background: var(--teal); color: var(--primary-text); }
#gift-editor { max-height: calc(100dvh - 32px); overflow: auto; }
#gift-editor-form, #gift-editor-controls { display: grid; gap: 8px; }
#gift-editor fieldset {
  display: grid; gap: 5px; min-width: 0; padding: 7px;
  border: 1px solid var(--edge); border-radius: 8px;
}
#gift-editor label {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
#gift-editor input { width: 94px; min-height: 36px; font: inherit; }
#gift-editor input[type="color"] { width: 48px; }
#gift-editor input[type="checkbox"] { width: 24px; }
#gift-editor-status:empty { display: none; }
#imagine-feedback {
  position: fixed; inset: 0 auto auto 0; margin: 0; width: min(360px, calc(100vw - 18px)); overflow: auto;
}
#imagine-feedback-result { min-height: 32px; font-size: .77rem; }
#spatial-map {
  position: fixed; inset: 0 auto auto 0; margin: 0; width: min(360px, calc(100vw - 18px));
  padding: 8px; overflow: auto;
}
#spatial-map[open] { display: grid; gap: 4px; }
#spatial-map::backdrop { background: #10181240; }
#spatial-map h2, #spatial-map p, #spatial-map header { margin: 0; }
#spatial-map p { font-size: .75rem; }
#spatial-map footer, .spatial-map-path, .spatial-map-position {
  display: flex; gap: 7px; align-items: center; justify-content: space-between;
}
#spatial-map-tools:not([hidden]) { display: flex; gap: 3px; flex-wrap: wrap; }
#spatial-map-tools button[aria-pressed="true"] { border-color: var(--teal); }
#spatial-map button { min-height: 32px; }
#spatial-map-canvas {
  width: 100%; height: clamp(98px, 24dvh, 160px); display: block;
  background: #17221e; border-radius: 8px; border: 1px solid var(--edge);
  cursor: crosshair; touch-action: none;
}
.spatial-map-path, .spatial-map-position { font-size: .79rem; }
.spatial-map-path button { width: 38px; }
#spatial-map-position { min-height: 28px; margin: 0; flex: 1; min-width: 0; accent-color: var(--teal); }
#spatial-map-status[data-phase="live"] { color: var(--teal); }
#imagine-feedback-form { display: grid; gap: 8px; padding-bottom: 4px; font-size: .83rem; }
#imagine-feedback-form p { margin: 0; }
#imagine-feedback-form label { display: grid; gap: 4px; }
#imagine-feedback-form textarea {
  width: 100%; resize: vertical; padding: 6px; font: inherit; color: var(--ink);
  background: light-dark(#fffdf7, #1b221f); border: 1px solid var(--edge); border-radius: 6px;
}
#imagine-feedback-form button { justify-self: start; min-height: 44px; padding: 6px 12px; }
#imagine-feedback-status:empty { display: none; }
#imagine-model-field:not([hidden]) {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#imagine-model { min-height: 44px; min-width: 0; font: inherit; }
.tray-actions button, #animation-drawer summary {
  width: 100%; min-width: 0; padding-inline: 2px; text-align: center;
  font-size: .72rem; line-height: 1.2;
}
#animation-drawer { position: relative; }
.more-bricks {
  inset: auto calc(100% + 8px) 0 auto;
  width: min(280px, calc(100vw - 100px));
}
.more-bricks:has([data-palette="wled"]) {
  max-height: min(370px, 50dvh);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.more-bricks:has([data-palette="wled"]) #presets button {
  touch-action: pan-y;
  overflow-wrap: anywhere;
}
.strip-piece { column-gap: 8px; border-radius: 4px 4px 12px 12px; border: 1px solid #383e36; background: linear-gradient(#353b34, #292f29); box-shadow: inset 0 1px #ffffff20, 0 2px 3px #33322620; }
.strip-piece .pixels { padding: 3px; border-radius: 4px; background: #1d231f; box-shadow: inset 0 1px 2px #10141099; }
.strip-piece .pixels { min-width: 0; }
@media (max-width: 460px) {
  .play { padding-inline: max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-right)); }
  #board { padding-inline: 5px; gap: 9px 4px; border-radius: 12px 12px 4px 4px; }
  .peg > .brick { padding-inline: 2px; }
  .brick > .grip, .params label span { padding-inline: 3px; }
  .strip-piece { display: grid; grid-template-columns: 1fr auto; }
  .strip-piece .pixels { grid-row: 2; grid-column: 1 / -1; }
  #connection { text-align: right; }
}
.brick:is([data-id="blend"], [data-id="add"], [data-id="tint"], [data-id="mask"]) {
  --brick-color: light-dark(#d8d3a3, #c2bb90);
  --control-ink: #474326;
  --control-paper: #fcf8dd;
}
#board { row-gap: 0; border-radius: 14px 14px 4px 4px; }
#board .flow-trace { z-index: 0; }
.flow-trace path[data-detached] { opacity: .52; stroke-dasharray: 3 4; }
.peg > .brick[data-detached] { translate: 0 -6px; }
.peg > .brick[data-detached] .studio-shell {
  filter: drop-shadow(0 6px 3px #111c1670);
}
.brick[data-detached] .studio-shell path { stroke-dasharray: 4 3; }
.brick[data-detached] .wire-port { outline: 1px dashed currentColor; outline-offset: -3px; }
#wire-strip { min-height: 32px; padding-inline: 7px; color: var(--ink); font-size: .72rem; }
.brick[data-wire-target] .studio-shell path { stroke: var(--teal); stroke-width: 2.3; }
.peg[data-reparent] > .brick .studio-shell path { stroke: var(--teal); stroke-width: 2.3; }
.wire-port {
  position: relative; left: calc((var(--socket-pos, .5) - .5) * 100%);
  justify-self: center; display: grid; place-items: center; color: #254c40;
  width: 36px; min-height: 0; padding: 0;
  background: transparent; border: 0; border-radius: 4px;
}
.wire-port[aria-pressed="true"] { color: #fff; background: #1d5e4b; }
#board .peg { overflow: visible; }

.peg[data-vacated] > .brick:not([data-ghost]) { opacity: 0; }
.flow-trace path[data-proposed] { stroke: var(--teal); stroke-width: 2.7; stroke-dasharray: 4 2; }


#board { --peg-gap: 8px; column-gap: var(--peg-gap); }
@media (max-width: 460px) {
  #board { --peg-gap: 4px; }
}
.peg > .brick {
  left: calc(-1 * var(--span-back, 0) * (100% + var(--peg-gap)));
  width: calc(var(--span, 1) * 100% + (var(--span, 1) - 1) * var(--peg-gap));
}
.peg[data-covered] > .slot { visibility: hidden; }
.peg[data-covered]::before { visibility: hidden; }

.peg[data-drop="fits"] > .brick:not([data-ghost]) .studio-shell path { stroke: var(--teal); stroke-dasharray: 4 3; }

.top { padding-bottom: 8px; border-bottom: 1px solid #77766538; }
.actions button, .tray-actions button, #animation-drawer summary { border-radius: 8px; }
.tray { box-shadow: inset 0 1px light-dark(#fff9, #c3dcca26), 0 2px 3px #1217122a; }
.tray h2 { letter-spacing: -.015em; }
#animation-drawer summary:focus-visible, dialog a:focus-visible {
  outline: 3px solid var(--teal); outline-offset: 2px;
}
.brick .studio-shell { filter: drop-shadow(0 2px 0 #29352e70) drop-shadow(0 3px 3px #19161342); }
dialog { box-shadow: 0 16px 48px #282b2440; }
dialog input { border: 1px solid var(--edge); border-radius: 6px; background: light-dark(#fffdf7, #1b221f); }
@media (prefers-reduced-motion: no-preference) {
  #palette .brick, #presets .brick, .actions button, .tray-actions button {
    transition: transform 140ms ease-out, box-shadow 140ms ease-out;
  }
  @media (hover: hover) {
    #palette .brick:hover, #presets .brick:hover { transform: translateY(-2px); }
  }
  #palette .brick:active, #presets .brick:active, .actions button:enabled:active,
  .tray-actions button:enabled:active { transform: translateY(1px); }
  dialog[open], #animation-drawer[open] .more-bricks {
    animation: play-surface-in 160ms ease-out both;
  }
  @keyframes play-surface-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

.material-definitions { position: absolute; pointer-events: none; }
.brick:not([data-ghost]) .studio-shell path { filter: url(#brick-rim); }


.brick[data-id="gift"] {
  --brick-color: light-dark(#e8b19b, #d4a28f);
}
.brick[data-id="gift"] > .grip::after {
  content: "";
  width: 10px;
  height: 10px;
  margin-left: auto;
  border: 1px solid #784f42;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent 38%, #784f42 38% 62%, transparent 62%),
    linear-gradient(transparent 38%, #784f42 38% 62%, transparent 62%);
}
.gift-shelf {
  margin-top: 8px; padding: 7px 8px;
  border: 1px solid var(--edge); border-radius: 10px;
  background: var(--paper);
}
.gift-shelf-header { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.gift-shelf h2 { font-size: .88rem; }
#wrap-stack, #wrap-form button { font-size: .76rem; }
#wrap-form { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
#wrap-form label { font-size: .76rem; }
#wrap-form input, #wrap-form select {
  min-width: 0; min-height: 36px; padding-inline: 7px;
  border: 1px solid var(--edge); border-radius: 6px; background: var(--button-fill); color: var(--ink);
}
#gift-name { flex: 1 1 115px; }
#gift-bricks { display: flex; flex-wrap: wrap; gap: 8px; }
#gift-bricks:not(:empty) { margin-top: 9px; }
#gift-bricks .gift-tile {
  padding: 7px 10px 10px; max-inline-size: 100%; min-height: 38px;
  font-size: .76rem; font-weight: 700; overflow-wrap: anywhere; touch-action: none; cursor: grab;
}
#gift-bricks .gift-tile:active { cursor: grabbing; }
#gift-status { margin-top: 5px; font-size: .75rem; }
#gift-status:empty { display: none; }

.tray-actions .imagine-brick {
  --brick-color: #53286f;
  color: #fff8ff;
  font-size: .82rem;
  font-weight: 750;
  text-shadow: 0 1px 4px #170c29;
}
.imagine-brick .studio-shell stop {
  stop-color: var(--imagine-violet);
  animation: imagine-color 7s ease-in-out infinite alternate;
}
.imagine-brick .highlight { --imagine-violet: #8256ad; --imagine-blue: #397e96; --imagine-rose: #a4508e; }
.imagine-brick .face { --imagine-violet: #53286f; --imagine-blue: #1d506c; --imagine-rose: #783365; }
.imagine-brick .foot { --imagine-violet: #34164d; --imagine-blue: #183148; --imagine-rose: #462044; }
.imagine-star {
  fill: #ffcafe;
  transform-box: fill-box;
  transform-origin: center;
  animation: imagine-twinkle 3.4s ease-in-out infinite;
}
.imagine-stars g:nth-child(2) .imagine-star { fill: #8bf9ef; animation-delay: -1.8s; }
.imagine-stars g:nth-child(3) .imagine-star { fill: #ffe2a5; animation-delay: -1s; }
.imagine-stars g:nth-child(4) .imagine-star { fill: #b8dbff; animation-delay: -2.6s; }
@keyframes imagine-color {
  50% { stop-color: var(--imagine-blue); }
  100% { stop-color: var(--imagine-rose); }
}
@keyframes imagine-twinkle {
  0%, 100% { opacity: .52; transform: scale(.78); }
  50% { opacity: 1; transform: scale(1.24); }
}
@media (prefers-reduced-motion: reduce) {
  .imagine-brick .studio-shell stop, .imagine-star { animation: none; }
}

.board-actions { display: flex; justify-content: end; gap: 5px; }
#kfir-coach {
  position: fixed; z-index: 6; display: flex; align-items: start; gap: 6px;
  width: min(245px, calc(100vw - 35px)); padding: 8px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--teal); border-radius: 10px;
  box-shadow: 0 3px 12px #1113; pointer-events: none;
}
#kfir-coach p { flex: 1; padding-inline-start: 4px; font-size: .79rem; line-height: 1.4; }
#kfir-dismiss-hint { flex: none; width: 38px; min-height: 38px; padding: 0; pointer-events: auto; }
[data-kfir-coached] { outline: 2px solid var(--teal); outline-offset: 2px; }

@media (max-width: 700px), (max-width: 1024px) and (max-height: 520px) {
  .play {
    --play-gap: 5px;
    position: relative;
    min-height: 0;
    gap: 4px;
  }
  :root:not([data-kfir]) .play { height: 100dvh; padding-block: 6px; }
  .play header.top { flex-wrap: nowrap; align-items: center; padding: 0 1px 3px; }
  :root[data-kfir] .play .top { flex-wrap: nowrap; align-items: center; }
  .top h1 {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
  }
  .top .wordmark { font-size: .85rem; white-space: nowrap; }
  .top .actions { flex-wrap: nowrap; gap: 3px; }
  :root[data-kfir] .top .actions { flex-wrap: nowrap; }
  .actions button { min-height: 34px; padding-inline: 6px; }
  .actions #theme-toggle { width: 34px; }
  #hint {
    min-height: 16px; padding: 0 2px; margin: 0;
    font-size: .71rem; line-height: 1.18;
  }
  .play-help-line { position: relative; display: grid; align-items: center; min-height: 34px; }
  .play-help-line #kfir-coach { position: absolute; inset: 0; width: auto; align-items: center; padding: 2px 5px; }
  .play-help-line #kfir-coach p { font-size: .71rem; line-height: 1.15; }
  .play-help-line #kfir-dismiss-hint { width: 28px; min-height: 28px; }
  .play-help-line:has(#hint[data-invalid]) #kfir-coach { visibility: hidden; }
  .instrument {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: var(--play-gap); min-height: 0;
  }
  .stack-workspace {
    position: relative; min-height: 0; display: grid; align-items: center;
    grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr) auto;
  }
  #board {
    flex: 1 1 0; min-height: 0; padding: 8px 5px 4px;
    grid-column: 1 / -1; align-self: stretch;
    grid-template-rows: repeat(4, minmax(0, 1fr)); row-gap: 0;
  }
  #board[data-expanded] { grid-template-rows: repeat(6, minmax(0, 1fr)); }
  #board .peg, #board .slot { min-height: 0; }
  #board .peg > .brick {
    grid-template-rows: 16px minmax(0, 1fr) 6px 8px;
    min-height: 0; padding: 1px 2px 2px; gap: 0;
  }
  #board .grip { font-size: .68rem; white-space: nowrap; overflow: hidden; }
  #board .peg > .brick[data-has-faders] {
    container-type: inline-size;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    grid-template-rows: 13px minmax(0, 1fr) 5px;
  }
  #board [data-has-faders] > :is(.grip, .params, .row-lights) { grid-column: 1 / -1; }
  #board [data-has-faders] > .grip { display: block; text-overflow: ellipsis; }
  #board [data-has-faders] > .wire-port {
    position: absolute; bottom: 0; height: 7px;
    left: calc(var(--socket-pos, .5) * 100%); translate: -50% 0;
  }
  @container (min-width: 92px) {
    #board [data-has-faders] > .grip { grid-area: 1 / 1 / 3 / 2; }
    #board [data-has-faders] > .params { grid-area: 1 / 2 / 3 / 3; }
    #board [data-has-faders] > .row-lights { grid-area: 3 / 1 / 4 / 3; }
  }
  #board .params { align-content: stretch; grid-auto-rows: minmax(0, 1fr); gap: 1px; }
  #board[data-expanded] .params .parameter-row label,
  #board[data-expanded] .params .modulate-parameter { min-height: 0; }
  #board .params[data-shared-fader] { position: relative; }
  #board .params[data-shared-fader] > .parameter-row:not([data-current]) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); pointer-events: none;
  }
  #board .params[data-shared-fader] > .parameter-row[data-current] label > span {
    display: flex; align-items: center; justify-content: space-between;
  }
  #board .params[data-shared-fader] > .parameter-row[data-current] label > span::after {
    content: "↕"; padding-inline: 2px; color: var(--fader-dark); background: var(--fader-light); border-radius: 3px;
  }
  #board .params label, #board .modulate-parameter { min-height: 0; }
  #board .params label span { font-size: .62rem; overflow: hidden; padding-inline: 2px; }
  #board .modulate-parameter { min-width: 16px; padding: 0; font-size: .72rem; }
  #board .wire-port { width: 26px; font-size: .63rem; line-height: 1; }
  #board .row-lights { min-height: 0; padding-block: 0; }
  #board .kfir-wled-params, #board .gift-tools button {
    min-height: 0; padding: 1px 2px; font-size: .59rem; overflow: hidden;
  }
  #board .gift-tools { gap: 1px; }
  #board .gift-tools .edit-gift, #generated-brick .gift-tools .edit-gift {
    flex: 0 0 20px; font-size: 0;
  }
  #board .gift-tools .edit-gift::after, #generated-brick .gift-tools .edit-gift::after {
    content: "✎"; font-size: .76rem;
  }
  .strip-piece {
    min-height: 28px; padding: 2px 5px; gap: 2px 4px;
    display: grid; grid-template-columns: 1fr auto;
  }
  .strip-piece .pixels { grid-row: 2; grid-column: 1 / -1; padding: 2px; }
  .strip-piece .pixels i { max-height: 6px; }
  .strip-label, #connection { font-size: .57rem; }
  #wire-strip { min-height: 24px; font-size: .62rem; }
  #play-space, #open-spatial-map, #proposal-actions button { min-height: 33px; padding-inline: 5px; font-size: .7rem; }
  .stack-workspace:has(#proposal-actions:not([hidden])) .board-actions { display: none; }
  .board-actions, #proposal-actions { justify-self: end; }
  .tray {
    min-width: 0; margin: 0; padding: 4px 5px 2px; align-items: center;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "shortcuts animations options" "generated generated feedback" "palette palette palette";
    gap: 0 5px;
  }
  .tray-heading { display: none; }
  .tray > .tray-actions { display: contents; }
  #tray-shortcuts { grid-area: shortcuts; grid-template-columns: repeat(2, minmax(0, 70px)); gap: 4px; }
  #tray-shortcuts > .brick { min-height: 34px; gap: 3px; padding: 3px 1px; font-size: .68rem; }
  #speech, #gift-shelf { inset: auto auto calc(100% + 5px) 0; }
  #animation-drawer { grid-area: animations; position: static; }
  #ideas { grid-area: options; }
  .tray #ideas, #animation-drawer summary { min-height: 34px; padding-inline: 5px; font-size: .66rem; }
  .gift-menu-icon { width: 12px; height: 9px; }
  #generated-brick { grid-area: generated; }
  #generated-brick button { min-height: 31px; padding: 3px; }
  #generated-brick:not(:empty) { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; align-items: center; }
  #generated-brick .gift-tools button { min-height: 24px; font-size: .64rem; }
  #generated-brick .gift-tools .edit-gift { font-size: 0; }
  #generated-brick .gift-tile span {
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  #palette {
    grid-area: palette; min-width: 0; display: grid; grid-template-columns: none;
    grid-auto-flow: column; grid-auto-columns: clamp(58px, 17vw, 76px); gap: 5px;
    overflow: auto hidden; overscroll-behavior-inline: contain; touch-action: pan-x;
    scrollbar-width: thin; padding: 6px 2px 4px;
  }
  #palette .brick { min-height: 44px; margin-top: 0; padding: 2px 2px 3px; touch-action: pan-x; }
  #palette img { width: 13px; height: 13px; }
  #palette .tile-name { font-size: .64rem; line-height: 1.08; overflow-wrap: anywhere; }
  #palette .custom-color-tile > .brick { min-height: 44px; padding-top: 19px; }
  .custom-color-tile input { top: 3px; height: 24px; padding: 3px 7px; }
  #animation-drawer .more-bricks {
    inset: auto 0 calc(100% + 4px) auto;
    width: min(430px, 100%);
    padding: 8px; max-height: min(320px, 46dvh); overflow-y: auto;
  }
  #play-guide {
    position: absolute; z-index: 11; inset: 38px 0 auto;
    max-height: calc(100% - 42px); overflow-y: auto;
  }
  #imagine-feedback-result { grid-area: feedback; min-height: 29px; font-size: .66rem; padding: 2px 4px; }
}
@media (max-width: 360px) and (max-height: 660px) {
  .top .wordmark { font-size: .72rem; letter-spacing: .04em; gap: .3em; }
  #board[data-expanded] .peg > .brick[data-has-faders] {
    grid-template-rows: 10px minmax(0, 1fr) 3px;
    padding-top: 0;
  }
  #board[data-expanded] [data-has-faders] > .grip { padding-inline-end: 13px; }
  #board[data-expanded] .params[data-shared-fader] .modulate-parameter { min-width: 12px; }
  #board[data-expanded] [data-has-faders] > .wire-port {
    inset: 0 0 auto auto; width: 13px; height: 10px; translate: none;
  }
}
@media (max-width: 1024px) and (max-height: 520px) {
  .play {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr); align-items: center;
  }
  .play header.top { grid-area: 1 / 2; border: 0; padding: 0; }
  .top .wordmark { display: none; }
  .top .wordmark[href] { display: inline-flex; align-items: center; min-height: 32px; padding-inline: 5px; }
  .top .wordmark[href] span { display: none; }
  .play-help-line { grid-area: 1 / 1; min-width: 0; min-height: 18px; }
  .instrument { grid-area: 2 / 1 / 3 / 3; align-self: stretch; }
  .tray {
    grid-template-columns: 110px minmax(0, 1fr) auto auto;
    grid-template-areas: "shortcuts palette animations options" "generated generated generated feedback";
  }
  .tray:has(#generated-brick:not(:empty)) {
    grid-template-columns: 110px minmax(0, 1fr) minmax(145px, auto) auto auto auto;
    grid-template-areas: "shortcuts palette generated feedback animations options";
  }
  #palette { grid-auto-columns: 62px; }
  .play-help-line #kfir-coach { inset: 0 0 auto; min-height: 25px; }
}
