:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --tile: #fff;
  --raised: #fff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --control: rgba(0, 0, 0, 0.05);
  --control-hover: rgba(0, 0, 0, 0.09);
  --accent: #0071e3;
  --accent-text: #fff;
  --danger: #c0392b;
  --danger-bg: rgba(192, 57, 43, 0.08);
  --ok: #1a7f37;
  --warn: #b45309;
  --shadow: rgba(0, 0, 0, 0.08);
  --bar: #1d1d1f;
  --bar-text: #f5f5f7;
  --bar-muted: rgba(245, 245, 247, 0.6);
  --bar-control: rgba(255, 255, 255, 0.12);
  --bar-control-active: rgba(255, 255, 255, 0.22);
  --bar-link: #2997ff;
  --logo-invert: 0;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --tile: #1d1d1f;
    --raised: #2c2c2e;
    --text: #f5f5f7;
    --muted: #86868b;
    --line: rgba(255, 255, 255, 0.12);
    --control: rgba(255, 255, 255, 0.08);
    --control-hover: rgba(255, 255, 255, 0.14);
    --accent: #2997ff;
    --accent-text: #fff;
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.12);
    --ok: #3fb950;
    --warn: #e3a008;
    --shadow: rgba(0, 0, 0, 0.5);
    --bar: #000;
    --bar-text: #f5f5f7;
    --bar-muted: rgba(245, 245, 247, 0.6);
    --bar-control: rgba(255, 255, 255, 0.12);
    --bar-control-active: rgba(255, 255, 255, 0.22);
    --logo-invert: 1;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); display: flex; flex-direction: column; }

