:root {
  color-scheme: light;
  --brand: #0f6cbd;
  --brand-hover: #115ea3;
  --brand-press: #0c3b5e;
  --brand-tint: #e6f2fb;
  --brand-soft: #cfe4f6;
  --ink: #f3f3f3;
  --panel: #ffffff;
  --wash: #f5f5f5;
  --well: #fafafa;
  --line: #e0e0e0;
  --line-strong: #d1d1d1;
  --text: #242424;
  --muted: #616161;
  --ok: #0e700e;
  --bad: #b10e1c;
  --ease: cubic-bezier(0.33, 0, 0.67, 1);
  --sans: "Segoe UI Variable", "Segoe UI", "Source Sans 3", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --radius: 4px;
  --radius-lg: 8px;
  --shadow-4: 0 0 2px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-8: 0 0 2px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-16: 0 0 2px rgba(0, 0, 0, 0.1), 0 8px 24px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  background: var(--panel);
  color: var(--text);
}
body::before,
body::after { display: none; }
body[data-auth="0"] { background: #f2f2f2; }
body[data-auth="0"] .band { display: none; }

.is-hidden, [hidden] { display: none !important; }

.band {
  z-index: 9;
  display: grid;
  grid-template-columns: auto minmax(14rem, 32rem) auto;
  align-items: center;
  gap: 16px;
  min-height: 48px;
  padding: 0 12px 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.band-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.band-word {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.icon-btn,
.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  box-shadow: none;
  border-radius: var(--radius);
}
.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
}
.ghost-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  border-color: var(--line);
}
.icon-btn:hover,
.ghost-btn:hover {
  background: var(--wash);
  color: var(--text);
}
.hud {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}
.hud-line {
  color: var(--muted);
  font-size: 0.78rem;
}
.hud-line strong { font-weight: 600; color: var(--text); }
.hud-run { display: inline-flex; align-items: center; gap: 6px; }
.hud-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a8a8a;
}
.band.is-live .hud-dot { background: var(--brand); }
.band.is-live #hud-run { color: var(--brand); }
.hud-cmd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--wash);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 0.84rem;
}
.hud-cmd kbd {
  font: 600 0.68rem var(--sans);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 1px 5px;
}
.hud-cmd:hover { background: #fff; border-color: var(--brand); color: var(--text); }
.band-mark { display: grid; }

.gate {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 3rem 1.25rem;
}
.ms-login { width: min(26rem, 100%); }
.ms-login-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}
.ms-login-foot {
  margin: 1rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}
.gate-kicker, .eyebrow {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--brand);
}
.gate-lead {
  margin: 0 0 1.1rem;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.3rem 1.35rem;
  box-shadow: var(--shadow-8);
}
.auth-card-kicker {
  margin: 0 0 0.3rem;
  font-size: 1.5rem;
  font-weight: 600;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.auth-tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.55rem 0.3rem;
  font-weight: 600;
}
.auth-tabs button.is-on {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.auth-form { display: grid; gap: 0.8rem; }
label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.76rem;
  font-weight: 600;
}
input, textarea, button { font: inherit; color: var(--text); }
input, textarea {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.62rem 0.72rem;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}
button {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 0.62rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--brand-hover); }
button:active { background: var(--brand-press); }
button:disabled { opacity: 0.45; cursor: wait; }
.error { color: var(--bad); margin: 0.25rem 0 0; font-size: 0.85rem; }

