:root {
  --bg: #15121c;
  --panel: #1d1927;
  --panel-2: #262134;
  --line: #352e48;
  --text: #ece8f6;
  --muted: #9a91b3;
  --accent: #ffcc4d;
  --accent-ink: #241a06;
  --err: #ff6b6b;
  --warn: #f0b35a;
  --ok: #7bd88f;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 var(--sans); display: grid; grid-template-rows: auto 1fr auto; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: progress; }
select, input[type=text], input[type=password], input[type=number], input:not([type]) {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
input[type=number] { width: 4em; }
code, .mono { font-family: var(--mono); font-size: 12px; }
.small { font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row.end { justify-content: flex-end; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; font-size: 15px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.logo { width: 16px; height: 16px; background: var(--accent); box-shadow: inset 0 0 0 4px var(--accent), inset 0 0 0 8px #1b1424; image-rendering: pixelated; }

.layout { display: grid; grid-template-columns: minmax(320px, 30%) 1fr 280px; min-height: 0; }
.panel { min-height: 0; overflow: auto; border-right: 1px solid var(--line); }
.panel.right { padding: 4px 14px 20px; border-right: 0; background: var(--panel); }
.panel.left { display: flex; flex-direction: column; background: var(--panel); }
.panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 0; background: transparent; padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#editor {
  flex: 1; width: 100%; resize: none; border: 0; padding: 12px 14px; background: var(--bg);
  font: 12px/1.5 var(--mono); tab-size: 2; white-space: pre; color: #d9d3ea;
}
.agent, .brief { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.hint { color: var(--muted); margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; color: var(--muted); }
.field > input, .field > select, .field > textarea { color: var(--text); }
.field.inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.field textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; resize: vertical; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin: 6px 0; }
.log { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.log li { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; white-space: pre-wrap; font-size: 12px; }
.log li.err { border-color: var(--err); }
.log li.ok { border-color: var(--ok); }
.log li img { display: block; max-width: 100%; image-rendering: pixelated; margin-top: 6px; border-radius: 4px; }
.brief pre { white-space: pre-wrap; font: 11px/1.5 var(--mono); color: #cfc8e2; }

.center { display: flex; flex-direction: column; background: var(--bg); }
.stage-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { border-radius: 999px; padding: 3px 12px; }
.chips button[aria-checked=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#scrub { width: 120px; accent-color: var(--accent); }
.stage { flex: 1; min-height: 260px; display: grid; place-items: center; overflow: hidden; position: relative; }
.stage.checker { background: repeating-conic-gradient(#221d2e 0 25%, #1a1624 0 50%) 0 0 / 24px 24px; }
.stage.dark { background: #0d0b12; }
.stage.light { background: #f4f1ea; }
.stage.sky { background: linear-gradient(#8fd3ff, #d7f1ff 70%, #9ad37a 70%, #7cbf5c); }
#view { image-rendering: pixelated; }
.lod-strip { display: flex; gap: 14px; align-items: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); overflow-x: auto; background: var(--panel); }
.lod-strip figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.lod-strip canvas { image-rendering: pixelated; background: repeating-conic-gradient(#2a2438 0 25%, #221d2e 0 50%) 0 0 / 12px 12px; border-radius: 4px; }
.lod-strip figcaption { font: 11px var(--mono); color: var(--muted); text-align: center; }
.lod-strip figcaption b { color: var(--text); font-weight: 600; }

.sheet-wrap { overflow: auto; max-height: 220px; background: repeating-conic-gradient(#2a2438 0 25%, #221d2e 0 50%) 0 0 / 8px 8px; border-radius: 6px; }
#sheet { image-rendering: pixelated; display: block; }
.webview { background: #f6f3ec; color: #2b2533; border-radius: 8px; padding: 10px; }
.webview .small { color: #6d6580; }
.webview code { color: #6b3fa0; }
.webview select { background: #fff; color: #2b2533; border-color: #d9d2e6; }
#webview-slot { min-height: 100px; display: grid; place-items: center; }

.status { padding: 6px 14px; border-top: 1px solid var(--line); background: var(--panel); font: 12px var(--mono); color: var(--muted); max-height: 120px; overflow: auto; }
.status .err { color: var(--err); cursor: pointer; }
.status .warn { color: var(--warn); cursor: pointer; }
.status .ok { color: var(--ok); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: min(720px, 92vw); padding: 18px 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 8px; font-size: 16px; }
dialog h3 { font-size: 12px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; }

@media (max-width: 1100px) {
  /* One column, the character first; the page scrolls instead of each panel. */
  html, body { height: auto; }
  body { display: block; }
  .layout { display: flex; flex-direction: column; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .panel.center { order: -1; }
  .stage { flex: none; height: clamp(280px, 60vw, 480px); }
  .panel.left { height: min(70vh, 620px); }
  .panel.left .tab-body { overflow: auto; }
  .status { position: sticky; bottom: 0; }
}

@media (max-width: 640px) {
  .bar { gap: 8px; padding: 8px 12px; }
  .bar .spacer { display: none; }
  .bar .brand { flex: 1 0 auto; }
  .bar .field.inline:has(select) { flex: 1 1 160px; }
  .bar .field.inline select { flex: 1; min-width: 0; }
  .bar > a.field { flex: 1 1 auto; justify-content: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; }
  .bar > button { flex: 1 1 auto; }
  .stage-toolbar { padding: 8px; }
  /* Forty animations would fill the screen: one row you swipe through. */
  .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 4px; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  .chips button { flex: none; }
  #scrub { flex: 1 1 120px; }
  .panel.right { padding: 4px 12px 20px; }
}

/* Fingers, not cursors: controls big enough to tap. */
@media (pointer: coarse) {
  button, select, input[type=text], input[type=password], input[type=number], input:not([type]) { min-height: 40px; }
  .tabs button { min-height: 44px; }
  .chips button { min-height: 36px; padding: 4px 14px; }
  .toggle { min-height: 36px; }
  .toggle input, .field input[type=checkbox] { width: 20px; height: 20px; }
  input[type=range] { min-height: 32px; }
  /* iOS zooms into any field under 16px when it is focused. */
  select, input, textarea, #editor { font-size: 16px; }
}
