:root {
  color-scheme: dark;
  --bg: #07101e;
  --panel: #0d192a;
  --panel-2: #122137;
  --line: #21334d;
  --text: #f4f7fb;
  --muted: #91a1b8;
  --accent: #f3b943;
  --accent-2: #ffc857;
  --danger: #ff6b6b;
  --ok: #41d99a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { background-image: radial-gradient(circle at 15% 0%, #17304b 0, transparent 33%), radial-gradient(circle at 90% 90%, #251c35 0, transparent 30%); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted, .microcopy { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.error { min-height: 20px; margin: 2px 0 0; color: #ff9b9b; font-size: 13px; }

.login-view { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.login-card { width: min(100%, 390px); padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: rgba(13,25,42,.94); box-shadow: 0 28px 80px rgba(0,0,0,.42); }
.brand-mark, .mini-mark { display: grid; place-items: center; background: var(--accent); color: #17120a; font-family: Georgia, serif; font-weight: 900; }
.brand-mark { width: 58px; height: 58px; margin-bottom: 28px; border-radius: 18px 18px 18px 5px; font-size: 34px; transform: rotate(-3deg); }
.mini-mark { width: 30px; height: 30px; border-radius: 9px 9px 9px 3px; font-size: 19px; }
.login-card h1 { margin: 0; font-family: Georgia, serif; font-size: 39px; letter-spacing: -.04em; }
.login-card > .muted { margin: 8px 0 26px; line-height: 1.5; }
.stack { display: grid; gap: 14px; }
.stack.compact { gap: 10px; }
label { display: grid; gap: 7px; color: #bcc8d8; font-size: 13px; font-weight: 700; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #091522; color: var(--text); padding: 13px 14px; transition: border .18s, box-shadow .18s; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(243,185,67,.12); }
textarea { resize: vertical; }
.primary, .ghost, .danger { border: 0; border-radius: 11px; padding: 12px 15px; font-weight: 800; }
.primary { background: var(--accent); color: #181105; }
.primary:hover { background: var(--accent-2); }
.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.danger { background: rgba(255,107,107,.13); color: #ff9797; border: 1px solid rgba(255,107,107,.25); }

.app-view { min-height: 100dvh; display: grid; grid-template-rows: auto auto 1fr auto auto; }
.topbar { height: 62px; padding: 0 max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(7,16,30,.84); backdrop-filter: blur(16px); }
.brand-row, .top-actions { display: flex; align-items: center; gap: 10px; }
.brand-row strong { font-family: Georgia, serif; font-size: 18px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); color: var(--text); font-size: 19px; }
.state-dot { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.state-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.state-dot.busy i { background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: pulse 1s infinite; }
.model-strip { display: flex; gap: 8px; padding: 10px 18px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #091422; }
.model-strip span { white-space: nowrap; padding: 6px 9px; border-radius: 8px; background: var(--panel); color: var(--muted); font-size: 11px; }
.model-strip b { color: var(--accent); margin-right: 5px; }
.messages { width: min(100%, 900px); margin: 0 auto; padding: 30px 18px 160px; overflow: auto; }
.welcome { margin: 9vh auto 0; max-width: 520px; text-align: center; color: var(--muted); }
.welcome h2 { margin: 0; color: var(--text); font-family: Georgia, serif; font-size: clamp(30px, 7vw, 48px); letter-spacing: -.04em; }
.message { display: grid; gap: 8px; margin: 0 0 26px; }
.message.user { justify-items: end; }
.message .meta { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.bubble { max-width: min(100%, 760px); overflow-wrap: anywhere; line-height: 1.65; }
.user .bubble { padding: 12px 16px; border-radius: 16px 16px 4px 16px; background: var(--accent); color: #1a1409; line-height: 1.45; }
.assistant .bubble { width: 100%; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 1.2em 0 .45em; font-family: Georgia, serif; line-height: 1.25; }
.bubble p { margin: .55em 0; }
.bubble a { color: #75c7ff; text-underline-offset: 3px; }
.bubble pre { overflow-x: auto; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #050b13; }
.bubble code { padding: 2px 5px; border-radius: 5px; background: #111f31; color: #ffda8a; }
.bubble pre code { padding: 0; background: transparent; color: #d9e5f5; }
.bubble table { width: 100%; margin: 14px 0; border-collapse: collapse; font-size: 14px; }
.bubble th, .bubble td { padding: 9px 10px; border: 1px solid var(--line); text-align: left; }
.bubble th { background: var(--panel-2); color: var(--accent); }
.cursor::after { content: ""; display: inline-block; width: 7px; height: 1.05em; margin-left: 3px; vertical-align: -.15em; background: var(--accent); animation: blink .8s infinite; }

.composer-wrap { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; padding: 12px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 24%); }
.composer { width: min(100%, 860px); min-height: 58px; margin: 0 auto; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: #0c1929; box-shadow: 0 16px 55px rgba(0,0,0,.5); }
.composer textarea { min-height: 40px; max-height: 160px; padding: 9px 5px; border: 0; background: transparent; box-shadow: none; resize: none; line-height: 1.45; }
.mic-button, .send-button { width: 41px; height: 41px; border: 0; border-radius: 13px; font-weight: 900; }
.mic-button { background: #152741; color: #86a2c3; }
.mic-button.recording { background: var(--danger); color: white; animation: pulse 1s infinite; }
.send-button { background: var(--accent); color: #181105; font-size: 24px; }
.send-button:disabled { opacity: .45; cursor: default; }
.composer-hint { margin: 7px auto 0; max-width: 860px; text-align: center; color: #667890; font-size: 10px; }
.speech-panel { position: fixed; z-index: 11; right: 18px; bottom: 106px; width: min(430px, calc(100% - 36px)); display: flex; gap: 14px; justify-content: space-between; align-items: center; padding: 14px; border: 1px solid #795c22; border-radius: 14px; background: #1b1b18; box-shadow: 0 15px 45px rgba(0,0,0,.44); }
.speech-panel p { margin: 5px 0 0; color: #cbd2db; font-size: 13px; line-height: 1.4; }
.wave { color: var(--accent); letter-spacing: 2px; animation: pulse 1s infinite; }

.settings { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(420px, 100%); overflow-y: auto; padding: 24px; background: #0a1625; border-left: 1px solid var(--line); box-shadow: -22px 0 70px rgba(0,0,0,.5); }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 25px; }
.settings-head h2 { margin: 0; font-family: Georgia, serif; font-size: 29px; }
.settings section { padding: 20px 0; border-top: 1px solid var(--line); }
.key-status { color: var(--muted); font-size: 13px; }
.key-status.ok { color: var(--ok); }
.microcopy { margin: 10px 0 0; font-size: 11px; line-height: 1.45; }
.toggle { grid-template-columns: auto auto 1fr; align-items: center; gap: 9px; margin-bottom: 20px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { width: 42px; height: 24px; position: relative; border-radius: 99px; background: #26374c; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #93a3b8; transition: .2s; }
.toggle input:checked + span { background: #5f481c; }
.toggle input:checked + span::after { left: 21px; background: var(--accent); }
.settings-actions { display: flex; gap: 10px; margin-top: 18px; }
.backdrop { position: fixed; z-index: 20; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 112px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 30px); padding: 11px 14px; border: 1px solid var(--line); border-radius: 11px; background: #15243a; box-shadow: 0 12px 36px rgba(0,0,0,.45); font-size: 13px; }

@keyframes pulse { 50% { opacity: .45; } }
@keyframes blink { 50% { opacity: 0; } }
@media (max-width: 600px) {
  .login-card { padding: 26px; }
  .state-dot { display: none; }
  .messages { padding-top: 22px; }
  .composer-hint { display: none; }
  .composer-wrap { padding-bottom: calc(9px + env(safe-area-inset-bottom)); }
  .settings { padding: 20px; }
}

