:root {
  --ink: #162130; --ink2: #202d3e; --canvas: #0c1119;
  --paper: #f8fafc; --paper2: #eef2f6; --line: #dce3eb; --line-dark: #334155;
  --text: #192433; --muted: #647386; --muted-dark: #94a3b4;
  --amber: #f4a51c; --amber-dark: #cf7c0a; --cyan: #30b6d7;
  --good: #14845c; --bad: #c24139; --radius: 7px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--canvas); color: var(--text); font-size: 13px; }
button, select, input { font: inherit; color: inherit; }
button { border: 1px solid var(--line); border-radius: 5px; background: white; padding: 7px 10px; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
button:hover:not(:disabled) { border-color: #aeb9c6; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid #df9717; outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.primary { border-color: var(--amber); background: var(--amber); color: #17202b; font-weight: 700; }
.primary:hover:not(:disabled) { border-color: #e69110; background: #f7b338; }
.primary.compact { padding: 8px 13px; }
.icon-btn { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; font-size: 17px; line-height: 1; }

/* App shell */
#app { width: 100%; height: 100dvh; display: grid; grid-template-columns: 238px minmax(360px, 1fr) 342px; grid-template-rows: 62px minmax(0, 1fr); }
#app-header { grid-row: 1; grid-column: 1 / -1; z-index: 5; display: grid; grid-template-columns: 238px minmax(200px, 1fr) auto; align-items: center; gap: 18px; padding: 0 18px 0 14px; background: var(--ink); color: #f2f5f8; border-bottom: 1px solid #2d3948; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 31px; height: 31px; color: var(--amber); }
.brand-mark svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.brand b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.25px; }
.brand small { display: block; color: #9eacbb; font-size: 10px; margin-top: 2px; }
.scene-context { min-width: 0; border-left: 1px solid #394656; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.scene-context strong { font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-context span { color: #9eacbb; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; gap: 9px; align-items: center; }
#help-btn { border-color: #465467; background: transparent; color: #d9e1e9; }
#library-toggle { display: none; }

/* Scene rail */
#side { grid-row: 2; grid-column: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding: 20px 13px 12px; background: #f0f3f6; border-right: 1px solid #dbe2e9; }
.library-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; margin-bottom: 14px; }
.library-heading h2 { margin: 0; color: #667487; font-size: 10px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
#scene-count { color: #788698; font-size: 11px; font-variant-numeric: tabular-nums; }
.import-btn { width: 100%; padding: 9px 11px; border-color: #263649; background: #263649; color: #fff; font-weight: 650; text-align: left; }
.import-btn span { color: #f8b330; padding-right: 6px; font-size: 16px; vertical-align: -1px; }
.library-hint { margin: 9px 4px 16px; color: #7a8796; font-size: 10px; line-height: 1.45; }
.list { overflow-y: auto; flex: 1; }
.list .item { position: relative; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 8px; padding: 11px 10px; margin-bottom: 8px; border: 1px solid #dce3ea; border-radius: 6px; background: rgba(255,255,255,.8); cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.list .item:hover { border-color: #aebbc9; background: #fff; }
.list .item.active { border-color: #d9961b; background: #fff; box-shadow: inset 3px 0 0 var(--amber); }
.list .item .scene-select { grid-column: 1; width: 100%; border: 0; border-radius: 0; background: transparent; padding: 0; text-align: left; }
.list .item .scene-select:hover:not(:disabled) { border-color: transparent; background: transparent; }
.list .item .n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #243244; font-weight: 650; font-size: 11px; }
.list .item .m { display: block; grid-column: auto; color: #738194; font-size: 10px; line-height: 1.4; }
.list .item .x { grid-row: 1 / 3; grid-column: 2; align-self: center; border: 0; background: none; color: #8390a0; padding: 5px; }
.list .item .x:hover { color: var(--bad); }
.tag { margin-left: 5px; color: #176c50; font-size: 9px; }
.library-footer { border-top: 1px solid #d9e0e7; padding: 12px 3px 0; display: flex; align-items: center; gap: 7px; color: #798697; font-size: 9px; }
.status-dot, .live-indicator i { width: 7px; height: 7px; border-radius: 50%; background: #1da374; box-shadow: 0 0 0 3px #d5eee5; flex: none; }

/* 3D canvas */
#stage { position: relative; grid-row: 2; grid-column: 2; min-width: 0; min-height: 0; overflow: hidden; background: #0b1119; }
#gl { width: 100%; height: 100%; display: block; cursor: crosshair; }
#toolbar { position: absolute; top: 13px; left: 14px; display: flex; gap: 8px; align-items: center; }
#toolbar button { background: rgba(22,33,48,.9); border-color: rgba(255,255,255,.16); color: #edf2f7; backdrop-filter: blur(8px); }
#toolbar .seg { display: flex; margin: 0; }
#toolbar .seg button { border-radius: 0; margin-left: -1px; }
#toolbar .seg button:first-child { margin-left: 0; border-radius: 5px 0 0 5px; }
#toolbar .seg button:last-child { border-radius: 0 5px 5px 0; }
#toolbar .seg button.active { border-color: var(--amber); background: var(--amber); color: #17202b; }
#toolbar .icon-btn { font-size: 20px; }
#hud { position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 205px); display: flex; gap: 13px; align-items: center; border: 1px solid rgba(255,255,255,.13); border-radius: 5px; background: rgba(15,23,33,.83); backdrop-filter: blur(8px); padding: 7px 10px; color: #b8c4d0; font-size: 10px; font-variant-numeric: tabular-nums; }
#hud-scene { color: #f0f4f8; }
#hud-cam, #hud-fps { white-space: nowrap; }
#minimap { position: absolute; right: 12px; bottom: 12px; width: 148px; height: 148px; border: 1px solid rgba(255,255,255,.36); border-radius: 5px; background: #000; box-shadow: 0 4px 20px #0005; }
#fly-hint { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); max-width: 90%; border: 1px solid #435366; border-radius: 5px; background: rgba(15,23,33,.92); padding: 8px 12px; color: #e8edf3; white-space: nowrap; font-size: 11px; }
#busy { position: absolute; inset: 0; z-index: 3; display: flex; gap: 10px; align-items: center; justify-content: center; background: rgba(10,16,24,.66); color: #f3f6f9; }
.spinner { width: 19px; height: 19px; border: 2px solid #536274; border-top-color: var(--amber); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Inspector */
#inspector { grid-row: 2; grid-column: 3; min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--paper); border-left: 1px solid #d9e0e8; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; min-height: 45px; padding: 0 16px; border-bottom: 1px solid var(--line); background: #fff; }
.tabs button { position: relative; border: 0; border-radius: 0; background: transparent; color: #718093; font-size: 11px; font-weight: 600; }
.tabs button.active { color: #1c2938; }
.tabs button.active::after { content: ""; position: absolute; right: 12px; bottom: -1px; left: 12px; height: 2px; background: var(--amber); }
.panel { min-height: 0; overflow: auto; flex: 1; padding: 18px 17px 22px; }
.inspector-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 20px; }
.inspector-title h1 { margin: 0; color: #1c2837; font-size: 18px; font-weight: 680; letter-spacing: -.4px; }
.inspector-title p { margin: 5px 0 0; color: #768497; font-size: 11px; }
.live-indicator { display: flex; gap: 7px; align-items: center; color: #637385; font-size: 9px; white-space: nowrap; padding-top: 5px; }
.live-indicator i { width: 6px; height: 6px; box-shadow: none; }
.group { padding: 0 0 17px; margin-bottom: 16px; border-bottom: 1px solid #e3e8ee; }
.group h3 { margin: 0 0 11px; color: #647386; font-size: 9px; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.group-heading { display: flex; align-items: center; justify-content: space-between; }
.experimental { margin-top: -9px; color: #8b6a2b; font-size: 8px; font-weight: 750; letter-spacing: .08em; }
label { display: block; margin: 10px 0; color: #6c7a8c; font-size: 10px; }
label input[type=file], label select, label input[type=number], label input[type=text] { display: block; width: 100%; margin-top: 5px; }
select, input[type=number], input[type=text] { border: 1px solid #d6dee7; border-radius: 4px; background: #fff; padding: 7px; color: #253344; font-size: 11px; }
label.row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 6px; }
label.row output { margin-left: auto; color: #354456; font-variant-numeric: tabular-nums; font-size: 10px; }
label.row input[type=range] { width: 100%; margin: 5px 0 0; accent-color: var(--amber-dark); }
label.check { justify-content: flex-start; gap: 6px; }
label.check input[type=checkbox] { accent-color: var(--amber-dark); }
input.mini { display: inline-block !important; width: 54px !important; margin: 0 2px !important; padding: 3px 4px; }
details { border: 1px solid #e0e6ed; border-radius: 5px; padding: 7px 9px; margin: 8px 0; }
summary { cursor: pointer; color: #354456; font-size: 11px; font-weight: 600; }
.seg { display: flex; gap: 0; margin-bottom: 9px; }
.seg button { flex: 1; min-width: 0; border-radius: 0; margin-left: -1px; padding: 7px 3px; color: #647386; font-size: 9px; white-space: nowrap; }
.seg button:first-child { margin-left: 0; border-radius: 5px 0 0 5px; }
.seg button:last-child { border-radius: 0 5px 5px 0; }
.seg button.active { position: relative; z-index: 1; border-color: #e6a638; background: #fff4df; color: #56390c; font-weight: 700; }
#tool button { font-size: 10px; padding: 7px 6px; }
#tool button span { margin-right: 4px; color: #68788d; font-size: 13px; }
.legend { height: 24px; margin: 7px 0 8px; position: relative; }
.legend .bar { height: 7px; border-radius: 3px; }
.legend .ticks { display: flex; justify-content: space-between; color: #8390a0; font-size: 9px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 5px 10px; color: #334255; font-size: 10px; font-variant-numeric: tabular-nums; }
.kv b { color: #748195; font-weight: 450; }
#profile { width: 100%; background: #111923; border: 1px solid #dce3eb; border-radius: 5px; margin-top: 8px; }
.note { color: #788698; font-size: 10px; line-height: 1.55; }
.btns { display: flex; gap: 7px; }
.btns button { flex: 1; font-size: 10px; }
.export-group { border-bottom: 0; padding-bottom: 0; }

/* Validation */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; margin: 2px 0 15px; }
.card { padding: 10px 8px; border: 1px solid #e0e6ed; border-radius: 5px; background: #fff; }
.card .v { color: #1e2d3e; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card .v small { color: #718093; font-size: 9px; font-weight: 500; }
.card .l { margin-top: 3px; color: #7a8797; font-size: 8px; letter-spacing: .07em; text-transform: uppercase; }
table.t { width: 100%; border-collapse: collapse; margin: 9px 0 17px; font-size: 9px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 6px 3px; border-bottom: 1px solid #e5e9ef; text-align: right; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { color: #778597; font-size: 8px; font-weight: 650; }
#metrics h3 { margin: 16px 0 7px; color: #4f5f72; font-size: 10px; font-weight: 700; }
.better { color: var(--good); } .worse { color: var(--bad); }

/* Import and help overlays */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(7,12,18,.68); backdrop-filter: blur(3px); }
.upload-dialog { position: relative; width: min(620px, 100%); max-height: min(90vh, 860px); overflow: auto; padding: 22px; border: 1px solid #dce3eb; border-radius: 8px; background: #f9fbfd; box-shadow: 0 24px 80px #0006; }
.modal-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 17px; }
.modal-heading h2 { margin: 0; font-size: 18px; color: #202d3d; }
.modal-heading p { margin: 5px 0 0; color: #718093; font-size: 11px; }
.drop { display: grid; place-items: center; min-height: 105px; padding: 16px; border: 1px dashed #aebbc9; border-radius: 6px; background: #fff; text-align: center; cursor: pointer; color: #738195; line-height: 1.65; }
.drop:hover, .drop.over { border-color: var(--amber-dark); background: #fffaf1; }
.drop input, .drop input[type=file] { display: none; }
.drop b { color: #29394c; font-size: 12px; }
.upload-dialog details { background: #fff; }
.upload-dialog details label { font-size: 10px; }
.upload-dialog .primary { width: 100%; margin-top: 10px; padding: 10px; }
.log { margin: 12px 0 0; padding: 10px; max-height: 180px; overflow: auto; border: 1px solid #dce3eb; border-radius: 5px; background: #f0f3f6; color: #334255; font-size: 10px; white-space: pre-wrap; }
#help { position: fixed; z-index: 30; top: 50%; left: 50%; transform: translate(-50%,-50%); width: min(500px, calc(100vw - 32px)); padding: 20px 22px; border: 1px solid #3a4859; border-radius: 8px; background: #172231; color: #edf2f7; box-shadow: 0 24px 80px #0009; }
#help h2 { margin: 0 0 10px; font-size: 15px; }
#help td { padding: 5px 8px 5px 0; color: #cbd5df; font-size: 10px; vertical-align: top; }
#help td:first-child { color: var(--amber); font-weight: 700; }
#help .muted { color: #9caabb; }
#help .primary { width: 100%; margin-top: 8px; }

@media (max-width: 1120px) {
  #app { grid-template-columns: 205px minmax(300px,1fr) 310px; }
  #app-header { grid-template-columns: 205px minmax(120px,1fr) auto; gap: 12px; }
  #side { padding-right: 10px; padding-left: 10px; }
  #inspector .panel { padding-right: 13px; padding-left: 13px; }
}
@media (max-width: 860px) {
  html, body { overflow: hidden; }
  #app { grid-template-columns: minmax(0,1fr); grid-template-rows: 54px minmax(280px, 52dvh) minmax(0,1fr); }
  #app-header { grid-row: 1; grid-column: 1; grid-template-columns: 34px minmax(0,1fr) auto; gap: 8px; padding: 0 10px; }
  #library-toggle { display: inline-grid; place-items: center; width: 31px; height: 31px; padding: 0; border-color: #405064; background: transparent; color: #eaf0f6; font-size: 15px; }
  #app-header .brand { gap: 7px; }
  .brand-mark { width: 25px; height: 25px; }
  .brand-mark svg { width: 23px; height: 23px; }
  .brand b { font-size: 12px; }
  .brand small { display: none; }
  .scene-context { display: none; }
  .header-actions { gap: 5px; }
  #help-btn { display: none; }
  #dl-dsm-header { padding: 7px 9px; font-size: 10px; }
  #side { display: none; }
  #app.library-open #side { position: fixed; z-index: 15; top: 54px; bottom: 0; left: 0; display: flex; width: min(300px, 84vw); box-shadow: 10px 0 30px #0004; }
  #stage { grid-row: 2; grid-column: 1; }
  #inspector { grid-row: 3; grid-column: 1; border-top: 1px solid #d8e0e8; border-left: 0; }
  .tabs { min-height: 39px; }
  .panel { padding: 13px 16px 18px; }
  .inspector-title { margin-bottom: 13px; }
  .group { padding-bottom: 12px; margin-bottom: 12px; }
  #minimap { width: 98px; height: 98px; right: 9px; bottom: 9px; }
  #hud { bottom: 9px; left: 9px; max-width: calc(100% - 122px); gap: 6px; padding: 6px 7px; font-size: 9px; }
  #hud-cam { display: none; }
  #toolbar { top: 9px; left: 9px; }
  #toolbar button { padding: 6px 8px; font-size: 10px; }
  #toolbar .icon-btn { width: 29px; height: 29px; font-size: 18px; }
  #help { max-height: calc(100dvh - 32px); overflow: auto; }
}
@media (max-width: 420px) {
  #app { grid-template-rows: 50px minmax(260px, 48dvh) minmax(0,1fr); }
  #app-header { padding: 0 7px; gap: 6px; }
  #library-toggle { width: 28px; height: 28px; }
  #dl-dsm-header { font-size: 9px; padding: 7px; }
  .icon-btn { width: 30px; height: 30px; }
  .panel { padding-right: 13px; padding-left: 13px; }
  .surface-modes button { font-size: 8px; }
}
