:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  --ink: #212431;
  --muted: #575d70;
  --line: #d6d8e1;
  --panel: rgb(255 255 255 / 78%);
  --stage: rgb(238 239 247 / 69%);
  --tile: rgb(255 255 255 / 74%);
  --grid-dot: rgb(93 102 143 / 22%);
  --studio-glow: rgb(255 255 255 / 92%);
  --studio-edge: rgb(172 198 230 / 59%);
  --accent: #5443bb;
  --accent-label: #fff;
  --error: #9c252c;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f2f2f8;
  --muted: #b9bdd0;
  --line: #505369;
  --panel: rgb(27 29 39 / 88%);
  --stage: rgb(29 31 45 / 80%);
  --tile: rgb(42 45 61 / 85%);
  --grid-dot: rgb(175 184 227 / 22%);
  --studio-glow: rgb(58 71 99 / 84%);
  --studio-edge: rgb(18 23 39 / 85%);
  --accent: #c2b5ff;
  --accent-label: #241653;
  --error: #ffadb2;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: transparent; }
button, select { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, textarea:focus-visible, canvas:focus-visible,
.view-input:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
button:enabled, select { cursor: pointer; }

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(249px, 320px);
  gap: 12px;
  min-height: 100dvh;
  padding: 12px;
}

.preview, .input-panel { border: 1px solid var(--line); border-radius: 13px; }
.preview { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 438px; overflow: hidden; background: var(--stage); }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 18px 18px;
  background-position: center;
}
.stage:has(#model:not([hidden])) { background: radial-gradient(ellipse at 48% 40%, var(--studio-glow) 5%, var(--studio-edge)); }
#model { position: absolute; inset: 0; width: 100%; height: 100%; outline-offset: -3px; touch-action: none; cursor: grab; }
#model:active { cursor: grabbing; }
.model-summary { position: absolute; inset: 14px auto auto 16px; max-width: calc(100% - 32px); pointer-events: none; }
.model-summary h2 { margin: 0 0 2px; font-size: 16px; font-weight: 650; text-wrap: balance; }
.model-summary p { margin: 0; color: var(--muted); font-size: 12px; }
.empty { text-align: center; padding: 24px; }
.empty h1, .panel-heading h2 { margin: 0; font-weight: 650; letter-spacing: -.03em; }
.empty h1 { font-size: 24px; }
.empty p { margin: 5px 0 0; font-size: 14px; color: var(--muted); }
.projection-mark { position: relative; width: 52px; height: 52px; margin: 0 auto 18px; transform: rotate(-29deg) skew(12deg); color: var(--accent); }
.projection-mark i { position: absolute; inset: 7px 5px 7px 5px; border: 1px solid currentColor; border-radius: 5px; background: color-mix(in oklab, currentColor 12%, transparent); }
.projection-mark i:nth-child(2) { transform: translate(5px, -7px); }
.projection-mark i:nth-child(3) { transform: translate(10px, -14px); }
.stage-help { position: absolute; bottom: 10px; margin: 0; padding: 4px 8px; border-radius: 6px; background: var(--panel); color: var(--muted); font-size: 12px; pointer-events: none; }
.view-toolbar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; }
.view-toolbar label { color: var(--muted); }
.view-toolbar :is(button, select) { min-height: 33px; padding: 4px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--tile); }
.view-toolbar #saveImage { margin-inline-start: auto; }
.device-controls { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 9px 16px; padding: 0 0 8px; border-bottom: 1px solid var(--line); }
.device-controls label { display: inline-flex; align-items: center; gap: 5px; min-height: 29px; }
.device-controls input { accent-color: var(--accent); }
.device-controls output { min-width: 3ch; font-variant-numeric: tabular-nums; }

.input-panel { align-self: start; padding: 16px; background: var(--panel); }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.panel-heading h2 { font-size: 19px; }
.panel-heading output { white-space: nowrap; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.instructions, .orientation, .status, .ai-input-note, .scene-notes { color: var(--muted); font-size: 13px; line-height: 1.45; }
.instructions { margin: 7px 0 15px; }
.orientation { margin: 13px 0; }
.status { margin: 0; }
.status:not(:empty) { margin-top: 8px; }
.status[data-error] { color: var(--error); }
.view-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.view-input { display: grid; position: relative; gap: 6px; cursor: pointer; color: var(--ink); font-size: 13px; font-weight: 600; min-width: 0; }
.view-input input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.view-input span:first-of-type { display: grid; place-items: center; height: 69px; border: 1px dashed var(--line); border-radius: 8px; background: var(--tile); color: var(--accent); font-size: 22px; font-weight: 400; overflow: hidden; }
.view-input:hover span:first-of-type { border-color: var(--accent); }
.view-input img { width: 100%; height: 100%; object-fit: contain; min-height: 0; padding: 4px; }
.generate { width: 100%; min-height: 40px; padding: 8px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-label); font-size: 14px; font-weight: 650; }
.generate:disabled { background: var(--tile); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.model-notes { display: block; font-size: 13px; font-weight: 600; }
.model-notes span { color: var(--muted); font-weight: 400; }
#modelNotes { display: block; width: 100%; min-height: 48px; margin: 5px 0 10px; padding: 6px 8px; resize: vertical; border: 1px solid var(--line); border-radius: 7px; background: var(--tile); color: var(--ink); font: inherit; font-size: 13px; }
.ai-input-note { margin: 7px 0 0; font-size: 12px; }
.scene-notes { margin-top: 8px; }
.scene-notes ul { margin: 5px 0 0; padding-inline-start: 18px; }

@media (max-width: 680px) {
  .viewer { grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 8px; }
  .preview { min-height: 320px; }
  .view-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
