:root {
  --bg: #000;
  --ink: #f2f2f2;
  --muted: #8a8a8a;
  --dim: #555;
  --hair: rgba(255, 255, 255, 0.09);
  --hair-2: rgba(255, 255, 255, 0.16);
  --glass: rgba(8, 8, 8, 0.72);
  --rail: 64px;
  --panel: 300px;
  --body: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.65 var(--body); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.mono { font-family: var(--mono); }
#starfield { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ---------- Rail ---------- */
.rail {
  width: var(--rail); flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 0; border-right: 1px solid var(--hair); background: rgba(0,0,0,.55); backdrop-filter: blur(12px);
}
.rail-logo { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 14px; }
.rail-logo img { filter: drop-shadow(0 0 8px rgba(255,255,255,.35)); }
.rail-btn {
  position: relative; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid transparent; background: none; color: var(--muted); transition: .2s;
}
.rail-btn:hover { color: var(--ink); border-color: var(--hair-2); background: rgba(255,255,255,.04); }
.rail-btn::after {
  content: attr(data-tip); position: absolute; left: 52px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font: 500 .72rem var(--mono); letter-spacing: .06em; padding: 5px 9px; border-radius: 6px;
  background: #fff; color: #000; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.rail-btn:hover::after { opacity: 1; }
.rail-spacer { flex: 1; }
.rail-status { display: grid; place-items: center; width: 40px; height: 40px; }

.pulse { width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 0 rgba(255,255,255,.6); animation: pulse 2.2s infinite; display: inline-block; }
.pulse.off { background: var(--dim); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }

/* ---------- History panel (slide-over) ---------- */
.panel {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: var(--rail); width: var(--panel);
  display: flex; flex-direction: column; gap: 10px; padding: 18px 14px;
  background: rgba(6,6,6,.96); border-right: 1px solid var(--hair-2); backdrop-filter: blur(18px);
  transform: translateX(calc(-100% - var(--rail))); transition: transform .28s cubic-bezier(.2,.8,.2,1);
}
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 6px; }
.label { font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--hair); border-radius: 8px; color: var(--dim); }
.search:focus-within { border-color: var(--hair-2); }
.search input { flex: 1; min-width: 0; padding: 9px 0; background: none; border: 0; outline: 0; color: var(--ink); font: inherit; font-size: .88rem; }
.search input::placeholder { color: var(--dim); }
.threads { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.group-label { font: .66rem var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--dim); padding: 14px 8px 6px; }
.thread {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 8px;
  border: 0; border-left: 1px solid transparent; background: none; color: var(--muted); font-size: .9rem;
}
.thread::before { content: ""; width: 5px; height: 5px; border: 1px solid var(--dim); border-radius: 50%; flex-shrink: 0; }
.thread:hover { color: var(--ink); background: rgba(255,255,255,.03); }
.thread.active { color: var(--ink); border-left-color: #fff; background: rgba(255,255,255,.05); }
.thread.active::before { background: #fff; border-color: #fff; }
.thread .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.thread .del { opacity: 0; display: grid; padding: 2px; border-radius: 4px; color: var(--dim); }
.thread:hover .del, .thread.active .del { opacity: 1; }
.thread .del:hover { color: #fff; }
.no-threads { color: var(--dim); font-size: .85rem; padding: 12px 8px; }
.panel-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px 0; border-top: 1px solid var(--hair); font-size: .78rem; color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; }
.link-btn { background: none; border: 0; color: var(--dim); font-size: .78rem; }
.link-btn:hover { color: #fff; }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .28s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 16px; height: 60px; padding: 0 26px;
  border-bottom: 1px solid var(--hair);
}
.wordmark { font-weight: 600; letter-spacing: .32em; font-size: .9rem; }
.wordmark span { color: var(--dim); margin-left: .5em; }
.title { flex: 1; min-width: 0; text-align: center; color: var(--muted); font-size: .9rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hud-right { display: flex; align-items: center; gap: 16px; }
.hud-clock { font-size: .74rem; letter-spacing: .12em; color: var(--dim); }
.mode { display: flex; border: 1px solid var(--hair-2); border-radius: 8px; overflow: hidden; }
.mode button { border: 0; background: none; padding: 5px 13px; font: 500 .74rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.mode button + button { border-left: 1px solid var(--hair-2); }
.mode button[aria-checked="true"] { background: #fff; color: #000; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: none; color: var(--ink); }
.icon-btn:hover { background: rgba(255,255,255,.07); }
.only-mobile { display: none; }

/* ---------- Chat ---------- */
.chat { flex: 1; overflow-y: auto; }
body.home .chat { display: none; }
.messages { max-width: 760px; margin: 0 auto; padding: 34px 26px 24px; display: flex; flex-direction: column; }
.msg { padding: 20px 0; border-bottom: 1px solid var(--hair); animation: rise .35s ease; }
.msg:last-child { border-bottom: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font: .7rem var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.msg-head .who { color: var(--muted); }
.msg.ai .msg-head .who { color: #fff; }
.msg-head .who::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%; border: 1px solid currentColor; vertical-align: 1px; }
.msg.ai .msg-head .who::before { background: #fff; }
.msg.user .bubble { color: var(--ink); font-size: 1.05rem; white-space: pre-wrap; word-wrap: break-word; }
.content { word-wrap: break-word; color: #e6e6e6; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 20px; }
.content li { margin: 4px 0; }
.content li::marker { color: var(--dim); }
.content h3, .content h4 { font-size: 1rem; font-weight: 600; margin: 18px 0 8px; }
.content code { font: .86em var(--mono); background: rgba(255,255,255,.07); padding: 2px 6px; border-radius: 4px; }
.content pre { margin: 4px 0 14px; border: 1px solid var(--hair-2); border-radius: 8px; background: rgba(10,10,10,.9); overflow: hidden; }
.content pre .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font: .7rem var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); border-bottom: 1px solid var(--hair); }
.content pre code { display: block; padding: 14px; overflow-x: auto; background: none; font-size: .84rem; line-height: 1.6; }
.content a { color: #fff; text-underline-offset: 3px; }
.content strong { color: #fff; font-weight: 600; }
.cursor::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 3px; vertical-align: -2px; background: #fff; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: inline-flex; align-items: center; gap: 10px; font: .78rem var(--mono); letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.thinking::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--hair-2); border-top-color: #fff; animation: spin .8s linear infinite; }
.thinking i { display: none; }
.thinking::after { content: "Computing trajectory"; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; gap: 2px; margin-top: 10px; margin-left: -8px; }
.actions button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--dim); font: .7rem var(--mono); letter-spacing: .08em; text-transform: uppercase; padding: 5px 8px; border-radius: 6px; }
.actions button:hover { color: #fff; background: rgba(255,255,255,.06); }
.small-btn { border: 1px solid var(--hair-2); background: none; color: var(--muted); font: .66rem var(--mono); letter-spacing: .08em; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; }
.small-btn:hover { color: #fff; }

/* ---------- Dock (composer area) ---------- */
.dock { position: relative; display: flex; flex-direction: column; align-items: center; padding: 10px 26px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
body.home .dock { flex: 1; justify-content: center; padding-bottom: 12vh; }

.orbits { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; display: none; }
body.home .orbits { display: block; }
.orbits i { position: absolute; left: 0; top: 0; border-radius: 50%; border: 1px solid rgba(255,255,255,.06); transform: translate(-50%, -50%); }
.orbits i:nth-child(1) { width: 560px; height: 560px; }
.orbits i:nth-child(2) { width: 820px; height: 820px; border-style: dashed; border-color: rgba(255,255,255,.05); animation: orbit 90s linear infinite; }
.orbits i:nth-child(3) { width: 1120px; height: 1120px; border-color: rgba(255,255,255,.035); }
.orbits i:nth-child(2)::after { content: ""; position: absolute; top: 50%; left: -3px; width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 12px #fff; }
.orbits i:nth-child(1)::after { content: ""; position: absolute; top: -2px; left: 50%; width: 4px; height: 4px; border-radius: 50%; background: rgba(255,255,255,.7); }
@keyframes orbit { to { transform: translate(-50%, -50%) rotate(360deg); } }

.empty { position: relative; text-align: center; margin-bottom: 30px; }
body:not(.home) .empty { display: none; }
.kicker { font-size: .74rem; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); margin: 0 0 14px; }
.empty h1 { margin: 0; font-weight: 300; font-size: clamp(2.4rem, 6vw, 4.2rem); line-height: 1.05; letter-spacing: -.02em; }
.sub { margin: 10px 0 0; color: var(--muted); font-size: 1.1rem; }

.composer {
  position: relative; width: 100%; max-width: 760px; padding: 14px 16px 10px;
  background: var(--glass); border: 1px solid var(--hair-2); border-radius: 4px; backdrop-filter: blur(16px);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: rgba(255,255,255,.35); box-shadow: 0 0 60px rgba(255,255,255,.07); }
.corner { position: absolute; width: 10px; height: 10px; border-color: #fff; border-style: solid; border-width: 0; }
.corner.tl { top: -1px; left: -1px; border-top-width: 1.5px; border-left-width: 1.5px; }
.corner.tr { top: -1px; right: -1px; border-top-width: 1.5px; border-right-width: 1.5px; }
.corner.bl { bottom: -1px; left: -1px; border-bottom-width: 1.5px; border-left-width: 1.5px; }
.corner.br { bottom: -1px; right: -1px; border-bottom-width: 1.5px; border-right-width: 1.5px; }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: none; color: var(--ink);
  font: inherit; font-size: 1.05rem; line-height: 1.5; padding: 2px 0 10px; max-height: 220px;
}
body.home .composer textarea { min-height: 56px; }
.composer textarea::placeholder { color: var(--dim); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.meta { font-size: .68rem; letter-spacing: .08em; color: var(--dim); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.send {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border: 0; border-radius: 3px;
  background: #fff; color: #000; font: 600 .74rem var(--mono); letter-spacing: .14em; text-transform: uppercase;
  transition: opacity .2s, transform .15s;
}
.send:hover:not(:disabled) { transform: translateX(2px); }
.send:disabled { opacity: .22; cursor: default; }
.send .i-stop { display: none; }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.send.stop .send-label::after { content: ""; }
.send.stop .send-label { font-size: 0; }
.send.stop .send-label::before { content: "Stop"; font-size: .74rem; }

.suggestions { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 760px; margin-top: 16px; }
body:not(.home) .suggestions { display: none; }
.suggestions button {
  display: inline-flex; gap: 6px; padding: 8px 14px; border: 1px solid var(--hair-2); border-radius: 999px;
  background: rgba(0,0,0,.5); font-size: .85rem; color: var(--muted); transition: .2s;
}
.suggestions button:hover { color: #fff; border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.05); }
.suggestions b { color: var(--ink); font-weight: 500; }
.hint { position: relative; margin: 12px 0 0; font-size: .72rem; color: var(--dim); text-align: center; }
body.home .hint { position: absolute; bottom: 16px; left: 0; right: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .rail { display: none; }
  .only-mobile { display: grid; }
  .panel { left: 0; width: min(86vw, 320px); transform: translateX(-100%); }
  .panel.open { transform: none; }
  .topbar { height: 56px; padding: 0 10px; gap: 8px; }
  .wordmark { flex: 1; text-align: center; font-size: .82rem; }
  body:not(.home) .wordmark { display: none; }
  body:not(.home) .title { display: block; }
  .title { display: none; }
  .hud-clock { display: none; }
  .hud-right { gap: 6px; }
  .mode button { padding: 4px 9px; font-size: .68rem; }
  .messages { padding: 18px 16px 12px; }
  .msg { padding: 16px 0; }
  .dock { padding: 8px 12px 12px; }
  body.home .dock { padding-bottom: 10vh; }
  .orbits i:nth-child(1) { width: 340px; height: 340px; }
  .orbits i:nth-child(2) { width: 520px; height: 520px; }
  .orbits i:nth-child(3) { width: 720px; height: 720px; }
  .meta { display: none; }
  .composer-row { justify-content: flex-end; }
  .suggestions button:nth-child(n+4) { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Compact composer once a conversation is under way */
body:not(.home) .composer { display: flex; align-items: flex-end; gap: 12px; padding: 10px 10px 10px 16px; }
body:not(.home) .composer textarea { flex: 1; min-width: 0; padding: 5px 0; }
body:not(.home) .composer .meta { display: none; }