.studio {
  z-index: 9;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) minmax(340px, 38%);
  background: var(--panel);
  transition: grid-template-columns 0.22s var(--ease);
}
.studio.is-rail-off { grid-template-columns: 0 minmax(0, 1fr) minmax(340px, 38%); }
.studio.is-preview-off { grid-template-columns: 248px minmax(0, 1fr) 0; }
.studio.is-rail-off.is-preview-off { grid-template-columns: 0 minmax(0, 1fr) 0; }
.studio.is-rail-off .rail,
.studio.is-preview-off .preview-pane {
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.rail {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--wash);
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 10px;
}
.rail-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.rail-head button {
  width: auto;
  height: 28px;
  padding: 0 10px;
  font-size: 0.75rem;
}
.rail-foot { margin-top: auto; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.account {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
}
.account-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
}
.account-copy { min-width: 0; }
.who { margin: 0; font-size: 0.84rem; font-weight: 600; }
.account-copy button {
  padding: 0;
  background: none;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
}
.account-copy button:hover { background: none; color: var(--brand); }
.chat-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 8px;
}
.chat-list-empty { margin: 12px 8px; color: var(--muted); font-size: 0.8rem; }
.chat-list button {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  text-align: left;
  font-size: 0.86rem;
}
.chat-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #fff;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.74rem;
}
.chat-copy { min-width: 0; display: grid; gap: 1px; }
.chat-name, .chat-meta {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-name { font-weight: 600; }
.chat-meta { color: var(--muted); font-size: 0.7rem; }
.chat-list button:hover { background: #ebebeb; color: var(--text); }
.chat-list button.is-on { background: var(--brand-tint); color: var(--text); }

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
.chat-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.chat-sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.8rem; }
.studio.is-chatting .chat-head h2 { font-size: 1.05rem; }
.thread {
  overflow: auto;
  padding: 20px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--well);
}
.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb {
  background: #c8c8c8;
  border-radius: 99px;
  border: 2px solid var(--well);
}
.thread-empty {
  margin: auto;
  max-width: 34rem;
  width: 100%;
  padding: 1rem 0 2rem;
}
.thread-empty-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand);
}
.thread-empty-title {
  margin: 0 0 0.4rem;
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.thread-empty p { margin: 0; color: var(--muted); line-height: 1.5; }
.prompt-list {
  display: grid;
  gap: 6px;
  margin-top: 1.15rem;
}
.prompt-list button {
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 0.7rem 0.85rem;
  font-weight: 500;
}
.prompt-list button:hover {
  background: var(--brand-tint);
  color: var(--text);
  border-color: var(--brand-soft);
}

.bubble {
  max-width: 42rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.rise { animation: rise 0.24s var(--ease); }
.bubble.user {
  margin-left: auto;
  background: var(--brand);
  color: #fff;
}
.bubble.assistant {
  background: #fff;
  border: 1px solid var(--line);
}
.bubble.think {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: fit-content;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.4rem 0.7rem;
}
.think-orb {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  animation: think-pulse 1.4s ease-out infinite;
}
.think-label { font-size: 0.84rem; }
.think-dots { display: flex; gap: 0.16rem; }
.think-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.3;
  animation: think-dot 1.1s infinite;
}
.think-dots i:nth-child(2) { animation-delay: 0.15s; }
.think-dots i:nth-child(3) { animation-delay: 0.3s; }
.bubble.think.is-done {
  opacity: 0.7;
  border-color: transparent;
  background: transparent;
  padding: 0.1rem 0;
}
.bubble.think.is-done .think-dots,
.bubble.think.is-done .think-orb { display: none; }
.stream-text.md { display: block; white-space: normal; }
.stream-text.md p { margin: 0 0 0.6rem; }
.stream-text.md p:last-child { margin-bottom: 0; }
.stream-text.md h1, .stream-text.md h2, .stream-text.md h3 { margin: 0 0 0.45rem; font-weight: 600; }
.stream-text.md ul, .stream-text.md ol { margin: 0 0 0.6rem 1.1rem; }
.stream-text.md code {
  font-size: 0.86em;
  font-family: var(--mono);
  background: var(--wash);
  padding: 0.08rem 0.28rem;
  border-radius: 2px;
}
.stream-text.md pre {
  margin: 0.35rem 0 0.65rem;
  padding: 0.7rem 0.8rem;
  overflow: auto;
  background: #1b1a19;
  color: #f3f2f1;
  border-radius: var(--radius);
  white-space: pre-wrap;
}
.stream-text.md pre code { padding: 0; background: none; color: inherit; }
.stream-text.md a { color: var(--brand); }
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--brand);
  animation: blink 0.9s steps(1) infinite;
}
.bubble.assistant:not(.is-stream) .caret { display: none; }

