:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --side: #f4f1ea;
  --ink: #1d1a14;
  --muted: #6f6a60;
  --line: #e7e1d4;
  --accent: #f5a524;
  --accent-strong: #c97c00;
  --accent-ink: #1b1407;
  --accent-soft: #fdf1da;
  --user-bubble: #f1ece0;
  --code-bg: #1e1b16;
  --danger: #d14343;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(30, 20, 0, .10);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14120f; --panel: #1b1915; --side: #100f0c; --ink: #f2eee6; --muted: #a59f93; --line: #2d2a24;
    --accent-strong: #f5b347; --accent-soft: #33280f; --user-bubble: #2a261e; --code-bg: #0d0c0a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14120f; --panel: #1b1915; --side: #100f0c; --ink: #f2eee6; --muted: #a59f93; --line: #2d2a24;
  --accent-strong: #f5b347; --accent-soft: #33280f; --user-bubble: #2a261e; --code-bg: #0d0c0a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15.5px/1.6 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.noscript { padding: 24px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons & inputs ---------- */
.primary, .ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 999px; cursor: pointer; text-decoration: none; white-space: nowrap;
  padding: 9px 16px; font-weight: 600; border: 1px solid transparent;
  transition: background .15s, border-color .15s, transform .05s;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { background: #e79a12; }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { border-color: var(--accent); }
.ghost.danger { color: var(--danger); }
.primary:active, .ghost:active { transform: translateY(1px); }
.small { padding: 6px 12px; font-size: .85rem; }
.big { padding: 13px 24px; font-size: 1.02rem; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-strong); font-weight: 650; cursor: pointer; text-decoration: underline; }
.icon-btn {
  background: transparent; border: 0; cursor: pointer; border-radius: 10px;
  width: 38px; height: 38px; display: inline-grid; place-items: center; font-size: 1.05rem; flex: none;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); }
.icon-btn.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
select, input[type="search"], .field input, .field textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 10px; font-size: .9rem; outline: none;
}
.field input:focus, .field textarea:focus, select:focus, input[type="search"]:focus { border-color: var(--accent); }
.lang-select { max-width: 150px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; }