/* Top bar — a dark band in both modes so the chrome reads as chrome */
.top { align-items: center; background: var(--bar); border-bottom: 1px solid var(--line); color: var(--bar-text); display: flex; gap: 12px; padding: 8px 16px; }
.top__brand { align-items: center; display: flex; font-weight: 600; gap: 10px; letter-spacing: -0.01em; white-space: nowrap; }
.top__logo { display: block; filter: invert(1); height: 12px; width: auto; }
.top__project { background: var(--bar-control); border: 0; border-radius: 8px; color: var(--bar-text); font: inherit; max-width: 320px; padding: 6px 8px; }
.top__project option { color: var(--text); background: var(--tile); }
.top__status { color: var(--bar-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top__status.is-running::before { animation: pulse 1.2s ease-in-out infinite; background: var(--bar-link); border-radius: 50%; content: ""; display: inline-block; height: 8px; margin-right: 8px; vertical-align: middle; width: 8px; }
.top__actions { display: flex; gap: 10px; align-items: center; }
.top__user { align-items: center; color: var(--bar-muted); display: inline-flex; font-size: 12px; gap: 6px; }
.top__avatar { border-radius: 50%; height: 22px; width: 22px; }
.top .seg { background: var(--bar-control); }
.top .seg__btn { color: var(--bar-muted); }
.top .seg__btn.is-active { background: var(--bar-control-active); box-shadow: none; color: var(--bar-text); }
.top .btn--ghost { background: var(--bar-control); color: var(--bar-text); }
.top .link { color: var(--bar-link); }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

.layout { display: grid; flex: 1; gap: 12px; grid-template-columns: 400px minmax(0, 1fr); min-height: 0; padding: 12px; }
.pane { background: var(--tile); border-radius: 18px; box-shadow: 0 1px 2px var(--shadow); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

.picker { border-bottom: 1px solid var(--line); padding: 12px; }
.picker select { background: var(--tile); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font: inherit; padding: 6px 8px; width: 100%; }
.picker__hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.tokens { border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.tokens__title { font-weight: 600; }
.tokens__list { display: grid; gap: 6px; grid-template-columns: 1fr 1fr; }
.tokens__row { display: flex; justify-content: flex-end; }
.token { align-items: center; display: flex; gap: 6px; font-size: 12px; min-width: 0; }
.token input[type="color"] { background: var(--tile); border: 1px solid var(--line); border-radius: 6px; flex: none; height: 24px; padding: 0; width: 30px; }
.token__name { color: var(--muted); flex: 1; font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.token__hex { background: var(--tile); border: 1px solid var(--line); border-radius: 6px; color: var(--text); font: 11px var(--mono); padding: 3px 4px; width: 66px; }
.slider { display: flex; flex-direction: column; font-size: 12px; gap: 2px; }
.slider__label { color: var(--muted); display: flex; justify-content: space-between; }
.slider__label output { color: var(--text); font-family: var(--mono); }
.slider input { accent-color: var(--accent); width: 100%; }
.fontpick { display: flex; flex-direction: column; font-size: 12px; gap: 4px; position: relative; }
.fontpick input { background: var(--tile); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font: 13px var(--font); padding: 6px 8px; width: 100%; }
.fontpick__list { background: var(--raised); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 32px var(--shadow); left: 0; max-height: 240px; overflow: auto; position: absolute; right: 0; top: 100%; z-index: 5; }
.fontpick__item { align-items: center; background: none; border: 0; color: var(--text); cursor: pointer; display: flex; font: 13px var(--font); gap: 8px; padding: 6px 10px; text-align: left; width: 100%; }
.fontpick__item:hover, .fontpick__item.is-active { background: var(--control); }
.fontpick__cat { color: var(--muted); font-size: 11px; margin-left: auto; }
.fontpick__sample { border: 1px solid var(--line); border-radius: 8px; font-size: 18px; line-height: 1.3; padding: 8px 10px; }

.chat { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { border-radius: var(--radius); padding: 8px 12px; white-space: pre-wrap; word-break: break-word; }
.msg--user { background: var(--accent); color: var(--accent-text); align-self: flex-end; max-width: 92%; }
.msg--assistant { background: var(--control); }
.msg--tool { color: var(--muted); font: 12px/1.4 var(--mono); padding: 2px 12px; }
.msg--error { background: var(--danger-bg); color: var(--danger); }
.msg--status { color: var(--muted); font-size: 12px; padding: 2px 12px; }
.msg--result { border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.msg--logs { color: var(--muted); font: 11px/1.4 var(--mono); padding: 2px 12px; }
.msg--logs summary { cursor: pointer; font: 12px var(--font); user-select: none; }
.msg--logs pre { margin: 6px 0 0; white-space: pre-wrap; }
.msg img { border-radius: 8px; display: block; max-width: 100%; margin-top: 6px; border: 1px solid var(--line); }

.composer { border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.composer textarea { background: var(--tile); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); font: inherit; padding: 8px 12px; resize: vertical; }
.composer__row { align-items: center; display: flex; gap: 8px; }
.composer__meta { color: var(--muted); flex: 1; font-size: 12px; }

.dropzone { align-items: center; background: var(--control); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); cursor: pointer; display: flex; font-size: 12px; justify-content: center; min-height: 48px; padding: 8px; position: relative; }
.dropzone.is-over { border-color: var(--accent); color: var(--accent); }
.dropzone img { border-radius: 8px; max-height: 140px; max-width: 100%; }
.dropzone__clear { background: rgba(0, 0, 0, 0.6); border: 0; border-radius: 50%; color: #fff; cursor: pointer; height: 22px; position: absolute; right: 6px; top: 6px; width: 22px; }

.commit { border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.commit__status { font-weight: 600; }
.commit__status[data-status="clean"] { color: var(--ok); }
.commit__status[data-status="dirty"], .commit__status[data-status="none"] { color: var(--warn); }
.commit__plan { color: var(--muted); font: 12px var(--mono); }
.commit__row { align-items: center; display: flex; gap: 8px; }
.commit__row .btn { margin-left: auto; }
.commit__row .btn--ghost { margin-left: 0; }
.commit__result { color: var(--muted); font-size: 12px; white-space: pre-wrap; }

.toolbar { align-items: center; border-bottom: 1px solid var(--line); display: flex; gap: 10px; padding: 8px 12px; }
.toolbar__meta { color: var(--muted); flex: 1; font: 12px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage { background: var(--bg); flex: 1; overflow: auto; padding: 12px; position: relative; }
.stage iframe { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: block; height: 100%; margin: 0 auto; width: 100%; }
.stage.is-constrained iframe { width: var(--w); }
.stage__empty { color: var(--muted); inset: 0; display: grid; place-items: center; position: absolute; pointer-events: none; }
.stage.has-preview .stage__empty { display: none; }

.btn { background: var(--accent); border: 0; border-radius: 999px; color: var(--accent-text); cursor: pointer; font: 600 13px var(--font); padding: 7px 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--ghost { background: var(--control); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--control-hover); }
.btn--small { font-size: 12px; padding: 5px 10px; }
.link { color: var(--accent); font-size: 13px; text-decoration: none; }
.check { align-items: center; color: var(--muted); display: inline-flex; font-size: 12px; gap: 6px; }
.seg { background: var(--control); border-radius: 10px; display: inline-flex; gap: 2px; padding: 2px; }
.seg__btn { background: none; border: 0; border-radius: 8px; color: var(--muted); cursor: pointer; font: 13px var(--font); padding: 5px 12px; }
.seg--small .seg__btn { font-size: 12px; padding: 4px 10px; }
.seg__btn.is-active { background: var(--raised); box-shadow: 0 1px 3px var(--shadow); color: var(--text); font-weight: 600; }

.field { color: var(--muted); display: flex; flex-direction: column; font-size: 12px; gap: 4px; }
.field input { background: var(--tile); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font: 14px var(--font); padding: 7px 10px; }

.login-body { align-items: center; justify-content: center; }
.login { background: var(--tile); border-radius: 18px; box-shadow: 0 12px 32px var(--shadow); display: flex; flex-direction: column; gap: 12px; padding: 32px; width: min(420px, 92vw); }
.login__logo { display: block; filter: invert(var(--logo-invert)); height: auto; margin-bottom: 8px; width: 140px; }
.login__title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.login__lead { color: var(--muted); margin: 0; }
.login__form { display: flex; flex-direction: column; gap: 10px; }
.login__row { align-items: center; display: flex; gap: 8px; justify-content: flex-end; }
.login__error { color: var(--danger); font-size: 12px; margin: 0; min-height: 1em; }
.btn--github { align-items: center; background: #24292f; color: #fff; display: inline-flex; gap: 8px; justify-content: center; padding: 10px 16px; text-decoration: none; }

.dialog { background: var(--tile); border: 0; border-radius: 18px; box-shadow: 0 24px 64px var(--shadow); color: var(--text); padding: 0; width: min(520px, 92vw); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog__form { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.dialog__title { font-size: 20px; font-weight: 700; margin: 0; }
.dialog__lead { color: var(--muted); font-size: 13px; margin: 0; }
.dialog__row { align-items: center; display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-auto-rows: minmax(360px, auto); }
}