.composer {
  display: grid;
  gap: 0.45rem;
  margin: 12px 20px 16px;
  padding: 10px 12px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: #fff;
}
.composer textarea {
  resize: none;
  min-height: 64px;
  border: 0;
  background: transparent;
  padding: 0.2rem 0.15rem;
  box-shadow: none;
}
.composer textarea:focus { box-shadow: none; }
.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.composer-hint {
  margin: 0 auto 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}
.composer #send { padding: 0.36rem 0.85rem; }
.composer.is-live { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }

.mode-tabs {
  display: flex;
  gap: 0;
  border-bottom: 0;
}
.mode-tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.28rem 0.55rem;
  border-radius: var(--radius);
  font-size: 0.76rem;
  font-weight: 600;
}
.mode-tabs button.is-on {
  background: var(--brand-tint);
  color: var(--brand);
}

.preview-pane {
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  background: var(--wash);
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.preview-tabs { display: flex; gap: 2px; }
.preview-tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
}
.preview-tabs button:hover:not(.is-on) { color: var(--text); background: var(--wash); }
.preview-tabs button.is-on { color: var(--brand); background: var(--brand-tint); }
.preview-status {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-stage {
  min-height: 0;
  overflow: hidden;
  background: #fff;
}
.preview-frame, .files-view {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.files-view {
  display: grid;
  grid-template-rows: auto auto 32% 1fr;
}
.files-empty {
  margin: 0;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  border-bottom: 1px solid var(--line);
  background: var(--well);
}
.files-empty.is-hidden { display: none; }
.files-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--wash);
}
.file-path {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--brand);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.files-chrome button { padding: 0.28rem 0.65rem; font-size: 0.75rem; }
.files-view ul {
  margin: 0;
  padding: 0.7rem 0.9rem;
  overflow: auto;
  border-bottom: 1px solid var(--line);
  list-style: none;
  background: var(--well);
}
.files-view li { padding: 0.16rem 0; }
.files-view button.link {
  background: none;
  color: var(--brand);
  padding: 0;
  font-weight: 500;
}
.files-view textarea {
  margin: 0;
  padding: 0.85rem;
  overflow: auto;
  font-size: 0.78rem;
  font-family: var(--mono);
  border: 0;
  border-radius: 0;
  resize: none;
}

.palette {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start center;
  padding-top: 14vh;
  background: rgba(0, 0, 0, 0.32);
}
.palette-card {
  width: min(36rem, calc(100vw - 2rem));
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-16);
}
.palette-kicker {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}
.palette-card input { width: 100%; }
.palette-card ul { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 2px; }
.palette-card li button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font-weight: 500;
}
.palette-card li button:hover,
.palette-card li button.is-on { background: var(--brand-tint); color: var(--text); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes think-pulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 108, 189, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(15, 108, 189, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 108, 189, 0); }
}
@keyframes think-dot {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}
@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes flash {
  0% { opacity: 0.35; }
  100% { opacity: 1; }
}
.preview-frame.flash { animation: flash 0.55s ease; }
.auth-card { animation: rise 0.3s var(--ease); }

@media (max-width: 1100px) {
  .studio { grid-template-columns: 220px minmax(0, 1fr) minmax(280px, 36%); }
  .studio.is-rail-off { grid-template-columns: 0 minmax(0, 1fr) minmax(280px, 36%); }
  .studio.is-preview-off { grid-template-columns: 220px minmax(0, 1fr) 0; }
  .hud-line:first-child { display: none; }
}

@media (max-width: 900px) {
  .studio,
  .studio.is-rail-off,
  .studio.is-preview-off,
  .studio.is-rail-off.is-preview-off {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 40vh;
  }
  .studio.is-rail-off .rail { display: none; }
  .studio.is-preview-off .preview-pane { display: none; }
  .preview-pane { border-left: 0; border-top: 1px solid var(--line); }
  .hud { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
