:root {
  color-scheme: dark;
  --bg: #090b0f;
  --panel: rgba(17, 20, 28, .82);
  --panel-2: rgba(27, 31, 42, .72);
  --border: rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.15);
  --text: #f7f8fb;
  --muted: #9aa2b2;
  --accent: #8b7cff;
  --accent-2: #4fd4ff;
  --good: #4ce0a1;
  --danger: #ff6b7a;
  --shadow: 0 22px 65px rgba(0,0,0,.34);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% -20%, rgba(88,74,255,.22), transparent 36%),
    radial-gradient(circle at 100% 0%, rgba(60,203,255,.12), transparent 26%),
    var(--bg);
}
button, textarea, input, select { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.app-header {
  position: sticky; top: 0; z-index: 20;
  min-height: 72px; padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(9,11,15,.95), rgba(9,11,15,.72));
  backdrop-filter: blur(18px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand-mark { width: 39px; height: 39px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(135deg, rgba(139,124,255,.25), rgba(79,212,255,.16)); border: 1px solid rgba(139,124,255,.32); box-shadow: inset 0 0 30px rgba(139,124,255,.12); }
.brand-mark svg { width: 23px; fill: #bcb4ff; }
.brand-title { font-weight: 720; letter-spacing: -.02em; }
.brand-subtitle { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--muted); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px rgba(76,224,161,.65); }
.status-dot.offline { background: var(--danger); box-shadow: none; }
.header-actions { display: flex; align-items: center; gap: 7px; }
.icon-btn { position: relative; width: 40px; height: 40px; border-radius: 12px; border: 1px solid transparent; background: transparent; display: grid; place-items: center; cursor: pointer; transition: .18s ease; }
.icon-btn:hover { background: rgba(255,255,255,.055); border-color: var(--border); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; opacity: .86; }
.key-btn { background: rgba(255,255,255,.045); border-color: var(--border); }
.key-state-dot { position: absolute; width: 8px; height: 8px; border-radius: 50%; right: 6px; bottom: 6px; background: #666d7d; border: 2px solid #11141b; }
.key-state-dot.ready { background: var(--good); }
.hidden { display: none !important; }

.chat { width: min(920px, 100%); margin: 0 auto; padding: 34px 18px 210px; }
.welcome { min-height: calc(100dvh - 330px); display: grid; place-items: center; align-content: center; text-align: center; }
.hero-orb { width: 76px; height: 76px; border-radius: 25px; position: relative; margin-bottom: 22px; overflow: hidden; background: linear-gradient(145deg, #1a1f2b, #0d1017); border: 1px solid rgba(255,255,255,.09); box-shadow: 0 24px 80px rgba(93,78,255,.22), inset 0 0 30px rgba(255,255,255,.04); }
.hero-orb span { position: absolute; inset: 18%; border-radius: 50%; filter: blur(2px); background: radial-gradient(circle at 30% 30%, #c6c0ff, #7768ff 45%, transparent 70%); animation: drift 5s ease-in-out infinite alternate; }
.hero-orb span:nth-child(2) { inset: 34% 10% 14% 40%; background: radial-gradient(circle, #67ddff, transparent 68%); animation-delay: -.8s; }
.hero-orb span:nth-child(3) { inset: 8% 44% 46% 8%; background: radial-gradient(circle, #f1b7ff, transparent 68%); animation-delay: -1.4s; }
@keyframes drift { to { transform: translate(7px, -5px) scale(1.08); } }
.welcome h1 { margin: 0; font-size: clamp(30px, 5vw, 46px); letter-spacing: -.045em; }
.welcome > p { max-width: 590px; margin: 13px auto 28px; line-height: 1.55; color: var(--muted); }
.starter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: min(690px, 100%); }
.starter { min-height: 110px; text-align: left; padding: 16px; border-radius: 18px; border: 1px solid var(--border); background: rgba(255,255,255,.03); cursor: pointer; transition: .2s ease; }
.starter:hover { transform: translateY(-2px); background: rgba(255,255,255,.055); border-color: var(--border-strong); }
.starter-icon { display: block; color: #bcb4ff; font-size: 20px; margin-bottom: 15px; }
.starter strong { display: block; font-size: 14px; }
.starter small { display: block; margin-top: 5px; color: var(--muted); line-height: 1.35; }

.message { display: grid; grid-template-columns: 36px minmax(0,1fr); gap: 12px; margin-bottom: 28px; animation: rise .24s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.message-avatar { width: 34px; height: 34px; border-radius: 11px; background: #181c25; border: 1px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #b9c0ce; }
.message.user .message-avatar::before { content: "YOU"; font-size: 8px; }
.message.assistant .message-avatar::before { content: "DS"; font-size: 9px; color: #c3bdff; }
.message.assistant .message-avatar { background: linear-gradient(145deg, rgba(139,124,255,.17), rgba(79,212,255,.08)); }
.message-meta { color: var(--muted); font-size: 11px; margin: 1px 0 7px; text-transform: uppercase; letter-spacing: .08em; }
.message-content { color: #ecedf2; line-height: 1.6; overflow-wrap: anywhere; }
.message-content > p { margin: 0; white-space: pre-wrap; }
.media-card { margin-top: 12px; width: min(620px,100%); border: 1px solid var(--border); background: rgba(255,255,255,.028); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.media-card img, .media-card video { display: block; width: 100%; max-height: 680px; object-fit: contain; background: #050609; }
.media-card audio { display: block; width: calc(100% - 28px); margin: 18px 14px; }
.media-footer { padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.media-label { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-actions { display: flex; gap: 7px; flex-shrink: 0; }
.tiny-btn { border: 1px solid var(--border); background: rgba(255,255,255,.045); border-radius: 9px; padding: 7px 10px; font-size: 11px; cursor: pointer; text-decoration: none; }
.tiny-btn:hover { background: rgba(255,255,255,.075); }
.progress-card { margin-top: 10px; max-width: 520px; padding: 14px; border: 1px solid var(--border); border-radius: 15px; background: rgba(255,255,255,.028); }
.progress-top { display:flex; align-items:center; justify-content:space-between; gap:12px; font-size:12px; }
.progress-status { color: #c7c2ff; }
.progress-track { margin-top: 11px; height: 5px; border-radius: 999px; background: rgba(255,255,255,.06); overflow: hidden; }
.progress-track span { display:block; width:36%; height:100%; border-radius:inherit; background: linear-gradient(90deg,var(--accent),var(--accent-2)); animation: loading 1.4s ease-in-out infinite alternate; }
@keyframes loading { from{transform:translateX(-70%)} to{transform:translateX(250%)} }
.error-card { margin-top: 10px; padding: 13px 14px; border-radius: 14px; border: 1px solid rgba(255,107,122,.22); background: rgba(255,107,122,.07); color: #ffc0c7; font-size: 13px; }
.raw-details { margin-top:10px; }
.raw-details summary { cursor:pointer; color:var(--muted); font-size:11px; }
.raw-details pre { max-height:300px; overflow:auto; padding:12px; background:#07090d; border:1px solid var(--border); border-radius:12px; font-size:11px; white-space:pre-wrap; }

.composer-wrap { position: fixed; z-index: 15; left: 50%; bottom: 0; transform: translateX(-50%); width: min(920px,100%); padding: 12px 18px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(to top, #090b0f 72%, rgba(9,11,15,.82), transparent); }
.mode-row { display: flex; gap: 7px; margin: 0 4px 8px; overflow-x: auto; scrollbar-width: none; }
.mode-row::-webkit-scrollbar { display:none; }
.mode-chip, .options-chip { border: 1px solid var(--border); background: rgba(255,255,255,.035); border-radius: 999px; padding: 7px 11px; font-size: 11px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.mode-chip.active { color: #f2f0ff; border-color: rgba(139,124,255,.35); background: rgba(139,124,255,.14); }
.options-chip { margin-left: auto; }
.options-chip span { color: #d6d1ff; margin-left: 5px; }
.options-panel { margin: 0 0 8px; padding: 12px; border: 1px solid var(--border); background: rgba(15,18,25,.95); backdrop-filter: blur(18px); border-radius: 16px; box-shadow: var(--shadow); }
.option-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.option-group label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.option-group select, .option-group input { width:100%; min-width:0; border:1px solid var(--border); border-radius:10px; background:#0b0e14; color:var(--text); padding:9px 10px; font-size:12px; outline:none; }
.composer { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; padding: 9px 9px 9px 15px; border-radius: 21px; border: 1px solid var(--border-strong); background: rgba(20,23,31,.92); backdrop-filter: blur(20px); box-shadow: 0 18px 60px rgba(0,0,0,.32); }
.composer:focus-within { border-color: rgba(139,124,255,.42); box-shadow: 0 18px 70px rgba(0,0,0,.34), 0 0 0 3px rgba(139,124,255,.07); }
.composer textarea { resize: none; max-height: 150px; min-height: 38px; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.45; padding: 8px 0 4px; }
.composer textarea::placeholder { color: #737b8b; }
.send-btn { width: 42px; height: 42px; border: 0; border-radius: 13px; display:grid; place-items:center; background: linear-gradient(135deg, #9b8cff, #6f62ee); cursor:pointer; box-shadow: 0 8px 22px rgba(112,98,238,.26); }
.send-btn:disabled { opacity:.45; cursor:not-allowed; }
.send-btn svg { width:18px; fill:white; }
.composer-note { margin-top: 7px; text-align: center; color: #656d7b; font-size: 9.5px; }

.key-dialog { width: min(520px, calc(100% - 28px)); border: 1px solid var(--border-strong); border-radius: 22px; background: #11141b; color: var(--text); padding: 0; box-shadow: 0 35px 100px rgba(0,0,0,.62); }
.key-dialog::backdrop { background: rgba(0,0,0,.68); backdrop-filter: blur(7px); }
.key-dialog form { padding: 20px; }
.dialog-head { display:flex; align-items:flex-start; justify-content:space-between; gap:14px; margin-bottom:20px; }
.dialog-head h2 { margin:0; font-size:20px; letter-spacing:-.02em; }
.dialog-head p { margin:5px 0 0; color:var(--muted); font-size:12px; }
.field-label { display:block; margin:13px 0 7px; color:#c7ccd6; font-size:11px; font-weight:650; }
.text-field, .password-field { width:100%; border:1px solid var(--border); border-radius:12px; background:#090b10; }
.text-field { padding:11px 12px; color:var(--text); outline:none; }
.password-field { display:grid; grid-template-columns:1fr auto; overflow:hidden; }
.password-field input { min-width:0; border:0; background:transparent; color:var(--text); padding:11px 12px; outline:none; }
.password-field button { border:0; border-left:1px solid var(--border); background:transparent; color:var(--muted); padding:0 12px; cursor:pointer; }
.field-help { color:#777f8f; font-size:10.5px; line-height:1.45; }
.security-note { margin-top:16px; display:grid; gap:5px; padding:12px 13px; border-radius:13px; background:rgba(255,197,96,.06); border:1px solid rgba(255,197,96,.14); }
.security-note strong { color:#ffd58b; font-size:11px; }
.security-note span { color:#a99b83; font-size:10.5px; line-height:1.45; }
.dialog-actions { display:flex; justify-content:space-between; gap:10px; margin-top:20px; }
.primary-btn, .secondary-btn { border-radius:11px; padding:10px 14px; border:1px solid var(--border); cursor:pointer; }
.primary-btn { background:#8172ff; border-color:#8172ff; color:white; }
.secondary-btn { background:transparent; color:var(--muted); }

@media (max-width: 680px) {
  .app-header { min-height:64px; padding-left:13px; padding-right:13px; }
  .brand-mark { width:35px; height:35px; border-radius:11px; }
  .brand-title { font-size:14px; }
  .chat { padding: 24px 13px 210px; }
  .starter-grid { grid-template-columns: 1fr; }
  .starter { min-height: 82px; }
  .starter-icon { margin-bottom:8px; }
  .composer-wrap { padding-left:10px; padding-right:10px; }
  .option-group { grid-template-columns:1fr; }
  .message { grid-template-columns:31px minmax(0,1fr); gap:9px; }
  .message-avatar { width:30px; height:30px; border-radius:9px; }
  .media-card { border-radius:15px; }
  .composer-note { display:none; }
}
