:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: #0c3f78;
  color: #f5fbff;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background-color: #0c3f78;
  background-image: linear-gradient(rgba(231, 246, 255, .1) 1px, transparent 1px), linear-gradient(90deg, rgba(231, 246, 255, .1) 1px, transparent 1px), linear-gradient(rgba(231, 246, 255, .04) 1px, transparent 1px), linear-gradient(90deg, rgba(231, 246, 255, .04) 1px, transparent 1px);
  background-position: -1px -1px;
  background-size: 32px 32px, 32px 32px, 8px 8px, 8px 8px;
}

main { max-width: 1440px; min-height: 100vh; margin: auto; padding: 24px 32px; }
header { margin-bottom: 20px; }
header > p:last-child { margin: 0; }
h1 { margin: 4px 0 10px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: .92; letter-spacing: -.05em; }
h2 { margin: 0 0 20px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; }
p { color: #d7ecfb; line-height: 1.5; }

.eyebrow { margin: 0; color: #b9e5ff; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .75rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.workspace { display: grid; align-items: start; grid-template-columns: minmax(280px, 360px) 1fr; column-gap: 24px; }
.sidebar { align-self: start; }
.sidebar-toggle { display: none; }
.sidebar, .result { min-width: 0; }

.parameters, .result { border: 1px solid #d9f1ff; background: #0e4e91; box-shadow: 6px 6px 0 rgba(2, 27, 58, .35); }
.parameters { padding: 24px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.parameter-row { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 20px 112px; align-items: center; gap: 8px; margin: 13px 0; font-size: .8rem; }
.parameter-row > label { min-width: 0; overflow-wrap: anywhere; }
.parameter-row > .input { grid-column: 3; width: 100%; }
.parameter-row > .input input { flex: 1; min-width: 0; width: 0; }
.parameter-row > .input select { min-width: 0; width: 100%; }
.parameter-help { display: grid; place-items: center; }
.parameter-help-trigger { display: grid; width: 20px; height: 20px; padding: 0; place-items: center; border: 1px solid #b9e5ff; border-radius: 50%; background: transparent; color: #b9e5ff; cursor: help; font: 700 .7rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; letter-spacing: normal; text-transform: none; transition: background-color .18s ease, color .18s ease; }
.parameter-help:hover .parameter-help-trigger, .parameter-help-trigger:focus-visible { background: #b9e5ff; color: #073767; }
.parameter-help-tooltip { position: absolute; z-index: 2; top: calc(100% + 4px); right: 0; left: 0; margin: 0; padding: 10px 12px; border: 1px solid #b9e5ff; background: #073767; box-shadow: 3px 3px 0 rgba(2, 27, 58, .45); color: #e7f6ff; font: .75rem/1.5 ui-sans-serif, system-ui, sans-serif; overflow-wrap: anywhere; opacity: 0; visibility: hidden; transform: translateY(-4px); pointer-events: none; transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s; }
.parameter-help:hover .parameter-help-tooltip, .parameter-help-trigger:focus-visible + .parameter-help-tooltip { opacity: 1; visibility: visible; transform: translateY(0); transition-delay: 0s; }
@media (hover: none) {
  .parameter-help-trigger:focus + .parameter-help-tooltip { opacity: 1; visibility: visible; transform: translateY(0); transition-delay: 0s; }
}
@media (prefers-reduced-motion: reduce) {
  .parameter-help-trigger, .parameter-help-tooltip { transition: none; }
}
.advanced-parameters { margin: 24px 0 20px; padding-top: 16px; border-top: 1px solid rgba(217, 241, 255, .65); }
.advanced-parameters > summary { color: #b9e5ff; cursor: pointer; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
.advanced-parameters > summary:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.advanced-parameters > p { margin: 10px 0 16px; color: #d7ecfb; font: .75rem/1.5 ui-sans-serif, system-ui, sans-serif; }

.input { display: flex; align-items: center; overflow: hidden; border: 1px solid #b9e5ff; background: #073767; }
.input input { width: 83px; padding: 9px 7px; border: 0; background: transparent; color: #fff; font: inherit; }
.input small { padding-right: 8px; color: #b9e5ff; }
fieldset { margin: 24px 0 20px; padding: 16px 0 0; border: 0; border-top: 1px solid rgba(217, 241, 255, .65); }
legend { padding: 0; color: #b9e5ff; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
.check { display: flex; align-items: center; gap: 9px; margin: 10px 0; font-size: .8rem; }
input[type="checkbox"] { accent-color: #e7f6ff; }

button, .button { display: inline-block; padding: 11px 16px; border: 1px solid #e7f6ff; border-radius: 0; background: #e7f6ff; color: #06315e; font: 700 .8rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; letter-spacing: .03em; cursor: pointer; text-decoration: none; text-transform: uppercase; }
button:hover, .button:hover { background: #0a3767; color: #fff; }
button:focus-visible, .button:focus-visible, input:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

.result { display: grid; min-height: 488px; grid-column: 2; grid-row: 1; align-self: start; padding: 14px 24px 24px; place-items: center; }

#generation-result { width: 100%; }
.empty { text-align: center; }
.empty p { margin-bottom: 4px; color: #fff; }
.empty span { color: #b9e5ff; font: .8rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.status {
  display: flex;
  min-height: 450px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  text-align: left;
}

.status p { margin: 4px 0 0; }
.spinner { display: block; width: 24px; height: 24px; border: 3px solid #73bde6; border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }

.complete, .error { width: 100%; max-width: 900px; margin-inline: auto; }
.complete h2 { margin: 7px 0; font-size: 1.1rem; }
.preview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
.preview-grid--1 { grid-template-columns: minmax(0, 1fr); }
.preview-grid--3, .preview-grid--5, .preview-grid--6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.preview-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.preview-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 4px; }
.preview-actions p { margin: 0; }
.stl-preview-card { position: relative; margin: 0; overflow: hidden; border: 1px solid #b9e5ff; background: #0b3d70; }
.stl-preview-stage { position: relative; min-height: 0; width: 100%; aspect-ratio: 4 / 3; outline: none; }
.stl-preview-stage:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.stl-preview-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.stl-preview-debug { position: absolute; z-index: 1; top: 8px; left: 8px; max-width: calc(100% - 16px); margin: 0; padding: 7px 8px; overflow: hidden; border: 1px solid rgba(185, 229, 255, .55); background: rgba(4, 29, 56, .78); color: #e7f6ff; font: .58rem/1.35 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; pointer-events: none; white-space: pre-wrap; }
.stl-preview-loading, .stl-preview-error { position: absolute; inset: 0; display: grid; place-content: center; gap: 9px; margin: 0; padding: 20px; background: rgba(6, 49, 94, .84); color: #e7f6ff; text-align: center; font: .75rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.stl-preview-loading[hidden], .stl-preview-error[hidden], .stl-preview-reset[hidden] { display: none; }
.stl-preview-loading progress { width: min(190px, 80vw); height: 6px; accent-color: #e7f6ff; }
.stl-preview-error { color: #ffe5d8; background: rgba(125, 49, 64, .92); }
.stl-preview-reset { position: absolute; right: 9px; bottom: 9px; z-index: 1; padding: 7px 9px; font-size: .65rem; opacity: .92; }
.stl-preview-card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-top: 1px solid #b9e5ff; color: #d7ecfb; background: #0a3767; font: .75rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.stl-preview-card figcaption span { color: #b9e5ff; font-size: .65rem; }

.error { padding: 14px; border: 1px solid #ffd1be; border-left: 4px solid #ffd1be; background: #7d3140; }
.error p { margin: 6px 0 0; color: #ffe5d8; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1200px) {
  main { padding: 32px 0; overflow-x: clip; }
  main > header { padding: 0 16px; }
  .workspace { width: calc(200% - 64px); min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; transform: translateX(var(--workspace-offset, calc(-50% + 64px))); transition: transform .4s ease-in-out; }
  .workspace.sidebar-open { --workspace-offset: 0px; }
  .workspace.dragging { transition: none; }
  .sidebar { position: relative; padding: 0 16px; touch-action: pan-y; }
  .parameters { position: relative; }
  .parameters h2 { padding-right: 48px; }
  .sidebar-toggle { position: absolute; display: block; top: 0; right: 0; width: 40px; height: 44px; padding: 0; border-color: #d9f1ff; background: #d9f1ff; font-size: 1rem; }
  .sidebar-toggle:hover { background: #d9f1ff; color: #06315e; }
  .sidebar-toggle svg { width: 24px; height: 24px; vertical-align: middle; transform: rotate(var(--arrow-angle, 0deg)); transition: transform .4s ease-in-out; }
  .sidebar-toggle[aria-expanded="true"] { --arrow-angle: 180deg; }
  .workspace.dragging .sidebar-toggle svg { transition: none; }
  .result { margin: 0 48px 0 0; }
}

@media (min-width: 761px) and (max-width: 1200px) {
  .workspace { width: calc(100% + 296px); grid-template-columns: 360px minmax(0, 1fr); transform: translateX(var(--workspace-offset, -296px)); }
  .result { margin-right: 16px; }
}

@media (max-width: 760px) {
  .result { min-height: 288px; }
  .status { min-height: 250px; }
  .preview-grid { grid-template-columns: minmax(0, 1fr); }
  .preview-actions { align-items: flex-start; flex-direction: column; }
  .stl-preview-card figcaption { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .workspace, .sidebar-toggle svg { transition: none; }
}
