:root {
  --bg: #111116; --panel: #18181f; --panel-2: #20202a; --line: #2c2c38; --line-2: #3a3a48;
  --text: #ecebf2; --muted: #9a99a8; --faint: #6b6a78;
  --accent: #8f88ee; --accent-ink: #15132e; --danger: #f08080; --ok: #5dcaa5;
  --stage: #16161c; --gen: #D85A30; --cut: #3FA7D6; --warn: #EF9F27;
  --radius: 8px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f3ef; --panel: #fbfaf7; --panel-2: #efeee9; --line: #e0ded7; --line-2: #cfcdc4;
    --text: #1d1d22; --muted: #5f5e66; --faint: #8a8992;
    --accent: #534AB7; --accent-ink: #ffffff; --danger: #b13a3a; --ok: #0f6e56;
    --stage: #e9e8e3;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); display: flex; flex-direction: column;
  overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, .btn, input, select, textarea { font: inherit; color: inherit; }
button, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer; min-height: 34px; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost, .btn.ghost { background: transparent; }
button.on { border-color: var(--accent); color: var(--accent); }
input:not([type]), input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 7px 10px; outline: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=color] { width: 40px; height: 30px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.01em; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linejoin: round; }
.mode { font-size: 12px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 99px; padding: 2px 10px; }
.mode.edit { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.top-actions > * { height: 36px; }
.baker { position: absolute; left: -10000px; top: 0; width: 320px; height: 320px; }

.tabs { display: none; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px minmax(0, 1fr) 320px; }
.panel { background: var(--panel); overflow-y: auto; padding: 14px; }
.library { border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.inspector { border-left: 1px solid var(--line); }
.inspector section + section { margin-top: 8px; border-top: 1px solid var(--line); }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.inspector section > h2:first-child { margin-top: 4px; }
.inspector section[data-panel=view] > h2:first-child { margin-top: 16px; }
label { display: block; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
label small { color: var(--faint); }
label output { float: right; color: var(--text); font-family: var(--mono); font-size: 12px; }
label.check, label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
label.check { margin: 0 0 8px; }
label.inline > input { margin-top: 0; }
.row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.toggles { display: flex; flex-direction: column; }
.dim { opacity: 0.45; pointer-events: none; transition: opacity 0.15s; }
.blurb, .hint { color: var(--muted); font-size: 12.5px; margin: -2px 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; font-size: 12.5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.info:empty { display: none; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-family: var(--mono); font-size: 12px; text-align: right; overflow-wrap: anywhere; }
.info .note { grid-column: 1 / -1; color: var(--muted); font-family: var(--font); text-align: left; margin-top: 4px; }
.use { font-size: 12.5px; color: var(--muted); }
.use code { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 4px 0 8px; overflow-wrap: anywhere; cursor: copy; }
body.public .edit-only, body:not(.public) .public-only { display: none !important; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 26px; padding: 2px 10px; font-size: 12px; border-radius: 99px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; text-align: left; min-height: 0; align-items: stretch; }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card .thumb { aspect-ratio: 1; border-radius: 6px; background: var(--stage); display: grid; place-items: center; overflow: hidden; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb svg { width: 34%; stroke: var(--faint); fill: none; stroke-width: 1.4; }
.card .name { font-size: 12.5px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .meta { font-size: 11px; color: var(--faint); }
.empty { color: var(--muted); font-size: 13px; grid-column: 1 / -1; padding: 12px 2px; }

.stage-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage { flex: 1; min-height: 0; position: relative; touch-action: none; background: var(--stage); }
.stage canvas { display: block; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.stage-bar .title { font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.stage-bar .title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty { font-size: 11px; font-weight: 500; color: var(--warn); border: 1px solid currentColor; border-radius: 99px; padding: 0 8px; }
.look { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.look span { margin-right: 4px; }
.look button { min-height: 28px; padding: 2px 9px; font-size: 12px; }
.toast { position: absolute; left: 50%; top: 14px; transform: translateX(-50%) translateY(-8px); opacity: 0;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 99px; padding: 6px 14px; font-size: 13px;
  pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { color: var(--danger); }

@media (max-width: 1080px) { .layout { grid-template-columns: 220px minmax(0, 1fr) 290px; } }
@media (max-width: 820px) {
  body { overflow: auto; height: auto; min-height: 100%; }
  .layout { display: flex; flex-direction: column; flex: none; }
  .stage-wrap { order: -1; }
  .stage { height: 52vh; flex: none; }
  .tabs { display: flex; gap: 6px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
  .tabs button { flex: 1; justify-content: center; }
  .panel { overflow: visible; border: 0; padding: 12px 16px 24px; }
  [data-panel] { display: none !important; }
  body[data-tab=library] [data-panel=library],
  body[data-tab=shape] [data-panel=shape],
  body[data-tab=view] [data-panel=view] { display: flex !important; flex-direction: column; }
  body[data-tab=library] .inspector { display: none; }
  body:not([data-tab=library]) .library { display: none; }
  .inspector section + section { border: 0; margin: 0; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .look span { display: none; }
}
@media (max-width: 420px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
