:root {
  --bg: #0f1116;
  --panel: #161920;
  --panel-2: #1b1f28;
  --panel-3: #222733;
  --line: #2a303d;
  --line-2: #353c4c;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --faint: #5d6579;
  --accent: #3b9dff;
  --accent-2: #2a6fdb;
  --accent-soft: rgba(59, 157, 255, 0.14);
  --warn: #ffb547;
  --danger: #ff5d6c;
  --ok: #3ddc97;
  --world: #ff8a3b;
  --radius: 8px;
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; flex: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

#app {
  display: grid;
  height: 100vh;
  grid-template-columns: 300px 1fr 330px;
  grid-template-rows: 46px 1fr 26px;
  grid-template-areas: "top top top" "left vp right" "status status status";
}

/* ------------------------------------------------------------------ top bar */
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; color: var(--muted); }
.brand img { width: 24px; height: 24px; }
.brand b { color: var(--text); font-weight: 600; }
.menus { display: flex; gap: 2px; }
.menus > .menu { position: relative; }
.menus > .menu > button { background: none; border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.menus > .menu > button:hover, .menus > .menu.open > button { background: var(--panel-3); color: var(--text); }
.dropdown { position: absolute; top: calc(100% + 4px); left: 0; min-width: 240px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 5px; box-shadow: 0 12px 32px rgba(0,0,0,.45); z-index: 50; display: none; }
.menu.open .dropdown { display: block; }
.dropdown button, .ctxmenu button { display: flex; width: 100%; align-items: center; gap: 10px; background: none; border: 0; padding: 7px 10px; border-radius: 5px; cursor: pointer; text-align: left; }
.dropdown button:hover, .ctxmenu button:hover { background: var(--accent-soft); }
.dropdown button:disabled { opacity: .4; cursor: default; background: none; }
.dropdown .kbd, .ctxmenu .kbd { margin-left: auto; color: var(--faint); font-size: 11px; }
.dropdown hr, .ctxmenu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }
.dropdown .check::before { content: ''; width: 14px; display: inline-block; }
.dropdown .check.on::before { content: '✓'; color: var(--accent); }

.toolgroup { display: flex; align-items: center; gap: 3px; padding-left: 8px; border-left: 1px solid var(--line); }
.tool { width: 32px; height: 30px; display: grid; place-items: center; border: 1px solid transparent; background: none; border-radius: 6px; color: var(--muted); cursor: pointer; }
.tool:hover { background: var(--panel-3); color: var(--text); }
.tool.on { background: var(--accent-soft); color: var(--accent); border-color: rgba(59,157,255,.35); }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 5px; }
.snapval { display: flex; align-items: center; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px 0 2px; height: 28px; color: var(--faint); }
.snapval input { width: 46px; background: none; border: 0; outline: none; text-align: right; }
.spacer { flex: 1; }
.mapname { background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; width: 220px; text-align: right; font-weight: 600; }
.mapname:hover, .mapname:focus { border-color: var(--line-2); background: var(--panel-2); outline: none; text-align: left; }
.savestate { color: var(--faint); font-size: 12px; white-space: nowrap; min-width: 60px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 7px; border: 1px solid var(--line-2); background: var(--panel-3); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent-2); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.iconbtn { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 5px; cursor: pointer; }
.iconbtn:hover { background: var(--panel-3); color: var(--text); }
.iconbtn.on { color: var(--accent); }

/* ------------------------------------------------------------------ panels */
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.panel.left { grid-area: left; border-right: 1px solid var(--line); }
.panel.right { grid-area: right; border-left: 1px solid var(--line); overflow-y: auto; }
.tabs { display: flex; padding: 6px 6px 0; gap: 2px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 4px 9px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tabpane.on { display: flex; }

.searchbar { display: flex; align-items: center; gap: 6px; margin: 10px; padding: 0 9px; height: 32px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; color: var(--faint); }
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input { flex: 1; min-width: 0; background: none; border: 0; outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 10px 8px; }
.chip { border: 1px solid var(--line-2); background: none; border-radius: 99px; padding: 3px 10px; font-size: 12px; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--accent-soft); border-color: rgba(59,157,255,.5); color: var(--accent); }
.listinfo { padding: 0 12px 6px; color: var(--faint); font-size: 11px; }

