:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #171a20;
  --panel-2: #1e222a;
  --line: #2a2f38;
  --line-2: #363c47;
  --text: #e4e7ec;
  --muted: #8a93a3;
  --accent: #f2a33a;
  --accent-ink: #1b1204;
  --x: #e5484d;
  --y: #46a758;
  --z: #3e7bfa;
  --danger: #e5484d;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 280px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "left view right";
}

/* ---------- barra superior ---------- */
#app > header {
  grid-area: top;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .01em; margin-right: 4px; }
.brand svg { width: 22px; height: 22px; }
.brand small { font: 500 11px var(--mono); color: var(--muted); }
.sep { width: 1px; height: 22px; background: var(--line); }
.group { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.tbtn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  background: transparent; border: 0; border-radius: 5px;
  color: var(--text); white-space: nowrap;
}
.tbtn:hover { background: var(--line); }
.tbtn:disabled { opacity: .35; background: transparent; }
.tbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tbtn svg { width: 16px; height: 16px; flex: none; }
.tbtn kbd { font: 500 10px var(--mono); opacity: .6; }
.ai-btn { border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); color: var(--accent); height: 32px; }
.ai-btn:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0;
  min-width: 240px; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  display: grid; gap: 1px;
}
.menu-list button {
  text-align: left; background: none; border: 0; border-radius: 5px; padding: 7px 10px;
  display: flex; justify-content: space-between; gap: 12px;
}
.menu-list button:hover { background: var(--line); }
.menu-list button span { color: var(--muted); font: 11px var(--mono); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.menu-list .cap { font: 500 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 6px 10px 2px; }

/* ---------- painéis ---------- */
aside {
  background: var(--panel);
  min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column;
}
#left { grid-area: left; border-right: 1px solid var(--line); }
#right { grid-area: right; border-left: 1px solid var(--line); }
aside section { padding: 14px; border-bottom: 1px solid var(--line); }
aside section.grow { flex: 1; }
h2 {
  margin: 0 0 10px;
  font: 500 10.5px var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
  display: flex; justify-content: space-between; gap: 8px;
}
h2.sub { margin-top: 20px; }
h2 output { letter-spacing: 0; text-transform: none; }
.lead { margin: 0 0 14px; color: var(--muted); }
.lead strong { color: var(--text); font-weight: 500; }

.shapes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.shape {
  display: grid; justify-items: center; gap: 4px;
  padding: 9px 2px 7px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  font-size: 11px; color: var(--muted);
}
.shape svg { width: 26px; height: 26px; color: var(--text); }
.shape:hover { border-color: var(--accent); color: var(--text); }
.shape:hover svg { color: var(--accent); }

.outliner { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.outliner li { display: flex; align-items: center; border-radius: 5px; }
.outliner li:hover { background: var(--panel-2); }
.outliner li.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.outliner .item {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; background: none; border: 0; text-align: left;
}
.outliner .item i { width: 9px; height: 9px; border-radius: 2px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.outliner .item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outliner li.off .item span { color: var(--muted); text-decoration: line-through; }
.outliner .eye { background: none; border: 0; padding: 4px 8px; color: var(--muted); display: flex; }
.outliner .eye:hover { color: var(--text); }
.outliner .eye svg { width: 15px; height: 15px; }
.empty-note { color: var(--muted); margin: 0; }
.empty-note.small { font-size: 11.5px; margin: 2px 0 10px; }

/* ---------- propriedades ---------- */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > span, .vec > span, .slider > span { font-size: 11.5px; color: var(--muted); }
.field > span em { font-style: normal; opacity: .8; }
.field input[type="text"], .field input[type="password"], .field textarea {
  min-height: 30px; padding: 6px 9px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.vec { display: grid; gap: 4px; margin-bottom: 12px; }
.vec .row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.num {
  display: flex; align-items: center; height: 28px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden;
}
.num:focus-within { border-color: var(--accent); }
.num b { font: 600 10px var(--mono); padding: 0 5px 0 7px; }
.num.x b { color: var(--x); } .num.y b { color: var(--y); } .num.z b { color: var(--z); }
.num input {
  width: 100%; min-width: 0; height: 100%; border: 0; background: none; padding: 0 4px 0 0;
  font: 12px var(--mono); font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.num input::-webkit-inner-spin-button { opacity: .4; }
.num input:focus { outline: none; }

.mat-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.swatch { position: relative; width: 38px; height: 30px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line-2); flex: none; }
.swatch input { position: absolute; inset: -6px; width: 60px; height: 50px; border: 0; padding: 0; cursor: pointer; }
.presets { display: flex; flex-wrap: wrap; gap: 5px; }
.presets button { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,.12); padding: 0; }
.slider { display: grid; grid-template-columns: 86px 1fr 46px; align-items: center; gap: 8px; margin-bottom: 8px; }
.slider output { font: 11px var(--mono); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 4px; color: var(--muted); font-size: 12px; }
.check input { accent-color: var(--accent); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.act {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  min-height: 32px; padding: 0 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
}
.act:hover { border-color: var(--line-2); background: var(--line); }
.act:disabled { opacity: .45; }
.act kbd { font: 10px var(--mono); color: var(--muted); }
.act.danger { color: var(--danger); }
.act.danger:hover { border-color: var(--danger); }
.act.wide { grid-column: 1 / -1; }
.act.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; justify-content: center; }
.act.primary kbd { color: var(--accent-ink); opacity: .6; }
.act.primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); }

.bool { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 4px; }
.bool .act { flex-direction: column; justify-content: center; gap: 3px; padding: 8px 4px; font-size: 11.5px; }
.bool .act svg { width: 22px; height: 22px; }

.brushes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.brush {
  height: 32px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; font-size: 12px;
}
.brush:hover { border-color: var(--line-2); }
.brush[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- viewport ---------- */
#view { grid-area: view; position: relative; min-height: 0; overflow: hidden; background: var(--bg); }
#view canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#view.sculpting canvas { cursor: crosshair; }
.hud {
  position: absolute; left: 12px; bottom: 12px; right: 12px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; justify-content: space-between;
  pointer-events: none;
}
.chip {
  pointer-events: auto;
  background: rgba(17,19,24,.82); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 10px; font: 11px var(--mono); color: var(--muted);
}
details.chip summary { cursor: pointer; color: var(--text); }
details.chip dl { display: grid; grid-template-columns: auto auto; gap: 3px 14px; margin: 8px 0 2px; }
details.chip dt { color: var(--text); }
details.chip dd { margin: 0; }
.axes { display: flex; gap: 10px; }
.axes b { font-weight: 500; }
.axes .x { color: var(--x); } .axes .y { color: var(--y); } .axes .z { color: var(--z); }

.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 24px);
  background: var(--accent); color: var(--accent-ink);
  padding: 7px 8px 7px 14px; border-radius: 8px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.banner-btn { background: rgba(0,0,0,.14); border: 0; border-radius: 5px; padding: 4px 10px; color: inherit; }
.banner-btn:hover { background: rgba(0,0,0,.24); }

#drop {
  position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 12px;
  display: grid; place-items: center; background: rgba(17,19,24,.7);
  font-size: 15px; pointer-events: none;
}
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-weight: 500;
  z-index: 50; max-width: calc(100% - 32px);
}

