/* ditherlab — lab chrome. Dark by default, light via [data-theme=light]. */
:root {
  --bg: #0b0d11;
  --bg2: #10131a;
  --panel: #141821;
  --panel2: #1a1f2a;
  --line: #242a37;
  --line2: #2f3747;
  --text: #d9dee8;
  --dim: #8791a3;
  --dim2: #5d667a;
  --accent: #7ee0b4;
  --accent2: #55b893;
  --warn: #f0b35a;
  --stage: #000;
  --stage-fg: #ececec;
  --mono: "Cascadia Mono", "Cascadia Code", "JetBrains Mono", "DejaVu Sans Mono", "Noto Sans Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 30px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f3f4f7;
  --bg2: #eceef3;
  --panel: #ffffff;
  --panel2: #f6f7fa;
  --line: #dfe3ea;
  --line2: #cdd3dd;
  --text: #1b2030;
  --dim: #5f697d;
  --dim2: #8a93a6;
  --accent: #0f8a62;
  --accent2: #0c6e4e;
  --stage: #0e1014;
  --stage-fg: #ececec;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 10px 30px rgba(20,30,50,.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; min-height: 100vh;
  display: grid; grid-template-columns: 320px 1fr; grid-template-rows: 52px 1fr;
  grid-template-areas: "top top" "side main";
  background: var(--bg); color: var(--text);
  font: 13px/1.45 var(--sans);
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 12px; color: var(--accent); }

/* ------------------------------------------------ header */
#top {
  grid-area: top; display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 300px; }
.logo {
  width: 22px; height: 22px; border-radius: 5px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent) 0 2px, transparent 2.5px),
    radial-gradient(circle at 70% 30%, var(--accent) 0 1.5px, transparent 2px),
    radial-gradient(circle at 50% 60%, var(--accent) 0 1.5px, transparent 2px),
    radial-gradient(circle at 30% 80%, var(--accent) 0 1px, transparent 1.5px),
    radial-gradient(circle at 75% 75%, var(--accent) 0 1px, transparent 1.5px),
    var(--panel2);
  border: 1px solid var(--line2);
}
h1 { margin: 0; font-size: 17px; letter-spacing: .5px; font-family: var(--mono); font-weight: 600; }
h1 span { color: var(--accent); }
.tag { color: var(--dim); font-size: 12px; }
#tabs { display: flex; gap: 2px; margin-left: auto; margin-right: auto; background: var(--panel); padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
#tabs button { border: none; background: transparent; color: var(--dim); padding: 5px 12px; border-radius: 6px; cursor: pointer; }
#tabs button.active { background: var(--panel2); color: var(--text); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
#tabs button:hover:not(.active) { color: var(--text); }
.right { display: flex; gap: 6px; min-width: 300px; justify-content: flex-end; }
.icon {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--dim); text-decoration: none; cursor: pointer;
}
.icon:hover { color: var(--accent); border-color: var(--accent2); }

/* ------------------------------------------------ sidebar */
#side {
  grid-area: side; overflow-y: auto; padding: 14px 14px 30px;
  background: var(--bg2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 9px; box-shadow: var(--shadow);
}
.panel h2, .panel summary {
  margin: 0; font-size: 11px; font-weight: 600; letter-spacing: 1.4px; text-transform: uppercase; color: var(--dim);
}
.panel summary { cursor: pointer; list-style: none; display: flex; align-items: center; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: "▾"; margin-left: auto; color: var(--dim2); transition: transform .15s; }
details.panel:not([open]) summary::after { transform: rotate(-90deg); }
details.panel:not([open]) { gap: 0; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 10px; cursor: pointer;
  border: 1.5px dashed var(--line2); border-radius: 8px; color: var(--dim); text-align: center; background: var(--panel2);
  transition: border-color .15s, color .15s;
}
.drop:hover, .drop.over, .drop:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.drop input { display: none; }
.drop .big { color: var(--text); font-weight: 600; }
.drop .small { font-size: 11px; }
.drop em { font-style: normal; font-size: 11px; margin-top: 6px; color: var(--dim2); word-break: break-all; max-width: 100%; }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
#cam { width: 100%; border-radius: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips button {
  border: 1px solid var(--line2); background: var(--panel2); color: var(--text); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; cursor: pointer;
}
.chips button:hover { border-color: var(--accent2); color: var(--accent); }
.chips button.active { background: var(--accent); color: #06110c; border-color: var(--accent); }

label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--dim); }
label.range { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; column-gap: 6px; }
label.range input[type="range"] { grid-column: 1 / -1; }
label.range output { color: var(--accent); font-variant-numeric: tabular-nums; }
label.range small { color: var(--dim2); }
.desc { margin: -4px 0 0; font-size: 11px; color: var(--dim2); }
.checks { display: flex; gap: 12px; flex-wrap: wrap; }
.checks label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
select, input[type="text"], input[type="number"], textarea {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line2); border-radius: 6px; padding: 6px 8px;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent2); }
input[type="range"] { accent-color: var(--accent); width: 100%; margin: 2px 0 0; }
input[type="checkbox"] { accent-color: var(--accent); }
.swatches { display: flex; height: 10px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line2); }
.swatches span { flex: 1; }