.grid { flex: 1; overflow-y: auto; padding: 0 8px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; align-content: start; }
.card { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; cursor: pointer; overflow: hidden; user-select: none; }
.card:hover { border-color: var(--accent); }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card .thumb { aspect-ratio: 1; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #2a3140, #171a21); }
.card .thumb img, .card .thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .thumb .ph { color: var(--faint); font: 11px var(--mono); }
.card .meta { padding: 4px 6px 5px; }
.card .id { font: 600 11px var(--mono); color: var(--accent); }
.card .nm { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .fav { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border: 0; background: rgba(0,0,0,.35); border-radius: 5px; color: #ffd23b; display: none; place-items: center; cursor: pointer; }
.card:hover .fav, .card .fav.on { display: grid; }

/* ------------------------------------------------------------------ outliner */
.outline { flex: 1; overflow-y: auto; padding: 4px 0 12px; }
.outline .row { display: flex; align-items: center; gap: 5px; height: 26px; padding-right: 6px; cursor: pointer; white-space: nowrap; user-select: none; }
.outline .row:hover { background: var(--panel-2); }
.outline .row.on { background: var(--accent-soft); }
.outline .row.drop { box-shadow: 0 -2px 0 var(--accent) inset; }
.outline .row .tw { width: 16px; display: grid; place-items: center; color: var(--faint); }
.outline .row .tw svg { width: 12px; height: 12px; transition: transform .12s; }
.outline .row .tw.open svg { transform: rotate(90deg); }
.outline .row .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.outline .row .lbl small { color: var(--faint); margin-left: 6px; font-family: var(--mono); font-size: 11px; }
.outline .row .acts { display: none; gap: 1px; }
.outline .row:hover .acts, .outline .row .acts .on { display: flex; }
.outline .row.dim .lbl { opacity: .45; }
.outline .section { padding: 10px 12px 4px; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; }
.outline .section span { flex: 1; }
.outline-tools { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------------ inspector */
.insp-empty { padding: 28px 22px; color: var(--muted); text-align: center; }
.insp-empty h3 { color: var(--text); margin: 10px 0 6px; font-size: 14px; }
.insp-empty .keys { margin-top: 18px; text-align: left; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12px; }
kbd { font: 11px var(--mono); background: var(--panel-3); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--text); white-space: nowrap; }
.sec { border-bottom: 1px solid var(--line); padding: 12px 14px; }
.sec h4 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); display: flex; align-items: center; gap: 6px; }
.sec h4 .grow { flex: 1; }
.title-row { display: flex; align-items: center; gap: 10px; }
.title-row .big { font-size: 15px; font-weight: 600; }
.title-row .sub { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.title-row .thumbsm { width: 54px; height: 54px; border-radius: 7px; background: radial-gradient(circle at 50% 40%, #2a3140, #171a21); flex: none; overflow: hidden; }
.title-row .thumbsm img { width: 100%; height: 100%; object-fit: contain; }
.fields { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.fields.two { grid-template-columns: 1fr 1fr; }
.fields.one { grid-template-columns: 1fr; }
.field { display: flex; align-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; height: 30px; min-width: 0; }
.field:focus-within { border-color: var(--accent); }
.field > span { padding: 0 6px 0 8px; color: var(--faint); font-size: 11px; font-weight: 600; cursor: ew-resize; user-select: none; }
.field > span.x { color: #ff6b6b; } .field > span.y { color: #6bdc7b; } .field > span.z { color: #5fa8ff; }
.field input, .field select { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 0 8px 0 0; font-family: var(--mono); font-size: 12px; height: 100%; }
.field select { font-family: var(--font); padding-left: 6px; }
.field input[type=color] { padding: 3px; height: 28px; }
.lblrow { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; margin: 10px 0 5px; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.note.warn { color: var(--warn); }

.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: grid; grid-template-columns: 22px 40px 1fr auto; align-items: center; gap: 8px; padding: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; cursor: pointer; }
.slot:hover { border-color: var(--line-2); }
.slot.on { border-color: var(--accent); }
.slot .ix { font: 600 12px var(--mono); color: var(--accent); text-align: center; }
.slot .sw { width: 40px; height: 40px; border-radius: 5px; background: #0b0d11 center/cover; image-rendering: auto; border: 1px solid var(--line); }
.slot .desc { min-width: 0; }
.slot .desc div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .desc .t1 { font-size: 12px; }
.slot .desc .t2 { font-size: 11px; color: var(--faint); font-family: var(--mono); }
.slot .desc .t2.ov { color: var(--ok); }
.slot .acts { display: flex; gap: 2px; }

/* ------------------------------------------------------------------ viewport */
.viewport { grid-area: vp; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #000; }
.viewport canvas { width: 100%; height: 100%; display: block; outline: none; }
.vp-hud { position: absolute; top: 10px; left: 10px; font: 11px var(--mono); color: rgba(255,255,255,.85); text-shadow: 0 1px 2px #000; pointer-events: none; white-space: pre; }
.vp-hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: rgba(15,17,22,.88); border: 1px solid var(--line-2); padding: 7px 14px; border-radius: 99px; color: var(--text); pointer-events: none; opacity: 0; transition: opacity .15s; white-space: nowrap; }
.vp-hint.on { opacity: 1; }
.marquee { position: absolute; border: 1px solid var(--accent); background: rgba(59,157,255,.12); pointer-events: none; display: none; }
.loading-pill { position: absolute; top: 10px; right: 10px; background: rgba(15,17,22,.85); border: 1px solid var(--line-2); border-radius: 99px; padding: 4px 12px; font-size: 12px; color: var(--muted); display: none; }
.loading-pill.on { display: block; }

/* ------------------------------------------------------------------ status */
.statusbar { grid-area: status; display: flex; align-items: center; gap: 18px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font: 11px var(--mono); white-space: nowrap; overflow: hidden; }
.statusbar .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; font-family: var(--font); }

/* ------------------------------------------------------------------ setup */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: radial-gradient(1200px 700px at 30% 20%, #1b2a44 0%, #0f1116 60%); overflow-y: auto; padding: 24px 16px; }
.setup { width: min(640px, 100%); }
.setup .logo { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.setup .logo img { width: 52px; height: 52px; }
.setup h1 { font-size: 26px; margin: 0; letter-spacing: -.01em; }
.setup h1 small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.setup .card2 { background: rgba(22,25,32,.92); border: 1px solid var(--line-2); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.setup .card2 + .card2 { margin-top: 14px; }
.setup h2 { font-size: 15px; margin: 0 0 6px; }
.setup p { color: var(--muted); margin: 0 0 14px; }
.setup .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setup .progress { height: 6px; background: var(--panel-3); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.setup .progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .2s; }
.setup .status { font-size: 12px; color: var(--muted); min-height: 18px; }
.setup .error { color: var(--danger); margin-top: 10px; }
.setup ul { margin: 0; padding-left: 18px; color: var(--muted); }
.setup li { margin: 3px 0; }
.setup .fine { font-size: 12px; color: var(--faint); margin-top: 12px; }

/* ------------------------------------------------------------------ modals */
.modal-root { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.modal-back { position: absolute; inset: 0; background: rgba(5,7,10,.6); display: grid; place-items: center; pointer-events: auto; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.modal.wide { width: min(1080px, 100%); height: min(760px, calc(100vh - 32px)); }
.modal.mid { width: min(760px, 100%); }
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 15px; flex: 1; }
.modal .body { padding: 16px; overflow-y: auto; flex: 1; min-height: 0; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal footer .left { margin-right: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; }
.modal textarea { width: 100%; min-height: 260px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: 12px/1.5 var(--mono); resize: vertical; outline: none; }
.modal textarea:focus { border-color: var(--accent); }
.form { display: grid; grid-template-columns: 140px 1fr; gap: 10px 14px; align-items: center; }
.form label { color: var(--muted); }
.form .field { height: 32px; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel-3); color: var(--text); }

/* texture browser */
.texbrowser { display: grid; grid-template-columns: 240px 1fr 260px; height: 100%; min-height: 0; }
.texbrowser .col { min-height: 0; display: flex; flex-direction: column; }
.texbrowser .col + .col { border-left: 1px solid var(--line); }
.txdlist { flex: 1; overflow-y: auto; padding: 0 6px 10px; }
.txdlist button { display: flex; width: 100%; justify-content: space-between; gap: 8px; border: 0; background: none; padding: 5px 8px; border-radius: 5px; cursor: pointer; color: var(--muted); font: 12px var(--mono); text-align: left; }
.txdlist button:hover { background: var(--panel-2); color: var(--text); }
.txdlist button.on { background: var(--accent-soft); color: var(--accent); }
.txdlist button small { color: var(--faint); }
.texgrid { flex: 1; overflow-y: auto; padding: 0 10px 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; align-content: start; }
.tex { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; cursor: pointer; }
.tex:hover { border-color: var(--line-2); }
.tex.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tex .im { aspect-ratio: 1; background: repeating-conic-gradient(#20242c 0 25%, #191c22 0 50%) 0 0/16px 16px; display: grid; place-items: center; }
.tex .im canvas { width: 100%; height: 100%; image-rendering: auto; }
.tex .nm { font: 11px var(--mono); padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.texside { padding: 14px; overflow-y: auto; }
.texside .big { aspect-ratio: 1; border-radius: 8px; background: repeating-conic-gradient(#20242c 0 25%, #191c22 0 50%) 0 0/16px 16px; overflow: hidden; margin-bottom: 12px; }
.texside .big canvas { width: 100%; height: 100%; }
.texside code { display: block; font: 11px var(--mono); color: var(--muted); background: var(--bg); padding: 8px; border-radius: 6px; margin-top: 10px; word-break: break-all; white-space: pre-wrap; }
.scanbar { padding: 8px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.scanbar .progress { flex: 1; height: 4px; background: var(--panel-3); border-radius: 99px; overflow: hidden; }
.scanbar .progress > div { height: 100%; background: var(--accent); width: 0; }

.textpreview { background: repeating-conic-gradient(#20242c 0 25%, #191c22 0 50%) 0 0/16px 16px; border-radius: 8px; display: grid; place-items: center; padding: 10px; margin-bottom: 14px; }
.textpreview canvas { max-width: 100%; border: 1px dashed var(--line-2); }

/* color picker */
.colorrow { display: flex; gap: 8px; align-items: center; }
.colorrow .swatch { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--line-2); background: repeating-conic-gradient(#555 0 25%, #333 0 50%) 0 0/10px 10px; position: relative; overflow: hidden; flex: none; }
.colorrow .swatch > i { position: absolute; inset: 0; }
.colorrow input[type=color] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.colorrow input[type=range] { flex: 1; }
.colorrow .hex { width: 110px; }

/* toasts & context menu */
.toasts { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); padding: 8px 14px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: pop .15s ease-out; max-width: 520px; }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.ctxmenu { position: fixed; z-index: 250; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 5px; min-width: 200px; box-shadow: 0 12px 32px rgba(0,0,0,.45); }

.tablelist { width: 100%; border-collapse: collapse; font-size: 12px; }
.tablelist th { text-align: left; color: var(--faint); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.tablelist td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.tablelist tr:hover td { background: var(--panel-2); }
.tablelist .mono { font-family: var(--mono); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; background: var(--panel-3); color: var(--muted); }
.pill.ok { background: rgba(61,220,151,.14); color: var(--ok); }
.pill.warn { background: rgba(255,181,71,.14); color: var(--warn); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3140; border-radius: 99px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 250px 1fr 290px; }
  .snapval, .brand span { display: none; }
}
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 46px 1fr 40vh 26px; grid-template-areas: "top" "vp" "right" "status"; }
  .panel.left { display: none; }
  .toolgroup, .mapname { display: none; }
}
