/* ================= AiLuna — pearl & liquid glass ================= */
:root {
  --fs: 16px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Sora", "Onest", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --r-xl: 28px; --r-lg: 22px; --r-md: 16px; --r-sm: 12px;
  --blur: 28px;

  --bg-0: #03050d; --bg-1: #08172a; --bg-2: #140b28;
  --text: #eaf1ff; --dim: #9eabca; --faint: #66729a;
  --glass: rgba(255, 255, 255, .05);
  --glass-2: rgba(255, 255, 255, .085);
  --glass-3: rgba(255, 255, 255, .13);
  --line: rgba(255, 255, 255, .12);
  --hi: rgba(255, 255, 255, .26);
  --shadow: 0 16px 48px rgba(0, 2, 14, .55);
  --code-bg: rgba(2, 5, 16, .78);
  --ok: #6ff0c0; --err: #ff8c9c; --warn: #ffd58c;
  --acc: #74f0dc; --acc-2: #3aa8f5; --acc-ink: #03141a;
  --pearl: #f4f2ff;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg-0: #e6ecf6; --bg-1: #f3f7ff; --bg-2: #efe9fb;
  --text: #0f1730; --dim: #4f5b7c; --faint: #8891ad;
  --glass: rgba(255, 255, 255, .55);
  --glass-2: rgba(255, 255, 255, .72);
  --glass-3: rgba(255, 255, 255, .88);
  --line: rgba(255, 255, 255, .92);
  --hi: rgba(255, 255, 255, 1);
  --shadow: 0 16px 40px rgba(30, 50, 110, .14);
  --code-bg: rgba(14, 22, 48, .92);
  --ok: #0c9b6c; --err: #d43a56; --warn: #a76a00;
  --acc-ink: #ffffff;
  color-scheme: light;
}
:root[data-accent="aqua"]  { --acc: #74f0dc; --acc-2: #3aa8f5; }
:root[data-accent="iris"]  { --acc: #b8a6ff; --acc-2: #7a5cff; }
:root[data-accent="solar"] { --acc: #ffd27a; --acc-2: #ff8a4c; }
:root[data-accent="rose"]  { --acc: #ffa8cf; --acc-2: #f2559a; }
:root[data-accent="pearl"] { --acc: #f2f4ff; --acc-2: #a9b4d6; }
:root[data-theme="light"][data-accent="aqua"]  { --acc: #0fb8a0; --acc-2: #1877d6; }
:root[data-theme="light"][data-accent="iris"]  { --acc: #7c62f5; --acc-2: #5638db; }
:root[data-theme="light"][data-accent="solar"] { --acc: #f09a1a; --acc-2: #d9541a; }
:root[data-theme="light"][data-accent="rose"]  { --acc: #e7508f; --acc-2: #b92e6c; }
:root[data-theme="light"][data-accent="pearl"] { --acc: #5d6b92; --acc-2: #2f3a5c; }
:root[data-accent="pearl"] { --acc-ink: #0b1020; }
:root[data-theme="light"][data-accent="pearl"] { --acc-ink: #ffffff; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: var(--font); font-size: var(--fs); line-height: 1.6; color: var(--text);
  background:
    radial-gradient(1000px 560px at 85% -10%, color-mix(in srgb, var(--acc-2) 20%, transparent), transparent 70%),
    radial-gradient(800px 500px at -10% 110%, color-mix(in srgb, #7a5cff 18%, transparent), transparent 70%),
    linear-gradient(165deg, var(--bg-1), var(--bg-0) 55%, var(--bg-2));
  overflow: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--acc); }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 10px; }
::selection { background: color-mix(in srgb, var(--acc) 38%, transparent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--glass-3); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
.wordmark { font-family: var(--display); font-weight: 600; letter-spacing: -.02em; }

/* ---------- Sky ---------- */
.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.sky::before {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image:
    radial-gradient(1px 1px at 30px 40px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 170px 120px, #fff 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 260px 30px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 330px 190px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90px 250px, #fff 50%, transparent 51%);
  background-size: 360px 300px;
  mask-image: linear-gradient(to bottom, #000, transparent 70%);
}
:root[data-theme="light"] .sky::before { display: none; }
.sky i { position: absolute; border-radius: 50%; filter: blur(100px); opacity: .32; animation: drift 42s ease-in-out infinite alternate; }
.sky .b1 { width: 44vmax; height: 44vmax; left: -14vmax; top: 35%; background: var(--acc-2); }
.sky .b2 { width: 34vmax; height: 34vmax; right: -10vmax; top: -12vmax; background: #7a5cff; opacity: .24; animation-delay: -14s; }
.sky .b3 { width: 26vmax; height: 26vmax; right: 22%; bottom: -12vmax; background: var(--acc); opacity: .14; animation-delay: -26s; }
:root[data-theme="light"] .sky i { opacity: .22; }
@keyframes drift { to { transform: translate(6vmax, -4vmax) scale(1.1); } }
.no-motion .sky i { animation: none; }
@media (prefers-reduced-motion: reduce) { .sky i { animation: none; } }

/* ---------- Glass ---------- */
.glass {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 -1px 0 rgba(0, 0, 0, .14), var(--shadow);
  position: relative;
}
.liquid { position: relative; isolation: isolate; }
.liquid::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(200px circle at var(--mx, 30%) var(--my, -40%), rgba(255, 255, 255, .16), transparent 65%);
}
.liquid::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: linear-gradient(180deg, rgba(255, 255, 255, .1), transparent 40%);
}
.no-liquid .liquid::before, .no-liquid .liquid::after { display: none; }
.press { transition: transform .35s var(--spring), background .2s, color .2s, opacity .2s; }
.press:active { transform: scale(.94); }

/* ---------- Orb (logo + progress) ---------- */
.orb { display: block; overflow: visible; }
.orb .ring-bg { fill: none; stroke: color-mix(in srgb, var(--acc) 22%, transparent); }
.orb .ring { fill: none; transition: stroke-dashoffset .6s var(--ease); }
.orb-spin { animation: spin 2.4s linear infinite; transform-origin: 50% 50%; transform-box: fill-box; }
@keyframes spin { to { transform: rotate(360deg); } }
.no-motion .orb-spin { animation-duration: 0s; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 20px; }
.login canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.login-card {
  position: relative; z-index: 1; width: min(400px, 100%); border-radius: 30px; padding: 30px 26px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; margin-top: 42vh;
  animation: cardIn 1s .5s var(--ease) both;
}
:root[data-theme="dark"] .login-card { background: rgba(10, 16, 34, .38); }
@keyframes cardIn { from { opacity: 0; transform: translateY(24px) scale(.98); } }
@media (max-height: 700px) { .login-card { margin-top: 34vh; } }
.login-brand { display: flex; align-items: center; gap: 12px; font-size: 30px; }
.login-brand .orb { width: 40px; height: 40px; }
.login-lead { color: var(--dim); font-size: 15.5px; }
.gbtn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 18px; border-radius: 99px;
  background: #fff; color: #1f1f1f; font-weight: 600; font-size: 15.5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3), inset 0 -2px 0 rgba(0, 0, 0, .06);
}
.gbtn svg { width: 22px; height: 22px; }
.gbtn:hover { filter: brightness(.97); }
.gbtn:disabled { opacity: .6; cursor: default; }
.login-status { font-size: 13.5px; color: var(--dim); min-height: 1.2em; line-height: 1.45; }
.login-status.err { color: var(--err); }

/* ---------- Install bar ---------- */
:root { --ib: 0px; }
.has-install { --ib: calc(56px + env(safe-area-inset-top)); }
.installbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60; height: var(--ib);
  padding: env(safe-area-inset-top) 10px 0 14px; display: flex; align-items: center; gap: 12px;
  background: rgba(8, 14, 32, .82); backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
  animation: ibIn .5s var(--ease) both;
}
:root[data-theme="light"] .installbar { background: rgba(255, 255, 255, .86); }
@keyframes ibIn { from { transform: translateY(-100%); } }
.installbar img { border-radius: 8px; flex-shrink: 0; }
.installbar .ib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; white-space: nowrap; overflow: hidden; }
.installbar .ib-text b { font-family: var(--display); font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; }
.installbar .ib-text small { color: var(--dim); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.installbar .icon-btn { width: 34px; height: 34px; }
.has-install .app { height: calc(100dvh - var(--ib)); margin-top: var(--ib); }
.has-install .login, .has-install .setup { top: var(--ib); }
@media (max-width: 899px) { .has-install .side { top: calc(var(--ib) + 8px); } }
.steps-list { display: flex; flex-direction: column; gap: 12px; margin: 6px 0 18px; padding: 0; list-style: none; counter-reset: s; }
.steps-list li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.5; font-size: 15px; }
.steps-list li::before { counter-increment: s; content: counter(s); flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--acc-ink); background: linear-gradient(140deg, var(--acc), var(--acc-2)); }

/* ---------- Setup ---------- */
.setup { position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; padding: 20px; }
.setup h2 { font-family: var(--display); font-size: 20px; margin-bottom: 10px; }
.setup p { color: var(--dim); line-height: 1.6; }

/* ---------- Layout ---------- */
.app { position: relative; z-index: 1; display: flex; height: 100dvh; }
.side {
  width: 292px; flex-shrink: 0; margin: 10px 0 10px 10px; border-radius: var(--r-xl);
  display: flex; flex-direction: column; gap: 8px; padding: 14px 12px 12px; overflow: hidden;
  transition: width .45s var(--ease), padding .45s var(--ease), transform .45s var(--ease);
}
:root[data-theme="dark"] .side { background: rgba(255, 255, 255, .04); }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 6px; min-height: 42px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; padding: 4px; border-radius: 12px; white-space: nowrap; }
.brand .orb { width: 30px; height: 30px; }
.new-chat {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--r-md);
  background: var(--glass-2); border: 1px solid var(--line); font-weight: 500; white-space: nowrap;
}
.new-chat:hover { background: var(--glass-3); }
.search { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--r-sm); color: var(--faint); cursor: text; }
.search:focus-within { background: var(--glass); color: var(--dim); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); font-size: 14px; }
.search input::placeholder { color: var(--faint); }
.history { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 2px 6px; }
.history .group { font-size: 12px; color: var(--faint); padding: 14px 10px 4px; font-weight: 500; }
.hitem {
  display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 10px; border-radius: var(--r-sm);
  font-size: 14.5px; color: var(--dim); cursor: pointer; transition: background .2s, color .2s;
}
.hitem:hover { background: var(--glass); color: var(--text); }
.hitem.on { background: var(--glass-2); color: var(--text); box-shadow: inset 0 1px 0 var(--hi); }
.hitem .ht { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem .pin { width: 14px; height: 14px; color: var(--acc); }
.hitem input { flex: 1; min-width: 0; background: var(--glass-2); border: 1px solid var(--acc); border-radius: 8px; padding: 2px 8px; outline: none; }
.hmore { opacity: 0; padding: 4px; border-radius: 8px; color: var(--dim); display: grid; place-items: center; }
.hitem:hover .hmore, .hitem.on .hmore { opacity: 1; }
.hmore:hover { background: var(--glass-2); color: var(--text); }
@media (pointer: coarse) { .hmore { opacity: .8; } }
.side-bottom { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.admin-btn, .install-btn { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-sm); font-weight: 500; font-size: 14.5px; white-space: nowrap; }
.admin-btn { color: var(--acc); }
.admin-btn:hover, .install-btn:hover { background: var(--glass-2); }
.profile { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 8px; border-radius: var(--r-md); text-align: left; width: 100%; }
.profile:hover { background: var(--glass-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; background: linear-gradient(140deg, var(--acc), var(--acc-2)); color: var(--acc-ink); display: grid; place-items: center; font-weight: 600; font-size: 14px; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.pname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; font-size: 14.5px; }
.profile svg { color: var(--faint); }

/* rail (yig'ilgan menyu) */
@media (min-width: 900px) {
  .app.rail .side { width: 74px; padding: 14px 10px 12px; }
  .app.rail .side .wordmark, .app.rail .side .new-chat span, .app.rail .side .search input, .app.rail .side .history,
  .app.rail .side .pname, .app.rail .side .profile > svg, .app.rail .side .admin-btn span, .app.rail .side .install-btn span { display: none; }
  .app.rail .side-top { flex-direction: column; gap: 8px; }
  .app.rail .new-chat, .app.rail .search, .app.rail .admin-btn, .app.rail .install-btn { justify-content: center; padding: 11px 0; }
  .app.rail .search { cursor: pointer; }
  .app.rail .side-bottom { margin-top: auto; }
  .app.rail .profile { justify-content: center; padding: 8px 0; }
}

.scrim { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.top { display: flex; align-items: center; gap: 6px; padding: 10px 14px 4px; min-height: 58px; }
.top-title { flex: 1; min-width: 0; font-weight: 500; font-size: 15px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--dim); flex-shrink: 0; }
.icon-btn:hover { background: var(--glass-2); color: var(--text); }
@media (min-width: 900px) { #menuBtn { display: none; } }

.chat { flex: 1; overflow-y: auto; padding: 8px 16px 28px; }
.col { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }

@media (max-width: 899px) {
  .side { position: fixed; z-index: 40; inset: 8px auto 8px 8px; margin: 0; width: min(86vw, 330px); transform: translateX(-115%); }
  :root[data-theme="dark"] .side { background: rgba(12, 18, 38, .72); }
  :root[data-theme="light"] .side { background: rgba(255, 255, 255, .8); }
  .app.side-open .side { transform: none; }
  #sideToggle { display: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(2, 4, 16, .45); opacity: 0; pointer-events: none; transition: opacity .3s; }
  .app.side-open .scrim { opacity: 1; pointer-events: auto; }
  .chat { padding: 4px 12px 24px; }
}

/* ---------- Welcome ---------- */
.welcome { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 20px; padding: 20px 4px 40px; max-width: 720px; margin: 0 auto; }
.hero-orb { width: 120px; height: 120px; filter: drop-shadow(0 0 40px color-mix(in srgb, var(--acc) 40%, transparent)); }
.welcome h1 { font-family: var(--display); font-weight: 300; font-size: clamp(30px, 5.4vw, 46px); line-height: 1.12; letter-spacing: -.03em; }
.welcome p.sub { color: var(--dim); max-width: 44ch; }
.notice { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r-lg); text-align: left; max-width: 520px; width: 100%; }
.notice .n-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--acc) 18%, transparent); color: var(--acc); flex-shrink: 0; }
.notice div { flex: 1; font-size: 14.5px; color: var(--dim); line-height: 1.45; }
.notice b { color: var(--text); font-weight: 600; display: block; }
.sugg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 600px; }
.sugg button { text-align: left; padding: 14px 16px; border-radius: var(--r-lg); font-size: 14.5px; line-height: 1.4; display: flex; gap: 12px; align-items: flex-start; }
.sugg button svg { color: var(--acc); margin-top: 1px; }
.sugg button:hover { background: var(--glass-2); }
@media (max-width: 520px) { .sugg { grid-template-columns: 1fr; } .hero-orb { width: 96px; height: 96px; } }

/* ---------- Messages ---------- */
.msg { display: flex; flex-direction: column; gap: 6px; animation: rise .35s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.no-motion .msg { animation: none; }
.msg.user { align-self: flex-end; align-items: flex-end; max-width: min(84%, 640px); }
.msg.user .bubble {
  padding: 10px 15px; border-radius: 22px 22px 6px 22px; white-space: pre-wrap; word-wrap: break-word;
  background: color-mix(in srgb, var(--acc-2) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--acc) 30%, transparent);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2);
}
.msg.user .bubble:empty { display: none; }
.ugal { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.ugal img { max-width: 220px; max-height: 220px; border-radius: 16px; display: block; object-fit: cover; border: 1px solid var(--line); cursor: zoom-in; background: var(--glass); }
.fchip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 14px; font-size: 13.5px; max-width: 280px; }
.fchip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fchip svg { color: var(--acc); width: 18px; height: 18px; }
.msg.ai { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 14px; }
.msg.ai > .av .orb { width: 30px; height: 30px; margin-top: 2px; }
.msg.ai .body { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 14.5px; flex-wrap: wrap; }
.thinking .lbl { background: linear-gradient(90deg, var(--dim), var(--text), var(--dim)); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shine 2.2s linear infinite; }
@keyframes shine { to { background-position: -200% 0; } }
.no-motion .thinking .lbl { animation: none; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; padding: 4px 10px; border-radius: 99px; background: var(--glass); border: 1px solid var(--line); color: var(--dim); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.ok { color: var(--ok); } .chip.err { color: var(--err); }
.chip svg { width: 14px; height: 14px; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.note { font-size: 13px; color: var(--warn); }
.errbox { color: var(--err); font-size: 14.5px; padding: 10px 14px; border-radius: var(--r-md); background: color-mix(in srgb, var(--err) 10%, transparent); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); }
.errbox button { color: var(--text); text-decoration: underline; margin-left: 6px; }
.caret { display: inline-block; width: 9px; height: 1.05em; margin-left: 2px; vertical-align: -3px; border-radius: 3px; background: var(--acc); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.mfoot { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; color: var(--faint); font-size: 12.5px; }
.mfoot .meta { display: flex; gap: 10px; margin-left: 8px; }
.act { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: var(--faint); }
.act svg { width: 17px; height: 17px; }
.act:hover { background: var(--glass-2); color: var(--text); }
.act.on { color: var(--acc); }
.msg.user .mfoot { opacity: 0; transition: opacity .2s; }
.msg.user:hover .mfoot { opacity: 1; }
@media (pointer: coarse) { .msg.user .mfoot { opacity: 1; } }

/* ---------- Markdown ---------- */
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md > * + * { margin-top: .75em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--display); line-height: 1.3; letter-spacing: -.015em; font-weight: 600; margin-top: 1.2em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; } .md h4 { font-size: 1em; }
.md > :first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md li + li { margin-top: .3em; }
.md li::marker { color: var(--acc); }
.md a { color: var(--acc); text-underline-offset: 3px; }
.md strong { font-weight: 600; }
.md blockquote { border-left: 3px solid var(--acc); padding: 2px 0 2px 14px; color: var(--dim); }
.md hr { border: 0; height: 1px; background: var(--line); }
.md :not(pre) > code { font-family: var(--mono); font-size: .86em; padding: 2px 6px; border-radius: 6px; background: var(--glass-2); border: 1px solid var(--line); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .93em; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; }
.md th { background: var(--glass); font-weight: 600; }
.md img { max-width: 100%; border-radius: 14px; }
.codebox { border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); background: var(--code-bg); position: relative; }
.code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; font-size: 12.5px; color: #a9b3d2; background: rgba(255, 255, 255, .04); border-bottom: 1px solid rgba(255, 255, 255, .07); }
.code-bar div { display: flex; gap: 4px; }
.code-bar button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 9px; color: #c9d0ea; font-size: 12.5px; }
.code-bar button svg { width: 15px; height: 15px; }
.code-bar button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.code-bar button.run { color: var(--acc); }
.codebox pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13.2px; line-height: 1.6; color: #e3e8f7; }
.codebox pre code { font-family: inherit; background: none !important; padding: 0 !important; }
.codebox.folded pre { max-height: 220px; overflow: hidden; }
.codebox .unfold { display: none; }
.codebox.folded .unfold { display: flex; position: absolute; left: 0; right: 0; bottom: 0; height: 90px; align-items: flex-end; justify-content: center; padding-bottom: 12px; background: linear-gradient(transparent, var(--code-bg) 70%); }
.unfold button { padding: 7px 16px; border-radius: 99px; background: rgba(255, 255, 255, .1); color: #fff; font-size: 13px; border: 1px solid rgba(255, 255, 255, .14); }
.project { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 14px; border-radius: var(--r-lg); }
.project .pj-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; color: var(--acc-ink); background: linear-gradient(140deg, var(--acc), var(--acc-2)); box-shadow: 0 8px 22px color-mix(in srgb, var(--acc-2) 40%, transparent); }
.project .pj-tx { flex: 1 1 170px; min-width: 0; }
.project .pj-tx b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project .pj-tx small { color: var(--dim); font-size: 13px; }
.project .btns { display: flex; gap: 8px; }
@media (max-width: 520px) { .project .btns { width: 100%; } .project .btns .btn { flex: 1; } }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 99px; font-weight: 500; font-size: 14.5px;
  background: var(--glass-2); border: 1px solid var(--line); white-space: nowrap;
}
.btn:hover { background: var(--glass-3); }
.btn.pri { background: linear-gradient(140deg, var(--acc), var(--acc-2)); color: var(--acc-ink); border-color: transparent; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 8px 24px color-mix(in srgb, var(--acc-2) 35%, transparent); }
.btn.pri:hover { filter: brightness(1.06); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .5; cursor: default; }
.gen-img { display: grid; gap: 10px; }
.gen-img figure { position: relative; border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line); max-width: 520px; }
.gen-img img { display: block; width: 100%; cursor: zoom-in; }
.gen-img figcaption { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.gen-img figcaption .act { background: rgba(6, 10, 26, .55); color: #fff; backdrop-filter: blur(10px); }

/* council */
.council { border-radius: var(--r-md); background: var(--glass); border: 1px solid var(--line); overflow: hidden; }
.council > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; font-size: 14px; color: var(--dim); }
.council > summary::-webkit-details-marker { display: none; }
.council > summary .orb { width: 20px; height: 20px; }
.council > summary .grow { flex: 1; }
.council > summary .chev { transition: transform .3s var(--ease); width: 16px; height: 16px; }
.council[open] > summary .chev { transform: rotate(90deg); }
.medals { display: flex; gap: 6px; flex-wrap: wrap; }
.medals span { font-size: 12.5px; padding: 3px 9px; border-radius: 99px; background: var(--glass-2); color: var(--text); }
.c-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { font-size: 13px; padding: 6px 12px; border-radius: 99px; background: var(--glass); border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.tabs button.on { background: var(--glass-3); color: var(--text); }
.tabs button.err { color: var(--err); }
.c-pane { font-size: 14.5px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.c-legend { font-size: 12.5px; color: var(--faint); }

/* ---------- Composer ---------- */
.composer-wrap { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 12px calc(8px + env(safe-area-inset-bottom)); position: relative; }
.composer { container-type: inline-size; border-radius: var(--r-xl); padding: 8px; display: flex; flex-direction: column; gap: 4px; transition: box-shadow .3s, border-color .3s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--acc) 45%, var(--line)); box-shadow: inset 0 1px 0 var(--hi), 0 0 0 4px color-mix(in srgb, var(--acc) 12%, transparent), var(--shadow); }
.composer textarea { width: 100%; background: none; border: 0; outline: none; resize: none; padding: 8px 10px 4px; max-height: 220px; line-height: 1.5; }
.composer textarea::placeholder { color: var(--faint); }
.tools { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tools-l, .tools-r { display: flex; align-items: center; gap: 4px; }
.tools .icon-btn { width: 36px; height: 36px; }
.send { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--acc-ink); background: linear-gradient(140deg, var(--acc), var(--acc-2)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), 0 6px 18px color-mix(in srgb, var(--acc-2) 45%, transparent); }
.send:disabled { opacity: .35; cursor: default; box-shadow: none; }
.send.stop { background: var(--text); color: var(--bg-0); }
.mic.rec { color: var(--err); background: color-mix(in srgb, var(--err) 14%, transparent); animation: pulse 1.2s infinite; }
.seg { position: relative; display: flex; background: var(--glass); border: 1px solid var(--line); border-radius: 99px; padding: 3px; margin-left: 4px; }
.seg .pill { position: absolute; top: 3px; bottom: 3px; left: 3px; border-radius: 99px; background: var(--glass-3); box-shadow: inset 0 1px 0 var(--hi), 0 2px 10px rgba(0, 0, 0, .18); transition: left .45s var(--spring), width .45s var(--spring); }
.seg button { position: relative; z-index: 1; display: flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 99px; font-size: 13.5px; color: var(--dim); transition: color .2s; }
.seg button svg { width: 16px; height: 16px; }
.seg button.on { color: var(--text); }
@container (max-width: 520px) {
  .seg button:not(.on) span { display: none; }
  .seg button { padding: 5px 9px; }
  .tools .icon-btn { width: 33px; height: 33px; }
  .tools-l, .tools-r { gap: 2px; }
}
.atts { display: flex; gap: 8px; overflow-x: auto; padding: 4px 4px 2px; }
.atts:empty { display: none; }
.att { position: relative; flex-shrink: 0; height: 64px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass-2); display: flex; align-items: center; gap: 8px; padding: 0 28px 0 10px; font-size: 13px; max-width: 230px; }
.att.media { width: 64px; padding: 0; overflow: hidden; }
.att.media img { width: 100%; height: 100%; object-fit: cover; }
.att .an { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.att .an span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att .an small { color: var(--faint); font-size: 11.5px; }
.att svg.i { color: var(--acc); }
.att .rm { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(4, 8, 24, .7); color: #fff; display: grid; place-items: center; }
.att .rm svg { width: 12px; height: 12px; stroke-width: 2.4; }
.att.loading::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .12), transparent); animation: shine 1.2s linear infinite; background-size: 200% 100%; }
.hint { text-align: center; font-size: 12px; color: var(--faint); padding-top: 6px; min-height: 1.4em; }
.hint:empty { padding-top: 2px; min-height: 0; }