button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line2); border-radius: 7px;
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent2); color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible, .drop:focus-visible, #art:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }
button.ghost { background: transparent; color: var(--dim); }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.flash { border-color: var(--accent); color: var(--accent); }
.foot { margin: 4px 2px 0; font-size: 11px; color: var(--dim2); }
.foot a { color: var(--dim); }

/* ------------------------------------------------ main */
main { grid-area: main; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.tab { display: none; flex: 1; min-height: 0; flex-direction: column; padding: 12px 14px 10px; gap: 10px; }
.tab.active { display: flex; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--dim); font-size: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .inline { flex-direction: row; align-items: center; gap: 6px; }
.toolbar input[type="range"] { width: 110px; margin: 0; }
.toolbar input[type="number"] { width: 72px; }
.toolbar input[type="text"] { width: 170px; font-family: var(--mono); }
.toolbar .hint { color: var(--dim2); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 7px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: transparent; color: var(--dim); padding: 5px 10px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.active { background: var(--panel2); color: var(--accent); }
.menu { position: relative; }
.menuList {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 4px; box-shadow: var(--shadow);
}
.menu.open .menuList { display: flex; flex-direction: column; }
.menuList button { background: transparent; border: none; text-align: left; border-radius: 5px; padding: 7px 10px; color: var(--text); }
.menuList button:hover { background: var(--panel2); }

.stage {
  flex: 1; min-height: 140px; overflow: auto; position: relative;
  background: var(--stage); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stage.checker {
  display: grid; place-items: center;
  background: repeating-conic-gradient(#15181f 0 25%, #0e1015 0 50%) 0 0 / 20px 20px;
}
#art, #banner {
  margin: 0; padding: 16px; min-width: 100%; min-height: 100%;
  font-family: var(--mono); font-size: 10px; line-height: 1; white-space: pre; color: var(--stage-fg);
}
#art.paper { background: #f4f1ea; color: #1a1a1a; }
#art.blocky { line-height: .95; }
#art:focus { outline: none; }
#banner { font-size: 12px; }
#srcCanvas { position: absolute; left: 16px; top: 16px; image-rendering: auto; opacity: 1; }
.stage.split #art { opacity: .92; }
.stage.split #srcCanvas { opacity: .45; mix-blend-mode: screen; pointer-events: none; }
canvas { image-rendering: pixelated; max-width: 100%; }
.status { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; min-height: 16px; }
.status code { font-size: 11px; }

#decodeIn {
  height: 170px; resize: vertical; font-family: var(--mono); font-size: 11px; line-height: 1.05; white-space: pre; overflow: auto;
}

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel); color: var(--text); border: 1px solid var(--accent2); border-radius: 8px; padding: 8px 14px;
  box-shadow: var(--shadow); transition: opacity .18s, transform .18s; font-size: 12px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; }
  #top { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .brand, .right { min-width: 0; }
  #tabs { order: 3; width: 100%; margin: 0; }
  #side { border-right: none; border-bottom: 1px solid var(--line); max-height: 50vh; }
}

