:root {
  --bg: #171b21; --panel: #1f242c; --panel2: #262c36; --line: #333b47; --text: #d9dee6; --dim: #8b95a5;
  --accent: #4da3ff; --accent2: #2f7cf6; --ok: #57d68d; --err: #ff7b72; --canvas: #212830;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font: 12px/1.35 "Segoe UI", system-ui, -apple-system, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
button:disabled { opacity: 0.35; cursor: default; }
[hidden] { display: none !important; }
#app { display: grid; grid-template-rows: auto auto 1fr auto auto auto; height: 100%; }

#titlebar { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 8px; background: #12161b; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; letter-spacing: 0.2px; color: #fff; margin-right: 6px; }
.brand svg { color: var(--accent); }
.menuwrap { position: relative; }
.menubtn { padding: 5px 10px; border-radius: 4px; }
.menubtn:hover, .qbtn:hover:not(:disabled) { background: var(--panel2); }
.menu { position: absolute; top: 30px; left: 0; z-index: 30; min-width: 290px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.5); }
.menu button { display: flex; justify-content: space-between; gap: 24px; width: 100%; padding: 6px 10px; border-radius: 4px; text-align: left; }
.menu button:hover { background: var(--accent2); color: #fff; }
.menu kbd { font: inherit; color: var(--dim); } .menu button:hover kbd { color: #dbe9ff; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#quick { display: flex; gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); }
.qbtn { display: grid; place-items: center; width: 28px; height: 26px; border-radius: 4px; color: var(--text); }
.edition { padding: 3px 10px; border-radius: 999px; font-size: 11px; letter-spacing: 0.3px; color: var(--dim); border: 1px solid var(--line); white-space: nowrap; }
.edition:hover { color: #fff; border-color: #5a6474; }
.edition.licensed { color: #9fdcb8; border-color: #2f5a44; }
.edition.ended { color: #fff; background: #b8431f; border-color: #b8431f; }
#docname { flex: 1; text-align: center; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#ribbon { display: flex; gap: 0; padding: 4px 4px 2px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.group { display: flex; flex-direction: column; padding: 0 8px; border-right: 1px solid var(--line); }
.group:last-child { border-right: 0; }
.tools { display: grid; grid-auto-flow: column; gap: 0 2px; align-content: start; flex: 1; }
.tool { display: flex; align-items: center; gap: 5px; padding: 2px 7px 2px 5px; border-radius: 4px; white-space: nowrap; color: var(--text); }
.tool:hover { background: var(--panel2); color: #fff; } .tool:active { background: var(--accent2); }
.tool svg { flex: none; color: #9fc6f5; }
.gtitle { margin-top: 2px; text-align: center; font-size: 10.5px; color: var(--dim); letter-spacing: 0.4px; }

#main { display: grid; grid-template-columns: 1fr 284px; min-height: 0; }
#canvasWrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--canvas); }
#cv { position: absolute; inset: 0; display: block; cursor: none; }
#cv3d { position: absolute; inset: 0; display: block; cursor: grab; }
#bar3d { position: absolute; top: 10px; left: 10px; display: flex; gap: 4px; align-items: center; padding: 4px; background: rgba(18, 22, 27, 0.9); border: 1px solid var(--line); border-radius: 6px; }
#bar3d button { padding: 4px 10px; border-radius: 4px; color: var(--text); }
#bar3d button:hover { background: var(--panel2); color: #fff; }
#bar3d button.primary { background: var(--accent2); color: #fff; }
#bar3d span { padding: 0 8px; color: var(--dim); }
#side { display: grid; grid-template-rows: minmax(120px, 1.25fr) minmax(110px, 1fr); min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
#side section { display: flex; flex-direction: column; min-height: 0; border-bottom: 1px solid var(--line); }
#side h3 { display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 5px 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--dim); background: #1a1f26; border-bottom: 1px solid var(--line); }
#props, #layers { overflow-y: auto; padding: 4px 6px 8px; scrollbar-width: thin; }
.phead { padding: 4px 2px 2px; font-weight: 600; color: #fff; }
.psub { margin: 6px 0 3px; padding: 2px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim); border-bottom: 1px solid var(--line); }
.prow { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 6px; padding: 1.5px 2px; }
.plabel { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow input[type=text], .prow select, .layer select, .dlg input:not([type=checkbox]):not([type=color]), .dlg select, .dlg textarea {
  width: 100%; min-width: 0; padding: 3px 5px; background: #14181d; border: 1px solid var(--line); border-radius: 3px; outline: none;
}
.prow input:focus, .prow select:focus, .layer select:focus, .dlg input:focus, .dlg select:focus, .dlg textarea:focus { border-color: var(--accent); }
.prow input.ro { background: transparent; border-color: transparent; color: var(--dim); }
.colorfield { display: flex; align-items: center; gap: 5px; min-width: 0; }
.swatch { flex: none; width: 13px; height: 13px; border: 1px solid #5a6474; border-radius: 2px; }
.hidden-color { position: absolute; width: 0; height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }

.layer { display: grid; grid-template-columns: 20px 20px 18px minmax(40px, 1fr) 58px 70px 18px; align-items: center; gap: 3px; padding: 2px 2px; border-radius: 3px; }
.layer:hover { background: var(--panel2); }
.layer.cur { background: #1d3552; }
.layer.cur .lname { color: #fff; font-weight: 600; }
.lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; padding: 2px; }
.layer input[type=color] { width: 16px; height: 16px; padding: 0; border: 1px solid #5a6474; border-radius: 2px; background: none; cursor: pointer; }
.layer input[type=color]::-webkit-color-swatch-wrapper { padding: 0; } .layer input[type=color]::-webkit-color-swatch { border: 0; }
.layer select { padding: 2px 1px; font-size: 11px; }
.ib { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 3px; color: var(--dim); }
.ib:hover { color: #fff; background: var(--line); }
.layer .del { visibility: hidden; } .layer:hover .del { visibility: visible; }

#tabs { display: flex; align-items: stretch; gap: 1px; height: 24px; padding: 0 6px; background: #1a1f26; border-top: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 0 14px; color: var(--dim); white-space: nowrap; border-bottom: 2px solid transparent; }
.tab:hover { color: #fff; background: var(--panel2); }
.tab.on { color: #fff; background: var(--panel2); border-bottom-color: var(--accent); }
.tab.add { padding: 0 9px; font-size: 15px; line-height: 1; }
.tab.view3d { margin-left: auto; }
#cmd { background: #12161b; border-top: 1px solid var(--line); font-family: Consolas, "Cascadia Mono", "SF Mono", monospace; font-size: 12px; }
#history { height: 58px; overflow-y: auto; padding: 3px 10px 0; color: #b9c2cf; scrollbar-width: thin; user-select: text; }
#history .cmd { color: #fff; } #history .dim { color: var(--dim); } #history .err { color: var(--err); } #history .ok { color: var(--ok); }
#cmdline { display: flex; align-items: center; gap: 8px; padding: 4px 10px 5px; border-top: 1px solid #1c222a; }
#prompt { color: #fff; white-space: nowrap; max-width: 75%; overflow: hidden; text-overflow: ellipsis; }
#prompt.idle { color: var(--dim); } #prompt.idle::before { content: "\25B8  "; color: var(--accent); }
.kw { color: var(--accent); cursor: pointer; } .kw:hover { text-decoration: underline; }
#cmdInput { flex: 1; min-width: 60px; padding: 2px 0; background: none; border: 0; outline: none; color: #fff; font: inherit; }
#cmdInput::placeholder { color: #4d5766; }

#status { display: flex; align-items: center; gap: 10px; height: 24px; padding: 0 8px; background: var(--panel); border-top: 1px solid var(--line); color: var(--dim); }
#coords { min-width: 150px; font-family: Consolas, monospace; color: var(--text); }
#toggles { display: flex; gap: 2px; }
.tg { padding: 2px 8px; border-radius: 3px; font-size: 11px; letter-spacing: 0.4px; color: var(--dim); }
.tg:hover { background: var(--panel2); } .tg.on { color: #fff; background: #1d4a82; }
.spacer { flex: 1; }

#modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(5, 8, 12, 0.55); }
.dlg { width: min(400px, 92vw); max-height: 88vh; overflow-y: auto; padding: 16px 18px 14px; background: var(--panel); border: 1px solid #414b5a; border-radius: 8px; box-shadow: 0 24px 64px rgba(0,0,0,.6); font-size: 13px; }
.dlg.wide { width: min(720px, 94vw); }
.dlg h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: #fff; }
.dlg label { display: grid; gap: 4px; margin-bottom: 9px; color: var(--dim); }
.dlg label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; color: var(--text); }
.dlg input:not([type=checkbox]):not([type=color]), .dlg select, .dlg textarea { padding: 6px 8px; color: var(--text); }
.dlg input[type=color] { width: 48px; height: 28px; padding: 0; background: none; border: 1px solid var(--line); }
.dlg textarea { resize: vertical; font-family: inherit; }
.dlg p { margin: 0 0 10px; line-height: 1.5; }
.dlg code { padding: 1px 4px; background: #14181d; border-radius: 3px; font-family: Consolas, monospace; }
.licence-box .lic-edition { font-size: 16px; font-weight: 600; color: #fff; margin-bottom: 4px; }
.licence-box .lic-detail { color: #f0b98a; }
.licence-box a { color: var(--accent); }
.dlg-err { min-height: 0; color: var(--err); }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dlg-btns button { padding: 6px 16px; border-radius: 4px; background: var(--panel2); border: 1px solid var(--line); }
.dlg-btns button:hover { border-color: #5a6474; }
.dlg-btns .primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.dlg-btns .primary:hover { background: #3f8cff; }
.help-table { max-height: 42vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }
.help table { width: 100%; border-collapse: collapse; font-size: 12px; }
.help th, .help td { padding: 3px 8px; text-align: left; border-bottom: 1px solid #2a313b; }
.help th { position: sticky; top: 0; background: #1a1f26; color: var(--dim); font-weight: 600; }
.help td:first-child { font-family: Consolas, monospace; color: #fff; } .help td:nth-child(2) { font-family: Consolas, monospace; color: var(--accent); }
::-webkit-scrollbar { width: 9px; height: 9px; } ::-webkit-scrollbar-thumb { background: #3a4350; border-radius: 5px; } ::-webkit-scrollbar-track { background: transparent; }
