:root {
  --bg: #ffffff;
  --surface: #f4f4f6;
  --surface-2: #ebebef;
  --border: #e3e3e8;
  --text: #17171c;
  --muted: #6b6b76;
  --accent: #6a5cff;
  --accent-2: #4f8cff;
  --on-accent: #ffffff;
  --danger: #d63c4a;
  --ok: #18a058;
  --radius: 16px;
  color-scheme: light dark;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #18191e;
    --surface-2: #22232a;
    --border: #2a2b33;
    --text: #ececf1;
    --muted: #8d8e99;
    --accent: #7c6cff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }

.app { height: 100dvh; display: flex; flex-direction: column; }

/* Header */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid transparent;
}
.top.scrolled { border-bottom-color: var(--border); }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  margin-left: 4px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 13px;
}
.chip:hover { background: var(--surface); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.ready .dot { background: var(--ok); }
.chip.busy .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.top-actions { margin-left: auto; display: flex; gap: 2px; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--surface); color: var(--text); }

/* Scroll area */
main { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }

.center {
  min-height: 100%; max-width: 440px; margin: 0 auto; padding: 24px 20px 40px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.center h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; font-weight: 650; margin: 18px 0 6px; }
#empty h1 { margin-top: 0; }
.sub { margin: 0 0 26px; color: var(--muted); }
.hero-mark { border-radius: 16px; box-shadow: 0 10px 30px -10px rgba(106, 92, 255, .6); }

/* Model options */
.options { display: grid; gap: 8px; width: 100%; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; border-radius: 14px; border: 1.5px solid var(--border); background: transparent;
  transition: border-color .15s, background .15s;
}
.option:hover:not(:disabled) { background: var(--surface); }
.option[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.option:disabled { opacity: .5; }
.option .radio { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--muted); display: grid; place-items: center; flex-shrink: 0; }
.option[aria-checked="true"] .radio { border-color: var(--accent); }
.option[aria-checked="true"] .radio::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.option .txt { display: flex; flex-direction: column; min-width: 0; }
.option .name { font-weight: 600; font-size: 15px; }
.option .meta { font-size: 13px; color: var(--muted); }
.option .tag { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.option .tag.ok { color: var(--ok); }

.primary {
  margin-top: 16px; width: 100%; height: 48px; border: 0; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent);
  font-weight: 600; font-size: 15px; transition: transform .1s, opacity .15s;
}
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .5; }

.progress { width: 100%; margin-top: 18px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }
.bar.indeterminate i { width: 35%; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.progress-meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.error { margin: 14px 0 0; font-size: 14px; color: var(--danger); }
.fine { display: flex; align-items: center; gap: 6px; margin: 22px 0 0; font-size: 13px; color: var(--muted); }
.fine svg { width: 14px; height: 14px; }

.suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.suggest button { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent; font-size: 14px; color: var(--text); }
.suggest button:hover { background: var(--surface); }

/* Messages */
#messages { max-width: 760px; margin: 0 auto; padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 22px; }
#messages:empty { display: none; }
.msg { display: flex; flex-direction: column; min-width: 0; animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg.user { align-items: flex-end; }
.msg.user .body {
  max-width: 85%; padding: 10px 15px; border-radius: 20px 20px 6px 20px; background: var(--surface-2);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .body { overflow-wrap: anywhere; }
.body p { margin: 0 0 .7em; }
.body p:last-child, .body ul:last-child, .body ol:last-child, .body pre:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: 0 0 .7em; padding-left: 1.3em; }
.body li { margin: .2em 0; }
.body h4 { margin: .9em 0 .4em; font-size: 15px; }
.body code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.body pre { margin: 0 0 .7em; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
.body pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; 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; } }
.msg-tools { display: flex; gap: 2px; margin-top: 4px; margin-left: -8px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-tools, .msg:last-child .msg-tools { opacity: 1; }
.msg-tools button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.msg-tools button:hover { background: var(--surface); color: var(--text); }
.msg-tools svg { width: 16px; height: 16px; }
.msg-meta { font-size: 12px; color: var(--muted); align-self: center; margin-left: 4px; }
.msg.error .body { color: var(--danger); }

/* Composer */
.composer { padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px); background: var(--bg); }
.composer form {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 7px 7px 7px 16px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface);
  transition: border-color .15s;
}
.composer form:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.45; padding: 7px 0; max-height: 200px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--text); color: var(--bg); flex-shrink: 0; transition: opacity .15s;
}
.send:disabled { opacity: .25; }
.send svg { width: 18px; height: 18px; stroke-width: 2.2; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.hint { max-width: 760px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* Settings sheet */
.sheet {
  width: min(420px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 18px;
  border: 1px solid var(--border); border-radius: 20px; background: var(--bg); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 18px; font-weight: 650; }
.group { margin-top: 14px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.rows { border: 1px solid var(--border); border-radius: 14px; }
.row { display: flex; justify-content: space-between; padding: 11px 14px; font-size: 14px; }
.row + .row { border-top: 1px solid var(--border); }
.row span:last-child { color: var(--muted); }
.actions { display: grid; gap: 8px; }
.actions button { height: 44px; border-radius: 12px; border: 1px solid var(--border); background: transparent; font-size: 14px; }
.actions button:hover { background: var(--surface); }
.actions .danger { color: var(--danger); }

@media (max-width: 640px) {
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 18px); }
  .sheet[open] { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(30px); opacity: .6; } }
  .center h1 { font-size: 24px; }
  .chip { padding: 5px 10px; }
  .msg.user .body { max-width: 90%; }
  .msg-tools { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