/* ---------- diálogo da IA ---------- */
dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 0; border: 1px solid var(--line-2); border-radius: 12px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 24px 64px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(8,9,12,.62); }
dialog form { padding: 18px 20px 16px; display: grid; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dlg-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; color: var(--muted); display: flex; }
.icon-btn:hover { background: var(--line); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.hint { color: var(--muted); font-size: 11.5px; }

.refs { display: flex; flex-wrap: wrap; gap: 8px; }
.refs.over { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }
.ref, .ref-add {
  position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line-2); background: var(--panel-2);
}
.ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref button {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; padding: 0;
}
.ref button svg { width: 12px; height: 12px; }
.ref-add {
  display: grid; place-content: center; justify-items: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; cursor: pointer; border-style: dashed;
}
.ref-add svg { width: 20px; height: 20px; }
.ref-add:hover { color: var(--accent); border-color: var(--accent); }

.seg { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.seg legend { font-size: 11.5px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.seg label {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer;
}
.seg label:has(input:checked) { border-color: var(--accent); }
.seg input { accent-color: var(--accent); margin: 0; }

.keybox { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; background: var(--panel-2); }
.keybox summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.keybox summary output { font: 11px var(--mono); color: var(--muted); }
.keybox[open] summary { margin-bottom: 10px; }
.keybox .field input { background: var(--panel); }

.ai-status {
  border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12.5px; display: flex; gap: 10px; align-items: flex-start;
}
.ai-status.error { border-color: var(--danger); color: #f3b2b4; }
.ai-status.ok { border-color: var(--y); }
.spin {
  width: 14px; height: 14px; flex: none; margin-top: 2px;
  border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-foot .act { min-width: 96px; justify-content: center; }

@media (max-width: 860px) {
  body { overflow: auto; }
  #app {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 62vh auto auto;
    grid-template-areas: "top" "view" "right" "left";
  }
  #left, #right { border: 0; border-top: 1px solid var(--line); overflow: visible; }
  .shapes { grid-template-columns: repeat(5, 1fr); }
  .tbtn .lbl, .tbtn kbd { display: none; }
  .hud details { display: none; }
}
@media (max-width: 420px) {
  .shapes { grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .spin { animation-duration: 3s; }
}