.pop { position: fixed; z-index: 95; min-width: 220px; border-radius: var(--r-lg); padding: 6px; display: flex; flex-direction: column; animation: popin .28s var(--spring); }
:root[data-theme="dark"] .pop { background: rgba(18, 26, 56, .78); }
:root[data-theme="light"] .pop { background: rgba(255, 255, 255, .9); }
@keyframes popin { from { opacity: 0; transform: scale(.94) translateY(6px); } }
.pop button { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; text-align: left; font-size: 14.5px; }
.pop button:hover { background: var(--glass-3); }
.pop button svg { color: var(--dim); }
.pop button.danger, .pop button.danger svg { color: var(--err); }
.pop .pop-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; color: var(--dim); line-height: 1.4; }
.pop .pop-head b { display: block; color: var(--text); font-size: 14.5px; }

.drop { position: absolute; inset: 10px; z-index: 50; border-radius: var(--r-xl); border: 2px dashed var(--acc); background: color-mix(in srgb, var(--acc) 12%, rgba(4, 8, 28, .6)); display: none; place-items: center; font-size: 18px; font-weight: 500; backdrop-filter: blur(8px); pointer-events: none; }
.drop.on { display: grid; }

/* ---------- Preview ---------- */
.preview { width: 0; flex-shrink: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: var(--r-xl); margin: 10px 10px 10px 0; opacity: 0; border-width: 0; transition: width .5s var(--ease), opacity .3s; }
.app.pv .preview { width: min(50vw, 820px); opacity: 1; border-width: 1px; margin-left: 10px; }
@media (min-width: 1100px) and (max-width: 1499px) { .app.pv .side { width: 74px; padding: 14px 10px 12px; } .app.pv .side .history, .app.pv .side .wordmark, .app.pv .side .new-chat span, .app.pv .side .search input, .app.pv .side .pname, .app.pv .side .profile > svg, .app.pv .side .admin-btn span { display: none; } }
.pv-top { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.pv-top b { flex: 1; min-width: 0; font-weight: 500; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }
@media (max-width: 1099px) {
  .preview { position: fixed; z-index: 70; inset: 0; margin: 0; border-radius: 0; width: 100% !important; transform: translateY(100%); transition: transform .5s var(--ease), opacity .3s; background: color-mix(in srgb, var(--bg-0) 96%, transparent); }
  .app.pv .preview { transform: none; margin: 0; }
  .pv-top { padding-top: calc(8px + env(safe-area-inset-top)); }
}

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgba(2, 4, 16, .5); backdrop-filter: blur(6px); animation: fade .25s; }
:root[data-theme="light"] .modal { background: rgba(50, 60, 110, .2); }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 660px; max-height: min(90dvh, 900px); border-radius: var(--r-xl); display: flex; flex-direction: column; overflow: hidden; animation: popin .35s var(--spring); }
:root[data-theme="dark"] .sheet { background: rgba(14, 22, 48, .78); }
:root[data-theme="light"] .sheet { background: rgba(255, 255, 255, .84); }
.sheet.wide { max-width: 920px; }
.sheet-top { display: flex; align-items: center; gap: 8px; padding: 14px 12px 10px 22px; border-bottom: 1px solid var(--line); }
.sheet-top h2 { flex: 1; font-family: var(--display); font-size: 19px; font-weight: 600; letter-spacing: -.015em; display: flex; align-items: center; gap: 10px; }
.sheet-top h2 svg { color: var(--acc); }
.sheet-body { overflow-y: auto; padding: 8px 22px 26px; }
.sheet-foot { padding: 12px 22px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.sheet-foot .status { margin: 0 auto 0 0; }
.sheet.small { max-width: 420px; }
.sheet.small .sheet-body { padding: 20px 22px 22px; }
@media (max-width: 600px) {
  .modal.bottom { place-items: end center; padding: 0; }
  .modal.bottom .sheet { max-height: 94dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; }
}
.atabs { display: flex; gap: 6px; padding: 10px 22px 4px; overflow-x: auto; scrollbar-width: none; }
.atabs::-webkit-scrollbar { display: none; }
.atabs button { padding: 8px 14px; border-radius: 99px; font-size: 14px; color: var(--dim); border: 1px solid transparent; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.atabs button svg { width: 17px; height: 17px; }
.atabs button.on { background: var(--glass-3); color: var(--text); border-color: var(--line); box-shadow: inset 0 1px 0 var(--hi); }
.sec { padding: 18px 0 6px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h3 { font-family: var(--display); font-size: 15.5px; font-weight: 600; margin-bottom: 4px; letter-spacing: -.01em; }
.sec > p { color: var(--dim); font-size: 13.5px; margin-bottom: 12px; line-height: 1.5; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.row > label, .row > .lab { flex: 1; font-size: 14.5px; }
.row > label small, .row > .lab small { display: block; color: var(--faint); font-size: 12.5px; line-height: 1.4; }
.field { width: 100%; padding: 10px 14px; border-radius: var(--r-sm); background: var(--glass); border: 1px solid var(--line); outline: none; font-size: 14.5px; }
.field:focus { border-color: var(--acc); }
.field.mono { font-family: var(--mono); font-size: 13px; }
textarea.field { resize: vertical; min-height: 84px; line-height: 1.5; }
select.field { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select.field option { background: #121a3a; color: #eaf1ff; }
:root[data-theme="light"] select.field option { background: #fff; color: #0f1730; }
.status { font-size: 13px; min-height: 1em; color: var(--dim); }
.status.ok { color: var(--ok); } .status.err { color: var(--err); }
.sw { position: relative; width: 46px; height: 28px; flex-shrink: 0; }
.sw input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.sw span { position: absolute; inset: 0; border-radius: 99px; background: var(--glass-3); border: 1px solid var(--line); transition: background .25s; }
.sw span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); transition: transform .4s var(--spring); }
.sw input:checked + span { background: linear-gradient(140deg, var(--acc), var(--acc-2)); }
.sw input:checked + span::after { transform: translateX(18px); }
.sw input:focus-visible + span { outline: 2px solid var(--acc); outline-offset: 2px; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; }
.opts button { padding: 7px 14px; border-radius: 99px; background: var(--glass); border: 1px solid var(--line); font-size: 13.5px; color: var(--dim); }
.opts button.on { background: var(--glass-3); color: var(--text); box-shadow: inset 0 1px 0 var(--hi); }
.swatches { display: flex; gap: 10px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5); }
.swatches button.on { border-color: var(--text); }
.range { width: 140px; accent-color: var(--acc); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0; }
.ver { color: var(--faint); font-size: 12.5px; padding-top: 16px; }
.me-card { display: flex; align-items: center; gap: 14px; padding: 16px 0 6px; }
.me-card .avatar { width: 52px; height: 52px; font-size: 20px; }
.me-card b { display: block; font-size: 16px; }
.me-card small { color: var(--dim); font-size: 13.5px; }

/* admin */
.pcard { border-radius: var(--r-md); border: 1px solid var(--line); background: var(--glass); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 10px; padding: 12px 0; }
.pcard-top { display: flex; align-items: center; gap: 10px; }
.pcard-top b { flex: 1; font-weight: 600; font-size: 14.5px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--glass-2); color: var(--faint); white-space: nowrap; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.pcard .krow { display: flex; gap: 8px; }
.pcard .krow .field { flex: 1; font-family: var(--mono); font-size: 13px; padding: 9px 12px; }
.pcard .acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pcard .acts a { font-size: 13px; margin-left: auto; }
.pcard .status { font-size: 12.5px; }
.mlist { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }
.mrow { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) auto; gap: 8px; align-items: center; padding: 10px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--glass); }
.mrow .field { padding: 8px 10px; font-size: 13.5px; }
.mrow .mid { font-family: var(--mono); font-size: 12.5px; }
.mrow .nokey { grid-column: 2 / -1; font-size: 12px; color: var(--warn); margin-top: -2px; }
@media (max-width: 640px) { .mrow { grid-template-columns: auto 1fr auto; } .mrow .prov, .mrow .mid { grid-column: 2 / 4; } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px 0 4px; }
.stat { border-radius: var(--r-md); border: 1px solid var(--line); background: var(--glass); padding: 12px 14px; }
.stat b { display: block; font-family: var(--display); font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.stat small { color: var(--dim); font-size: 12.5px; }
.ulist { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; }
.urow { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); background: var(--glass); border: 1px solid var(--line); }
.urow .avatar { width: 36px; height: 36px; }
.urow .ui { flex: 1; min-width: 0; line-height: 1.35; }
.urow .ui b { display: block; font-weight: 500; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.urow .ui small { color: var(--faint); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.urow .uc { text-align: right; font-size: 12.5px; color: var(--dim); white-space: nowrap; }
.urow .uc b { display: block; color: var(--text); font-size: 14px; }
.urow.blocked { opacity: .55; }

/* camera, lightbox, toasts */
.cam { width: 100%; max-width: 560px; border-radius: var(--r-xl); overflow: hidden; display: flex; flex-direction: column; background: #000; }
.cam video { width: 100%; max-height: 70dvh; object-fit: cover; background: #000; display: block; }
.cam-bar { display: flex; align-items: center; justify-content: space-around; padding: 14px; background: rgba(6, 10, 26, .8); }
.cam-bar .icon-btn { color: #fff; }
.shutter { width: 66px; height: 66px; border-radius: 50%; border: 4px solid #fff; background: rgba(255, 255, 255, .25); }
.shutter:active { background: #fff; }
.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(1, 2, 10, .92); display: grid; place-items: center; padding: 20px; animation: fade .2s; }
.lightbox img { max-width: 100%; max-height: 86dvh; border-radius: 14px; }
.lightbox .lb-bar { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; display: flex; gap: 6px; }
.lightbox .icon-btn { color: #fff; background: rgba(255, 255, 255, .1); }
.toasts { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { padding: 10px 18px; border-radius: 99px; font-size: 14px; animation: popin .3s var(--spring); pointer-events: auto; text-align: center; }
:root[data-theme="dark"] .toast { background: rgba(20, 30, 64, .86); }
.toast.err { color: var(--err); }
.toast.ok { color: var(--ok); }
@media (max-height: 640px) { .hint { display: none; } }
