:root {
  --bg: #05060d;
  --surface: #0c0e1a;
  --surface-2: #151829;
  --ink: #e9edff;
  --muted: #9198b8;
  --faint: #5a6080;
  --line: #1c2036;
  --accent: #aab6ff;
  --accent-ink: #090b18;
  --glow-a: #8a9cff;
  --glow-b: #d6e2ff;
  --glow-c: #6a7cff;
  --ambient: rgb(110 125 255 / 0.13);
  --danger: #f0846f;
  --ok: #7fe0b0;
  --user-bubble: #e9edff;
  --user-ink: #070914;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px -14px rgb(0 0 0 / 0.7);
  --radius: 18px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-2: #e5e9f4;
  --ink: #12142a;
  --muted: #5b6282;
  --faint: #979dba;
  --line: #dadeee;
  --accent: #4c56d8;
  --accent-ink: #ffffff;
  --ambient: rgb(110 125 255 / 0.18);
  --danger: #c2412d;
  --ok: #1f8a5b;
  --user-bubble: #12142a;
  --user-ink: #f3f5ff;
  --shadow: 0 1px 2px rgb(20 25 60 / 0.05), 0 8px 24px -12px rgb(20 25 60 / 0.2);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(900px 520px at 50% -8%, var(--ambient), transparent 70%), var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* The sky (sky.js): slow milky waves behind everything. */
.sky { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.sky canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-orb { position: relative; width: 18px; height: 18px; }
.brand-orb canvas { position: absolute; left: -90%; top: -90%; width: 280%; height: 280%; pointer-events: none; }
.brand-name { font-weight: 650; letter-spacing: -0.02em; font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  position: relative; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.badge {
  position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 650; line-height: 17px; text-align: center;
}
/* Stage */
.stage {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  width: 100%; max-width: 760px; margin: 0 auto;
}
.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 24px; scroll-behavior: smooth; }

/* Hero */
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 9vh 0 12px; }
.chat.has-log .hero { display: none; }
.hero-title { margin: 56px 0 6px; font-size: clamp(28px, 6vw, 38px); font-weight: 650; letter-spacing: -0.03em; }
.hero-sub { margin: 0; max-width: 430px; color: var(--muted); }

/* The orb: a canvas haze (orb.js). The canvas spills past the button so the glow can breathe. */
.orb {
  --size: 168px;
  position: relative; width: var(--size); height: var(--size);
  border: 0; padding: 0; background: none; border-radius: 50%;
}
.orb-canvas {
  position: absolute; left: -60%; top: -60%; width: 220%; height: 220%;
  pointer-events: none; transition: filter 0.8s ease;
}
.orb[data-state="loading"] .orb-canvas { filter: saturate(0.45) brightness(0.8); }
.orb:not(:disabled):hover .orb-canvas { filter: brightness(1.12); }

/* Boot progress */
.boot { margin-top: 22px; width: min(340px, 100%); }
.boot[hidden] { display: none; }
.boot-bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.boot-bar span {
  display: block; height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--glow-b), var(--glow-a));
  transition: width 0.3s;
}
.boot-text { margin: 10px 0 0; font-size: 13.5px; color: var(--muted); min-height: 1.5em; }
.boot.error .boot-text { color: var(--danger); }
.boot.error .boot-bar { display: none; }

.ideas { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 26px; max-width: 560px; }
.ideas[hidden] { display: none; }
.idea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; color: var(--muted); transition: color 0.15s, border-color 0.15s;
}
.idea:hover { color: var(--ink); border-color: var(--faint); }

