:root {
  --bg: #02070f;
  --panel: rgba(8, 22, 38, 0.82);
  --panel-solid: #071423;
  --line: rgba(79, 209, 255, 0.18);
  --line-strong: rgba(79, 209, 255, 0.45);
  --cyan: #4fd1ff;
  --cyan-soft: #9be7ff;
  --text: #dcefff;
  --muted: #7d98b3;
  --danger: #ff6b7a;
  --user-bubble: rgba(79, 209, 255, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(ellipse at 50% -10%, #0b2a45 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(79, 209, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 209, 255, 0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.brand { font-weight: 600; letter-spacing: 0.32em; color: var(--cyan-soft); text-shadow: 0 0 12px rgba(79,209,255,.55); }

/* ---------- reattore ---------- */
.reactor { position: relative; width: 120px; height: 120px; flex: none; }
.reactor .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--line-strong);
  box-shadow: 0 0 18px rgba(79,209,255,.35), inset 0 0 18px rgba(79,209,255,.25); }
.reactor .ring.r2 { inset: 14%; border-style: dashed; border-color: rgba(79,209,255,.6); animation: spin 14s linear infinite; }
.reactor .ring.r3 { inset: 28%; border-width: 3px; border-color: rgba(79,209,255,.75); border-left-color: transparent; border-right-color: transparent; animation: spin 5s linear infinite reverse; }
.reactor .core { position: absolute; inset: 38%; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--cyan-soft) 35%, var(--cyan) 60%, transparent 75%);
  box-shadow: 0 0 30px var(--cyan), 0 0 60px rgba(79,209,255,.5); animation: pulse 3s ease-in-out infinite; }
.reactor.small { width: 30px; height: 30px; }
.reactor.small .ring { border-width: 1px; }
.reactor.small .ring.r3 { border-width: 2px; }
body.busy .reactor .core { animation-duration: .7s; }
body.busy .reactor .ring.r3 { animation-duration: 1.2s; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: .75; transform: scale(.92); } 50% { opacity: 1; transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .reactor * { animation: none !important; } }

/* ---------- login ---------- */
.login-wrap { position: relative; z-index: 1; min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 24px; backdrop-filter: blur(10px);
  box-shadow: 0 0 40px rgba(79,209,255,.08); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .sub { margin: -10px 0 4px; color: var(--muted); font-size: 13px; }
.login-card form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.field input { background: rgba(2,7,15,.7); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }
.field input:focus { border-color: var(--cyan); outline: none; box-shadow: 0 0 0 3px rgba(79,209,255,.15); }
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; min-width: 0; padding-right: 46px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 34px;
  background: none; border: 0; border-radius: 8px; font-size: 16px; opacity: .55; }
.pw-toggle[aria-pressed="true"] { opacity: 1; background: rgba(79,209,255,.15); }
.btn-primary { background: linear-gradient(180deg, rgba(79,209,255,.3), rgba(79,209,255,.15)); border: 1px solid var(--line-strong);
  color: var(--cyan-soft); border-radius: 10px; padding: 11px; letter-spacing: .15em; text-transform: uppercase; font-weight: 600; }
.btn-primary:hover { background: rgba(79,209,255,.32); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); font-size: 13px; min-height: 1.2em; margin: 0; text-align: center; }

/* ---------- app ---------- */
.app { position: relative; z-index: 1; height: 100%; display: grid; grid-template-columns: 270px 1fr; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; backdrop-filter: blur(10px); }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.sidebar-head .brand { font-size: 14px; }
.new-chat { margin: 12px; padding: 10px; border-radius: 10px; border: 1px dashed var(--line-strong); background: transparent; color: var(--cyan-soft); text-align: left; }
.new-chat:hover { background: rgba(79,209,255,.08); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; margin: 0; list-style: none; }
.conv-list li { display: flex; align-items: center; border-radius: 8px; }
.conv-list li.active, .conv-list li:hover { background: rgba(79,209,255,.09); }
.conv-list li.active { box-shadow: inset 2px 0 0 var(--cyan); }
.conv-list .open { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 9px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.conv-list .del { background: none; border: 0; color: var(--muted); padding: 6px 10px; opacity: 0; }
.conv-list li:hover .del, .conv-list li.active .del { opacity: 1; }
.conv-list .del:hover { color: var(--danger); }
.sidebar-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; }
.link-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; color: var(--muted); font-size: 12px; }
.link-btn:hover { color: var(--text); border-color: var(--line-strong); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(2,7,15,.5); backdrop-filter: blur(8px); }
.icon-btn { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: rgba(8,22,38,.6); color: var(--cyan-soft); }
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn.on { background: rgba(79,209,255,.22); border-color: var(--cyan); box-shadow: 0 0 12px rgba(79,209,255,.4); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }
.topbar .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 14px; }
.topbar select { max-width: 46vw; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; padding: 40px 16px; min-height: 60vh; }
.empty h2 { margin: 0; font-weight: 400; font-size: 22px; color: var(--cyan-soft); }
.empty p { margin: 0; color: var(--muted); }

.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant .bubble { flex: 1; padding-top: 3px; }
.msg.assistant .avatar { margin-top: 2px; }
.msg .meta { margin-top: 6px; font-size: 11px; color: var(--muted); letter-spacing: .05em; }
.msg .err { color: var(--danger); }
.bubble p { margin: 0 0 .7em; } .bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: .9em 0 .4em; line-height: 1.3; color: var(--cyan-soft); }
.bubble h1 { font-size: 1.3em; } .bubble h2 { font-size: 1.18em; } .bubble h3, .bubble h4 { font-size: 1.05em; }
.bubble ul, .bubble ol { margin: 0 0 .7em; padding-left: 1.4em; }
.bubble li { margin: .2em 0; }
.bubble a { color: var(--cyan); }
.bubble code { font-family: var(--mono); font-size: .88em; background: rgba(79,209,255,.1); border-radius: 5px; padding: .1em .35em; }
.bubble pre { background: #010409; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 .8em; }
.bubble pre code { background: none; padding: 0; font-size: 13px; }
.bubble blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 2px solid var(--line-strong); color: var(--muted); }
.cursor::after { content: "▍"; color: var(--cyan); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); animation: dot 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%,80%,100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.composer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(2,7,15,.6); backdrop-filter: blur(8px); }
.composer form { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 40vh; min-height: 44px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; font-size: 16px; line-height: 1.4; }
.composer textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(79,209,255,.12); }
.composer .icon-btn { width: 44px; height: 44px; border-radius: 12px; }
.send-btn { background: rgba(79,209,255,.25) !important; border-color: var(--line-strong) !important; }
.mic-btn.listening { background: rgba(255,107,122,.25); border-color: var(--danger); color: #ffd0d5; animation: pulse 1.2s infinite; }
.hint { max-width: 820px; margin: 6px auto 0; font-size: 11px; color: var(--muted); text-align: center; min-height: 1em; }

.scrim { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 20; transform: translateX(-100%); transition: transform .2s ease; background: var(--panel-solid); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.5); }
  .menu-btn { display: grid; }
  .topbar .title { display: none; }
  .topbar select { flex: 1; max-width: none; }
  .messages { padding: 16px 12px; }
  .msg.user .bubble { max-width: 92%; }
  .reactor.big { width: 96px; height: 96px; }
}
