:root {
	--bg: #15181c;
	--panel: #1d2127;
	--panel2: #242931;
	--line: #323843;
	--text: #d9dee5;
	--dim: #8a94a3;
	--accent: #ffb347;
	--accent2: #6cb6ff;
	--warn: #ffcc66;
	--err: #ff7a7a;
	--ok: #7ad491;
	--font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Consolas, monospace;
	color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); display: flex; flex-direction: column; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 3px 9px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
button.danger:hover { border-color: var(--err); color: var(--err); }
button.primary { border-color: var(--accent); color: var(--accent); }
select, input[type=text], input[type=number], input[type=search], input:not([type]) { background: #11141a; border: 1px solid var(--line); border-radius: 3px; padding: 2px 5px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent2); border-color: var(--accent2); }
input[type=color] { width: 34px; height: 22px; padding: 0 1px; border: 1px solid var(--line); background: #11141a; border-radius: 3px; }
input[type=range] { accent-color: var(--accent); }
.dim { color: var(--dim); }
.sep { display: inline-block; width: 1px; height: 18px; background: var(--line); margin: 0 4px; vertical-align: middle; }

#topbar { display: flex; align-items: center; gap: 14px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--accent); letter-spacing: .3px; }
.brand span { color: var(--dim); font-weight: 400; }
.filename { display: flex; align-items: center; font-family: var(--mono); }
.filename input { width: 150px; font-family: var(--mono); }
#topbar nav { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }

#layout { flex: 1; display: grid; grid-template-columns: 270px 1fr 400px; min-height: 0; }
aside { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; border-radius: 0; background: transparent; padding: 7px 10px; color: var(--dim); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.panel { display: none; flex: 1; min-height: 0; overflow: auto; padding: 8px; }
.panel.active { display: flex; flex-direction: column; gap: 6px; }
.toolbar { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1; }
.badge { background: var(--warn); color: #111; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 700; }
.badge:empty { display: none; }
.badge.err { background: var(--err); }
.note { color: var(--dim); font-size: 12px; margin: 4px 0; }

/* type tree */
.tree { font-family: var(--mono); font-size: 12.5px; margin-top: 4px; }
.tree .node { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 3px; cursor: pointer; white-space: nowrap; }
.tree .node:hover { background: var(--panel2); }
.tree .node.selected { background: #33404f; }
.tree .node .rel { font-size: 10.5px; padding: 0 4px; border-radius: 3px; border: 1px solid var(--line); color: var(--dim); font-family: var(--font); }
.tree .node .rel.main { color: var(--accent); border-color: var(--accent); }
.tree .node .rel.spray { color: var(--accent2); border-color: #3e5f80; }
.tree .node .rel.overlay { color: #c9a0ff; border-color: #5b4a78; }
.tree .node.missing .label { color: var(--err); text-decoration: underline dotted; }
.tree .node .swatch { width: 18px; height: 18px; border-radius: 2px; background: #000; flex: none; }
.tree .children { margin-left: 14px; border-left: 1px dotted var(--line); padding-left: 4px; }
.tree h4 { margin: 10px 0 4px; font: 600 11px var(--font); color: var(--dim); text-transform: uppercase; letter-spacing: .5px; }

/* sprites */
.sprite-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.sprite-card { background: #101318; border: 1px solid var(--line); border-radius: 4px; padding: 3px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.sprite-card:hover, .sprite-card.selected { border-color: var(--accent); }
.sprite-card .thumb { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; }
.sprite-card canvas { max-width: 64px; max-height: 64px; image-rendering: pixelated; }
.sprite-card .n { font-size: 10px; color: var(--dim); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sprite-card .src { font-size: 9px; color: #6d7787; }
.sprite-detail { background: #101318; border: 1px solid var(--line); border-radius: 4px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.sprite-detail canvas { image-rendering: pixelated; align-self: center; max-width: 100%; }
.sprite-detail .meta { font-size: 11.5px; color: var(--dim); }

/* center */
#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#viewport { position: relative; flex: 1; min-height: 0; }
#view { width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
#view:active { cursor: grabbing; }
#hud { position: absolute; left: 8px; top: 8px; font: 12px var(--mono); background: rgba(10, 12, 15, .72); padding: 6px 8px; border-radius: 4px; pointer-events: none; white-space: pre; }
#hud .over { color: var(--err); }
#hud .near { color: var(--warn); }
#cameraHint { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: var(--dim); pointer-events: none; }
#compareLabels { position: absolute; inset: 0; pointer-events: none; }
#compareLabels div { position: absolute; transform: translate(-50%, 0); font: 11px var(--mono); background: rgba(0, 0, 0, .6); padding: 1px 5px; border-radius: 3px; }
#transport { display: flex; gap: 6px; align-items: center; padding: 6px 8px; background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap; }
#transport label { display: flex; gap: 4px; align-items: center; color: var(--dim); }
#autoTrigger { width: 54px; }

/* forms */
.form { display: flex; flex-direction: column; gap: 4px; }
.form h3 { margin: 10px 0 2px; font: 600 11.5px var(--font); color: var(--accent); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
.form h3:first-child { margin-top: 0; }
.field { display: grid; grid-template-columns: 112px 1fr auto; gap: 6px; align-items: center; }
.field > label { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }
.field.set > label { color: var(--text); }
.field .ctl { display: flex; gap: 4px; align-items: center; min-width: 0; }
.field .ctl input[type=text], .field .ctl input:not([type]), .field .ctl select { flex: 1; min-width: 0; font-family: var(--mono); }
.field .ctl input[type=range] { width: 92px; flex: none; }
.field .reset { padding: 0 6px; color: var(--dim); }
.field .unit { color: var(--dim); font-size: 11px; }
.field input.bad { border-color: var(--warn); }
.field.row2 { grid-template-columns: 112px 1fr; }
.colors { display: flex; gap: 10px; align-items: center; color: var(--dim); font-size: 12px; margin: 2px 0 4px; flex-wrap: wrap; }
.colors label { display: flex; gap: 4px; align-items: center; }
.gradient { height: 10px; border-radius: 3px; border: 1px solid var(--line); flex: 1; min-width: 60px; }
.info-line { font-size: 12px; color: var(--dim); }
.unknown-list { font-family: var(--mono); font-size: 12px; }
.check { display: flex; gap: 6px; align-items: center; }
.vec { display: flex; gap: 3px; }
.vec input { width: 64px; flex: 1; }

/* script text */
.text-wrap { flex: 1; display: flex; min-height: 300px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: #0f1216; }
.line-numbers { font: 12.5px/1.45 var(--mono); color: #4f5866; text-align: right; padding: 6px 6px 6px 4px; user-select: none; overflow: hidden; white-space: pre; min-width: 36px; background: #0c0e12; }
#scriptText { flex: 1; resize: none; border: 0; background: transparent; font: 12.5px/1.45 var(--mono); padding: 6px; tab-size: 4; white-space: pre; overflow: auto; }
#scriptText:focus { outline: none; }

/* problems */
#problems { display: flex; flex-direction: column; gap: 4px; }
.problem { display: grid; grid-template-columns: 56px 1fr; gap: 6px; padding: 4px 6px; border-radius: 3px; background: var(--panel2); cursor: default; font-size: 12.5px; }
.problem[data-pos] { cursor: pointer; }
.problem .lv { font: 700 10.5px var(--font); text-transform: uppercase; }
.problem.game .lv { color: var(--err); }
.problem.warn .lv { color: var(--warn); }
.problem.info .lv { color: var(--accent2); }
.problem.ok .lv { color: var(--ok); }
.problem code { font-family: var(--mono); }

/* dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 0; max-width: min(860px, 94vw); width: 680px; max-height: 88vh; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog form { display: flex; flex-direction: column; max-height: 88vh; }
#dialogBody { padding: 14px 16px; overflow: auto; }
#dialogBody h2 { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
#dialogBody h3 { margin: 14px 0 4px; font-size: 13px; color: var(--accent2); }
#dialogBody pre { background: #0f1216; border: 1px solid var(--line); border-radius: 4px; padding: 8px; font: 12px var(--mono); overflow: auto; white-space: pre; }
#dialogBody table { border-collapse: collapse; width: 100%; font-size: 12px; }
#dialogBody td, #dialogBody th { border-bottom: 1px solid var(--line); padding: 3px 6px; vertical-align: top; text-align: left; }
#dialogBody td:first-child { font-family: var(--mono); white-space: nowrap; }
#dialogBody kbd { font: 11px var(--mono); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; background: #0f1216; }
#dialogButtons { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 16px; margin: 0; border-top: 1px solid var(--line); }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px; }
.pick-list button { text-align: left; overflow: hidden; text-overflow: ellipsis; }
.pick-list button small { color: var(--dim); }

[hidden] { display: none !important; }
#dropzone { position: fixed; inset: 0; background: rgba(20, 30, 45, .82); display: flex; align-items: center; justify-content: center; z-index: 50; border: 3px dashed var(--accent); }
#dropzone div { font-size: 22px; color: var(--accent); }
#toast { position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); background: #2b323c; border: 1px solid var(--line); border-radius: 5px; padding: 7px 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 60; max-width: 80vw; }
#toast.show { opacity: 1; }
#toast.err { border-color: var(--err); }

@media (max-width: 1100px) {
	#layout { grid-template-columns: 220px 1fr 340px; }
}
@media (max-width: 820px) {
	body { overflow: auto; }
	#layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; }
	#left, #right { max-height: 60vh; }
}
