@font-face {
  font-family: Geist;
  src: url("vendor/geist/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("vendor/geist/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ui-font-sans: Geist, ui-sans-serif, system-ui, sans-serif;
  --ui-font-mono: "Geist Mono", ui-monospace, Menlo, monospace;
  --ui-radius: 6px;
  --ui-font-size: 0.8125rem;
  --bg: light-dark(#fafafa, #0a0a0a);
  --surface: light-dark(#ffffff, #111111);
  --line: light-dark(#ebebeb, #262626);
  --text: light-dark(#171717, #ededed);
  --muted: light-dark(#666666, #a1a1a1);
  --subtle: light-dark(#f2f2f2, #1a1a1a);
  --error: light-dark(#d32f2f, #ff6166);
  --ok: light-dark(#18794e, #4cc38a);
  color-scheme: light dark;
  /* UI SDK's components read these. */
  --ui-background: var(--surface);
  --ui-foreground: var(--text);
  --ui-muted: var(--subtle);
  --ui-muted-foreground: var(--muted);
  --ui-border: var(--line);
  --ui-input: light-dark(#dedede, #333333);
  --ui-ring: light-dark(#e5e5e5, #333333);
  --ui-ring-border: light-dark(#a1a1a1, #666666);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--ui-font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h2 { margin: 0; font-size: 13px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Buttons and inputs */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.button:hover:not(:disabled) { background: var(--subtle); }
.button:active:not(:disabled) { transform: scale(0.98); }
.button:disabled { opacity: 0.45; cursor: default; }
.button.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--text) 85%, var(--bg)); }
.button.ghost { border-color: transparent; background: transparent; }
.button.ghost:hover:not(:disabled) { background: var(--subtle); }
.button.icon-only { width: 32px; padding: 0; }
.button.small { height: 28px; padding: 0 10px; font-size: 12px; }
.button.icon-only.small { width: 28px; padding: 0; }
.button.wide { width: 100%; }
.button:focus-visible, .input:focus-visible, textarea:focus-visible, .layer-row:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--text) 40%, transparent);
  outline-offset: 1px;
}
.input, textarea {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file:focus-within { outline: 2px solid color-mix(in srgb, var(--text) 40%, transparent); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 52px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.crumbs { display: flex; align-items: center; gap: 10px; min-width: 0; }
.crumbs a { color: var(--text); font-weight: 600; text-decoration: none; }
.slash { color: var(--line); font-size: 20px; font-weight: 300; }
.current { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.toolbar { display: flex; align-items: center; gap: 6px; }
.divider { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* Workspace */
.workspace { flex: 1; min-height: 0; border: 0; border-radius: 0; }
.workspace > ui-resizable-panel { padding: 0; }
ui-resizable-handle {
  position: relative;
  width: 1px;
  background: var(--line);
  outline: none;
}
ui-resizable-handle::after { content: ""; position: absolute; inset: 0 -4px; z-index: 1; cursor: col-resize; }
ui-resizable-handle[data-hovering], ui-resizable-handle[data-dragging], ui-resizable-handle:focus-visible {
  background: color-mix(in srgb, var(--text) 35%, transparent);
}
.aside { display: flex; flex-direction: column; min-height: 0; background: var(--surface); overflow: hidden; }
.panel { padding: 12px; border-bottom: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; gap: 4px; min-height: 28px; margin-bottom: 8px; }
.panel-head h2 { flex: 1; }
.panel-head .hint { flex: none; }

/* Layers */
.layers { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.layer-props { display: grid; grid-template-columns: minmax(0, 1fr) 112px; gap: 8px; margin-bottom: 8px; }
.layer-list { display: flex; flex-direction: column; margin: 0 -4px; padding: 0 4px; overflow-y: auto; flex: 1; min-height: 80px; overscroll-behavior: contain; }
.layer-row {
  display: grid;
  grid-template-columns: 28px 40px minmax(0, 1fr);
  touch-action: none;
  user-select: none;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 2px;
  border-radius: 6px;
  cursor: pointer;
}
.layer-row:hover { background: var(--subtle); }
.layer-row[aria-selected="true"] { background: color-mix(in srgb, var(--text) 8%, transparent); }
.layer-row .eye { width: 28px; height: 28px; border: 0; border-radius: 4px; background: transparent; color: var(--text); cursor: pointer; display: grid; place-items: center; }
.layer-row .eye:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.layer-row .eye span { width: 15px; height: 15px; background: currentColor; mask: var(--ui-icon-eye) center / contain no-repeat; }
.layer-row .eye[aria-pressed="false"] { color: var(--muted); }
.layer-row .eye[aria-pressed="false"] span { mask-image: var(--ui-icon-eye-off); }
.layer-row .thumb {
  width: 40px; height: 30px;
  object-fit: contain;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--line);
  background: repeating-conic-gradient(light-dark(#e8e8e8, #2a2a2a) 0 25%, light-dark(#fff, #1f1f1f) 0 50%) 0 0 / 8px 8px;
}
.layer-row[data-hidden] .thumb { opacity: 0.4; }
.layer-text { min-width: 0; }
/* While a row moves, it marks the drop place; the copy follows the pointer. */
.layer-row[data-moving] { background: transparent; outline: 1px dashed color-mix(in srgb, var(--text) 30%, transparent); outline-offset: -1px; }
.layer-row[data-moving] > * { opacity: 0.35; }
[data-drag-preview].layer-row { background: var(--surface); box-shadow: var(--ui-shadow); border-radius: 6px; cursor: grabbing; }
.remember { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 12px; cursor: pointer; }
.layer-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.layer-meta { display: block; color: var(--muted); font-size: 11px; }
.layer-row[data-hidden] .layer-name { color: var(--muted); }

/* Sliders and selects: UI SDK's look, fitted to the panels. */
[data-slot="slider"], [data-slot="select-trigger"] { min-width: 0; }
[data-slot="select-trigger"] { width: 100%; }
.slider.compact { flex-direction: row; align-items: center; gap: 10px; }
.slider.compact ui-slider-value { order: 2; min-width: 4ch; text-align: right; }
[data-slot="select-value"] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.param-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.param { margin-top: 12px; }
.adjust .button.wide { margin-top: 12px; }

/* Stage */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle, color-mix(in srgb, var(--text) 12%, transparent) 1px, transparent 1px);
  background-size: 16px 16px;
}
#canvas {
  border-radius: 4px;
  box-shadow: 0 0 0 1px var(--line), 0 8px 30px -12px rgb(0 0 0 / 0.25);
  background: repeating-conic-gradient(light-dark(#eee, #222) 0 25%, light-dark(#fff, #2a2a2a) 0 50%) 0 0 / 16px 16px;
}
#canvas.pixelated { image-rendering: pixelated; }
.statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 32px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  flex: none;
}
.statusbar .spacer { flex: 1; }
#message { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
#isolated-wrap { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot[data-ok="true"] { background: var(--ok); }
.dot[data-ok="false"] { background: var(--error); }

/* Agent */
.agent-head { padding: 12px 12px 0; margin: 0; }
.agent-config { display: grid; gap: 8px; padding: 10px 12px 12px; border-bottom: 1px solid var(--line); }
.agent-config ui-segmented-control { width: 100%; }
.agent-config ui-segmented-control-item { flex: 1; justify-content: center; }
.key { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.model .input { min-width: 0; }
ui-combobox-content ui-combobox-item { font-size: 13px; }
.chat { list-style: none; margin: 0; padding: 12px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.chat li { overflow-wrap: anywhere; flex-shrink: 0; }
.chat .empty { margin: auto 8px; text-align: center; color: var(--muted); font-size: 12px; }
.chat .task { align-self: flex-end; max-width: 90%; padding: 8px 12px; border-radius: 12px 12px 4px 12px; background: var(--text); color: var(--bg); }
.chat .say { padding: 2px 2px; line-height: 1.55; }
.chat .call, .chat .error {
  display: block;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: 11px/1.5 var(--ui-font-mono);
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat .call::before { content: "✓ "; color: var(--ok); }
.chat .error { color: var(--error); white-space: normal; border-color: color-mix(in srgb, var(--error) 35%, var(--line)); }
.chat .error::before { content: "✕ "; }
.composer { padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: none; line-height: 1.5; }
.composer-actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.composer-actions .model { flex: 1; min-width: 0; }
.composer-actions .model .input { height: 28px; font-size: 12px; }
.key-form { display: grid; gap: 8px; }
.key-saved { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 2px 2px 2px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: 12px; }
.key-saved[hidden], .key-form[hidden] { display: none; }
.key-saved-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-saved-text > span:first-child { color: var(--text); font-weight: 500; }
.key-saved .mask { font-family: var(--ui-font-mono); }

/* New image dialog */
.new-dialog { width: min(420px, calc(100vw - 32px)); display: grid; gap: 14px; padding: 20px; border-radius: 12px; }
.new-dialog ui-dialog-title { font-size: 15px; font-weight: 600; }
.new-dialog ui-dialog-description { color: var(--muted); margin-top: -8px; }
.size-fields { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.size-fields label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.size-fields .times { padding-bottom: 7px; color: var(--muted); }
.new-dialog ui-segmented-control { width: 100%; }
.new-dialog ui-segmented-control-item { flex: 1; justify-content: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* Popups from UI SDK: match the page's surfaces. */
ui-select-content, ui-menu-content, ui-combobox-content, ui-dialog-content {
  --ui-background: var(--surface);
  border-radius: 8px;
}
ui-combobox-content { max-height: min(360px, var(--available-height, 360px)); }
ui-tooltip-content { font-size: 12px; }

/* Phones and narrow windows: one column, page scrolls. */
@media (max-width: 860px) {
  body { height: auto; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .toolbar { flex-wrap: wrap; }
  /* The resizable lays its panels out in a row with inline styles. */
  .workspace { flex-direction: column !important; overflow: visible; }
  .workspace > ui-resizable-panel { flex: none !important; width: auto; overflow: visible; }
  .aside { border-top: 1px solid var(--line); }
  .canvas-wrap { flex: none; }
  .workspace > ui-resizable-handle { display: none; }
  #stage { order: -1; }
  .canvas-wrap { height: 60vh; padding: 12px; }
  .statusbar { flex-wrap: wrap; height: auto; padding: 6px 12px; white-space: normal; }
  .layer-list { max-height: 40vh; }
  .chat { max-height: 50vh; min-height: 120px; }
  .input, textarea { font-size: 16px; }
}
