/* Lab controls inherit the studio palette; presets tune the accent on the entire page. */
.page-lab {
  --lab-hue: 192;
  --lab-radius: 16px;
  --lab-duration: 320ms;
  --accent: hsl(var(--lab-hue) 92% 66%);
  --accent-hi: hsl(var(--lab-hue) 85% 81%);
  --edge: color-mix(in srgb, var(--accent) 23%, var(--bg));
  --panel: color-mix(in srgb, var(--card-a) 60%, var(--bg));
  background: radial-gradient(ellipse 85% 32rem at 68% 7rem, #152442, transparent), var(--bg);
}
.lab-wrap { max-width: 1352px; margin: auto; padding: 0 var(--gutter) clamp(3rem,7vw,7rem); }
.lab-hero {
  display: grid; grid-template-columns: 1.03fr 1fr; gap: 6%; align-items: center;
  min-height: clamp(280px,28vw,390px); padding-block: 2.5rem;
}
.lab-hero h1 { max-width: 15ch; font-size: clamp(2.6rem,4.7vw,4.6rem); line-height: 1.1; }
.lab-hero p { max-width: 54ch; margin-top: 1.1rem; color: var(--muted); font-size: clamp(1rem,1.35vw,1.15rem); }
.lab-art {
  position: relative; isolation: isolate; min-height: 240px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 60%, color-mix(in srgb,var(--accent) 12%,transparent), transparent 66%);
}
.lab-art::before {
  content: ""; position: absolute; inset: 5% 0; background-image: radial-gradient(#8fadd04d 1px, transparent 1px);
  background-size: 18px 18px; mask-image: radial-gradient(ellipse,black 28%,transparent 71%);
}
.swatch-stack { position: absolute; inset: 0; width: 68%; margin: auto; transform: rotate(-13deg) skewY(-5deg); }
.swatch-stack i {
  position: absolute; inset: 18% 10% 20%; border-radius: var(--lab-radius); border: 1px solid #a1cbef99;
  box-shadow: -10px 14px 20px #02071460, inset 0 1px 0 #ffe8ff77;
}
.swatch-stack i:nth-child(1) { transform: translate(14%,16%); background: linear-gradient(125deg,#18334e,var(--violet) 140%); }
.swatch-stack i:nth-child(2) { transform: translate(3%,2%); background: linear-gradient(120deg,#145d87,var(--blue)); }
.swatch-stack i:nth-child(3) {
  transform: translate(-8%,-12%);
  background: repeating-radial-gradient(ellipse at 96% 132%,transparent 0 7px,#c9f6ff59 8px,transparent 9px 15px),
    radial-gradient(ellipse at 18% 12%,var(--accent-hi),transparent 52%),
    linear-gradient(112deg,#277eaa 10%,#254b9a 55%,#7650a9);
}
.lab-index {
  display: flex; flex-wrap: wrap; gap: .5rem; padding-block: 1.1rem;
  border-block: 1px solid var(--edge); margin-bottom: 1.5rem;
}
.lab-index a {
  display: inline-flex; align-items: center; min-height: 36px; padding: .28rem .85rem;
  text-decoration: none; color: var(--text); font-size: .875rem; border-radius: var(--lab-radius);
  background: var(--panel); border: 1px solid var(--edge);
}
.lab-cards { display: grid; grid-template-columns: repeat(12,minmax(0,1fr)); gap: clamp(.9rem,1.6vw,1.4rem); }
.lab-card {
  min-width: 0; grid-column: span 12; padding: clamp(1.1rem,2.5vw,2.25rem); scroll-margin-top: 1rem;
  border: 1px solid var(--edge); border-radius: var(--lab-radius);
  background: linear-gradient(128deg,var(--panel),var(--card-b) 115%); box-shadow: 0 10px 36px #03091333;
}
.lab-card h2, .lab-wrap dialog h2 { font-size: clamp(1.45rem,2.15vw,2rem); }
.lab-desc, .lab-wrap dialog p { margin: .55rem 0 1.2rem; color: var(--muted); }
@media (min-width: 1040px) {
  #palette { display: grid; grid-template-columns: 1.45fr 1fr; align-items: center; column-gap: 4%; }
  #palette .lab-desc { margin-bottom: 0; }
  #palette .launcher { grid-column: 2; grid-row: 1 / span 2; }
  #gauges, #theme, #micro { grid-column: span 5; }
  #board, #logs, #gallery { grid-column: span 7; }
}
.lab-wrap :is(button,select,input) { font: inherit; }
.lab-wrap :is(button,select,input:not([type=range])) {
  border: 1px solid var(--edge); border-radius: min(var(--lab-radius),12px); color: var(--text);
  background: var(--bg); min-height: 40px; padding: .45rem .75rem; max-width: 100%;
}
.lab-wrap button, .lab-wrap select { cursor: pointer; }
.lab-wrap button { font-size: .9rem; line-height: 1.3; }
.lab-wrap :is(button:enabled:hover,.lab-index a:hover) { border-color: var(--accent); color: var(--accent-hi); }
.lab-wrap button:disabled { opacity: .43; cursor: default; }
.lab-wrap button:is([aria-current=page],[aria-pressed=true]) { border-color: var(--accent); color: var(--accent-hi); }
.lab-wrap button.launcher {
  width: 100%; display: flex; align-items: center; gap: 1rem; padding: 1rem;
  color: var(--accent-hi); background: linear-gradient(110deg,var(--bg),var(--panel)); text-align: start;
}
.launcher kbd { padding: .22rem .6rem; border: 1px solid var(--edge); border-bottom-width: 3px; border-radius: 5px; font: 650 1rem monospace; }
.launcher span { margin-inline-start: auto; font-size: 1.45rem; }
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: .55rem; }
.controls label { display: grid; gap: .22rem; color: var(--muted); font-size: .88rem; min-width: 0; }
#stock-search { width: min(20rem,100%); }
.table-scroll { margin: 1rem 0 .5rem; overflow-x: auto; border: 1px solid var(--edge); border-radius: min(var(--lab-radius),12px); }
.table-scroll table { width: 100%; min-width: 37rem; border-collapse: collapse; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-scroll :is(th,td) { padding: .55rem 1rem; text-align: end; }
.table-scroll :is(th,td):is(:first-child,:last-child) { text-align: start; }
.table-scroll th { background: var(--bg); color: var(--muted); }
.table-scroll th button { padding: .25rem 0; border: 0; min-height: 32px; color: inherit; font-weight: 600; }
.table-scroll th span { margin-inline-start: .3rem; }
.table-scroll tbody tr + tr { border-top: 1px solid var(--edge); }
.stock-state { display: inline-flex; align-items: center; gap: .5em; font-size: .86rem; }
.stock-state::before { content: ""; width: .5em; height: .5em; border-radius: 50%; background: var(--accent); }
.state-1::before { background: #f7c378; }
.state-2::before { background: #95a0b6; }
.rise { color: #ffa3a7; } .fall { color: #77deb0; }
.table-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; color: var(--muted); font-size: .85rem; }
.pagination { margin-top: .75rem; gap: .35rem; }
.pagination button { min-width: 34px; min-height: 36px; }
.gauge-bank { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: .6rem; margin: 1.4rem 0; }
.gauge { text-align: center; min-width: 0; }
.dial { position: relative; display: grid; place-items: center; width: 100%; max-width: 116px; margin: auto; }
.dial svg { grid-area: 1/1; width: 100%; transform: rotate(-90deg); }
.dial circle { stroke-width: 6; fill: none; }
.dial .rim { stroke: var(--edge); }
.dial .arc { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 100; }
.gauge:nth-child(even) .arc { stroke: color-mix(in srgb,var(--accent),var(--violet) 60%); }
.dial strong { grid-area: 1/1; font-size: clamp(1rem,1.7vw,1.45rem); font-variant-numeric: tabular-nums; }
.gauge figcaption { margin-top: .4rem; font-size: .85rem; color: var(--muted); }
.board { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .55rem; align-items: stretch; }
.lane { display: flex; flex-direction: column; background: var(--bg); padding: .55rem; border-radius: min(var(--lab-radius),12px); border-top: 2px solid var(--accent); }
.lane:nth-child(2) { border-color: var(--blue); }
.lane:nth-child(3) { border-color: var(--violet); }
.lane h3 { display: flex; justify-content: space-between; align-items: baseline; gap: .25rem; font: 600 .88rem var(--font-body); }
.lane h3 span { color: var(--muted); font: .8rem monospace; }
.lane ol { flex: 1; list-style: none; min-height: 44px; padding-block: .45rem; }
.task { position: relative; border: 1px solid var(--edge); border-radius: min(var(--lab-radius),10px); padding: .55rem; background: var(--panel); cursor: grab; }
.task + .task { margin-top: .5rem; }
.task strong { font-size: .88rem; font-weight: 500; }
.task-controls { display: flex; flex-wrap: wrap; gap: 3px; margin-top: .45rem; }
.task-controls button { min-height: 29px; min-width: 27px; padding: 0 .28rem; }
.task.dragging { opacity: .5; }
.drop-before::before, .drop-end::after { content: ""; display: block; height: 3px; background: var(--accent); }
.drop-before::before { position: absolute; top: -4px; inset-inline: 0; }
.drop-end::after { margin-top: .25rem; }
.log-filters button { font: .8rem ui-monospace,monospace; }
.log-filters [aria-pressed=false] { opacity: .65; text-decoration: line-through; }
[data-level="0"] b { color: #7cdcff; } [data-level="1"] b { color: #f9c782; }
[data-level="2"] b { color: #ffa1ab; } [data-level="3"] b { color: #c7acff; }
.terminal { margin: .75rem 0; height: 14rem; padding: .75rem; overflow: auto; overscroll-behavior: contain; background: #050c17; border: 1px solid var(--edge); border-radius: min(var(--lab-radius),12px); }
.log-line { display: grid; grid-template-columns: 8ch 5ch 1fr; gap: .8em; padding: .25rem 0; font: .83rem/1.5 ui-monospace,monospace; }
.log-line time { color: var(--muted); }
.sliders { display: grid; gap: .85rem; margin-bottom: 1.2rem; }
.slider { display: grid; grid-template-columns: 1fr auto; gap: .2rem; }
.slider output { color: var(--accent-hi); font-variant-numeric: tabular-nums; }
.slider input { grid-column: span 2; margin: 0; height: 24px; width: 100%; accent-color: var(--accent); cursor: pointer; }
.gallery-window { overflow: hidden; border-radius: var(--lab-radius); touch-action: pan-y; user-select: none; cursor: grab; }
.gallery-window.dragging { cursor: grabbing; }
.slide-track { display: flex; transition: transform var(--lab-duration) ease-out; }
.dragging .slide-track { transition: none; }
.slide { position: relative; flex: 0 0 100%; aspect-ratio: 2.35; min-height: 145px; display: flex; align-items: end; }
.slide figcaption { width: 100%; padding: 2rem 1rem .75rem; background: linear-gradient(transparent,#050c19d9); color: white; font: 600 1.1rem var(--font-zh-serif); }
.art-0 { background: repeating-radial-gradient(ellipse at 18% 160%,transparent 0 9px,#b6efec80 10px,transparent 12px 25px),linear-gradient(125deg,#206779,#28a5ad 28%,#06445e 56%,#424ca0); }
.art-1 { background: conic-gradient(from 18deg at 68% 80%,#ffc7a2 0 12%,#e98a75 12% 35%,#ad586e 35% 57%,#734875 57% 77%,#fec99b 77%); }
.art-2 { background: repeating-radial-gradient(ellipse at 70% 50%,#383361 0 10%,#ab8ede 11% 13%,#7268b1 14% 18%); }
.art-3 { background: repeating-radial-gradient(ellipse at 9% -55%,#6c493b 0 2px,transparent 3px 19px),linear-gradient(160deg,#ddae75,#dfc49a 45%,#a56944 72%,#584446); }
.art-4 { background: repeating-linear-gradient(112deg,transparent 0 7%,#91eecc55 10%,transparent 14%),linear-gradient(30deg,#22354c,#468597 50%,#8f83bf); }
.gallery-nav { display: flex; align-items: center; justify-content: space-between; gap: .25rem; margin-top: .75rem; }
.dots { display: flex; }
.dots button { display: grid; place-items: center; min-height: 34px; width: 30px; padding: 0; background: transparent; border: 0; }
.dots button::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dots [aria-current]::after { width: 19px; border-radius: 8px; background: var(--accent); }
.lab-wrap .disclosure { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; text-align: start; }
.disclosure span { color: var(--accent); transition: transform var(--lab-duration); }
.disclosure[aria-expanded=true] span { transform: rotate(45deg); }
#answer { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--lab-duration); }
#answer:not([inert]) { grid-template-rows: 1fr; }
#answer > div { overflow: hidden; }
#answer p { padding: .7rem; color: var(--muted); }
.micro-controls { margin-top: 1rem; }
html:has(.lab-wrap dialog[open]) { overflow: hidden; }
.lab-wrap dialog { width: min(32rem, calc(100vw - 32px)); max-height: 78dvh; padding: 1.3rem; color: var(--text); border: 1px solid var(--accent); border-radius: var(--lab-radius); background: var(--panel); box-shadow: 0 18px 68px #0009; }
.lab-wrap dialog::backdrop { background: #020714c9; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
#query { width: 100%; }
#commands { margin-top: .8rem; overflow: auto; max-height: 42dvh; list-style: none; }
#commands li { padding: .6rem .8rem; border-radius: min(var(--lab-radius),8px); cursor: pointer; }
#commands [aria-selected=true] { background: var(--edge); box-shadow: inset 3px 0 var(--accent); }
#commands mark { color: var(--accent-hi); background: transparent; font-weight: bold; text-decoration: underline; }
#lab-tip, .toast { z-index: 5; color: var(--text); border: 1px solid var(--accent); border-radius: var(--lab-radius); background: var(--panel); box-shadow: 0 8px 25px #0008; }
#lab-tip { position: fixed; pointer-events: none; max-width: calc(100vw - 16px); padding: .4rem .7rem; font-size: .85rem; }
.toasts { position: fixed; z-index: 5; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; max-width: calc(100% - 2rem); max-height: 60vh; overflow: auto; }
.toast { display: flex; gap: .8rem; align-items: center; justify-content: space-between; padding: .5rem .55rem .5rem 1rem; }
.sr-lab { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 700px) {
  .lab-hero { grid-template-columns: 1fr; gap: .25rem; padding-block: 1.8rem .4rem; }
  .lab-art { min-height: 150px; }
  .swatch-stack { width: min(65%,230px); }
  .lab-index { gap: .35rem; }
  .lab-index a { padding: .25rem .6rem; }
  .board { grid-template-columns: 1fr; gap: .75rem; }
  .task { display: flex; align-items: center; justify-content: space-between; gap: .3rem; }
  .task-controls { flex-shrink: 0; margin: 0; }
  .task-controls button { min-width: 32px; min-height: 36px; }
  .controls label:first-child:has(input[type=search]) { width: 100%; }
  #stock-search { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .page-lab *, .page-lab *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}
