/* WCA AI - navy + gold, dark by default, light when the OS is light. */
:root {
  --bg: #0b1426;
  --panel: #101c33;
  --panel-2: #16243f;
  --line: #22324f;
  --text: #e8edf6;
  --muted: #8d9ab3;
  --gold: #e3b64a;
  --gold-deep: #c99a2e;
  --navy: #0b1b3a;
  --user: #1d3460;
  --code: #0a111f;
  --danger: #ff6b6b;
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --panel-2: #eef1f7;
    --line: #dde3ee;
    --text: #132036;
    --muted: #5b6880;
    --user: #e5ebf7;
    --code: #0f1a2e;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------------------------------------------------------------- login */
.login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px;
}
.login-logo { border-radius: 50%; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; letter-spacing: .5px; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 16px; outline: none;
}
.login-card input:focus { border-color: var(--gold); }
.btn-primary {
  width: 100%; padding: 13px; border: 0; border-radius: 12px; background: var(--gold);
  color: #1b1405; font-weight: 700;
}
.btn-primary:disabled { opacity: .6; }

/* ------------------------------------------------------------------ app */
.app { height: 100%; display: flex; }
.drawer {
  width: 280px; flex: none; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px; }
.drawer-head img { border-radius: 50%; }
.brand { font-weight: 800; letter-spacing: .4px; flex: 1; }
.new-chat {
  display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); font-weight: 600;
}
.new-chat svg { width: 18px; height: 18px; color: var(--gold); }
.search {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  color: var(--text); font-size: 14px; outline: none;
}
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.group { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; margin: 14px 8px 4px; }
.chat-item {
  display: flex; align-items: center; width: 100%; text-align: left; border: 0; background: none;
  border-radius: 10px; padding: 9px 8px 9px 10px; font-size: 14.5px; gap: 6px;
}
.chat-item span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--gold); }
.chat-item .more { opacity: 0; padding: 2px; border: 0; background: none; color: var(--muted); }
.chat-item:hover .more, .chat-item.active .more { opacity: 1; }
.chat-item .more svg { width: 18px; height: 18px; }
.drawer-foot { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 0; border-top: 1px solid var(--line); }
.link-btn { border: 0; background: none; color: var(--muted); padding: 6px 0; font-size: 14px; text-decoration: none; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
}
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: none; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.only-mobile { display: none; }
.model-pill {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 7px 10px 7px 14px; font-weight: 700; font-size: 15px;
}
.model-pill .muted { font-weight: 500; font-size: 13.5px; }
.model-pill svg { width: 18px; height: 18px; color: var(--muted); }

.menu {
  position: absolute; z-index: 30; top: calc(max(10px, env(safe-area-inset-top)) + 52px); left: 12px;
  width: min(300px, calc(100% - 24px)); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 8px; box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}
.menu-title { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; padding: 8px 8px 4px; }
.model-opt {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none;
  border-radius: 10px; padding: 9px 10px; text-align: left;
}
.model-opt:hover { background: var(--panel-2); }
.model-opt b { font-size: 15px; }
.model-opt small { color: var(--muted); }
.model-opt.on { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--gold); }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--panel-2); border-radius: 12px; margin: 2px 4px 6px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--gold); color: #1b1405; font-weight: 700; }

/* --------------------------------------------------------------- thread */
.thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; scroll-behavior: smooth; }
.messages, .empty { max-width: 780px; margin: 0 auto; }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 9vh; }
.empty img { border-radius: 50%; }
.empty h2 { font-size: 22px; margin: 16px 0 20px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.suggest button {
  text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 14px;
  padding: 12px 14px; font-size: 14px; color: var(--muted);
}
.suggest button:hover { color: var(--text); border-color: var(--gold-deep); }

.msg { margin: 18px 0; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  max-width: 85%; background: var(--user); border-radius: var(--radius) var(--radius) 6px var(--radius);
  padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg-images img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: .85; }
.msg-actions button { border: 0; background: none; color: var(--muted); padding: 5px 6px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.msg-actions button:hover { background: var(--panel-2); color: var(--text); }
.msg-actions svg { width: 17px; height: 17px; }

.msg.ai { display: grid; grid-template-columns: 30px 1fr; gap: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; margin-top: 2px; }
.ai-body { min-width: 0; }
.thinking { margin-bottom: 8px; }
.thinking summary { cursor: pointer; color: var(--muted); font-size: 14px; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "›"; font-size: 18px; line-height: 1; transition: transform .15s; }
.thinking[open] summary::before { transform: rotate(90deg); }
.thinking .think-text { color: var(--muted); font-size: 14px; border-left: 2px solid var(--line); padding: 4px 0 4px 12px; margin: 6px 0 0 4px; white-space: pre-wrap; }
.live .thinking summary { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.sources a {
  max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12.5px;
  color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
.sources a:hover { color: var(--text); border-color: var(--gold-deep); }
.dots { display: inline-flex; gap: 4px; padding: 8px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.err-box { color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; }

/* ------------------------------------------------------------- markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.1em 0 .5em; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .8em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md a { color: var(--gold); }
.md blockquote { margin: 0 0 .8em; padding: 2px 0 2px 14px; border-left: 3px solid var(--gold-deep); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code { font: 0.88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--panel-2); padding: .15em .4em; border-radius: 6px; }
.md .codeblock { margin: 0 0 .9em; border-radius: 12px; overflow: hidden; background: var(--code); border: 1px solid var(--line); }
.md .codeblock header { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px 6px 14px; font-size: 12.5px; color: #9fb0cc; background: rgba(255, 255, 255, .04); }
.md .codeblock header button { border: 0; background: none; color: #9fb0cc; font-size: 12.5px; padding: 2px 6px; border-radius: 6px; }
.md .codeblock header button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.md pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; color: #e3e9f5; font-size: 13.5px; line-height: 1.5; }
.md .table-wrap { overflow-x: auto; margin: 0 0 .9em; }
.md table { border-collapse: collapse; font-size: 14.5px; min-width: 60%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); }

/* ------------------------------------------------------------- composer */
.composer { padding: 6px 16px max(10px, env(safe-area-inset-bottom)); }
.composer-box, .attachments, .hint { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 10px 10px 8px 16px;
}
.composer-box:focus-within { border-color: var(--gold-deep); }
#input {
  width: 100%; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; max-height: 40vh; padding: 4px 4px 6px 0;
}
.composer-row { display: flex; align-items: center; gap: 4px; margin-left: -8px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: none;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--muted);
}
.chip-btn svg { width: 17px; height: 17px; }
.chip-btn[aria-pressed="true"] { color: #1b1405; background: var(--gold); border-color: var(--gold); font-weight: 600; }
.send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--gold); color: #1b1405;
  display: grid; place-items: center;
}
.send:disabled { opacity: .4; cursor: default; }
.send .i-stop { display: none; }
.send.busy .i-send { display: none; }
.send.busy .i-stop { display: block; fill: currentColor; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.att { position: relative; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); display: block; }
.att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 14px; line-height: 22px; padding: 0; }
.hint { text-align: center; margin-top: 6px; margin-bottom: 0; }

.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px;
  pointer-events: none; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* --------------------------------------------------------------- mobile */
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .drawer {
    position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .app.drawer-open .drawer { transform: none; }
  .app.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .45); }
  .chat-item .more { opacity: 1; }
  .thread { padding: 4px 14px 20px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .suggest { grid-template-columns: 1fr; }
  .suggest button:nth-child(n+3) { display: none; }
  .bubble { max-width: 90%; }
  .msg.ai { grid-template-columns: 1fr; }
  .avatar { display: none; }
  .hint { display: none; }
}

