:root {
  --bg: #111317;
  --panel: #1a1d22;
  --panel-2: #20242a;
  --panel-3: #282d34;
  --border: #303640;
  --text: #e9edf2;
  --muted: #929aa6;
  --accent: #7b61ff;
  --accent-2: #9e8cff;
  --danger: #e35d6a;
  --success: #53c78a;
  --warn: #e7b85e;
  --field: #13161a;
  --topbar-h: 52px;
  --tool-h: 42px;
  --bottom-h: 180px;
  --left-w: 250px;
  --right-w: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

#app { height: 100vh; display: grid; grid-template-rows: var(--topbar-h) var(--tool-h) 1fr var(--bottom-h); }

.topbar { background: #15181c; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 12px; gap: 18px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 210px; }
.brand-mark { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 8px; background: linear-gradient(145deg, var(--accent), #4a35d5); font-weight: 900; }
.brand strong { display: block; font-size: 13px; letter-spacing: .1px; }
.brand small { display: block; color: var(--muted); font-size: 10px; margin-top: 1px; }
.menu-bar { display: flex; height: 100%; align-items: center; }
.menu { position: relative; height: 100%; display: flex; align-items: center; }
.menu-trigger { height: 100%; border: 0; background: transparent; padding: 0 12px; color: #cfd5dc; cursor: pointer; font-size: 13px; }
.menu:hover .menu-trigger { background: var(--panel-2); }
.menu-dropdown { display: none; position: absolute; top: 46px; left: 0; min-width: 210px; padding: 6px; background: #20242a; border: 1px solid #3a414c; border-radius: 7px; box-shadow: 0 14px 35px rgba(0,0,0,.4); z-index: 100; }
.menu:hover .menu-dropdown { display: grid; }
.menu-dropdown.two-col { grid-template-columns: 1fr 1fr; min-width: 280px; }
.menu-dropdown button { border: 0; text-align: left; padding: 8px 9px; border-radius: 5px; background: transparent; cursor: pointer; color: #dbe0e7; font-size: 12px; display: flex; justify-content: space-between; }
.menu-dropdown button:hover { background: #303641; }
.menu-dropdown span { color: var(--muted); font-size: 10px; margin-left: 12px; }
.separator { height: 1px; background: var(--border); margin: 4px; grid-column: 1 / -1; }
.top-actions { margin-left: auto; display: flex; gap: 7px; }
.btn { border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); padding: 7px 11px; cursor: pointer; font-size: 12px; }
.btn:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.play { border-color: #316c4c; background: #1d5037; }
.btn.stop { border-color: #7b3b43; background: #5c282f; }
.hidden { display: none !important; }

.toolstrip { background: #191c21; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 5px 10px; }
.toolgroup { display: flex; gap: 4px; align-items: center; padding-right: 10px; border-right: 1px solid var(--border); }
.tool { border: 1px solid transparent; background: transparent; min-width: 30px; height: 29px; border-radius: 5px; cursor: pointer; color: #b8c0ca; }
.tool:hover, .tool.active { background: var(--panel-3); border-color: #3b424d; color: #fff; }
.tool-text { border: 0; background: transparent; color: #aeb6c1; cursor: pointer; font-size: 11px; padding: 5px 7px; border-radius: 4px; }
.tool-text:hover { background: var(--panel-2); }
.compact-label { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.compact-label select { background: var(--field); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 3px 5px; font-size: 11px; }
.compact-check { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.status-chip { margin-left: auto; font-size: 10px; color: var(--muted); }

.workspace { min-height: 0; display: grid; grid-template-columns: var(--left-w) minmax(300px, 1fr) var(--right-w); }
.panel { min-width: 0; min-height: 0; background: var(--panel); overflow: hidden; }
.hierarchy-panel { border-right: 1px solid var(--border); }
.inspector-panel { border-left: 1px solid var(--border); overflow-y: auto; }
.panel-title { height: 36px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 10px; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: #bac2cc; background: #1b1f24; position: sticky; top: 0; z-index: 2; }
.panel-title button { width: 24px; height: 22px; background: transparent; border: 0; color: var(--muted); cursor: pointer; }
.hierarchy-search { padding: 8px; border-bottom: 1px solid var(--border); }
.hierarchy-search input { width: 100%; border: 1px solid var(--border); background: var(--field); color: var(--text); border-radius: 5px; padding: 7px 8px; font-size: 11px; outline: none; }
.tree { overflow: auto; height: calc(100% - 83px); padding: 5px 0 20px; user-select: none; }
.tree-row { height: 26px; display: flex; align-items: center; gap: 5px; cursor: pointer; color: #bdc5ce; font-size: 11px; white-space: nowrap; padding-right: 8px; }
.tree-row:hover { background: #242930; }
.tree-row.selected { background: #34304d; color: white; }
.tree-indent { display: inline-block; flex: 0 0 auto; }
.tree-arrow { width: 14px; text-align: center; color: #77818e; }
.tree-icon { width: 16px; text-align: center; color: #9aa4b1; }
.tree-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-visibility { flex:0 0 24px; width:24px; height:22px; padding:0; display:grid; place-items:center; border:0; border-radius:4px; background:transparent; color:#8f99a5; cursor:pointer; font-size:12px; }
.tree-visibility:hover { background:#303641; color:#fff; }
.tree-hidden { opacity: .45; }
.tree-hidden .tree-visibility { opacity:1; color:#69727e; }

.viewport-wrap { min-width: 0; min-height: 0; position: relative; background: #131519; overflow: hidden; }
.viewport { position: absolute; inset: 0; }
.viewport canvas { width: 100%; height: 100%; display: block; outline: none; }
.viewport-corner { position: absolute; top: 9px; display: flex; gap: 6px; pointer-events: none; }
.viewport-corner.top-left { left: 9px; }
.viewport-corner.top-right { right: 9px; }
.viewport-corner span { font-size: 9px; background: rgba(10,12,15,.72); color: #aeb6c1; border: 1px solid rgba(120,130,145,.22); border-radius: 4px; padding: 4px 6px; backdrop-filter: blur(5px); }
.viewport-hint { position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%); color: #8d97a3; background: rgba(11,13,16,.65); border-radius: 4px; padding: 4px 8px; font-size: 9px; pointer-events: none; }

.empty-state { color: var(--muted); font-size: 12px; padding: 20px; text-align: center; }
.inspector { padding-bottom: 20px; }
.inspector-section { border-bottom: 1px solid var(--border); padding: 10px; display: grid; gap: 8px; }
.section-head { font-size: 10px; text-transform: uppercase; color: #aab3be; font-weight: 700; letter-spacing: .55px; margin-bottom: 2px; }
.inspector-section label { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; font-size: 10px; color: #a7b0bb; }
.inspector-section label.inline { display: flex; grid-template-columns: none; gap: 6px; }
.inspector-section input[type="text"], .inspector-section input[type="number"], .inspector-section textarea, .project-grid input { min-width: 0; width: 100%; color: #e5e9ee; background: var(--field); border: 1px solid var(--border); border-radius: 4px; padding: 5px 6px; outline: none; font-size: 11px; }
.inspector-section input[type="color"] { width: 100%; height: 27px; padding: 2px; background: var(--field); border: 1px solid var(--border); border-radius: 4px; }
.inspector-section textarea { resize: vertical; font-family: "Cascadia Code", Consolas, monospace; line-height: 1.4; }
.inspector-section .help { color: #7f8996; font-size: 9px; line-height: 1.45; margin: 0 0 2px; }
.inspector-section code { color: #beaefc; }
.vector-row { display: grid; grid-template-columns: 55px 1fr 1fr 1fr; gap: 4px; align-items: center; }
.vector-row span { font-size: 9px; color: #8f99a5; }
.vector-row input { min-width: 0; width: 100%; color: #dde2e8; background: var(--field); border: 1px solid var(--border); border-radius: 4px; padding: 5px 4px; font-size: 10px; }
.wide-btn { border: 1px solid var(--border); background: var(--panel-2); color: #cbd2da; border-radius: 4px; padding: 6px; cursor: pointer; font-size: 10px; }

.bottom-panel { min-height: 0; background: #16191e; border-top: 1px solid var(--border); display: grid; grid-template-rows: 31px 1fr; position:relative; }
.bottom-resizer { position:absolute; z-index:30; left:0; right:0; top:-4px; height:8px; cursor:ns-resize; background:transparent; touch-action:none; }
.bottom-resizer::after { content:""; position:absolute; left:50%; top:2px; width:54px; height:2px; transform:translateX(-50%); border-radius:2px; background:#3c434d; opacity:.7; }
.bottom-resizer:hover::after, body.resizing-bottom .bottom-resizer::after { background:var(--accent-2); opacity:1; }
body.resizing-bottom { cursor:ns-resize; user-select:none; }
.bottom-tabs { display: flex; align-items: end; padding-left: 7px; border-bottom: 1px solid var(--border); }
.bottom-tab { border: 0; height: 30px; padding: 0 14px; background: transparent; color: #8f98a4; font-size: 10px; cursor: pointer; border-bottom: 2px solid transparent; }
.bottom-tab.active { color: #e6e9ee; border-bottom-color: var(--accent); }
.bottom-content { min-height: 0; overflow: auto; }
.tab-pane { display: none; height: 100%; padding: 9px 12px; }
.tab-pane.active { display: block; }
.console-toolbar { height: 23px; }
.console-toolbar button { border: 1px solid var(--border); background: var(--panel-2); color: #adb6c1; border-radius: 4px; font-size: 9px; padding: 3px 8px; cursor: pointer; }
.console-output { height: calc(100% - 24px); overflow: auto; font-family: "Cascadia Code", Consolas, monospace; font-size: 10px; line-height: 1.5; color: #9ea8b5; }
.console-line { padding: 1px 0; }
.console-line.info { color: #aeb7c2; }
.console-line.success { color: #78d6a2; }
.console-line.warn { color: #e6c073; }
.console-line.error { color: #ef808c; }
.project-grid { display: grid; grid-template-columns: 1fr 180px 2fr; gap: 14px; align-items: end; }
.project-grid > div { display: grid; gap: 6px; }
.project-grid strong { font-size: 9px; text-transform: uppercase; color: #929ba8; }
.settings-grid { display: flex; gap: 24px; align-items: center; height: 100%; }
.settings-grid label { display: flex; align-items: center; gap: 8px; font-size: 10px; color: #9ea7b3; }
.help-pane { color: #9da6b2; font-size: 10px; line-height: 1.8; }
.help-pane strong { color: #ccd2d9; }

.toast-container { position: fixed; right: 14px; bottom: calc(var(--bottom-h) + 15px); z-index: 999; display: grid; gap: 7px; pointer-events: none; }
.toast { background: #272d35; border: 1px solid #3b434e; border-left: 3px solid var(--accent); box-shadow: 0 10px 25px rgba(0,0,0,.35); color: #dfe4e9; border-radius: 6px; padding: 9px 12px; min-width: 220px; max-width: 360px; font-size: 11px; animation: toastIn .18s ease-out; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 980px) {
  :root { --left-w: 205px; --right-w: 285px; }
  .brand { min-width: 155px; }
  .brand small { display: none; }
  .menu-trigger { padding: 0 7px; }
  .btn.ghost { display: none; }
}

/* Texture assets */
.texture-editor { display:grid; gap:7px; padding:8px; background:#181b20; border:1px solid var(--border); border-radius:6px; }
.texture-editor-head { display:flex; align-items:center; justify-content:space-between; color:#aab3be; font-size:10px; }
.texture-editor-head button, .texture-actions button, .assets-toolbar button { border:1px solid var(--border); background:var(--panel-2); color:#cbd2da; border-radius:4px; padding:5px 8px; cursor:pointer; font-size:9px; }
.texture-preview-wrap { height:86px; display:grid; place-items:center; border:1px dashed #3a414b; border-radius:5px; background:#111318; overflow:hidden; }
.texture-preview { width:100%; height:100%; object-fit:contain; image-rendering:auto; }
.texture-preview-empty { color:#68727e; font-size:9px; }
.texture-select, #texWrap { width:100%; min-width:0; color:#e5e9ee; background:var(--field); border:1px solid var(--border); border-radius:4px; padding:5px 6px; font-size:10px; }
.texture-settings-row { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.texture-settings-row label { display:grid; grid-template-columns:1fr !important; gap:4px !important; }
.texture-settings-row input { width:100%; color:#e5e9ee; background:var(--field); border:1px solid var(--border); border-radius:4px; padding:5px; font-size:10px; }
.texture-actions { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
.assets-toolbar { display:flex; align-items:center; gap:10px; height:25px; color:#aeb7c2; font-size:10px; }
.assets-toolbar span { color:#77818e; }
.assets-toolbar button { margin-left:auto; }
.texture-assets-gallery { display:flex; gap:8px; overflow-x:auto; padding-top:6px; height:calc(100% - 30px); }
.texture-card { flex:0 0 104px; height:92px; display:grid; grid-template-rows:65px 1fr; gap:3px; padding:4px; background:#1d2127; border:1px solid var(--border); border-radius:6px; color:#aeb7c2; cursor:pointer; overflow:hidden; }
.texture-card:hover { border-color:#5f55a3; background:#242831; }
.texture-card img { width:100%; height:65px; object-fit:cover; border-radius:3px; background:#101216; }
.texture-card span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:8px; text-align:left; padding:1px 2px; }
.asset-empty { color:#77818e; font-size:10px; padding:12px 0; }

/* MEXT + Breso runtime components */
.component-box { display:grid; gap:6px; padding:7px; border:1px solid var(--border); border-radius:5px; background:#171a1f; }
.component-box label { grid-template-columns:82px 1fr !important; }
.asset-columns { height:100%; display:grid; grid-template-columns:1fr 1fr; gap:16px; min-width:0; }
.asset-column { min-width:0; min-height:0; display:grid; grid-template-rows:28px 1fr; }
.audio-assets-gallery { min-height:0; display:flex; gap:8px; overflow:auto; padding-top:6px; }
.audio-card { flex:0 0 210px; height:86px; display:grid; gap:5px; padding:7px; border:1px solid var(--border); border-radius:6px; background:#1d2127; cursor:pointer; }
.audio-card:hover { border-color:#5f55a3; background:#242831; }
.audio-card strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#b9c1cb; font-size:9px; }
.audio-card audio { width:100%; height:32px; }
.settings-scroll { height:100%; display:flex; gap:18px; align-items:stretch; overflow-x:auto; padding-bottom:3px; }
.settings-group { min-width:220px; display:grid; grid-template-columns:1fr 1fr; gap:7px 10px; align-content:start; padding:7px 10px; border:1px solid var(--border); border-radius:6px; background:#181b20; }
.settings-group strong { grid-column:1/-1; font-size:9px; text-transform:uppercase; letter-spacing:.55px; color:#aab3be; }
.settings-group label { display:flex; align-items:center; justify-content:space-between; gap:7px; color:#9ea7b3; font-size:9px; }
.settings-group input[type="number"] { width:78px; color:#e5e9ee; background:var(--field); border:1px solid var(--border); border-radius:4px; padding:4px 5px; font-size:9px; }
.settings-group input[type="color"] { width:52px; height:25px; background:var(--field); border:1px solid var(--border); border-radius:4px; }
.settings-group input[type="range"] { width:95px; }
.settings-group select { min-width:120px; max-width:180px; color:#e5e9ee; background:var(--field); border:1px solid var(--border); border-radius:4px; padding:4px 5px; font-size:9px; }
.settings-group > .component-box { grid-column:1/-1; }
.settings-group .component-box strong { font-size:9px; color:#b7c0cb; text-transform:none; letter-spacing:0; }
.settings-group .component-box small { color:#7f8995; font-size:8px; line-height:1.35; }

@media (max-width: 1100px) {
  .asset-columns { grid-template-columns:1fr; grid-template-rows:1fr 1fr; }
}


/* v8: particle inspector + runtime global monitor */
.inspector-output { justify-self:end; min-width:86px; text-align:right; color:#d6dce5; font:600 9px ui-monospace,SFMono-Regular,Consolas,monospace; }
.live-values-group { min-width:300px; }
.live-grid { grid-column:1/-1; display:grid; grid-template-columns:88px minmax(150px,1fr); gap:5px 9px; align-items:center; }
.live-grid span { color:#87919d; font-size:8px; text-transform:uppercase; letter-spacing:.35px; }
.live-grid code { color:#d9e1ea; background:#111419; border:1px solid #2d333c; border-radius:4px; padding:4px 6px; font-size:9px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.settings-note { grid-column:1/-1; color:#7f8995; font-size:8px; line-height:1.4; }
.teleport-dev-group { min-width:270px; }
.settings-actions { grid-column:1/-1; display:flex; flex-wrap:wrap; gap:6px; }
.settings-actions button { border:1px solid var(--border); background:var(--panel-2); color:#cbd2da; border-radius:4px; padding:5px 8px; cursor:pointer; font-size:9px; }
.settings-actions button:hover { border-color:#5f55a3; background:#242831; }

/* v9: Integrated Script Engine */
.script-top-menu .menu-trigger { color:#d9d1ff; }
.script-top-menu .menu-trigger:hover { background:#2b273c; color:#fff; }
.script-editor-modal { position:fixed; inset:0; z-index:1200; background:rgba(5,7,10,.78); backdrop-filter:blur(6px); display:grid; place-items:center; padding:24px; }
.script-editor-window { width:min(1180px,96vw); height:min(780px,90vh); min-height:520px; display:grid; grid-template-rows:52px 1fr; overflow:hidden; border:1px solid #3b424e; border-radius:10px; background:#111419; box-shadow:0 28px 80px rgba(0,0,0,.58); }
.script-editor-header { display:flex; align-items:center; justify-content:space-between; gap:14px; padding:0 12px 0 16px; border-bottom:1px solid #303640; background:#181b20; }
.script-editor-header strong { display:block; font-size:13px; color:#eef1f5; }
.script-editor-header small { display:block; margin-top:2px; font-size:9px; color:#7f8995; }
.script-editor-header-actions { display:flex; gap:7px; }
.script-editor-header-actions button,.script-file-actions button { border:1px solid #363d47; background:#232830; color:#cbd2db; border-radius:5px; padding:6px 10px; cursor:pointer; font-size:10px; }
.script-editor-header-actions button:hover,.script-file-actions button:hover { border-color:#6557b4; background:#2b3040; }
.script-editor-header-actions .run { border-color:#32684b; background:#1d4b34; color:#d8f4e4; }
.script-editor-body { min-height:0; display:grid; grid-template-columns:220px minmax(0,1fr); }
.script-files-pane { min-height:0; display:grid; grid-template-rows:36px 1fr auto; border-right:1px solid #303640; background:#171a1f; }
.script-files-title { display:flex; align-items:center; padding:0 11px; border-bottom:1px solid #2d333c; color:#9099a5; font-size:9px; font-weight:700; text-transform:uppercase; letter-spacing:.55px; }
.script-file-list { min-height:0; overflow:auto; padding:6px; }
.script-file { width:100%; display:flex; align-items:center; gap:7px; padding:7px 8px; border:1px solid transparent; border-radius:5px; background:transparent; color:#aeb7c2; cursor:pointer; text-align:left; font-size:10px; }
.script-file:hover { background:#22272e; }
.script-file.active { background:#302b48; border-color:#4d456e; color:#fff; }
.script-file-icon { flex:0 0 auto; display:grid; place-items:center; width:25px; height:18px; border-radius:4px; background:#d5bd42; color:#151515; font-size:8px; font-weight:900; }
.script-file-actions { display:grid; grid-template-columns:1fr 1fr; gap:5px; padding:7px; border-top:1px solid #2d333c; }
.script-file-actions button:first-child { grid-column:1/-1; }
.script-code-pane { min-width:0; min-height:0; display:grid; grid-template-rows:36px 1fr 28px; background:#0f1216; }
.script-code-toolbar { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:0 12px; border-bottom:1px solid #2b3139; background:#15191e; color:#d8dde4; font:600 10px "Cascadia Code",Consolas,monospace; }
.script-code-hint { color:#6f7986; font:400 9px Inter,system-ui,sans-serif; }
.script-code-shell { min-height:0; display:grid; grid-template-columns:52px 1fr; overflow:hidden; background:#101318; }
.script-line-numbers { margin:0; padding:12px 9px 28px 0; overflow:hidden; user-select:none; text-align:right; color:#56606c; background:#0d1014; border-right:1px solid #242a31; font:12px/1.62 "Cascadia Code",Consolas,monospace; white-space:pre; }
.script-code-stage { position:relative; min-width:0; min-height:0; overflow:hidden; }
.script-code-highlight,.script-code-input { position:absolute; inset:0; margin:0; padding:12px 14px 40px; border:0; outline:0; tab-size:2; font:12px/1.62 "Cascadia Code",Consolas,"Liberation Mono",monospace; white-space:pre; overflow:auto; }
.script-code-highlight { pointer-events:none; color:#d4d9df; background:#101318; }
.script-code-input { z-index:2; resize:none; color:transparent; caret-color:#f3f5f7; background:transparent; -webkit-text-fill-color:transparent; }
.script-code-input::selection { background:rgba(123,97,255,.42); }
.script-code-input::-webkit-scrollbar { width:11px; height:11px; }
.script-code-input::-webkit-scrollbar-thumb { background:#343b45; border-radius:8px; border:3px solid #101318; }
.script-code-highlight { scrollbar-width:none; }
.script-code-highlight::-webkit-scrollbar { display:none; }
.script-editor-statusbar { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:0 10px; border-top:1px solid #2b3139; background:#171a1f; color:#75808d; font-size:8px; overflow:hidden; }
.script-editor-statusbar span { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.script-editor-statusbar code { color:#a99bff; }
.script-editor-statusbar strong { color:#aeb7c2; font-weight:600; }
.script-editor-statusbar strong[data-type="success"] { color:#62d296; }
.script-editor-statusbar strong[data-type="error"] { color:#ef808c; }
.script-editor-statusbar strong[data-type="warn"] { color:#e6c073; }
.tok-comment { color:#68747f; font-style:italic; }
.tok-string { color:#d8b46a; }
.tok-number { color:#86c7d7; }
.tok-keyword { color:#b78cff; font-weight:600; }
.tok-literal { color:#72b9e7; }
.tok-type { color:#7ed2b2; }
@media (max-width:760px){.script-editor-body{grid-template-columns:155px 1fr}.script-code-hint{display:none}.script-editor-modal{padding:8px}.script-editor-window{width:99vw;height:94vh}}
