:root {
  color-scheme: dark;
  --bg: #090c12;
  --surface: rgb(16 23 35 / 90%);
  --surface-strong: #111a29;
  --surface-soft: #0d1420;
  --ink: #f5f7ff;
  --muted: #9fb0ca;
  --muted-strong: #c2cee0;
  --line: rgb(113 151 213 / 22%);
  --line-strong: rgb(145 187 255 / 42%);
  --blue: #4388ff;
  --violet: #825dff;
  --label: #91bbff;
  --danger: #ff9a9a;
  --danger-bg: rgb(107 35 50 / 28%);
  --shadow: 0 18px 55px rgb(0 0 0 / 13%);
  --headline-accent: #a8bfff;
  --focus-surface: #121d2e;
  --placeholder: rgb(159 176 202 / 62%);
  --page-glow-a: rgb(68 117 255 / 11%);
  --page-glow-b: rgb(130 93 255 / 7%);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: rgb(255 255 255 / 92%);
  --surface-strong: #f8faff;
  --surface-soft: #edf2f8;
  --ink: #101724;
  --muted: #64738a;
  --muted-strong: #39485e;
  --line: rgb(36 73 120 / 16%);
  --line-strong: rgb(36 73 120 / 34%);
  --label: #2868cc;
  --danger: #b4233a;
  --danger-bg: rgb(180 35 58 / 8%);
  --shadow: 0 18px 55px rgb(32 52 82 / 10%);
  --headline-accent: #466fc4;
  --focus-surface: #ffffff;
  --placeholder: rgb(100 115 138 / 68%);
  --page-glow-a: rgb(68 117 255 / 8%);
  --page-glow-b: rgb(130 93 255 / 5%);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
[hidden] { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 76% 4%, var(--page-glow-a), transparent 27rem),
    radial-gradient(circle at 13% 44%, var(--page-glow-b), transparent 25rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
.page-shell { width: min(1184px, calc(100% - 48px)); margin: 0 auto; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; object-fit: contain; }
.brand small {
  display: block;
  margin-top: 1px;
  color: var(--label);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0;
}
.top-actions { display: flex; align-items: center; gap: 24px; }
.nav-link {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: color 180ms ease;
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { color: var(--label); }
.status { color: var(--muted); font-size: 12px; }
.theme-picker { display: inline-flex; }
.theme-picker select {
  width: 100px;
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 11px;
}
.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  background: #72d7a1;
  box-shadow: 0 0 0 4px rgb(114 215 161 / 10%);
}

.workspace { padding: 52px 0 72px; }
.intro { width: min(100%, 1000px); margin: 0 auto; }
.eyebrow {
  margin: 0 0 14px;
  color: var(--label);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}
h1 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Songti SC", STSong, serif;
  font-size: 64px;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0;
  text-wrap: balance;
}
h1 em {
  color: var(--headline-accent);
  font-style: normal;
}
.intro-copy {
  max-width: 62ch;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.8;
  text-wrap: pretty;
}
.retention-notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  width: min(100%, 1000px);
  margin: 32px auto 0;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.retention-count {
  color: var(--label);
  font-family: Georgia, "Songti SC", STSong, serif;
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}
.retention-notice strong { display: block; color: var(--ink); font-size: 13px; }
.retention-notice p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.65; }
.retention-notice p + p { margin-top: 2px; }
.retention-tag { color: var(--label); font-size: 10px; font-weight: 700; }
.retention-tag.storage-error { color: var(--danger); }