/* ------------------------------------------------- files, code, images */
.file-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.file-row.left { justify-content: flex-start; margin: 6px 0 0; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
  font-size: 13.5px; text-decoration: none;
}
.file-chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-chip svg { width: 17px; height: 17px; color: var(--gold); }
a.file-chip:hover { border-color: var(--gold-deep); }
.att-file { height: 64px; }
.coderun { margin: 8px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.coderun summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13.5px; color: var(--muted); }
.coderun summary::-webkit-details-marker { display: none; }
.coderun summary svg { width: 17px; height: 17px; color: var(--gold); }
.coderun pre, .coderesult pre {
  margin: 0; padding: 10px 12px; overflow-x: auto; background: var(--code); color: #e3e9f5;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.coderun pre { border-radius: 0 0 12px 12px; }
.coderesult { margin: 0 0 10px; }
.coderesult pre { border-radius: 12px; border: 1px solid var(--line); max-height: 320px; overflow-y: auto; }
.coderesult pre.err { color: #ffb3b3; }
.gen-image { margin: 8px 0 12px; max-width: 520px; }
.gen-image img { display: block; width: 100%; height: auto; border-radius: 16px; border: 1px solid var(--line); background: var(--panel-2); min-height: 120px; }
.gen-image .dl { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; color: var(--muted); font-size: 13px; text-decoration: none; }
.gen-image .dl svg { width: 16px; height: 16px; }
.gen-image .dl:hover { color: var(--text); }
.msg.ai.tool { margin-top: -6px; }
.md .codeblock header .cb-actions { display: flex; gap: 2px; }
.md .codeblock header [data-preview] { color: var(--gold); font-weight: 600; }
.preview {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.md .svg-view { background: #fff; display: grid; place-items: center; padding: 12px; }
.md .svg-view img { max-width: 100%; max-height: 420px; height: auto; display: block; }
.md .svgblock details summary { cursor: pointer; padding: 8px 14px; font-size: 12.5px; color: #9fb0cc; list-style: none; }
.md .svgblock details summary::-webkit-details-marker { display: none; }
.gen-video { margin: 8px 0 12px; max-width: 560px; }
.gen-video.portrait { max-width: 300px; }
.gen-video video { display: block; width: 100%; border-radius: 16px; background: #000; border: 1px solid var(--line); }
.gen-video .dl { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; color: var(--muted); font-size: 13px; text-decoration: none; }
.gen-video .dl svg { width: 16px; height: 16px; }
.video-wait {
  display: flex; align-items: center; gap: 10px; padding: 18px 16px; border: 1px dashed var(--gold-deep);
  border-radius: 16px; color: var(--muted); font-size: 14px; background: var(--panel);
}
.video-wait svg { color: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
.video-wait.failed { border-color: var(--danger); color: var(--danger); }
.video-wait.failed svg { animation: none; color: var(--danger); }
.mic { color: var(--muted); }
.mic.on { color: #fff; background: #e5484d; animation: micpulse 1.2s ease-in-out infinite; }
.mic.unsupported { opacity: .4; }
@keyframes micpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .5); } 50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); } }
#voiceBtn.speaking svg { animation: pulse 1s ease-in-out infinite; }
@media (max-width: 420px) {
  .composer-box { padding-right: 6px; }
  .composer-row { gap: 3px; margin-left: -10px; }
  .composer-row .icon-btn { width: 34px; height: 34px; }
  .send { width: 38px; height: 38px; }
  .chip-btn { padding: 5px 8px; font-size: 13px; gap: 4px; }
  .chip-btn svg { width: 15px; height: 15px; }
}