/* ---------- Landing ---------- */
.landing { max-width: 1120px; margin: 0 auto; padding: 18px 16px 44px; }
.landing-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.landing-top-actions { display: flex; gap: 8px; align-items: center; }
.invite { margin: 18px auto 0; max-width: 720px; text-align: center; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.hero { text-align: center; padding: 64px 0 24px; max-width: 860px; margin: 0 auto; }
.eyebrow { color: var(--accent-strong); font-weight: 700; letter-spacing: .05em; text-transform: uppercase; font-size: .8rem; margin: 0 0 14px; }
.hero h1 { font-size: clamp(2rem, 5.2vw, 3.3rem); line-height: 1.1; letter-spacing: -.03em; margin: 0 auto 18px; max-width: 800px; }
.lead { font-size: 1.12rem; color: var(--muted); margin: 0 auto 26px; max-width: 660px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check.center { justify-content: center; margin-top: 14px; color: var(--muted); font-size: .88rem; }
.fine { color: var(--muted); font-size: .86rem; margin: 10px 0 0; }
.preview { display: block; width: 100%; height: auto; margin: 40px auto 0; border-radius: 18px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 56px; }
.features article { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.features h3 { margin: 10px 0 6px; font-size: 1.02rem; }
.features p { margin: 0; color: var(--muted); font-size: .92rem; }
.f-icon { font-size: 1.6rem; }
.how, .faq { max-width: 760px; margin: 64px auto 0; }
.how h2, .faq h2 { text-align: center; font-size: 1.7rem; letter-spacing: -.02em; margin: 0 0 22px; }
.how ol { list-style: none; counter-reset: step; padding: 0; margin: 0 0 26px; display: grid; gap: 12px; }
.how li { counter-increment: step; display: grid; grid-template-columns: 44px 1fr; gap: 2px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.how li::before { content: counter(step); grid-row: span 2; width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; }
.how li span { color: var(--muted); font-size: .94rem; }
.how > .primary { display: flex; margin: 0 auto; width: fit-content; }
.faq details { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; }
.faq summary { cursor: pointer; font-weight: 650; }
.faq p { color: var(--muted); margin: 10px 0 2px; }
.landing-foot { text-align: center; margin-top: 56px; color: var(--muted); font-size: .85rem; }
.badge { height: 34px; }
@media (max-width: 960px) { .features { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .features { grid-template-columns: 1fr; } .hero { padding-top: 36px; } .lang-select { max-width: 110px; } }

/* ---------- App layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 284px; flex: none; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px; gap: 10px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; }
.new-chat { width: 100%; }
.side-search { width: 100%; }
.side-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 4px 4px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; padding: 0 6px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: .92rem; }
.chat-item:hover { background: var(--accent-soft); }
.chat-item.active { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 4px; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.account { display: flex; gap: 10px; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--line); object-fit: cover; flex: none; }
.account-text { min-width: 0; }
.user-name { font-weight: 650; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance { font-size: .82rem; color: var(--ink); }
.msgs-left { font-size: .76rem; color: var(--muted); }
.side-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.side-badge img { height: 26px; }
.scrim { display: none; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.model-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; max-width: 60vw; font-weight: 650;
}
.model-btn #modelName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-btn:hover { border-color: var(--accent); }
.caret { color: var(--muted); }
.price-chip { font-size: .75rem; font-weight: 650; color: var(--accent-strong); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.assistant-chip { font-size: .82rem; background: var(--accent-soft); padding: 4px 10px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.low-banner { background: var(--accent-soft); border-bottom: 1px solid var(--line); padding: 8px 16px; font-size: .9rem; text-align: center; }

.scroll { flex: 1; overflow-y: auto; }
.welcome, .intro { max-width: 880px; margin: 0 auto; padding: 44px 16px 16px; text-align: center; }
.welcome h2, .intro h2 { font-size: clamp(1.5rem, 4vw, 2.1rem); margin: 0 0 6px; letter-spacing: -.02em; }
.intro-em { font-size: 2.6rem; }
.starters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin: 22px auto 0; max-width: 760px; }
.starter { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: .88rem; text-align: left; }
.starter:hover { border-color: var(--accent); background: var(--accent-soft); }
#assistants .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 22px; text-align: left; }
.assistant-card {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.assistant-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.assistant-card .em { font-size: 1.4rem; }
.assistant-card b { display: block; margin: 6px 0 2px; }
.assistant-card span.d { color: var(--muted); font-size: .86rem; }
.assistant-card.create { border-style: dashed; background: transparent; }
.card-edit { position: absolute; top: 8px; right: 8px; border: 0; background: var(--accent-soft); border-radius: 8px; cursor: pointer; padding: 2px 7px; }

/* ---------- Messages ---------- */
.messages { max-width: 820px; margin: 0 auto; padding: 18px 16px 30px; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 14px; border-radius: 18px 18px 4px 18px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble img { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; margin-bottom: 6px; }
.file-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.file-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; font-size: .82rem; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 .8em; }
.body ul, .body ol { padding-left: 1.4em; margin: 0 0 .8em; }
.body h1, .body h2, .body h3 { line-height: 1.25; margin: 1.1em 0 .5em; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 .8em; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; }
.body blockquote { border-left: 3px solid var(--accent); margin: 0 0 .8em; padding: 2px 12px; color: var(--muted); }
.body code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.body pre { position: relative; background: var(--code-bg); color: #eee; border-radius: 12px; padding: 14px; overflow-x: auto; margin: 0 0 .8em; }
.body pre code { background: none; padding: 0; color: inherit; font-size: .86rem; }
.body img { max-width: 100%; border-radius: 10px; }
.copy-code { position: absolute; top: 8px; right: 8px; font-size: .75rem; border: 1px solid #444; background: #2a2620; color: #ddd; border-radius: 8px; padding: 3px 8px; cursor: pointer; }
.gen-image { max-width: min(100%, 560px); border-radius: 14px; display: block; border: 1px solid var(--line); background: var(--panel); }
.thinking { font-size: .85rem; color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 10px; white-space: pre-wrap; max-height: 180px; overflow-y: auto; }
.thinking summary { cursor: pointer; }
.meta { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: .8rem; flex-wrap: wrap; }
.meta button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 3px 7px; border-radius: 8px; font-size: .82rem; }
.meta button:hover { background: var(--accent-soft); color: var(--ink); }
.meta .cost { margin-left: 4px; }
.error-box { background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); padding: 10px 14px; border-radius: 12px; margin-top: 6px; }
.error-box a { font-weight: 650; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer-wrap { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); max-width: 852px; width: 100%; margin: 0 auto; }
.mode-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--side); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg-btn { border: 0; background: none; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .86rem; font-weight: 600; color: var(--muted); }
.seg-btn.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.image-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.image-opts select { max-width: 260px; }
.composer {
  display: flex; align-items: flex-end; gap: 2px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 6px 6px 6px 8px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; resize: none; padding: 8px 4px; max-height: 220px; line-height: 1.45; }
.send-btn { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; cursor: pointer; background: var(--accent); color: var(--accent-ink); font-size: 1rem; font-weight: 700; }
.send-btn.stop { background: var(--ink); color: var(--bg); }
.cost-hint { text-align: center; color: var(--muted); font-size: .78rem; margin: 6px 0 0; min-height: 1em; }
.attach-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.thumb { position: relative; }
.thumb img { height: 64px; border-radius: 10px; border: 1px solid var(--line); display: block; }
.thumb.file { display: flex; flex-direction: column; justify-content: center; height: 64px; max-width: 220px; padding: 6px 28px 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: .84rem; }
.thumb.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb.file small { color: var(--muted); }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); cursor: pointer; font-size: .7rem; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 18px; width: min(700px, 100%); max-height: 88dvh; display: flex; flex-direction: column; padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); overflow-y: auto; }
.modal-card.narrow { width: min(500px, 100%); gap: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; }
.search { width: 100%; margin: 12px 0 8px; padding: 10px 14px; border-radius: 12px; }
.filters { display: flex; gap: 16px; flex-wrap: wrap; font-size: .88rem; margin-bottom: 4px; }
.model-list { overflow-y: auto; margin: 6px -6px 0; padding: 0 6px; display: flex; flex-direction: column; gap: 4px; min-height: 120px; }
.model-group { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 4px 4px; }
.model-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; }
.model-row:hover { background: var(--accent-soft); }
.model-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.model-row .mr-main { flex: 1; min-width: 0; }
.pick-label { font-size: .72rem; font-weight: 700; color: var(--accent-strong); text-transform: uppercase; letter-spacing: .04em; }
.model-row .mr-title { font-weight: 650; }
.model-row .mr-desc { color: var(--muted); font-size: .83rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-row .tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.tag { font-size: .7rem; border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; color: var(--muted); }
.model-row .mr-price { text-align: right; font-size: .84rem; font-weight: 650; color: var(--accent-strong); white-space: nowrap; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; }
.field select, .field input, .field textarea { font-weight: 400; width: 100%; }
.field small { font-weight: 400; }
.settings-actions, .editor-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.editor { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: flex; gap: 10px; }
.emoji-field { width: 80px; }
.emoji-field input { text-align: center; font-size: 1.2rem; }
.grow { flex: 1; }
.spacer { flex: 1; }
.import-card { display: flex; gap: 12px; align-items: flex-start; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.import-card .em { font-size: 2rem; }
.import-card p { margin: 4px 0; }

.toast { position: fixed; bottom: 104px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; z-index: 60; max-width: calc(100% - 32px); box-shadow: var(--shadow); text-align: center; }

.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); width: min(300px, 86vw); }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar { padding: 8px 10px; }
  .model-btn { max-width: 64vw; }
  .assistant-chip { display: none; }
  .welcome, .intro { padding-top: 22px; }
  #assistants .grid { grid-template-columns: 1fr 1fr; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 420px) {
  .composer .icon-btn { width: 34px; }
  .assistant-card { padding: 12px; }
}
@media (max-width: 340px) { #assistants .grid { grid-template-columns: 1fr; } }