.studio-grid {
  display: grid;
  width: min(100%, 1000px);
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  margin: 40px auto 0;
  align-items: start;
}
.control-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
}
.composer-topline {
  display: grid;
  grid-template-columns: minmax(15rem, 0.8fr) minmax(20rem, 1.2fr);
  gap: 28px;
  align-items: end;
}
.model-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 12px 0;
}
.model-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 10px;
  color: var(--ink);
  background: linear-gradient(135deg, var(--blue), var(--violet));
  font-size: 11px;
  font-weight: 800;
}
.model-strip strong { display: block; color: var(--ink); font-size: 13px; }
.model-strip small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.field { display: grid; gap: 8px; }
label { color: var(--muted-strong); font-size: 12px; font-weight: 650; }
textarea,
select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface-strong);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
textarea { min-height: 220px; resize: vertical; padding: 16px; font-size: 14px; line-height: 1.65; }
select { height: 42px; padding: 0 11px; font-size: 13px; }
input { height: 44px; padding: 0 66px 0 12px; font-size: 13px; }
select:disabled { cursor: not-allowed; opacity: 0.58; }
textarea:hover,
select:hover,
input:hover { border-color: var(--line-strong); }
textarea:focus,
select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(67 136 255 / 16%);
  background: var(--focus-surface);
}
textarea::placeholder,
input::placeholder { color: var(--placeholder); }
.key-input-wrap { position: relative; }
.visibility-button {
  position: absolute;
  top: 50%;
  right: 6px;
  min-width: 48px;
  height: 32px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 8px;
  color: var(--label);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.visibility-button:hover { color: var(--ink); background: rgb(145 187 255 / 9%); }
.visibility-button:focus-visible,
.nav-link:focus-visible,
.text-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible {
  outline: 2px solid var(--label);
  outline-offset: 3px;
}
.field-help,
.privacy-note {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}
.field-meta,
.result-heading {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.section-label {
  display: block;
  margin-bottom: 5px;
  color: var(--label);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}
.optimizer-tools {
  display: grid;
  gap: 14px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.tool-heading,
.gallery-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.tool-heading h2,
.gallery-heading h2 {
  margin: 0;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0;
}
.optimizer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.compact-button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--label);
  background: var(--surface-strong);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.compact-button:hover { border-color: var(--line-strong); color: var(--ink); }
.compact-button:disabled { cursor: wait; opacity: 0.58; }
.optimize-button { min-height: 42px; padding: 0 15px; }
.optimize-button:disabled { cursor: not-allowed; opacity: 0.5; transform: none; }
.creative-presets {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 20px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}
.creative-presets legend {
  padding: 0 8px 0 0;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
}
.preset-group { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 10px; align-items: start; }
.preset-group > span { padding-top: 7px; color: var(--muted); font-size: 11px; }
.preset-list { display: flex; flex-wrap: wrap; gap: 7px; }
.preset-list button {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted-strong);
  background: var(--surface-strong);
  font-size: 11px;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}
.preset-list button:hover { border-color: var(--line-strong); color: var(--ink); }
.preset-list button[aria-pressed="true"] {
  border-color: rgb(67 136 255 / 62%);
  color: var(--ink);
  background: rgb(67 136 255 / 18%);
}
.options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.advanced-settings { padding-top: 18px; border-top: 1px solid var(--line); }
.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  list-style-position: inside;
}
.advanced-settings summary small { color: var(--muted); font-size: 10px; font-weight: 500; text-align: right; }
.advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 10px;
  padding-top: 18px;
}
.compression-field { grid-column: 1 / -1; }
.compression-field label { display: flex; justify-content: space-between; }
.compression-field output { color: var(--label); font-variant-numeric: tabular-nums; }
input[type="range"] {
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  accent-color: var(--blue);
  cursor: pointer;
}
input[type="range"]:focus { background: transparent; box-shadow: none; }
input[type="range"]:disabled { cursor: not-allowed; opacity: 0.42; }

.primary-button,
.secondary-button {
  min-height: 46px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 180ms ease, filter 180ms ease, border-color 180ms ease;
}
.primary-button {
  border: 1px solid transparent;
  background: linear-gradient(110deg, var(--blue), var(--violet));
  box-shadow: 0 12px 30px rgb(67 99 255 / 18%);
}
.primary-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-button:active,
.secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { cursor: wait; opacity: 0.62; transform: none; filter: none; }
.composer-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.composer-submit .privacy-note { max-width: 54ch; }
.composer-submit .primary-button { width: 220px; flex: 0 0 220px; }

