:root {
  --bg: #262624;
  --panel: #1f1e1d;
  --raised: #30302e;
  --line: #3a3936;
  --text: #ecebe6;
  --muted: #a6a39b;
  --faint: #7d7a73;
  --accent: #d97757;
  --user: #141413;
  --code: #1a1a19;
  --err: #ffb4a8;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, -apple-system, system-ui, "Segoe UI", sans-serif; }
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }

#app { display: grid; grid-template-columns: var(--left, 48%) 6px 1fr; height: 100vh; }
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#art { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
#split { cursor: col-resize; background: transparent; }
#split:hover { background: var(--line); }

.bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 48px; }
.spacer { flex: 1; }
.brand { font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }
.logo.big { font-size: 30px; margin-bottom: 6px; }
.chip { font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 2px 9px; border-radius: 99px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost { background: none; border: 1px solid transparent; color: var(--muted); padding: 4px 9px; border-radius: 7px; text-decoration: none; font-size: 13px; }
.ghost:hover:not(:disabled) { background: var(--raised); color: var(--text); }

#scroll { flex: 1; overflow-y: auto; position: relative; }
#messages { max-width: 720px; margin: 0 auto; padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 18px; }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 6px; }
#empty[hidden] { display: none; }
.empty-title { color: var(--text); font-size: 15px; }
.empty-sub { color: var(--muted); max-width: 380px; }
#suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; max-width: 520px; }
#suggest button { background: var(--raised); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; color: var(--muted); font-size: 13px; }
#suggest button:hover { color: var(--text); border-color: #55534e; }

.msg-user { align-self: flex-end; max-width: 80%; background: var(--user); border: 1px solid var(--line); padding: 8px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-model { display: flex; flex-direction: column; gap: 8px; }
.who { font-size: 12px; color: var(--faint); display: flex; gap: 8px; align-items: center; }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; overflow: hidden; }
.card.active { border-color: #5c5a54; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; }
.card-head:hover { background: #242422; }
.card-icon { width: 30px; height: 30px; border-radius: 7px; background: var(--raised); display: grid; place-items: center; color: var(--accent); flex: none; font-size: 13px; }
.card-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-sub.err { color: var(--err); }
.card pre { margin: 0; max-height: 180px; overflow: hidden; padding: 10px 12px; font: 11.5px/1.45 var(--mono); color: #c9c6bd; background: var(--code); border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.card pre.open { max-height: none; }
.card .more { display: block; width: 100%; background: var(--code); border: 0; border-top: 1px solid var(--line); color: var(--faint); font-size: 12px; padding: 4px; }
.actions { display: flex; gap: 4px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .25; } }

#composer { margin: 0 auto 14px; width: calc(100% - 32px); max-width: 720px; background: var(--raised); border: 1px solid var(--line); border-radius: 16px; padding: 12px 12px 8px 16px; }
#composer:focus-within { border-color: #55534e; }
#input { width: 100%; background: none; border: 0; outline: none; resize: none; max-height: 160px; padding: 2px 0 8px; }
#input::placeholder { color: var(--faint); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; padding: 3px 10px; border-radius: 6px; color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--raised); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.seg.small button { padding: 2px 9px; }
.temp { display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; }
.temp input { width: 80px; accent-color: var(--accent); }
.temp span { font-family: var(--mono); width: 30px; }
.send { width: 32px; height: 32px; border-radius: 9px; border: 0; background: var(--accent); color: #1f1e1d; font-weight: 700; }
.send.stop { background: var(--text); }

.art-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#art-body { flex: 1; position: relative; min-height: 0; margin: 0 10px 10px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #1a1a19; }
#stage { position: absolute; inset: 0; }
#stage canvas, #stage .stage-svg { width: 100%; height: 100%; display: block; }
#stage .stage-svg { object-fit: contain; background: #f4f1ea; }
.stage-error { position: absolute; left: 12px; right: 12px; bottom: 12px; background: #3a1d1d; color: var(--err); padding: 10px 12px; border-radius: 8px; font: 12px/1.45 var(--mono); white-space: pre-wrap; max-height: 45%; overflow: auto; }
#code { position: absolute; inset: 0; margin: 0; overflow: auto; padding: 14px 16px; font: 12px/1.5 var(--mono); color: #d6d3ca; background: var(--code); white-space: pre; }
#art-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--faint); pointer-events: none; }
#art-empty[hidden], #code[hidden] { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 44vh 0 1fr; height: 100dvh; }
  #art { grid-row: 1; border-left: 0; border-bottom: 1px solid var(--line); }
  #split { display: none; }
  #chat { grid-row: 3; }
  #messages { padding: 8px 16px 20px; }
  #composer { width: calc(100% - 24px); }
  .bar { padding: 8px 12px; }
}
