:root {
  --bg: #14181d; --panel: #1c2229; --panel2: #232a33; --line: #323b46; --text: #e6eaef; --muted: #93a0ae;
  --accent: #3aa0d8; --accent-ink: #06222f; --danger: #e5616b; --warn: #e8b23d; --ok: #4fbf8b;
  --canvas: #0e1114; --radius: 6px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; }
.boot { margin: auto; color: var(--muted); }
#measure { position: fixed; left: -100000px; top: 0; width: 1600px; visibility: hidden; pointer-events: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; } h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
input[type=text], input[type=number], input[type=search], input[type=url], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 7px; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; width: 100%; min-height: 54px; }
.full { width: 100%; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 10px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 2px 7px; font-size: 12px; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.icon-btn { background: none; border: 1px solid transparent; border-radius: var(--radius); padding: 3px 6px; cursor: pointer; color: var(--muted); line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--panel2); }
.icon-btn.on { color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.tag.ok { color: var(--ok); border-color: var(--ok); }
.tag.kind { color: var(--accent); border-color: var(--accent); }

/* top bar */
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto; min-height: 44px; }
.topbar .brand { font-weight: 700; letter-spacing: .01em; margin-right: 6px; }
.topbar .brand span { color: var(--accent); }
.topbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 2px; }
.topbar input.name { width: 220px; font-weight: 600; }