.result-panel {
  position: static;
  display: flex;
  min-height: 620px;
  flex-direction: column;
  padding: 18px;
}
.result-heading { padding: 2px 4px 14px; font-weight: 700; }
.result-heading > span:first-child { color: var(--muted-strong); }
.result-stage {
  position: relative;
  display: grid;
  min-height: 560px;
  flex: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgb(113 151 213 / 12%);
  border-radius: 12px;
  background: var(--surface-soft);
}
.empty-state { color: var(--muted); text-align: center; align-content: center; }
.empty-state p { margin: 16px 0 0; color: var(--muted-strong); font-size: 13px; }
.empty-state small { display: block; margin-top: 7px; font-size: 11px; }
.empty-art {
  display: grid;
  width: 136px;
  height: 136px;
  place-items: center;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: radial-gradient(circle, rgb(67 136 255 / 12%), transparent 68%);
  box-shadow: inset 0 0 40px rgb(67 136 255 / 5%);
}
.empty-logo { width: 88px; height: 88px; object-fit: contain; filter: saturate(0.82); opacity: 0.82; }
.loading-mark {
  width: 70px;
  height: 70px;
  margin-bottom: 2px;
  border: 2px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: loading-turn 900ms linear infinite;
}
.result-stage > img:not(.empty-logo) { width: 100%; height: 100%; object-fit: contain; }
.result-actions { display: flex; gap: 10px; align-items: center; padding: 14px 2px 0; }
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}
.secondary-button:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.text-button {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}
.text-button:hover { color: var(--ink); }
.text-button:disabled { cursor: not-allowed; opacity: 0.42; }
.text-button[data-confirming="true"] { color: var(--danger); }
.error-message {
  width: min(100%, 1000px);
  margin: 16px auto 0;
  border: 1px solid rgb(255 154 154 / 28%);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--danger);
  background: var(--danger-bg);
  font-size: 13px;
}
.session-gallery {
  width: min(100%, 1000px);
  margin: 48px auto 0;
  padding: 26px 0 8px;
  border-top: 1px solid var(--line);
}
.chat-view {
  width: min(100%, 1000px);
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 24px;
  margin: 40px auto 0;
}
.chat-sidebar {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  align-self: start;
}
.chat-sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted-strong); font-size: 12px; }
.chat-sidebar-heading .compact-button { min-height: 28px; padding: 0 8px; }
.recent-chats { display: grid; gap: 5px; margin-top: 14px; }
.recent-chats button { min-width: 0; overflow: hidden; padding: 9px 8px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; font-size: 11px; }
.recent-chats button:hover { color: var(--ink); background: var(--surface-soft); }
.chat-main { min-width: 0; }
.chat-message { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.chat-message.user { align-items: flex-end; }
.chat-message.assistant { align-items: flex-start; }
.chat-message p { max-width: 78%; margin: 0; padding: 10px 13px; border: 1px solid var(--line); border-radius: 11px 3px 11px 11px; color: var(--muted-strong); background: var(--surface); font-size: 12px; line-height: 1.6; }
.chat-message.user p { border-radius: 11px 3px 11px 11px; color: var(--ink); background: rgb(67 136 255 / 12%); }
.chat-message.assistant p { border-radius: 3px 11px 11px 11px; }
.chat-message img { width: min(260px, 70%); max-height: 300px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
}
.chat-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.chat-heading h2 { margin: 0; color: var(--ink); font-size: 22px; }
.chat-heading .section-label { margin: 0 0 3px; }
.chat-status { color: var(--muted); font-size: 11px; }
.chat-thread { padding: 24px 0 0; }
.chat-prompt-wrap { display: flex; align-items: flex-start; gap: 12px; max-width: 760px; margin-left: auto; }
.chat-avatar {
  display: grid; width: 30px; height: 30px; flex: 0 0 30px; place-items: center;
  border: 1px solid var(--line); border-radius: 9px; color: var(--label); background: var(--surface-strong); font-size: 11px; font-weight: 700;
}
.chat-prompt { margin: 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px 3px 12px 12px; color: var(--muted-strong); background: var(--surface); font-size: 13px; line-height: 1.7; white-space: pre-wrap; }
.chat-thread > .result-stage { min-height: 190px; margin-top: 24px; border: 1px solid var(--line); border-radius: 12px; }
.chat-thread > .result-stage:not(.empty-state) { min-height: 0; border: 0; background: transparent; }
.chat-thread > .result-actions { justify-content: flex-start; padding: 10px 0 0; }
.continue-form { display: grid; gap: 9px; margin-top: 20px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.continue-form input { height: 36px; }
.continue-form textarea { min-height: 72px; resize: vertical; padding: 10px 12px; font-size: 12px; }
.continue-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; }
.continue-actions select { width: 150px; height: 32px; font-size: 11px; }
.continue-actions .primary-button { min-height: 34px; padding: 0 18px; }
.gallery-actions { display: flex; align-items: center; gap: 8px; }
.history-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.history-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  transition: border-color 160ms ease, transform 160ms ease;
}
.history-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.history-card.selected {
  border-color: rgb(67 136 255 / 72%);
  box-shadow: 0 0 0 2px rgb(67 136 255 / 12%);
}
.history-select {
  position: absolute;
  z-index: 1;
  top: 7px;
  right: 7px;
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid rgb(245 247 255 / 18%);
  border-radius: 7px;
  color: var(--ink);
  background: rgb(9 12 18 / 82%);
  backdrop-filter: blur(8px);
  font-size: 10px;
  cursor: pointer;
}
.history-select input {
  width: 14px;
  height: 14px;
  margin: 0;
  padding: 0;
  accent-color: var(--blue);
}
.history-item {
  display: grid;
  width: 100%;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: var(--surface-soft);
  cursor: pointer;
  text-align: left;
}
.history-item:focus-visible { outline: 2px solid var(--label); outline-offset: 3px; }
.history-item img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-strong); }
.history-item span { display: block; min-width: 0; padding: 8px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

footer {
  min-height: 72px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 11px;
}
footer > span:first-child { color: var(--label); font-weight: 700; }
.footer-meta { display: flex; align-items: center; gap: 10px; }
.footer-meta i { width: 3px; height: 3px; border-radius: 50%; background: var(--blue); }
footer code { color: var(--muted-strong); }

@keyframes loading-turn { to { transform: rotate(360deg); } }
@media (max-width: 800px) {
  .page-shell { width: min(100% - 32px, 640px); }
  .workspace { padding-top: 42px; }
  h1 { font-size: 48px; }
  .studio-grid { margin-top: 32px; }
  .composer-topline { grid-template-columns: 1fr; gap: 14px; }
  .result-panel { position: static; min-height: 420px; }
  .result-stage { min-height: 348px; }
  .history-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .page-shell { width: min(100% - 24px, 640px); }
  .top-actions { gap: 8px; }
  .nav-link { display: none; }
  .theme-picker select { width: 88px; padding: 0 6px; }
  .status { font-size: 0; }
  .status-dot { margin-right: 0; }
  .workspace { padding: 34px 0 48px; }
  h1 { font-size: 40px; }
  .intro-copy { font-size: 14px; }
  .retention-notice { grid-template-columns: auto minmax(0, 1fr); }
  .retention-tag:not(.storage-error) { display: none; }
  .control-panel { padding: 18px; }
  .composer-submit { align-items: stretch; flex-direction: column; gap: 14px; }
  .composer-submit .primary-button { width: 100%; flex-basis: auto; }
  .optimizer-row { grid-template-columns: 1fr; }
  .optimize-button { width: 100%; }
  .preset-group { grid-template-columns: 1fr; gap: 6px; }
  .preset-group > span { padding-top: 0; }
  .options { grid-template-columns: 1fr; }
  .advanced-grid { grid-template-columns: 1fr; }
  .compression-field { grid-column: auto; }
  .advanced-settings summary { align-items: flex-start; flex-direction: column; gap: 4px; }
  .result-panel { min-height: 390px; }
  .result-stage { min-height: 310px; }
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-heading { align-items: flex-start; flex-direction: column; }
  .chat-heading { grid-template-columns: 1fr auto; align-items: start; }
  .chat-heading .text-button { grid-column: 1 / -1; justify-self: start; }
  .chat-heading h2 { font-size: 18px; }
  .chat-prompt-wrap { margin-left: 0; }
  .chat-view { grid-template-columns: 1fr; gap: 14px; }
  .chat-sidebar { order: 2; }
  .chat-main { order: 1; }
  .chat-message p { max-width: 90%; }
  .chat-message img { width: min(220px, 76%); }
  .continue-actions { flex-wrap: wrap; justify-content: stretch; }
  .continue-actions .primary-button { flex: 1; }
  .continue-actions select { flex: 1; width: auto; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; padding: 18px 0; }
  .footer-meta { max-width: 100%; flex-wrap: wrap; }
  .footer-meta code:first-child { overflow-wrap: anywhere; }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f3f6fb;
    --surface: rgb(255 255 255 / 92%);
    --surface-strong: #f8faff;
    --surface-soft: #edf2f8;
    --ink: #101724;
    --muted: #64738a;
    --muted-strong: #39485e;
    --line: rgb(36 73 120 / 16%);
    --line-strong: rgb(36 73 120 / 34%);
    --label: #2868cc;
    --danger: #b4233a;
    --danger-bg: rgb(180 35 58 / 8%);
    --shadow: 0 18px 55px rgb(32 52 82 / 10%);
    --headline-accent: #466fc4;
    --focus-surface: #ffffff;
    --placeholder: rgb(100 115 138 / 68%);
    --page-glow-a: rgb(68 117 255 / 8%);
    --page-glow-b: rgb(130 93 255 / 5%);
  }
}