/* Messages */
.log { display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 88%; overflow-wrap: anywhere; animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; translate: 0 6px; } }
.msg.user {
  align-self: flex-end; background: var(--user-bubble); color: var(--user-ink);
  padding: 9px 15px; border-radius: var(--radius) var(--radius) 6px var(--radius);
  white-space: pre-wrap;
}
.msg.bot { align-self: flex-start; }
.msg.bot:empty { display: none; }
.msg.bot p { margin: 0 0 0.6em; }
.msg.bot p:last-child, .msg.bot ul:last-child, .msg.bot ol:last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { margin: 0 0 0.6em; padding-left: 1.3em; }
.msg.bot code { font: 0.9em var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.msg.bot pre { background: var(--surface-2); padding: 12px; border-radius: 12px; overflow-x: auto; margin: 0 0 0.6em; }
.msg.bot pre code { background: none; padding: 0; }
.msg.bot.typing:empty { display: block; }
.msg.bot.typing:empty::after {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }
.tool {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 9px;
  animation: rise 0.25s ease-out;
}
.tool svg { width: 15px; height: 15px; }
.tool.ok svg { color: var(--ok); }
.tool.fail { color: var(--danger); }
.tool button { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* Composer */
.composer { padding: 6px 16px max(12px, env(safe-area-inset-bottom)); }
.composer-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); padding: 10px 10px 8px 16px;
}
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent;
  min-height: 26px; max-height: 180px; padding: 4px 0; line-height: 1.45;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.toggles, .sends { display: flex; align-items: center; gap: 6px; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  font-size: 13px; color: var(--faint); transition: all 0.15s;
}
.chip-toggle svg { width: 16px; height: 16px; }
.chip-toggle[aria-pressed="true"] { color: var(--ink); border-color: var(--faint); background: var(--surface-2); }
.mic, .send {
  position: relative; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%; border: 0; transition: transform 0.12s, opacity 0.2s;
}
.mic:active, .send:active { transform: scale(0.94); }
.mic:disabled, .send:disabled { opacity: 0.35; cursor: default; }
.mic { background: var(--surface-2); color: var(--ink); overflow: hidden; }
.mic svg { position: relative; }
.mic-level {
  --level: 0; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, var(--glow-b), var(--glow-a));
  opacity: 0; transform: scale(calc(0.6 + var(--level) * 0.8)); transition: opacity 0.2s, transform 0.08s;
}
.mic.on { color: #fff; }
.mic.on .mic-level { opacity: 1; }
.mic.loading .mic-level { opacity: 0.5; animation: blink 1s infinite; }
.send { background: var(--ink); color: var(--bg); }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.status { margin: 8px 0 0; text-align: center; font-size: 12.5px; color: var(--faint); }

/* Files drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20;
  width: min(400px, 100vw); background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px -30px rgb(0 0 0 / 0.4);
  display: flex; flex-direction: column;
  animation: slide 0.22s ease-out;
}
.drawer[hidden] { display: none; }
@keyframes slide { from { translate: 40px 0; opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: max(14px, env(safe-area-inset-top)) 12px 10px 20px; }
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-actions { display: flex; align-items: center; gap: 4px; }
.text-btn { border: 0; background: none; padding: 7px 10px; border-radius: 10px; font-size: 14px; color: var(--accent); font-weight: 550; }
.text-btn:hover { background: var(--surface-2); }
.text-btn.danger { color: var(--danger); }
.solid-btn { border: 0; background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 11px; font-size: 14px; font-weight: 600; }
.file-list { flex: 1; overflow-y: auto; padding: 0 10px; }
.file-list[hidden] { display: none; }
.file {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 0; background: none; padding: 10px; border-radius: 12px;
}
.file:hover { background: var(--surface-2); }
.file-icon {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--surface-2); color: var(--muted);
}
.file-icon svg { width: 17px; height: 17px; }
.file:hover .file-icon { background: var(--bg); }
.file-meta { min-width: 0; }
.file-name { display: block; font-size: 14.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-sub { display: block; font-size: 12.5px; color: var(--faint); }
.file.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } }
.empty-files { padding: 30px 14px; text-align: center; color: var(--faint); font-size: 14px; }
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 0 16px; }
.editor[hidden] { display: none; }
.ed-name { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; font: 14px var(--mono); }
.ed-body {
  flex: 1; min-height: 160px; resize: none; border: 1px solid var(--line); background: var(--bg);
  border-radius: 12px; padding: 12px; font: 14px/1.55 var(--mono); outline: 0;
}
.ed-body:focus, .ed-name:focus { border-color: var(--faint); outline: 0; }
.ed-row { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.drawer-foot { padding: 14px 20px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.drop-hint, .storage { margin: 0 0 6px; font-size: 12.5px; color: var(--faint); }
.drawer-foot .text-btn { padding: 6px 0; font-size: 13px; }
.drawer-foot .text-btn:hover { background: none; text-decoration: underline; }

.dropzone {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(6px);
}
.dropzone[hidden] { display: none; }
.dropzone p {
  margin: 0; padding: 36px 48px; border: 2px dashed var(--accent); border-radius: 24px;
  color: var(--accent); font-weight: 600; background: var(--surface);
}

/* Settings */
.settings-btn {
  position: fixed; right: 16px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 15;
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  box-shadow: var(--shadow); transition: color 0.15s, transform 0.3s;
}
.settings-btn:hover, .settings-btn[aria-expanded="true"] { color: var(--ink); }
.settings-btn[aria-expanded="true"] { transform: rotate(45deg); }
.settings-btn svg { width: 17px; height: 17px; }
.settings {
  position: fixed; right: 16px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 46px); z-index: 16;
  width: min(310px, calc(100vw - 32px)); max-height: calc(100dvh - 90px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 20px 50px -20px rgb(0 0 0 / 0.5); padding: 16px 16px 10px;
  transform-origin: bottom right; animation: pop 0.18s ease-out;
}
.settings[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(6px); } }
.settings-title { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.set-row:first-of-type { border-top: 0; }
.set-row.stack { flex-direction: column; align-items: stretch; gap: 8px; }
.set-label { display: flex; flex-direction: column; color: var(--ink); }
.set-label small { color: var(--faint); font-size: 12px; }
.set-label output { color: var(--faint); font-size: 12.5px; margin-left: 6px; }
.stack .set-label { flex-direction: row; align-items: baseline; }
.set-inline { display: flex; gap: 6px; align-items: center; }
.set-inline.between { justify-content: space-between; }
.set-inline .text-btn { padding: 4px 8px; font-size: 13px; }
.set-select {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 7px 10px; font-size: 13.5px; color: var(--ink);
}
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button {
  border: 0; background: none; padding: 5px 11px; border-radius: 8px; font-size: 13px; color: var(--muted);
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.18); }
.switch {
  appearance: none; flex: none; width: 38px; height: 22px; border-radius: 11px; margin: 0;
  background: var(--surface-2); border: 1px solid var(--line); position: relative; cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--faint); transition: transform 0.2s, background 0.2s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(16px); background: var(--accent-ink); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

@media (max-width: 860px) {
  .status { padding: 0 40px; }
}
@media (max-width: 520px) {
  .orb { --size: 140px; }
  .hero { padding-top: 3vh; }
  .chip-toggle span { display: none; }
  .chip-toggle { width: 34px; padding: 0; justify-content: center; }
}
