:root {
    --bg: #101117;
    --surface: #191b23;
    --raised: #232631;
    --line: #333747;
    --text: #e8e9ef;
    --muted: #9a9eb0;
    --accent: #e8e13c;
    --info: #5fd8ff;
    --danger: #ff5c6c;
    --ok: #4bea52;
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.4 system-ui, sans-serif;
}

[hidden] { display: none !important; }

header, #conflict {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

#conflict { background: #4a2028; }

.spacer { flex: 1; }

nav { display: flex; gap: 2px; flex-wrap: wrap; }

button, select, input, textarea, .file {
    font: inherit;
    color: var(--text);
    background: var(--raised);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 4px 8px;
}

button, select, .file, summary { cursor: pointer; }

button:hover:not(:disabled), .file:hover { border-color: var(--muted); }

button:disabled { opacity: .4; cursor: default; }

:focus-visible { outline: 2px solid var(--info); outline-offset: 1px; }

button.active, .tab.active { background: var(--accent); border-color: var(--accent); color: #16161a; }

button.primary { background: var(--info); border-color: var(--info); color: #0d1a20; font-weight: 600; }

button.danger { border-color: var(--danger); color: var(--danger); }

.file { position: relative; display: inline-block; text-align: center; }

.file input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

#save-state { color: var(--muted); min-width: 150px; text-align: right; }

#save-state.error, #save-state.conflict { color: var(--danger); }

main { flex: 1; display: flex; min-height: 0; }

aside { background: var(--surface); overflow-y: auto; padding: 8px; }

#toolbar { width: 190px; display: flex; flex-direction: column; gap: 6px; border-right: 1px solid var(--line); }

#tools, #reference-controls { display: flex; flex-direction: column; gap: 4px; }

#tools button { text-align: left; }

#toolbar hr { width: 100%; border: 0; border-top: 1px solid var(--line); }

#panel { width: 340px; border-left: 1px solid var(--line); }

#stage { flex: 1; position: relative; min-width: 0; }

#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; }

#canvas:focus { outline: none; }

#canvas[data-tool="hand"], #canvas.panning { cursor: grab; }

#canvas[data-tool="node"], #canvas[data-tool="pencil"], #canvas[data-tool="link"] { cursor: crosshair; }

#cursor { position: absolute; right: 8px; bottom: 6px; color: var(--muted); pointer-events: none; }

.grid { stroke: #23252f; stroke-width: 1; vector-effect: non-scaling-stroke; fill: none; }

.limit, .frame, .marquee { fill: none; vector-effect: non-scaling-stroke; }

.limit { stroke: var(--line); }

.frame { stroke: var(--info); stroke-dasharray: 6 4; opacity: .7; }

.frame-label { fill: var(--info); font-size: 6px; opacity: .8; }

.link { fill: none; stroke-width: 2; }

.link.selected { stroke-width: 3.5; stroke-dasharray: 3 2; }

.link-hit { fill: none; stroke: transparent; stroke-width: 7; }

.node { cursor: pointer; }

.node .outline { fill: none; stroke: transparent; stroke-width: 1.2; }

.node.broken .outline { stroke: var(--danger); stroke-dasharray: 2 2; }

.node.selected .outline { stroke: var(--info); stroke-dasharray: none; }

.initials { fill: var(--text); font-size: 6px; text-anchor: middle; pointer-events: none; }

.badge { fill: var(--accent); font-size: 5px; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 2; }

.pixel { image-rendering: pixelated; }

.preview { fill: none; stroke: var(--info); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }

.ghost { fill: none; stroke: var(--info); stroke-width: 1; opacity: .7; pointer-events: none; }

.marquee { stroke: var(--info); fill: rgba(95, 216, 255, .12); }

section h3 { margin: 12px 0 6px; font-size: 13px; color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; flex: 1; min-width: 0; }

.field span { color: var(--muted); font-size: 12px; }

.field input[type="color"] { padding: 0; height: 28px; width: 100%; }

textarea { resize: vertical; }

.row { display: flex; gap: 6px; align-items: center; }

.row.wrap { flex-wrap: wrap; }

.row select { flex: 1; min-width: 0; }

.short { width: 70px; }

.stage { border: 1px solid var(--line); border-radius: 4px; padding: 6px; margin-bottom: 6px; }

.stage strong { flex: 1; }

.effect { border-top: 1px solid var(--line); margin: 6px 0; padding-top: 6px; }

.sources label { display: flex; gap: 3px; align-items: center; }

.icon-field { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }

.icon-field img { width: 28px; height: 28px; margin-bottom: 6px; }

.icon-field p { width: 100%; margin: 0 0 6px; }

.hint { color: var(--muted); }

.warning { color: #ffb454; }

.error { color: var(--danger); }

ul { padding-left: 18px; margin: 4px 0; }

.problems li { cursor: pointer; margin-bottom: 3px; }

.problems li:hover { color: var(--info); }

dialog {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 380px;
    max-width: min(640px, 92vw);
}

dialog::backdrop { background: rgba(0, 0, 0, .6); }

dialog h2 { margin: 0 0 10px; font-size: 15px; }

.modal-body input { width: 100%; }

.modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }

th { text-align: left; padding: 2px 12px 2px 0; font-weight: 600; }

td { padding: 2px 8px 2px 0; }

.palette { list-style: none; padding: 0; max-height: 50vh; overflow-y: auto; }

.palette li { padding: 4px 8px; cursor: pointer; border-radius: 4px; }

.palette li.active, .palette li:hover { background: var(--raised); }

#toasts { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; }

.toast { background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; }

.toast.error { border-color: var(--danger); }

.toast.success { border-color: var(--ok); }
