:root {
  color-scheme: light;
  --ink: #172128;
  --muted: #65727a;
  --line: #d8dedc;
  --soft: #f2f5f3;
  --paper: #fbfcfa;
  --green: #167a56;
  --green-dark: #0b593d;
  --green-soft: #e5f3ec;
  --yellow: #f5cb4b;
  --blue: #2f6fed;
  --red: #c74444;
  --shadow: 0 12px 36px rgba(28, 45, 38, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: #edf1ee; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,.75), rgba(255,255,255,.75)),
    linear-gradient(90deg, transparent 31px, rgba(20,65,48,.035) 32px),
    linear-gradient(transparent 31px, rgba(20,65,48,.035) 32px);
  background-size: auto, 32px 32px, 32px 32px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, select { font: inherit; }
button { color: inherit; }

.test-banner {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 20px;
  color: #3c3209;
  background: var(--yellow);
  border-bottom: 1px solid #d7ae2f;
  font-size: 12px;
}
.test-banner strong { text-transform: uppercase; font-size: 10px; letter-spacing: .08em; }

.topbar {
  min-height: 64px;
  padding: 10px clamp(16px, 3vw, 42px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 19px; font-weight: 800; text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand b { color: var(--green); }
.run-state { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #aab3ae; box-shadow: 0 0 0 4px #edf0ee; }
.status-dot.live { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.status-dot.busy { background: #d5a914; box-shadow: 0 0 0 4px #fff4c4; animation: pulse 1s infinite; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }

main { width: min(1800px, 100%); margin: auto; padding: 26px clamp(14px, 2vw, 32px) 70px; }
.page-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 520px); gap: 30px; align-items: end; margin-bottom: 18px; }
.page-heading h1 { margin: 4px 0 0; font-size: clamp(30px, 4vw, 52px); line-height: 1; }
.page-heading > p { margin: 0; color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0; color: var(--green); font-size: 10px; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }

.privacy-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 11px 14px;
  color: #164934;
  background: var(--green-soft);
  border: 1px solid #bedecf;
  border-radius: 6px;
  font-size: 12px;
}
.privacy-strip > span { display: grid; place-items: center; flex: 0 0 28px; height: 28px; border: 1px solid #8fc4ab; border-radius: 50%; font-weight: 900; }
.privacy-strip p { margin: 0; }

.studio-shell { display: grid; grid-template-columns: 272px minmax(470px, 1fr) 300px; align-items: start; gap: 12px; }
.control-column, .data-column { display: grid; gap: 12px; }
.panel, .comparison-column {
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}
.panel { padding: 14px; }
.panel-title { min-height: 30px; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.panel-title > div { display: flex; align-items: center; gap: 8px; }
.panel-title span:first-child, .debug-panel summary b { color: var(--green); font: 700 10px/1 "SFMono-Regular", Consolas, monospace; }
.panel-title h2 { margin: 0; font-size: 14px; }
.quiet { color: var(--muted) !important; font-size: 10px !important; }

.upload-zone {
  min-height: 140px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  padding: 18px;
  text-align: center;
  border: 1px dashed #aebbb4;
  border-radius: 5px;
  background: var(--paper);
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .2s;
}
.upload-zone:hover, .upload-zone.dragging { border-color: var(--green); background: var(--green-soft); transform: translateY(-1px); }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon { display: grid; place-items: center; width: 32px; height: 32px; margin-bottom: 4px; border-radius: 50%; color: white; background: var(--green); font-size: 20px; }
.upload-zone strong { font-size: 13px; }
.upload-zone small, .source-thumb small { color: var(--muted); font-size: 10px; }
.source-thumb { position: relative; min-height: 76px; display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 10px; padding: 7px; background: var(--soft); border-radius: 5px; }
.source-thumb img { width: 64px; height: 62px; object-fit: cover; border-radius: 3px; }
.source-thumb div { min-width: 0; display: grid; gap: 3px; }
.source-thumb strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.icon-button { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: white; cursor: pointer; }
.crop-editor { display: grid; gap: 7px; margin-top: 10px; }
.crop-head { display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.crop-tools { display: flex; gap: 4px; }
.crop-tools button { width: 27px; height: 27px; padding: 0; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; }
.crop-editor canvas { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #e8ece9; border: 1px solid var(--line); border-radius: 4px; cursor: grab; touch-action: none; }
.crop-editor canvas:active { cursor: grabbing; }
.crop-editor > small { color: var(--muted); font-size: 9px; text-align: center; }

fieldset { min-width: 0; margin: 14px 0 0; padding: 0; border: 0; }
legend { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: var(--soft); border-radius: 5px; }
.segmented input, .mode-list input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: grid; gap: 1px; padding: 8px; text-align: center; border: 1px solid transparent; border-radius: 3px; font-size: 11px; font-weight: 750; cursor: pointer; }
.segmented small { color: var(--muted); font-size: 9px; font-weight: 500; }
.segmented input:checked + span { background: white; border-color: var(--line); box-shadow: 0 2px 6px rgba(0,0,0,.05); }
.mode-list { display: grid; gap: 5px; }
.mode-list label { display: block; }
.mode-list span { display: grid; gap: 2px; padding: 9px 10px 9px 31px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; position: relative; }
.mode-list span::before { content: ""; position: absolute; left: 10px; top: 12px; width: 10px; height: 10px; border: 1px solid #a5afaa; border-radius: 50%; }
.mode-list input:checked + span { border-color: var(--green); background: var(--green-soft); }
.mode-list input:checked + span::before { border: 3px solid var(--green); background: white; }
.mode-list b { font-size: 11px; }
.mode-list small { color: var(--muted); font-size: 9px; line-height: 1.35; }
.inline-status { margin: 7px 0 0; color: var(--muted); font-size: 9px; line-height: 1.4; }

.primary-action, .secondary-action {
  min-height: 39px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 13px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}
.primary-action { width: 100%; margin-top: 14px; color: white; background: var(--green); border: 1px solid var(--green); }
.primary-action:hover:not(:disabled) { background: var(--green-dark); }
.primary-action:disabled, .secondary-action:disabled { opacity: .42; cursor: not-allowed; }
kbd { padding: 2px 5px; color: #d8eee4; border: 1px solid rgba(255,255,255,.24); border-radius: 3px; font: 9px/1.4 "SFMono-Regular", Consolas, monospace; }
.secondary-action { border: 1px solid var(--line); background: white; }
.secondary-action:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.secondary-action.full { width: 100%; justify-content: center; margin-top: 7px; }
.progress-track { height: 3px; margin-top: 8px; overflow: hidden; background: var(--soft); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--green); transition: width .2s; }
.text-button { padding: 0; color: var(--green); background: transparent; border: 0; font-size: 10px; font-weight: 750; cursor: pointer; }

.recipe-groups { display: grid; gap: 12px; }
.recipe-group h3 { margin: 0 0 5px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.recipe-option { display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 6px; min-height: 31px; cursor: pointer; }
.recipe-option input { accent-color: var(--green); }
.recipe-option span { font-size: 10px; font-weight: 650; }
.recipe-option code { color: var(--muted); font-size: 8px; }

.comparison-column { min-height: 750px; padding: 16px; }
.workspace-head { min-height: 48px; display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; border-bottom: 1px solid var(--line); }
.workspace-head h2 { margin: 3px 0 12px; font-size: 18px; }
.workspace-actions { display: flex; align-items: center; gap: 10px; }
.download-action { min-height: 42px; padding: 0 18px; border: 1px solid var(--green); background: var(--green); color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.download-action:hover:not(:disabled) { background: var(--green-dark); }
.download-action:disabled { opacity: .38; cursor: not-allowed; }
.view-tools { display: flex; gap: 4px; }
.tool { min-height: 28px; padding: 0 8px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 3px; font-size: 9px; cursor: pointer; }
.tool.active { color: white; background: var(--ink); border-color: var(--ink); }
.empty-workspace { min-height: 604px; display: grid; justify-items: center; align-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-workspace strong { color: var(--ink); font-size: 14px; }
.empty-workspace span { font-size: 10px; }
.empty-grid { width: 180px; height: 180px; margin-bottom: 12px; opacity: .55; border: 1px solid #c5cdc8; background: repeating-linear-gradient(0deg, transparent 0 17px, #cbd2ce 18px), repeating-linear-gradient(90deg, transparent 0 17px, #cbd2ce 18px); transform: perspective(500px) rotateX(55deg) rotateZ(-30deg); box-shadow: -18px 22px 0 rgba(25,80,59,.06); }
.comparison-grid { min-height: 604px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; gap: 10px; padding: 18px 0; }
.effect-tile { min-width: 0; padding: 0; overflow: hidden; border: 2px solid transparent; background: #fff; color: inherit; text-align: left; cursor: pointer; transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease; }
.effect-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgb(23 35 29 / 12%); }
.effect-tile.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgb(26 120 76 / 15%); }
.effect-tile .canvas-frame { min-height: 0; aspect-ratio: 1; }
.effect-tile .canvas-frame canvas { width: 100%; max-height: none; }
.effect-tile > span { display: flex; justify-content: space-between; gap: 8px; padding: 9px 10px 10px; }
.effect-tile strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.effect-tile small { flex: none; color: var(--muted); font-size: 9px; }
.compare-pane { min-width: 0; display: grid; gap: 7px; }
.compare-pane header { display: flex; justify-content: space-between; align-items: center; font-size: 10px; }
.variant-badge { display: inline-flex; padding: 3px 5px; color: white; background: var(--ink); border-radius: 2px; font: 750 8px/1.2 "SFMono-Regular", Consolas, monospace; }
.variant-badge.optimised { background: var(--green); }
.variant-badge.faster { background: var(--blue); }
.canvas-frame { position: relative; display: grid; place-items: center; min-height: 340px; overflow: hidden; background: #eef1ef; border: 1px solid var(--line); }
.canvas-frame canvas { width: min(88%, 520px); height: auto; max-height: 520px; object-fit: contain; image-rendering: pixelated; }
.canvas-frame.grid canvas { background-size: 8px 8px; }
.compare-pane footer { display: flex; justify-content: space-between; color: var(--muted); font-size: 9px; }
.compare-footer { min-height: 48px; display: flex; align-items: end; justify-content: space-between; gap: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.compare-selects { display: flex; align-items: end; gap: 6px; }
.compare-selects label { display: grid; gap: 3px; color: var(--muted); font-size: 8px; text-transform: uppercase; }
.compare-selects select { max-width: 145px; height: 29px; border: 1px solid var(--line); background: white; font-size: 9px; }

.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--line); }
.metric-grid > div { min-height: 55px; display: grid; align-content: center; gap: 3px; padding: 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-grid > div:nth-child(2n) { border-right: 0; }
.metric-grid > div:nth-last-child(-n+2) { border-bottom: 0; }
.metric-grid small { color: var(--muted); font-size: 8px; text-transform: uppercase; }
.metric-grid strong { font: 700 16px/1 "SFMono-Regular", Consolas, monospace; }
.metric-callout { margin-top: 9px; padding: 9px; color: var(--muted); background: var(--soft); border-radius: 3px; font-size: 9px; line-height: 1.45; }
.bom-head, .bom-row { display: grid; grid-template-columns: 1fr 38px 44px; gap: 5px; align-items: center; }
.bom-head { padding: 0 5px 5px; color: var(--muted); font-size: 8px; text-transform: uppercase; }
.bom-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); }
.bom-row { min-height: 31px; padding: 4px 5px; border-bottom: 1px solid var(--line); font-size: 9px; }
.bom-row:last-child { border: 0; }
.bom-color { min-width: 0; display: flex; align-items: center; gap: 6px; }
.bom-color i { flex: 0 0 15px; height: 15px; border: 1px solid rgba(0,0,0,.2); }
.bom-color span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bom-row code { text-align: right; font-size: 8px; }
.empty-copy { margin: 20px; color: var(--muted); text-align: center; font-size: 9px; }
.debug-panel details > summary { display: flex; justify-content: space-between; cursor: pointer; font-size: 13px; font-weight: 750; }
.debug-panel summary span:first-child { display: flex; gap: 8px; align-items: center; }
.debug-tabs { display: flex; gap: 4px; margin: 13px 0 8px; }
.debug-tabs button { padding: 4px 7px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; font-size: 9px; cursor: pointer; }
.debug-tabs button.active { color: var(--green); border-color: var(--green); }
.debug-summary { display: grid; gap: 5px; }
.debug-line { display: flex; justify-content: space-between; gap: 8px; font-size: 8px; }
.debug-line span { color: var(--muted); }
.debug-line code { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debug-panel pre { max-height: 245px; margin: 0; padding: 9px; overflow: auto; color: #c8e9d8; background: #15201b; font: 8px/1.5 "SFMono-Regular", Consolas, monospace; }

.results-section { margin-top: 18px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 10px; }
.section-head h2 { margin: 3px 0 0; font-size: 21px; }
.section-head > p { margin: 0; color: var(--muted); font-size: 10px; }
.results-rail { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 340px); gap: 10px; overflow-x: auto; padding: 1px 1px 12px; scroll-snap-type: x proximity; }
.result-placeholder, .recipe-result { min-height: 170px; padding: 14px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 6px; scroll-snap-align: start; }
.result-placeholder { display: grid; align-content: center; gap: 5px; color: var(--muted); }
.result-placeholder span { color: var(--green); font: 10px "SFMono-Regular", Consolas, monospace; }
.result-placeholder strong { color: var(--ink); }
.result-placeholder small { font-size: 10px; }
.recipe-result { cursor: pointer; transition: border-color .2s, transform .2s; }
.recipe-result:hover, .recipe-result.selected { border-color: var(--green); transform: translateY(-2px); }
.recipe-result-head { display: flex; justify-content: space-between; margin-bottom: 9px; }
.recipe-result h3 { margin: 0; font-size: 13px; }
.recipe-result-head small { color: var(--muted); font-size: 8px; }
.variant-stack { display: grid; gap: 5px; }
.variant-row { display: grid; grid-template-columns: 54px 1fr auto; gap: 8px; align-items: center; min-height: 51px; padding: 5px; background: var(--soft); border: 1px solid transparent; border-radius: 3px; }
.variant-row.selected { border-color: var(--green); background: var(--green-soft); }
.variant-row canvas { width: 54px; height: 42px; object-fit: contain; image-rendering: pixelated; background: #ddd; }
.variant-row div { display: grid; gap: 2px; }
.variant-row strong { font-size: 9px; }
.variant-row small { color: var(--muted); font-size: 8px; }
.variant-row code { color: var(--muted); font-size: 8px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: 330px; padding: 11px 14px; color: white; background: var(--ink); border-radius: 4px; box-shadow: 0 12px 40px rgba(0,0,0,.2); font-size: 11px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 1180px) {
  .studio-shell { grid-template-columns: 250px minmax(450px, 1fr); }
  .data-column { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 780px) {
  .test-banner { align-items: flex-start; flex-direction: column; gap: 2px; }
  .run-state .mono { display: none; }
  main { padding-inline: 10px; }
  .page-heading { grid-template-columns: 1fr; gap: 10px; }
  .page-heading > p { font-size: 13px; }
  .studio-shell { grid-template-columns: 1fr; }
  .control-column { grid-template-columns: 1fr; }
  .data-column { grid-column: auto; grid-template-columns: 1fr; }
  .comparison-column { min-height: 560px; order: 2; }
  .control-column { order: 1; }
  .data-column { order: 3; }
  .workspace-head { align-items: stretch; flex-direction: column; }
  .workspace-actions { justify-content: space-between; flex-wrap: wrap; padding-bottom: 12px; }
  .workspace-head { position: sticky; top: 0; z-index: 4; padding-top: 10px; background: #fff; }
  .download-action { order: -1; flex: 1 1 100%; }
  .comparison-grid { min-height: 440px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .canvas-frame { min-height: 280px; }
  .empty-workspace { min-height: 420px; }
  .compare-footer, .section-head { align-items: stretch; flex-direction: column; }
  .compare-selects { display: grid; grid-template-columns: 1fr auto 1fr; }
  .compare-selects select { max-width: 100%; width: 100%; }
  .results-rail { grid-auto-columns: minmax(250px, 88vw); }
}