/* ------------------------------------------------ v0.3 additions */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; padding: 10px; align-content: start; background: var(--bg2); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.card:hover { border-color: var(--accent2); }
.card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card pre { margin: 0; padding: 8px; font-family: var(--mono); font-size: 4px; line-height: 1; white-space: pre; color: var(--stage-fg); background: var(--stage); overflow: hidden; flex: 1; }
.card pre.blocky { line-height: .95; }
.card .cap { padding: 6px 10px; font-size: 12px; color: var(--text); display: flex; justify-content: space-between; gap: 8px; }
.card .cap small { color: var(--dim2); }
.theme-card { cursor: default; }
.theme-card .body { padding: 10px 12px; font-size: 12px; color: var(--dim); display: flex; flex-direction: column; gap: 6px; }
.theme-card h3 { margin: 0; font-size: 13px; color: var(--text); font-family: var(--mono); display: flex; justify-content: space-between; align-items: center; }
.theme-card h3 button { padding: 3px 9px; font-size: 11px; }
.theme-card code { font-size: 11px; color: var(--accent); word-break: break-all; }
.theme-card ul { margin: 0; padding-left: 16px; }
.theme-card li { margin: 1px 0; }
#cropBox { position: absolute; border: 1.5px dashed var(--accent); background: rgba(126,224,180,.12); pointer-events: none; }
.stage.cropping { cursor: crosshair; }
#art3d { margin: 0; padding: 16px; font-family: var(--mono); font-size: 12px; line-height: 1; white-space: pre; color: var(--stage-fg); }
#motion { align-items: center; }
#motion .inline { flex-direction: row; align-items: center; gap: 4px; }
#motion input[type="number"] { width: 54px; padding: 3px 6px; }
#recBtn.rec { color: #ff6b6b; border-color: #ff6b6b; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 10px; background: var(--panel2); border: 1px solid var(--line2); color: var(--warn); margin-left: 6px; }

.split2 { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(260px, 38%) 1fr; gap: 10px; }
.split2 textarea { font-family: var(--mono); font-size: 12px; line-height: 1.35; resize: none; white-space: pre; overflow: auto; }
.split2 .stage { min-height: 0; }
#sceneArt { margin: 0; padding: 14px; font-family: var(--mono); font-size: 9px; line-height: 1; white-space: pre; color: var(--stage-fg); }
#autoBtn.busy { color: var(--warn); border-color: var(--warn); }

/* ------------------------------------------------ v0.11: browser surfaces carry the design */
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); }
input, textarea { caret-color: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--dim2); }
::-webkit-scrollbar-track { background: transparent; }
.status, .time, td { font-variant-numeric: tabular-nums; }

/* one authored moment: panels rise as a tab arrives (and nowhere else) */
@media (prefers-reduced-motion: no-preference) {
  .tab.active { animation: rise .28s cubic-bezier(.16,1,.3,1); }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }
}

/* the stage is a phosphor monitor when asked to be */
.stage.crt pre { text-shadow: 0 0 6px color-mix(in srgb, currentColor 55%, transparent); }
.stage.crt::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.22) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.34) 100%);
}
#dxStage { position: relative; min-height: 300px; }

/* director */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 2px; }
.chips button, .fxchips button {
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line2); background: var(--panel);
  color: var(--dim); cursor: pointer; transition: color .15s, border-color .15s, box-shadow .15s;
}
.chips button:hover, .fxchips button:hover { color: var(--text); border-color: var(--accent2); }
.chips button.on, .fxchips button.on {
  color: var(--accent); border-color: var(--accent2);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent), 0 2px 10px color-mix(in srgb, var(--accent) 18%, transparent);
}
.fxchips { display: inline-flex; gap: 6px; }
.transport { display: flex; align-items: center; gap: 12px; padding: 10px 2px 0; }
.transport .play {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line2); background: var(--panel2);
  color: var(--accent); font-size: 13px; line-height: 1; cursor: pointer;
}
.transport .play:hover { border-color: var(--accent2); box-shadow: 0 2px 12px color-mix(in srgb, var(--accent) 22%, transparent); }
.transport input[type="range"] { flex: 1; accent-color: var(--accent); }
.transport .time { color: var(--dim); min-width: 64px; text-align: right; }

/* command palette */
#cmdk { position: fixed; inset: 0; z-index: 60; background: rgba(4,6,10,.55); display: grid; place-items: start center; padding-top: 12vh; }
#cmdk[hidden] { display: none; }
.pal-box { width: min(560px, 92vw); background: var(--panel); border: 1px solid var(--line2); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.pal-box input { width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: var(--panel2); outline: none; }
#palList { max-height: 46vh; overflow: auto; padding: 6px; }
#palList .item { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--text); }
#palList .item .k { color: var(--dim2); }
#palList .item.sel, #palList .item:hover { background: color-mix(in srgb, var(--accent) 12%, var(--panel2)); color: var(--text); }
