:root {
    --bg: #1d1f22;
    --panel: #2a2d31;
    --panel2: #33373c;
    --edge: #44494f;
    --hi: #5a6068;
    --text: #e4e6e8;
    --dim: #a3a8ae;
    --accent: #e8a33a;
    --accent2: #4fa3d1;
    --sel: #ff5a4a;
    --radius: 6px;
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 -apple-system, "Segoe UI", system-ui, sans-serif; }
button, select, input { font: inherit; color: inherit; }
button {
    background: linear-gradient(#3b4046, #30343a); border: 1px solid var(--edge); border-radius: var(--radius);
    padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--hi); background: linear-gradient(#454b52, #383d43); }
button.active { border-color: var(--accent); color: #fff; box-shadow: inset 0 0 0 1px rgba(232, 163, 58, .35); }
button.ghost { background: transparent; }
select, input[type=number], input[type=text] {
    background: #24272b; border: 1px solid var(--edge); border-radius: 4px; padding: 3px 5px;
}
input[type=number] { width: 70px; }
input[type=color] { width: 34px; height: 22px; padding: 0; border: 1px solid var(--edge); border-radius: 4px; background: none; }
input[type=range] { accent-color: var(--accent); }
#app { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; min-width: 900px; }

#topbar { display: flex; align-items: center; gap: 14px; padding: 6px 12px; background: #17191b; border-bottom: 1px solid #000; }
.brand { font-weight: 700; letter-spacing: .5px; font-size: 15px; }
.brand span { font-weight: 400; color: var(--accent); font-style: italic; }
#menus { display: flex; gap: 2px; }
#menus .menu { position: relative; }
#menus .menu > button { background: none; border: none; padding: 4px 8px; }
#menus .menu > button:hover, #menus .menu.open > button { background: var(--panel2); }
#menus .menu .items { display: none; position: absolute; top: 100%; left: 0; z-index: 50; min-width: 220px; background: var(--panel); border: 1px solid var(--edge); border-radius: var(--radius); padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#menus .menu.open .items { display: block; }
#menus .items button { display: flex; width: 100%; justify-content: space-between; background: none; border: none; text-align: left; padding: 5px 8px; }
#menus .items button:hover { background: var(--panel2); }
#menus .items .kbd { color: var(--dim); }
#menus .items hr { border: none; border-top: 1px solid var(--edge); margin: 4px 0; }
#tabs { display: flex; gap: 4px; margin-left: auto; }
#tabs button { padding: 4px 16px; font-weight: 600; }

#palette { background: var(--panel); border-bottom: 1px solid #000; min-height: 86px; }
.pane { display: none; padding: 8px 12px; gap: 6px; align-items: flex-start; flex-wrap: wrap; }
.pane.active { display: flex; }
.group { display: flex; flex-direction: column; gap: 4px; padding-right: 10px; margin-right: 4px; border-right: 1px solid var(--edge); }
.group:last-child { border-right: none; }
.group > .gtitle { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.group > .items { display: flex; gap: 4px; flex-wrap: wrap; }
.tool { width: 52px; height: 52px; padding: 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10px; color: var(--dim); }
.tool svg { width: 30px; height: 30px; }
.tool:hover { color: var(--text); }
.scrub { min-width: 92px; padding: 4px 8px; text-align: left; position: relative; cursor: ew-resize; user-select: none; }
.scrub .lbl { color: var(--dim); font-size: 11px; display: block; }
.scrub .val { font-weight: 600; }
.scrub .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); border-radius: 0 0 0 var(--radius); }
.swatchRow { display: flex; gap: 6px; align-items: center; }
.swatchRow label { display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--dim); gap: 2px; }
.sunball { width: 70px; height: 70px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #8ab6e8, #2b4f80 70%, #142540); position: relative; cursor: crosshair; border: 1px solid var(--edge); }
.sunball .dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #ffd760; box-shadow: 0 0 8px #ffcc33; }
.sunball .dot.below { background: #c9d4e6; box-shadow: none; opacity: .7; }

main { display: grid; grid-template-columns: 220px 1fr 260px; min-height: 0; }
#control { background: var(--panel); border-right: 1px solid #000; padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.nano { display: flex; flex-direction: column; gap: 4px; }
#nano { width: 200px; height: 150px; border-radius: 4px; border: 1px solid #000; background: #000; cursor: pointer; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--dim); }
.row.tight { justify-content: flex-start; }
.camtools { display: flex; gap: 10px; align-items: center; }
.trackball { width: 96px; height: 96px; border-radius: 50%; background: radial-gradient(circle at 38% 32%, #f0a070, #c4552c 55%, #6e2b13); box-shadow: inset -6px -8px 14px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.6); cursor: grab; position: relative; }
.trackball::after { content: "⤧"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; color: rgba(40,20,10,.55); }
.cross { display: flex; gap: 6px; }
.crossPad { width: 44px; height: 44px; border-radius: 8px; background: #3a3f45; border: 1px solid var(--edge); display: grid; place-items: center; color: var(--dim); cursor: move; user-select: none; font-size: 11px; }
.crossPad.tall { width: 28px; height: 70px; cursor: ns-resize; }
.renderbox { display: flex; flex-direction: column; gap: 6px; }
button.render { font-size: 16px; font-weight: 700; padding: 10px; background: radial-gradient(circle at 35% 30%, #fafafa, #b9bec4 45%, #6d7379); color: #1b1d20; border: 1px solid #000; border-radius: 30px; box-shadow: 0 2px 6px rgba(0,0,0,.6); }
button.render:hover { filter: brightness(1.08); }
#progress { height: 4px; background: #222; border-radius: 2px; overflow: hidden; }
#progress div { height: 100%; width: 0; background: var(--accent2); transition: width .1s; }
.textDisplay { margin-top: auto; background: #15171a; border: 1px solid #000; border-radius: 4px; padding: 8px; min-height: 96px; color: #cfd8df; font-size: 12px; white-space: pre-wrap; }
.textDisplay b { color: #fff; }

#work { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #101113; }
#docWrap { flex: 1; display: grid; place-items: center; overflow: auto; padding: 12px; min-height: 0; }
#doc { position: relative; box-shadow: 0 0 0 1px #000, 0 8px 30px rgba(0,0,0,.6); background: #c9c6be; }
#doc canvas { position: absolute; left: 0; top: 0; }
#renderCanvas { image-rendering: auto; }
#wireCanvas { cursor: default; }
#objIcons { position: absolute; display: none; flex-direction: column; gap: 3px; }
#objIcons button { width: 22px; height: 20px; padding: 0; font-size: 11px; font-weight: 700; border-radius: 3px; background: #f2f0ea; color: #222; border: 1px solid #555; }
#objIcons button:hover { background: #fff; }
#displayModes { display: flex; gap: 4px; padding: 6px 10px; background: var(--panel); border-top: 1px solid #000; }
#displayModes .sep { flex: 1; }

#inspector { background: var(--panel); border-left: 1px solid #000; padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
#inspector h3 { margin: 0; font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .6px; }
.objlist { display: flex; flex-direction: column; gap: 1px; max-height: 210px; overflow-y: auto; background: #1f2225; border: 1px solid #000; border-radius: 4px; }
.objlist div { padding: 3px 8px; cursor: pointer; display: flex; justify-content: space-between; }
.objlist div:hover { background: var(--panel2); }
.objlist div.sel { background: #5a2a24; color: #fff; }
.objlist .k { color: var(--dim); font-size: 11px; }
.fields { display: grid; grid-template-columns: 62px 1fr 1fr 1fr; gap: 3px 4px; align-items: center; }
.fields span { color: var(--dim); font-size: 11px; }
.fields input { width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; gap: 4px; }
.presetGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.presetGrid button { padding: 3px; font-size: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.presetGrid canvas, .presetGrid img { width: 64px; height: 48px; border-radius: 3px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--hi); border-radius: 10px; padding: 0; max-width: 96vw; max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg { display: flex; flex-direction: column; max-height: 92vh; }
.dlg header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--edge); }
.dlg header h2 { margin: 0; font-size: 15px; }
.dlg header .hint { color: var(--dim); font-size: 12px; }
.dlg .body { padding: 12px 14px; overflow: auto; display: flex; gap: 14px; }
.dlg footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--edge); }
.dlg footer .left { margin-right: auto; display: flex; gap: 6px; }
.mlab { border-collapse: collapse; font-size: 12px; }
.mlab th { color: var(--dim); font-weight: 500; text-align: left; padding: 2px 6px; }
.mlab td { padding: 3px 6px; border-top: 1px solid #383c41; }
.mlab td.ch { color: var(--dim); white-space: nowrap; }
.mlab .drv { display: flex; gap: 2px; }
.mlab .drv button { width: 22px; height: 20px; padding: 0; font-size: 11px; }
.mlab input[type=range] { width: 130px; }
.texcard { border: 1px solid var(--edge); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: #2e3236; }
.texcard h4 { margin: 0; display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.comp { display: grid; grid-template-columns: 74px 1fr; gap: 3px 6px; font-size: 12px; align-items: center; padding: 6px; border-radius: 4px; background: #26292d; }
.comp span { color: var(--dim); }
.gradient { height: 18px; border-radius: 3px; border: 1px solid #000; position: relative; cursor: copy; }
.stops { position: relative; height: 18px; }
.stops input[type=color] { position: absolute; width: 18px; height: 18px; transform: translateX(-9px); }
canvas.preview { border-radius: 6px; border: 1px solid #000; background: #000; }
.terrainBtns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.terrainBtns button { font-size: 12px; padding: 5px 4px; }
#guide { position: fixed; inset: 40px 10% ; z-index: 80; background: var(--panel); border: 1px solid var(--hi); border-radius: 10px; overflow: auto; padding: 18px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
#guide h2 { margin-top: 0; }
#guide h3 { color: var(--accent); margin-bottom: 4px; }
#guide dl { display: grid; grid-template-columns: 180px 1fr; gap: 4px 12px; margin: 0; }
#guide dt { font-weight: 600; }
#guide dd { margin: 0; color: #cfd3d7; }
#guide .close { position: sticky; top: 0; float: right; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111; border: 1px solid var(--hi); padding: 8px 14px; border-radius: 8px; z-index: 90; }
