:root {
  color-scheme: dark light;
  --bg: #121110;
  --bg-2: #1a1917;
  --bg-3: #23211e;
  --line: #2e2b27;
  --text: #f1ede6;
  --muted: #9a938a;
  --accent: #f2b544;
  --accent-ink: #1a1408;
  --user: #2b2a33;
  --model: #1f1e1b;
  --danger: #e5705f;
  --ok: #7fc67a;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf7f2;
    --bg-2: #ffffff;
    --bg-3: #f1ece4;
    --line: #e4ddd2;
    --text: #1d1a16;
    --muted: #6d665e;
    --accent: #c98a12;
    --accent-ink: #ffffff;
    --user: #e9e2d6;
    --model: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.only-mobile { display: none; }
button { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100dvh;
}

/* —— sidebar —— */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 6px;
}
.brand-mark { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; letter-spacing: 0.01em; }
.brand-mark:hover { text-decoration: none; }
.brand-name em { font-style: normal; color: var(--accent); }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe3a3, var(--accent) 60%, #a86f0b);
  box-shadow: 0 0 0 3px rgba(242, 181, 68, 0.15);
}
.sidebar-lead { margin: 0; padding: 0 18px 12px; color: var(--muted); font-size: 0.9rem; }
.model-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.series {
  margin: 10px 8px 4px;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.model-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}
.model-btn:hover { background: var(--bg-3); }
.model-btn.active { background: var(--bg-3); border-color: var(--line); }
.model-btn .name { font-weight: 600; }
.model-btn .kind { grid-column: 1 / -1; color: var(--muted); font-size: 0.78rem; }
.model-btn .tag {
  font-size: 0.66rem; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px; align-self: start;
  background: rgba(242, 181, 68, 0.14); color: var(--accent);
}
.model-btn .tag.off { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.model-btn.off { opacity: 0.55; }
.sidebar-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.sidebar-foot p { margin: 0 0 6px; }

/* —— main —— */
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 1.05rem; }
.topbar p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 0.72rem; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.pill.warn { color: var(--accent); border-color: rgba(242, 181, 68, 0.4); }
.ghost-btn, .icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 12px; cursor: pointer; color: var(--muted);
}
.ghost-btn:hover, .icon-btn:hover { color: var(--text); background: var(--bg-3); }
.icon-btn { padding: 4px 10px; font-size: 1.1rem; line-height: 1.2; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.thread-inner { width: min(820px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.empty {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 24px 12px;
}
.empty-orb {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe3a3, var(--accent) 55%, #7a4f05);
  box-shadow: 0 0 60px rgba(242, 181, 68, 0.25);
}
.empty h2 { margin: 0 0 6px; font-size: 1.3rem; }
.empty p { margin: 0 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: 0.85rem; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }

.msg { display: flex; flex-direction: column; gap: 4px; max-width: 82%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.model { align-self: flex-start; }
.msg .who { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; }
.bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 6px; }
.msg.model .bubble { background: var(--model); border-bottom-left-radius: 6px; }
.msg.error .bubble { border-color: rgba(229, 112, 95, 0.5); color: var(--danger); }
.bubble .prompt-echo { color: var(--muted); }
.bubble .continuation { color: var(--text); }
.bubble audio { display: block; margin-top: 8px; width: 280px; max-width: 100%; }
.bubble img { display: block; max-width: 260px; max-height: 200px; border-radius: 10px; margin-top: 6px; }
.bubble .meta { display: block; margin-top: 6px; font-size: 0.74rem; color: var(--muted); font-family: var(--mono); }
.bubble.thinking { color: var(--muted); }
.bubble.thinking::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.bubble .actions { margin-top: 8px; display: flex; gap: 8px; }
.bubble .mini { font-size: 0.78rem; padding: 4px 10px; }

.reading { display: grid; gap: 8px; min-width: 260px; }
.reading .row { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; align-items: center; font-size: 0.86rem; }
.reading .bar { height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.reading .bar i { display: block; height: 100%; background: var(--accent); }
.reading .val { font-family: var(--mono); font-size: 0.76rem; color: var(--muted); }
.reading .label { text-transform: capitalize; }
.reading .note { font-size: 0.8rem; color: var(--muted); }

/* —— composer —— */
.composer {
  padding: 10px 20px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer-extra { width: min(820px, 100%); margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.composer-extra:empty { display: none; }
.composer-extra label { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.composer-extra select, .composer-extra input[type="range"] {
  font: inherit; font-size: 0.82rem; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px;
}
.composer-extra input[type="range"] { padding: 0; width: 110px; border: 0; background: transparent; }
.composer-extra textarea.sketch {
  flex: 1 1 100%; min-height: 84px; resize: vertical;
  font: inherit; font-size: 0.9rem; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.composer-extra .file-btn {
  border: 1px dashed var(--line); border-radius: 10px; padding: 6px 12px;
  background: transparent; cursor: pointer; color: var(--muted); font-size: 0.82rem;
}
.composer-extra .file-btn:hover { color: var(--text); border-color: var(--accent); }
.composer-extra .file-name { font-size: 0.8rem; color: var(--muted); }
.composer-extra input[type="file"] { display: none; }
.rec-btn {
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px;
  background: var(--bg-2); cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.rec-btn .rdot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.rec-btn.on { border-color: var(--danger); }
.rec-btn.on .rdot { animation: blink 1s infinite; }
.composer-row {
  width: min(820px, 100%); margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 18px; padding: 6px 6px 6px 14px;
}
.composer-row:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: 0; background: transparent; color: var(--text); font: inherit;
  resize: none; outline: none; padding: 8px 0; max-height: 200px; line-height: 1.4;
}
.send-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: 0.45; cursor: default; }
.composer-hint { width: min(820px, 100%); margin: 8px auto 0; text-align: center; min-height: 1em; }
.scrim { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 20;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 15; }
  .scrim.show { display: block; }
  .msg { max-width: 92%; }
  .thread { padding: 16px 12px 8px; }
  .composer { padding: 8px 12px 12px; }
  .topbar { padding: 10px 12px; }
}
