:root {
  --bg: #05060f;
  --text: #e8eaf6;
  --muted: #8b90b3;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --pink: #f472b6;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.1);
  --grad: linear-gradient(120deg, var(--cyan), var(--violet) 55%, var(--pink));
  --radius: 22px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 15.5px;
  line-height: 1.6;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; color: inherit; }

#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.aurora {
  position: fixed; inset: -20%; z-index: 0; pointer-events: none;
  background:
    radial-gradient(40% 35% at 20% 15%, rgba(124, 58, 237, 0.28), transparent 70%),
    radial-gradient(35% 30% at 85% 25%, rgba(34, 211, 238, 0.18), transparent 70%),
    radial-gradient(45% 40% at 60% 95%, rgba(244, 114, 182, 0.14), transparent 70%);
  filter: blur(20px);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(3%, -2%, 0) scale(1.06); } }

.glass {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.app {
  position: relative; z-index: 1;
  height: 100%;
  display: flex; flex-direction: column;
  padding: 14px; gap: 14px;
  max-width: 1500px; margin: 0 auto;
}

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 14px 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.atom { width: 34px; height: 34px; animation: spin 14s linear infinite; filter: drop-shadow(0 0 8px rgba(34, 211, 238, 0.6)); }
.nucleus { fill: #fff; animation: pulse 2.4s ease-in-out infinite; transform-origin: 32px 32px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(1.35); opacity: 0.85; } }
.brand-name { white-space: nowrap;
  font-weight: 700; letter-spacing: 0.2em; font-size: 18px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--muted); font-family: var(--mono);
  padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border);
}
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 10px #34d399; animation: blink 2s infinite; }
.status.busy .dot { background: var(--violet); box-shadow: 0 0 12px var(--violet); animation-duration: 0.6s; }
@keyframes blink { 50% { opacity: 0.35; } }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.btn {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.05);
  padding: 7px 14px; border-radius: 12px; cursor: pointer; font-size: 13.5px;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }
.btn:active { transform: scale(0.97); }

.seg { display: flex; padding: 3px; gap: 2px; border-radius: 13px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); }
.seg button { border: none; background: transparent; padding: 5px 11px; border-radius: 10px; cursor: pointer; font-size: 13px; color: var(--muted); transition: all 0.2s; }
.seg button:hover { color: var(--text); }
.seg button.on { background: linear-gradient(135deg, rgba(34, 211, 238, 0.25), rgba(168, 85, 247, 0.3)); color: #fff; box-shadow: 0 0 14px rgba(168, 85, 247, 0.3); }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 14px; }
.layout.core-hidden { grid-template-columns: minmax(0, 1fr) 0; }
.layout.core-hidden .core { display: none; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 26px 26px 10px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar, .hist::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .hist::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 8px; }

.welcome { max-width: 720px; margin: 4vh auto 0; text-align: center; animation: rise 0.8s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.welcome h1 { font-size: clamp(30px, 4.4vw, 48px); margin: 22px 0 6px; line-height: 1.15; font-weight: 700; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--muted); font-size: 16.5px; margin: 0 auto 26px; max-width: 560px; }
.sub b { color: var(--text); }

.orb { position: relative; width: 132px; height: 132px; margin: 0 auto; }
.orb-core {
  position: absolute; inset: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #67e8f9 25%, #8b5cf6 60%, #3b0764 100%);
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.6), 0 0 90px rgba(168, 85, 247, 0.45);
  animation: breathe 4s ease-in-out infinite;
}
.orb-ring { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, 0.0); }
.orb-ring::after {
  content: ""; position: absolute; top: -4px; left: 50%; width: 8px; height: 8px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 12px #fff, 0 0 20px var(--cyan);
}
.orb-ring.r1 { border-color: rgba(34, 211, 238, 0.35); transform: rotateX(70deg); animation: orbit1 5s linear infinite; }
.orb-ring.r2 { border-color: rgba(168, 85, 247, 0.35); animation: orbit2 7s linear infinite; }
.orb-ring.r3 { border-color: rgba(244, 114, 182, 0.3); animation: orbit3 9s linear infinite; }
@keyframes orbit1 { from { transform: rotateX(70deg) rotateZ(0); } to { transform: rotateX(70deg) rotateZ(360deg); } }
@keyframes orbit2 { from { transform: rotateY(70deg) rotateZ(0); } to { transform: rotateY(70deg) rotateZ(360deg); } }
@keyframes orbit3 { from { transform: rotateX(55deg) rotateY(45deg) rotateZ(0); } to { transform: rotateX(55deg) rotateY(45deg) rotateZ(360deg); } }
@keyframes breathe { 50% { transform: scale(1.08); filter: hue-rotate(25deg); } }