/* library */
.library-wrap { flex: 1; display: flex; min-height: 0; }
.folders { flex: 0 0 240px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.folders h3 { padding: 4px 6px 6px; }
.folder-row { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 5px; cursor: pointer; background: none; border: 1px solid transparent; text-align: left; width: 100%; }
.folder-row:hover { background: var(--panel2); }
.folder-row.on { background: #1f4259; }
.folder-row.drop { border-color: var(--accent); background: var(--panel2); }
.folder-row .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row .count { color: var(--muted); font-size: 11px; }
.folder-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; padding: 0 2px; }
.card[draggable=true] { cursor: default; }
.card.dragging { opacity: .5; }
.library { flex: 1; overflow: auto; padding: 16px 20px 40px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.lib-section { margin: 18px 0 8px; display: flex; align-items: center; gap: 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card .thumb { aspect-ratio: 16 / 9; background: var(--canvas); cursor: pointer; overflow: hidden; display: flex; align-items: center; justify-content: center; border: 0; padding: 0; width: 100%; }
.card .thumb svg { max-width: 100%; max-height: 100%; display: block; }
.card .meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.empty { color: var(--muted); padding: 24px; border: 1px dashed var(--line); border-radius: 8px; text-align: center; }

/* editor layout */
.editor { flex: 1; display: grid; grid-template-columns: 260px 1fr 300px; min-height: 0; }
.side { background: var(--panel); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); overflow-y: auto; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 4px; cursor: pointer; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 4px; padding: 5px 8px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
#canvas-wrap { user-select: none; flex: 1; position: relative; overflow: hidden; background: var(--canvas); min-height: 0; outline: none; }
#stage { position: absolute; box-shadow: 0 0 0 1px #000, 0 8px 30px rgba(0,0,0,.5); }
#art { position: absolute; inset: 0; }
#overlay { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#overlay .handle { pointer-events: all; fill: #fff; stroke: #1689c9; }
#overlay .selbox { fill: none; stroke: #1689c9; }
#overlay .guide { stroke: #ff3ea5; }
#overlay .marquee { fill: rgba(22,137,201,.12); stroke: #1689c9; }
#overlay .scope { fill: none; stroke: #e8b23d; stroke-dasharray: 6 4; }
#overlay .gridline { stroke: rgba(120,140,160,.28); }
.statusbar { display: flex; gap: 12px; padding: 3px 10px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

/* layers */
.layer { display: flex; align-items: center; gap: 4px; padding: 3px 4px; border-radius: 4px; cursor: default; border: 1px solid transparent; }
.layer:hover { background: var(--panel2); }
.layer.sel { background: #1f4259; }
.layer.drop-before { border-top-color: var(--accent); }
.layer.drop-after { border-bottom-color: var(--accent); }
.layer.drop-into { border-color: var(--accent); }
.layer .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .ltype { color: var(--muted); font-size: 11px; width: 14px; text-align: center; }
.layer .icon-btn { padding: 1px 3px; font-size: 12px; }
.layer.is-hidden .lname { opacity: .45; }
.layer .slotmark { color: var(--warn); font-size: 10px; }

/* properties */
.props { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.props section { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.props section:last-child { border-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { color: var(--muted); font-size: 11px; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; }
.field.inline > span { flex: 0 0 84px; }
.field.inline > :last-child { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.grid2 input, .grid4 input { width: 100%; }
.check { display: flex; align-items: center; gap: 6px; }
.color-btn { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px 6px; cursor: pointer; width: 100%; text-align: left; }
.swatch { width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(255,255,255,.35); flex: 0 0 auto; background-image: linear-gradient(45deg,#888 25%,transparent 25%,transparent 75%,#888 75%),linear-gradient(45deg,#888 25%,#555 25%,#555 75%,#888 75%); background-size: 8px 8px; background-position: 0 0,4px 4px; position: relative; }
.swatch i { position: absolute; inset: 0; border-radius: 2px; }
.role-list { display: flex; flex-direction: column; gap: 1px; max-height: 420px; overflow: auto; min-width: 220px; }
.role-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; background: none; border: 0; text-align: left; }
.role-item:hover, .role-item.on { background: var(--panel2); }
.role-item small { color: var(--muted); margin-left: auto; font-family: ui-monospace, monospace; }
.locked-mark { color: var(--warn); }

/* icon / component library */
.icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.icon-cell { aspect-ratio: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px; cursor: pointer; color: var(--text); position: relative; }
.icon-cell:hover { border-color: var(--accent); }
.icon-cell.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.icon-cell svg { width: 100%; height: 100%; display: block; }
.icon-cell .keep { position: absolute; right: 2px; top: 1px; font-size: 9px; color: var(--warn); }
.comp-item { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; overflow: hidden; background: var(--panel2); }
.comp-item .thumb { background: var(--canvas); padding: 6px; cursor: pointer; display: block; width: 100%; border: 0; }
.comp-item .thumb svg { max-width: 100%; height: auto; max-height: 120px; display: block; margin: 0 auto; }
.comp-item .row { padding: 4px 6px; }

/* slot form */
.slot-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; background: var(--panel2); }
.slot-card > header { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.icon-pick { display: flex; align-items: center; gap: 8px; }
.icon-pick .preview { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 6px; padding: 5px; background: var(--bg); flex: 0 0 auto; color: var(--text); }
.icon-pick .preview svg { width: 100%; height: 100%; display: block; }

/* modal, popover, toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal.wide { width: min(1180px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.popover { position: fixed; z-index: 200; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.6); max-width: 340px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

/* palette editor */
.pal-layout { display: grid; grid-template-columns: 220px 1fr; gap: 14px; min-height: 420px; }
.pal-list { display: flex; flex-direction: column; gap: 2px; }
.pal-list button { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; cursor: pointer; text-align: left; }
.pal-list button.on { background: var(--panel2); border-color: var(--line); }
.pal-chips { display: flex; margin-left: auto; }
.pal-chips i { width: 10px; height: 14px; display: block; }
.pal-chips i:first-child { border-radius: 3px 0 0 3px; } .pal-chips i:last-child { border-radius: 0 3px 3px 0; }
.role-row { display: grid; grid-template-columns: 34px 92px 110px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; }
.role-row input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
.role-row code { font-family: ui-monospace, monospace; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.preview-grid figure { margin: 0; }
.preview-grid figcaption { padding: 4px 2px; color: var(--muted); }
.preview-grid svg { width: 100%; height: auto; border-radius: 4px; display: block; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 500; font-size: 11px; }
table.list input { width: 100%; }
.menu { display: flex; flex-direction: column; min-width: 190px; }
.menu button { background: none; border: 0; text-align: left; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.menu button:hover { background: var(--panel2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-btn { position: relative; }
.version-row { display: grid; grid-template-columns: 200px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.version-row svg { width: 200px; height: auto; display: block; border-radius: 4px; }
