:root {
  --bg: #15171c;
  --panel: #1d2027;
  --panel-2: #252932;
  --line: #333845;
  --text: #dfe3ea;
  --muted: #8c93a3;
  --accent: #e8743b;
  --error: #ff6b6b;
  --warning: #f0c05a;
  --info: #7cb7ff;
  --select: #3dd6ff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
button, select, input, textarea, .button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 8px;
}
button, .button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
a { color: var(--info); }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 0 6px; }
small { text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); }

.bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { color: var(--accent); margin-right: 8px; }
.status { color: var(--muted); margin-left: auto; }
.hint { margin: 0; padding: 6px 12px; background: #2a2418; color: #f3d9a6; border-bottom: 1px solid var(--line); }
.hint[hidden] { display: none; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 240px minmax(300px, 1fr) minmax(360px, 1.25fr); grid-template-rows: minmax(0, 1fr); }
.side { border-right: 1px solid var(--line); padding: 0 10px 10px; overflow: auto; background: var(--panel); }
.layers, .files, .tree, .diagnostics { list-style: none; margin: 0; padding: 0; }
.layers li { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.layers li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers button { padding: 0 6px; }
#file-filter { width: 100%; margin-bottom: 6px; }
.files li { padding: 2px 4px; cursor: pointer; border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.files li:hover { background: var(--panel-2); }
.files li.open { background: #3a2a20; color: #ffd2b8; }
.files li .layer-tag { color: var(--muted); font-size: 11px; }
.files li.edited::after { content: " ●"; color: var(--accent); }

.code { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
.code-head { display: flex; justify-content: space-between; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--muted); }
.editor { flex: 1; min-height: 0; overflow: hidden; }
.editor .cm-editor { height: 100%; }
.editor .cm-scroller { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar, .anim, .row { display: flex; gap: 6px; align-items: center; padding: 6px 8px; flex-wrap: wrap; }
.toolbar { background: var(--panel); border-bottom: 1px solid var(--line); }
#screen { width: 260px; font-family: ui-monospace, Menlo, monospace; }
.anim { border-bottom: 1px solid var(--line); }
#time { flex: 1; min-width: 100px; }
.stage { position: relative; flex: 2; min-height: 180px; overflow: auto; display: grid; place-items: center; }
.stage.checker { background: repeating-conic-gradient(#2b2e36 0 25%, #22252c 0 50%) 0 0 / 20px 20px; }
.stage.dark { background: #000; }
.stage.light { background: #c8ccd4; }
.stage canvas { grid-area: 1 / 1; image-rendering: pixelated; }
#overlay { pointer-events: auto; cursor: crosshair; }
.stage canvas[hidden] { display: none; }
.empty { grid-area: 1 / 1; max-width: 420px; padding: 14px 18px; text-align: center; color: var(--text); background: rgba(21, 23, 28, .88); border: 1px solid var(--line); border-radius: 6px; }
.empty[hidden] { display: none; }

.tabs { display: flex; gap: 2px; padding: 0 8px; background: var(--panel); border-top: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: none; padding: 6px 10px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); box-shadow: inset 0 -2px var(--accent); }
.badge { background: var(--panel-2); border-radius: 8px; padding: 0 6px; font-size: 11px; }
.badge.has-errors { background: #5a2020; color: #ffc9c9; }
.panels { flex: 1; min-height: 140px; overflow: hidden; display: flex; }
.panel { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.panel[hidden] { display: none; }
.panel textarea { flex: 1; margin: 0 8px 8px; min-height: 120px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; resize: none; }
.inspector { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(260px, 1.6fr); min-height: 0; flex: 1; }
.tree { overflow: auto; padding: 4px; border-right: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.tree li { white-space: nowrap; }
.tree .node { cursor: pointer; padding: 0 4px; border-radius: 3px; display: inline-block; }
.tree .node:hover { background: var(--panel-2); }
.tree .node.selected { background: #133b47; color: #bff3ff; }
.tree .node.hidden-node { color: var(--muted); font-style: italic; }
.tree .type { color: var(--muted); }
.tree .toggle { display: inline-block; width: 12px; color: var(--muted); cursor: pointer; }
.tree ul { list-style: none; padding-left: 12px; margin: 0; }
.props { overflow: auto; padding: 6px 8px; }
.props table { border-collapse: collapse; width: 100%; font-size: 12px; }
.props td { border-bottom: 1px solid var(--line); padding: 3px 4px; vertical-align: top; }
.props td:first-child { color: #ffcf9e; font-family: ui-monospace, Menlo, monospace; white-space: nowrap; }
.props td.value { font-family: ui-monospace, Menlo, monospace; word-break: break-all; }
.props td.source { color: var(--muted); word-break: break-all; min-width: 120px; }
.props .link { color: var(--info); cursor: pointer; text-decoration: underline dotted; }
.props h3 { margin: 4px 0; font-size: 13px; }
.diagnostics li { padding: 4px 8px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.diagnostics .sev { width: 56px; flex: none; font-size: 11px; text-transform: uppercase; }
.diagnostics .sev.error { color: var(--error); }
.diagnostics .sev.warning { color: var(--warning); }
.diagnostics .sev.info { color: var(--info); }
.diagnostics .stage-name { color: var(--muted); width: 56px; flex: none; }
.diagnostics .where { color: var(--info); cursor: pointer; margin-left: auto; white-space: nowrap; }
.flags label { margin-right: 8px; white-space: nowrap; }

.foot { padding: 6px 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; }
.drop { position: fixed; inset: 0; display: grid; place-items: center; font-size: 22px; background: rgba(20, 22, 28, .85); border: 3px dashed var(--accent); z-index: 10; }
.drop[hidden] { display: none; }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; grid-auto-rows: minmax(320px, auto); overflow: auto; }
  .side { max-height: 240px; }
}

.export { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 8px; padding: 8px; min-height: 0; flex: 1; }
.export-form { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
.export-form label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12px; }
.export-form input, .export-form select { color: var(--text); }
.export-form .row { padding: 0; }
.triple { display: flex; gap: 4px; }
.triple input { width: 64px; }
.export-preview { overflow: auto; min-width: 0; border: 1px solid var(--line); border-radius: 4px; }
.preview-files { margin: 0; padding: 8px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; white-space: pre-wrap; }
@media (max-width: 1100px) { .export { grid-template-columns: 1fr; } }
