/* Foundry3D Studio — dark, compact, professional 3D workspace. */

:root {
  --bg: #0a0b0d;
  --bg2: #101216;
  --bg3: #16181d;
  --line: #22262d;
  --line2: #2c313a;
  --text: #e6e8eb;
  --dim: #9aa1ab;
  --dim2: #6d747e;
  --accent: #2a6df4;
  --accent2: #5b94ff;
  --danger: #e5484d;
  --ok: #3dd68c;
  --warn: #ffb224;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.studio {
  display: grid;
  height: 100dvh;
  grid-template-rows: 46px 1fr;
  grid-template-columns: 228px 1fr 316px;
  grid-template-areas: "top top top" "left center right";
}

#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-name { font-weight: 650; letter-spacing: 0.01em; font-size: 14px; }
.logo { display: inline-flex; }

#workspaceTabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}
#workspaceTabs::-webkit-scrollbar { display: none; }

.ws {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  cursor: pointer;
}
.ws:hover { color: var(--text); background: #171a20; }
.ws.on { color: var(--text); background: #1c2027; border-color: var(--line2); }

.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line2);
  background: var(--bg3);
  color: var(--dim);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: #1e4d3a; background: #0d1a15; }
.pill.warn { color: var(--warn); border-color: #4d3a1a; background: #1d160b; }
.pill.bad { color: var(--danger); border-color: #5c2026; background: #1c0d0f; }

.stats { font-family: var(--mono); font-size: 11px; color: var(--dim2); white-space: nowrap; }
@media (max-width: 900px) { .stats { display: none; } }

/* Left column */
#left {
  grid-area: left;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head {
  padding: 10px 12px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim2);
  font-weight: 600;
}
#hierarchy { flex: 1; overflow-y: auto; padding: 0 4px 8px; min-height: 0; }
.side-foot { padding: 8px; border-top: 1px solid var(--line); display: flex; gap: 6px; }

.tree-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 7px;
  cursor: pointer;
  min-width: 0;
}
.tree-row:hover { background: #171a20; }
.tree-row.on { background: #1e2942; }
.tree-row .tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .tree-id { font-family: var(--mono); font-size: 10px; color: var(--dim2); }
.tree-row .dot { width: 7px; height: 7px; border-radius: 50%; background: #5b6470; flex: none; }
.tree-row .dot.compound { background: #8b5cf6; }
.tree-row .dot.primitive { background: #2a9df4; }
.tree-row .dot.group { background: #9aa1ab; }
.tree-row .dot.terrain, .tree-row .dot.env { background: #3dd68c; }
.tree-row .dot.character { background: #ffb224; }
.tree-row .dot.artifact { background: #e5489b; }
.tree-row .dot.light { background: #ffd60a; }
.tree-group { padding: 8px 8px 2px; font-size: 11px; color: var(--dim2); text-transform: uppercase; letter-spacing: 0.08em; }

/* Center */
#center {
  grid-area: center;
  position: relative;
  min-width: 0;
  min-height: 0;
}
.viewport { position: absolute; inset: 0; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.viewport-overlay {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  padding: 8px;
  gap: 8px;
}
.viewport-hint {
  font-size: 11px;
  color: var(--dim);
  background: rgba(10, 11, 13, 0.55);
  border: 1px solid var(--line);
  padding: 3px 10px;
  border-radius: 999px;
  backdrop-filter: blur(6px);
}
.engine-error {
  background: #2a1013;
  border: 1px solid #5c2026;
  color: #ffb4ab;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 80%;
  pointer-events: auto;
}

.timelinebar {
  position: absolute;
  left: 10px; right: 10px; bottom: 10px;
  background: rgba(16, 18, 22, 0.86);
  border: 1px solid var(--line2);
  border-radius: 10px;
  padding: 6px 10px;
  backdrop-filter: blur(8px);
}
.timeline { display: flex; align-items: center; gap: 10px; }
.tl-empty { color: var(--dim2); font-size: 12px; }
.tl-controls { display: flex; align-items: center; gap: 6px; flex: none; }
.tl-name { font-weight: 600; white-space: nowrap; }
.tl-scrub { flex: 1; accent-color: var(--accent); }
.tl-time { font-family: var(--mono); font-size: 11px; color: var(--dim); white-space: nowrap; }

/* Right column */
#right {
  grid-area: right;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.panel {
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-sub { font-size: 11px; color: var(--dim2); text-transform: uppercase; letter-spacing: 0.06em; }
.tag {
  font-family: var(--mono);
  font-size: 10px;
  background: #1c2027;
  border: 1px solid var(--line2);
  padding: 1px 7px;
  border-radius: 999px;
  color: var(--dim);
}
.field-row { display: flex; gap: 6px; align-items: center; }
.field-row.wrap { flex-wrap: wrap; }
.hint { color: var(--dim2); font-size: 12px; }
.empty { color: var(--dim2); font-size: 12px; padding: 6px 2px; }

.btn {
  background: #1c2027;
  color: var(--text);
  border: 1px solid var(--line2);
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  padding: 6px 11px;
  cursor: pointer;
}
.btn:hover { background: #232a35; border-color: #3a4250; }
.btn.small { padding: 5px 9px; }
.btn.danger { background: #2a1416; border-color: #5c2026; color: #ffb4ab; }
.btn.danger:hover { background: #3a1a1d; }
.btn.ghost { background: transparent; }
body.busy .btn { opacity: 0.65; pointer-events: none; }
body.dragging::after {
  content: "Drop a .glb / .gltf / .obj / .stl file to import";
  position: fixed;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--accent2);
  font-size: 14px;
  font-weight: 600;
  background: rgba(42, 109, 244, 0.08);
  pointer-events: none;
  z-index: 60;
}

.chip {
  background: transparent;
  border: 1px solid var(--line2);
  color: var(--dim);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #3a4250; }
.chip.on { color: #fff; background: var(--accent); border-color: var(--accent); }

select, input[type="text"], input[type="number"] {
  background: #0e1013;
  border: 1px solid var(--line2);
  color: var(--text);
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  padding: 6px 8px;
  min-width: 0;
  flex: 1;
}
select { cursor: pointer; }
input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 0; }
input[type="color"] {
  background: #0e1013;
  border: 1px solid var(--line2);
  border-radius: 7px;
  padding: 2px;
  width: 46px;
  height: 30px;
  cursor: pointer;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.cell { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cell span { font-size: 10px; color: var(--dim2); text-transform: uppercase; letter-spacing: 0.05em; }
.cell.wide { grid-column: 1 / -1; }

.clip-row, .light-row, .asset-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.light-row { flex-direction: column; align-items: stretch; }
.light-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.clip-row.on { border-color: var(--accent); }
.clip-name, .asset-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.x {
  background: transparent;
  border: none;
  color: var(--dim2);
  cursor: pointer;
  font: inherit;
  padding: 2px 6px;
  border-radius: 6px;
}
.x:hover { color: var(--danger); background: #231214; }

.finding {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 4px 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.finding .sev {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.finding.error .sev { color: var(--danger); }
.finding.warning .sev { color: var(--warn); }
.finding.info .sev { color: var(--ok); }
.finding .msg { font-size: 12px; }
.finding .fix { grid-column: 2; font-size: 11px; color: var(--dim2); }

/* Modal + toast */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.modal.on { display: flex; }
.modal-body {
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: 12px;
  max-width: min(1100px, 94vw);
  max-height: 92dvh;
  overflow: auto;
  padding: 14px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.modal-images { display: flex; flex-direction: column; gap: 10px; }
.modal-images img { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%) translateY(8px);
  background: #1c2027;
  border: 1px solid var(--line2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms, transform 160ms;
  z-index: 50;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: #5c2026; color: #ffb4ab; }

/* Compact mobile: single column, dockable inspector */
@media (max-width: 860px) {
  .studio {
    grid-template-rows: 46px 1fr auto;
    grid-template-columns: 1fr;
    grid-template-areas: "top" "center" "right";
  }
  #left { display: none; }
  #right {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 42dvh;
  }
}