/* Full-viewport chat route, matching the VibeStudio workspace composition. */
.workspace:has(#chat-view:not([hidden])) {
  width: 100%;
  padding: 0;
}
.workspace:has(#chat-view:not([hidden])) > .intro,
.workspace:has(#chat-view:not([hidden])) > .retention-notice,
.workspace:has(#chat-view:not([hidden])) > #session-gallery,
.workspace:has(#chat-view:not([hidden])) > #studio,
.workspace:has(#chat-view:not([hidden])) > #error-message {
  display: none !important;
}
body:has(#chat-view:not([hidden])) { overflow: hidden; }
.page-shell:has(#chat-view:not([hidden])) { width: 100%; max-width: none; }
.page-shell:has(#chat-view:not([hidden])) { height: 100dvh; overflow: hidden; }
.page-shell:has(#chat-view:not([hidden])) .topbar {
  height: 64px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.page-shell:has(#chat-view:not([hidden])) footer { display: none; }
.page-shell:has(#chat-view:not([hidden])) .chat-view {
  width: 100%;
  min-height: calc(100dvh - 64px);
  margin: 0;
  border: 0;
  grid-template-columns: 250px minmax(0, 1fr) !important;
  gap: 0;
}
.page-shell:has(#chat-view:not([hidden])) .chat-sidebar,
.page-shell:has(#chat-view:not([hidden])) .chat-main { min-height: calc(100dvh - 64px); }
.page-shell:has(#chat-view:not([hidden])) .chat-view { height: calc(100dvh - 64px); overflow: hidden; }
.page-shell:has(#chat-view:not([hidden])) .chat-sidebar { overflow-y: auto; }
.page-shell:has(#chat-view:not([hidden])) .chat-main { overflow: hidden; }
.page-shell:has(#chat-view:not([hidden])) .chat-sidebar { background: var(--surface); }
.page-shell:has(#chat-view:not([hidden])) .chat-main { background: var(--bg); }
.page-shell:has(#chat-view:not([hidden])) .chat-heading,
.page-shell:has(#chat-view:not([hidden])) .chat-thread,
.page-shell:has(#chat-view:not([hidden])) .continue-form { width: auto; }
.page-shell:has(#chat-view:not([hidden])) .chat-thread { margin: 0; padding-right: 8vw; padding-left: 8vw; }

:root[data-theme="light"] .page-shell:has(#chat-view:not([hidden])) {
  --bg: #f5f4ed;
  --surface: #fbfaf5;
  --surface-strong: #f8f7f1;
  --surface-soft: #efeee7;
  --ink: #262522;
  --muted: #827d72;
  --muted-strong: #4c4942;
  --line: #e7e2d8;
  --line-strong: #d8cfc2;
  --label: #c96442;
  --blue: #c96442;
}

/* The conversation route has exactly two columns: directory and messages. */
.page-shell:has(#chat-view:not([hidden])) .chat-view {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) !important;
  gap: 0;
}
.page-shell:has(#chat-view:not([hidden])) .chat-sidebar {
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 0;
}
.page-shell:has(#chat-view:not([hidden])) .recent-chats {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.chat-storage-note {
  flex: 0 0 auto;
  margin: 12px 2px 0;
  padding: 12px 8px 2px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.chat-storage-note strong { display: block; color: var(--muted-strong); font-size: 11px; }
.chat-storage-note p { margin: 5px 0 0; font-size: 10px; line-height: 1.55; }
.chat-storage-note details { margin-top: 7px; }
.chat-storage-note summary { color: var(--label); font-size: 10px; cursor: pointer; }
.chat-storage-note details p { padding-bottom: 6px; }
.page-shell:has(#chat-view:not([hidden])) .chat-main {
  position: relative;
  min-width: 0;
  overflow: hidden;
}
.page-shell:has(#chat-view:not([hidden])) .chat-heading {
  grid-template-columns: 34px minmax(0, 1fr) auto;
  min-height: 62px;
  padding: 10px 26px;
}
.page-shell:has(#chat-view:not([hidden])) .chat-heading .text-button {
  width: 30px;
  overflow: hidden;
  color: var(--muted-strong);
  font-size: 0;
  white-space: nowrap;
}
.page-shell:has(#chat-view:not([hidden])) .chat-heading .text-button::before {
  content: "‹";
  font-size: 24px;
  line-height: 1;
}
.page-shell:has(#chat-view:not([hidden])) .chat-heading h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Georgia, "Songti SC", STSong, serif;
  font-size: 14px;
}
.page-shell:has(#chat-view:not([hidden])) .chat-thread {
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 190px;
}
.page-shell:has(#chat-view:not([hidden])) .chat-thread > .result-stage,
.page-shell:has(#chat-view:not([hidden])) .chat-thread > .result-actions { display: none !important; }
.page-shell:has(#chat-view:not([hidden])) .chat-message { margin: 24px 0; }
.page-shell:has(#chat-view:not([hidden])) .chat-message.user { align-items: flex-end; }
.page-shell:has(#chat-view:not([hidden])) .chat-message.assistant { align-items: flex-start; }
.page-shell:has(#chat-view:not([hidden])) .chat-message p {
  max-width: 650px;
  color: var(--muted-strong);
  line-height: 1.75;
}
.page-shell:has(#chat-view:not([hidden])) .chat-message.user p { color: var(--ink); }
.page-shell:has(#chat-view:not([hidden])) .chat-message img {
  width: min(360px, 72%);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 10%);
}
.page-shell:has(#chat-view:not([hidden])) .continue-form {
  position: absolute;
  right: auto;
  bottom: 16px;
  left: 50%;
  display: block;
  width: min(800px, calc(100% - 48px));
  margin: 0;
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgb(0 0 0 / 10%);
  transform: translateX(-50%);
}
.chat-api-row {
  display: flex;
  align-items: center;
  min-height: 27px;
  gap: 8px;
  padding: 0 2px 8px;
}
.chat-key-mark { color: var(--label); font-family: ui-monospace, monospace; font-size: 9px; font-weight: 700; }
.chat-api-row input { height: 25px; padding: 0; border: 0; border-radius: 0; background: transparent; font-size: 11px; }
.chat-compose-row { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.chat-compose-row textarea { flex: 1; min-height: 42px; max-height: 120px; padding: 10px 6px; border: 0; border-radius: 8px; background: transparent; resize: none; font-size: 13px; }
.chat-image-button { display: grid; width: 32px; height: 32px; flex: 0 0 32px; padding: 0; place-items: center; border: 0; border-radius: 8px; color: var(--muted-strong); background: transparent; cursor: pointer; }
.chat-image-button:hover { color: var(--label); background: var(--surface-soft); }
.image-plus-icon { position: relative; display: block; width: 21px; height: 20px; }
.image-plus-icon::before {
  content: "";
  position: absolute;
  bottom: 1px;
  left: 1px;
  width: 15px;
  height: 14px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}
.image-plus-sun {
  position: absolute;
  z-index: 1;
  top: 7px;
  left: 5px;
  width: 3px;
  height: 3px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}
.image-plus-mountain {
  position: absolute;
  z-index: 1;
  bottom: 4px;
  left: 4px;
  width: 10px;
  height: 6px;
  background: currentColor;
  clip-path: polygon(0 100%, 35% 35%, 55% 65%, 72% 42%, 100% 100%);
}
.image-plus-mark { position: absolute; z-index: 2; top: 0; right: 0; width: 9px; height: 9px; }
.image-plus-mark::before,
.image-plus-mark::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 1px;
  width: 8px;
  height: 1.5px;
  border-radius: 1px;
  background: currentColor;
}
.image-plus-mark::after { transform: rotate(90deg); }
.chat-send-button { display: grid; width: 40px; height: 40px; flex: 0 0 40px; place-items: center; border: 0; border-radius: 12px; color: #fff; background: var(--label); cursor: pointer; font-size: 20px; }
.chat-send-button:hover { filter: brightness(1.08); }
.chat-send-button:disabled { cursor: wait; opacity: .6; }
.chat-reference { position: relative; width: 48px; height: 48px; flex: 0 0 48px; overflow: hidden; border-radius: 9px; background: var(--surface-soft); }
.chat-reference img { width: 100%; height: 100%; object-fit: cover; }
.chat-reference button {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  width: 18px;
  height: 18px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgb(9 12 18 / 82%);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.page-shell:has(#chat-view:not([hidden])) .continue-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.page-shell:has(#chat-view:not([hidden])) .continue-actions select { order: 1; width: 150px; height: 30px; border: 0; background: var(--surface-soft); font-size: 11px; }
.page-shell:has(#chat-view:not([hidden])) .continue-actions #chat-optimize { order: 2; }
.page-shell:has(#chat-view:not([hidden])) .continue-actions #chat-load-models { order: 0; }
@media (max-width: 800px) {
  .page-shell:has(#chat-view:not([hidden])) .chat-view { grid-template-columns: 1fr !important; }
  .page-shell:has(#chat-view:not([hidden])) .chat-sidebar { min-height: 112px; max-height: 112px; border-right: 0; border-bottom: 1px solid var(--line); }
  .page-shell:has(#chat-view:not([hidden])) .chat-main { min-height: calc(100dvh - 176px); }
  .page-shell:has(#chat-view:not([hidden])) .chat-thread { width: calc(100% - 28px); }
  .page-shell:has(#chat-view:not([hidden])) .continue-form { width: calc(100% - 28px); }
}

/* VibeStudio-inspired conversation workspace */
.chat-view {
  width: calc(100% + 48px);
  margin: 24px -24px 0;
  min-height: 720px;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 0;
  border: 1px solid var(--line);
  background: var(--bg);
}
.chat-sidebar {
  min-height: 720px;
  padding: 16px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-strong);
}
.chat-main { border: 0; border-radius: 0; }
.chat-sidebar-heading {
  min-height: 30px;
  padding: 0 6px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
}
.chat-sidebar-heading::before { content: "▢  对话"; color: var(--label); margin-right: auto; }
.chat-sidebar-heading strong { display: none; }
.chat-sidebar-heading .compact-button { border: 0; color: var(--muted-strong); background: transparent; }
.recent-chats { gap: 3px; margin-top: 12px; }
.recent-chats button { padding: 10px 9px; border-radius: 10px; font-size: 12px; }
.recent-chats button:hover, .recent-chats button[aria-current="true"] { color: var(--ink); background: var(--surface-soft); }
.chat-main {
  position: relative;
  display: flex;
  min-height: 720px;
  flex-direction: column;
  background: var(--bg);
}
.chat-heading {
  flex: 0 0 auto;
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 62px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.chat-heading h2 { font-size: 14px; font-weight: 500; }
.chat-heading .section-label { display: none; }
.chat-heading .text-button { color: var(--muted-strong); font-size: 18px; line-height: 1; }
.chat-thread {
  flex: 1 1 auto;
  width: min(760px, calc(100% - 44px));
  margin: 0 auto;
  padding: 24px 0 160px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.chat-prompt-wrap { max-width: 640px; gap: 8px; }
.chat-avatar { width: 22px; height: 22px; flex-basis: 22px; border-radius: 50%; font-size: 9px; color: var(--label); background: var(--surface-soft); }
.chat-prompt { padding: 0; border: 0; background: transparent; font-size: 13px; line-height: 1.8; }
.chat-thread > .result-stage { min-height: 0; margin: 38px 0 0; border: 0; border-radius: 0; background: transparent; }
.chat-thread > .result-stage.empty-state { min-height: 260px; border: 0; }
.chat-thread > .result-stage[hidden] { display: none; }
.chat-thread > .result-actions { padding: 10px 0 0; }
.chat-message { margin: 28px 0; }
.chat-message p { max-width: 640px; padding: 0; border: 0; background: transparent; font-size: 13px; line-height: 1.8; }
.chat-message.user p { background: transparent; }
.chat-message img { width: min(360px, 72%); max-height: 420px; border-radius: 13px; box-shadow: 0 8px 24px rgb(0 0 0 / 10%); }
.continue-form {
  position: absolute;
  right: 22px;
  bottom: 18px;
  left: 22px;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  margin: 0 auto;
  width: min(800px, calc(100% - 44px));
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgb(0 0 0 / 10%);
}
.continue-form input { grid-column: 1 / -1; height: 30px; border: 0; background: transparent; }
.continue-form textarea { grid-column: 1; min-height: 42px; border: 0; background: transparent; resize: none; }
.continue-actions { grid-column: 1 / -1; justify-content: flex-start; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.continue-actions .primary-button { margin-left: auto; min-width: 42px; padding: 0 16px; border-radius: 10px; }
.continue-actions select { order: 1; }
.continue-actions #chat-optimize { order: 2; }
.continue-actions #continue-button { order: 3; }
@media (max-width: 800px) {
  .chat-view { width: 100%; margin: 18px 0 0; grid-template-columns: 1fr; }
  .chat-sidebar { min-height: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-main { min-height: 680px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
