:root {
  --bg: #0f1218;
  --panel: #151a22;
  --panel-2: #1c222c;
  --line: #2a323e;
  --text: #e8ebf0;
  --muted: #8f99a8;
  --accent: #e7b450;
  --accent-ink: #1b1406;
  --red: #c9424c;
  --stage: linear-gradient(180deg, #eef1f5 0%, #d9dfe7 100%);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 360px 1fr; height: 100vh; }

/* ---------- pannello ---------- */
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 18px 18px 40px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.logo svg { width: 28px; height: 28px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }

.group { border-top: 1px solid var(--line); padding: 16px 0 6px; }
.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.group h2 span { width: 20px; height: 20px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 11px; color: var(--accent); }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }

.drop { display: block; position: relative; border: 1px dashed #3a4452; border-radius: 10px; overflow: hidden; cursor: pointer; background: #0b0d12; min-height: 120px; }
.drop.over { border-color: var(--accent); }
.drop canvas { display: block; width: 100%; height: auto; }
.drop-hint { position: absolute; left: 8px; bottom: 8px; background: rgba(10,12,16,.78); padding: 4px 9px; border-radius: 6px; font-size: 12px; }

.row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; margin-bottom: 9px; }
.row label { font-size: 13px; }
.row output { font-family: var(--mono); font-size: 12px; color: var(--accent); min-width: 56px; text-align: right; }
.row input[type=range] { grid-column: 1 / -1; }
.row.disabled { opacity: .4; pointer-events: none; }
.row.check { grid-template-columns: auto 1fr; }
.row select { grid-column: 1 / -1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--line); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--line); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); margin-top: -5.5px; border: 2px solid var(--panel); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

.shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.shape { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px 6px; cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.shape:hover { border-color: #4a5566; }
.shape.on { border-color: var(--accent); background: #262116; }
.shape svg { width: 100%; height: 54px; display: block; }
.shape svg path { fill: rgba(231,180,80,.14); stroke: var(--accent); stroke-width: 1.4; }
.shape svg line { stroke: var(--accent); stroke-width: .8; opacity: .55; }
.shape span { display: block; font-size: 11px; margin-top: 4px; line-height: 1.2; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0 12px; }
.stats div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.stats b { display: block; font-family: var(--mono); font-size: 13px; color: var(--text); font-weight: 500; }
.stats small { color: var(--muted); font-size: 11px; }

button.primary { width: 100%; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 12px; font-weight: 700; cursor: pointer; }
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled { opacity: .5; cursor: wait; }

.tips { margin-top: 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tips summary { cursor: pointer; font-weight: 600; }
.tips ul { margin: 8px 0 0; padding-left: 18px; color: #c4cbd6; font-size: 12.5px; }
.tips li { margin-bottom: 5px; }

/* ---------- area 3D ---------- */
.stage { position: relative; background: var(--stage); overflow: hidden; }
.stage.lit { background: #07080d; }
.viewport { position: absolute; inset: 0; }
.viewport canvas { display: block; }
.toolbar { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; flex-wrap: wrap; gap: 8px; z-index: 2; align-items: center; }
.seg { display: flex; background: rgba(21,26,34,.92); border: 1px solid rgba(255,255,255,.06); border-radius: 10px; padding: 3px; backdrop-filter: blur(6px); }
.seg button { background: none; border: 0; padding: 6px 11px; border-radius: 7px; cursor: pointer; color: #c6cdd8; font-size: 13px; }
.seg button:hover { color: #fff; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ghost { background: rgba(21,26,34,.92); border: 1px solid rgba(255,255,255,.06); color: #c6cdd8; border-radius: 10px; padding: 9px 12px; cursor: pointer; margin-left: auto; }
.light-ctrl { display: flex; align-items: center; gap: 10px; background: rgba(21,26,34,.92); border-radius: 10px; padding: 4px 12px; }
.light-ctrl[hidden] { display: none; }
.light-ctrl input { width: 110px; }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatches button.on { border-color: #fff; }
.hud { position: absolute; left: 14px; bottom: 14px; display: flex; gap: 8px; z-index: 2; font-family: var(--mono); font-size: 12px; }
.hud > div { background: rgba(21,26,34,.92); color: #dfe4ea; padding: 6px 10px; border-radius: 8px; }
.busy { color: var(--accent) !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; }
  .stage { grid-row: 1; height: 58vh; position: sticky; top: 0; z-index: 1; }
  .panel { grid-row: 2; border-right: 0; padding: 16px; }
  .toolbar { left: 8px; right: 8px; top: 8px; gap: 6px; }
  .seg button { padding: 5px 8px; font-size: 12px; }
  .ghost { display: none; }
}