.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04);
  padding: 10px 16px; border-radius: 14px; cursor: pointer; font-size: 14px;
  transition: all 0.25s;
}
.chip:hover { background: rgba(168, 85, 247, 0.14); border-color: rgba(168, 85, 247, 0.5); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(168, 85, 247, 0.2); }

.msg { display: flex; gap: 12px; max-width: 860px; margin: 0 auto 22px; animation: rise 0.35s ease both; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(168, 85, 247, 0.2));
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px; max-width: 78%;
  white-space: pre-wrap; word-wrap: break-word;
}
.avatar {
  flex: 0 0 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #67e8f9 25%, #8b5cf6 65%, #3b0764);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.45);
  margin-top: 2px;
}
.msg.bot .avatar.live { animation: breathe 1.2s ease-in-out infinite; }
.msg.bot .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg.bot .content { word-wrap: break-word; }
.meta { font-size: 11.5px; color: var(--muted); font-family: var(--mono); margin-top: 6px; opacity: 0.7; }
.msg.error .content { color: #fca5a5; }

/* markdown */
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; }
.content h1, .content h2, .content h3, .content h4 { margin: 18px 0 8px; line-height: 1.3; }
.content h1 { font-size: 1.45em; } .content h2 { font-size: 1.25em; } .content h3 { font-size: 1.1em; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 22px; }
.content li { margin: 3px 0; }
.content strong { color: #fff; }
.content a { color: var(--cyan); }
.content blockquote { margin: 0 0 12px; padding: 6px 14px; border-left: 3px solid var(--violet); background: rgba(168, 85, 247, 0.08); border-radius: 0 10px 10px 0; }
.content code { font-family: var(--mono); font-size: 0.88em; background: rgba(255, 255, 255, 0.08); padding: 2px 6px; border-radius: 6px; }
.content pre { background: rgba(0, 0, 0, 0.4); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; overflow-x: auto; margin: 0 0 12px; }
.content pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }
.content table { border-collapse: collapse; margin: 0 0 12px; width: 100%; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.content th { background: rgba(255, 255, 255, 0.05); }
.content hr { border: none; height: 1px; background: var(--border); margin: 16px 0; }
.math { font-family: "Cambria Math", "STIX Two Math", serif; font-style: italic; color: #c4b5fd; }

.typing { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13.5px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); animation: hop 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; background: var(--violet); }
.typing i:nth-child(3) { animation-delay: 0.3s; background: var(--pink); }
@keyframes hop { 0%, 100% { transform: translateY(0); opacity: 0.5; } 50% { transform: translateY(-5px); opacity: 1; } }
.cursor::after { content: "▍"; color: var(--cyan); animation: blink 0.9s infinite; margin-left: 1px; }

/* quantum experiment card */
.qcard {
  position: relative; margin: 6px 0 14px; padding: 16px 18px; border-radius: 18px;
  background: linear-gradient(160deg, rgba(34, 211, 238, 0.08), rgba(168, 85, 247, 0.1));
  border: 1px solid rgba(34, 211, 238, 0.28);
  overflow: hidden;
}
.qcard::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.06) 50%, transparent 70%);
  transform: translateX(-100%); animation: sheen 3.5s ease-in-out infinite;
}
@keyframes sheen { 60%, 100% { transform: translateX(100%); } }
.qcard-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.qcard-title { font-weight: 600; font-size: 15.5px; }
.qcard-tag { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 8px; background: rgba(34, 211, 238, 0.15); color: #a5f3fc; }
.qcard-tag.v { background: rgba(168, 85, 247, 0.18); color: #e9d5ff; }
.qcard-actions { margin-left: auto; display: flex; gap: 6px; }
.qcard-actions .btn { padding: 4px 10px; font-size: 12px; border-radius: 9px; }
.qcard .loading { color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.qcard .err { color: #fca5a5; font-size: 14px; }
.qcard .facts { font-size: 13px; color: var(--muted); margin-top: 10px; font-family: var(--mono); }
.qcard .facts b { color: var(--text); font-weight: 600; }
.circuit-svg { width: 100%; overflow-x: auto; margin: 4px 0 10px; }
.circuit-svg svg { display: block; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(70px, auto) 1fr 58px; align-items: center; gap: 10px; font-family: var(--mono); font-size: 12.5px; }
.bar .lab { color: #e0e7ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.bar .track { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.bar .fill { display: block; height: 100%; border-radius: 6px; background: var(--grad); box-shadow: 0 0 12px rgba(34, 211, 238, 0.5); animation: grow 0.9s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes grow { from { width: 0; } }
.bar .pct { text-align: right; color: var(--muted); }

/* ---------- composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  margin: 8px 22px 0; padding: 8px 8px 8px 18px;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--border); border-radius: 18px;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.composer:focus-within { border-color: rgba(168, 85, 247, 0.6); box-shadow: 0 0 0 4px rgba(168, 85, 247, 0.12), 0 0 40px rgba(34, 211, 238, 0.12); }
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent;
  padding: 9px 0; max-height: 200px; font-size: 15.5px; line-height: 1.5;
}
.composer textarea::placeholder { color: #6b7099; }
.send {
  flex: 0 0 42px; height: 42px; border-radius: 13px; border: none; cursor: pointer;
  background: var(--grad); display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4); transition: transform 0.15s, opacity 0.2s, filter 0.2s;
}
.send svg { width: 20px; height: 20px; fill: #fff; }
.send:hover { transform: translateY(-1px) scale(1.04); filter: brightness(1.1); }
.send:disabled { opacity: 0.4; cursor: default; transform: none; }
.send.stop { background: rgba(255, 255, 255, 0.12); box-shadow: none; }
.hint { text-align: center; font-size: 11.5px; color: #5f6488; margin: 8px 0 12px; padding: 0 16px; }

/* ---------- core panel ---------- */
.core { display: flex; flex-direction: column; padding: 16px; gap: 12px; min-height: 0; overflow: hidden; }
.core-head { display: flex; align-items: center; justify-content: space-between; }
.core-title { font-family: var(--mono); font-size: 12px; letter-spacing: 0.25em; color: var(--muted); }
.badge { font-family: var(--mono); font-size: 11px; padding: 3px 9px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); color: var(--muted); border: 1px solid var(--border); }
.badge.on { color: #a5f3fc; border-color: rgba(34, 211, 238, 0.4); background: rgba(34, 211, 238, 0.1); }
.grid-wrap { position: relative; border-radius: 16px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--border); aspect-ratio: 1 / 1; max-height: 340px; width: 100%; overflow: hidden; }
#qgrid { width: 100%; height: calc(100% - 30px); display: block; }
.grid-label { position: absolute; left: 10px; right: 10px; bottom: 7px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--muted); background: rgba(5, 6, 15, 0.6); padding: 2px 8px; border-radius: 6px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); border-radius: 12px; padding: 7px 10px; display: flex; flex-direction: column; min-width: 0; }
.stat.wide { grid-column: 1 / -1; }
.stat .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat .v { font-family: var(--mono); font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.core-title-sm { font-weight: 600; font-size: 14px; }
.hist { overflow-y: auto; min-height: 0; flex: 1; padding-right: 4px; }
.muted { color: var(--muted); font-size: 13.5px; margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 860px) {
  body { font-size: 15px; }
  .app { padding: 8px; gap: 8px; }
  .status { display: none; }
  .layout, .layout.core-hidden { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand-name { white-space: nowrap; font-size: 15px; letter-spacing: 0.22em; }
  .btn { padding: 6px 10px; font-size: 13px; }
  .qcard { padding: 14px; }
  .qcard-actions { margin-left: 0; width: 100%; }
  .bar { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 46px; }
  .chips { gap: 8px; }
  .chip { padding: 8px 12px; font-size: 13.5px; }
  .core { position: fixed; inset: auto 8px 8px 8px; max-height: 78vh; z-index: 5; background: rgba(10, 11, 26, 0.92); }
  .layout:not(.core-open) .core { display: none; }
  .messages { padding: 18px 14px 8px; }
  .composer { margin: 6px 10px 0; }
  .msg.user .bubble { max-width: 88%; }
  .grid-wrap { max-height: 240px; }
}
@media (max-width: 480px) { .hide-sm { display: none; } .avatar { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.math-block { margin: 4px 0 14px; padding: 12px 16px; text-align: center; font-size: 1.12em; border-radius: 14px; background: rgba(168, 85, 247, 0.07); border: 1px solid rgba(168, 85, 247, 0.18); overflow-x: auto; }
.acro { margin: -2px auto 14px; font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.04em; color: var(--muted); }
.acro b { color: var(--cyan); font-weight: 600; text-shadow: 0 0 10px rgba(34, 211, 238, 0.7); }
.meta { display: flex; align-items: center; gap: 10px; }
.copy { border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04); color: var(--muted); font-size: 11.5px; padding: 2px 9px; border-radius: 8px; cursor: pointer; opacity: 0; transition: opacity 0.2s, color 0.2s; font-family: inherit; }
.msg.bot:hover .copy, .copy:focus { opacity: 1; }
.copy:hover { color: var(--text); border-color: rgba(168, 85, 247, 0.5); }
@media (hover: none) { .copy { opacity: 1; } }
.msg.error .copy { display: none; }
