:root {
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  color-scheme: light;
  --bg: #f5f3ed;
  --panel: #fffdfa;
  --ink: #292d2b;
  --muted: #696e68;
  --line: #d9ddd5;
  --accent: #345f51;
  --bubble: #e7ede5;
  --shadow: 0 16px 60px #172b2018;
}
* {
  box-sizing: border-box;
}
body[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #131b21;
  --panel: #1b252d;
  --ink: #e7eee9;
  --muted: #a5b5b3;
  --line: #36434b;
  --accent: #9dd9bf;
  --bubble: #293b41;
  --shadow: 0 16px 60px #0006;
}
body[data-theme="clay"] {
  --bg: #f1e8dd;
  --panel: #fbf4eb;
  --ink: #45342d;
  --muted: #7b655b;
  --line: #dbcabe;
  --accent: #86503a;
  --bubble: #e9dacb;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button,
.file-button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 12px;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.15s;
}
button:hover,
.file-button:hover {
  background: var(--bubble);
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
button.primary {
  background: var(--accent);
  color: var(--panel);
  border-color: transparent;
}
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px;
  min-width: 0;
}
input[type="checkbox"] {
  width: auto;
}
input:focus,
textarea:focus,
button:focus-visible,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label {
  display: block;
  margin: 10px 0;
}
.check {
  display: flex;
  gap: 9px;
  align-items: center;
}
p {
  margin: 8px 0;
}
.hint,
.composer-hint {
  color: var(--muted);
  font-size: 12px;
}
.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
}
h1 {
  font-size: 46px;
  line-height: 1.2;
  font-weight: 550;
  margin: 22px 0;
}
h2 {
  font-size: 21px;
  font-weight: 550;
}
h3 {
  font-size: 16px;
}
section > h3 {
  margin-top: 0;
}
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(100%, 450px);
}
.gate form {
  margin: 26px 0;
}
.gate .primary {
  width: 100%;
  margin-top: 10px;
}
[hidden] {
  display: none !important;
}
#app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  overflow: hidden;
}
.sidebar {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  min-height: 0;
  background: var(--panel);
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sidebar-head strong {
  font-weight: 550;
  letter-spacing: 1px;
}
#close-sidebar {
  display: none;
}
#chat-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
#chat-list button {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 5px;
  border-color: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chat-list button[aria-current="true"] {
  background: var(--bubble);
}
.sidebar-foot {
  display: grid;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.chat-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.topbar {
  height: 68px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
}
#menu {
  display: none;
}
.title-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.title-stack strong {
  font-size: 14px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-stack span {
  font-size: 11px;
  color: var(--muted);
}
.route-button {
  max-width: 40%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px max(24px, calc((100% - 780px) / 2));
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.welcome {
  height: 100%;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}
.welcome h2 {
  font-size: 30px;
  color: var(--ink);
  margin: 14px 0;
}
.message {
  margin: 0 0 30px;
  overflow-wrap: anywhere;
}
.message .meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 7px;
}
.message .content {
  white-space: pre-wrap;
  line-height: 1.8;
}
.message.user {
  margin-left: auto;
  background: var(--bubble);
  padding: 12px 18px;
  border-radius: 18px;
  max-width: 88%;
  width: fit-content;
}
.message.assistant {
  padding: 0 4px;
}
.message details {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 9px 12px;
  border-radius: 10px;
  margin: 8px 0;
  font-size: 13px;
}
.message details p {
  white-space: pre-wrap;
}
.message .finish {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}
summary {
  cursor: pointer;
}
.composer {
  padding: 10px 24px max(10px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  width: min(100%, 850px);
  align-self: center;
}
.composer form {
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 4px 24px #00000005;
}
.composer textarea {
  resize: none;
  border: 0;
  background: transparent;
  min-height: 52px;
  max-height: 150px;
  padding: 6px 8px;
}
.composer textarea:focus {
  outline: none;
}
.composer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.composer-actions button,
.file-button {
  font-size: 12px;
  min-height: 36px;
  padding: 6px 10px;
}
.file-button {
  margin: 0;
}
.spacer {
  flex: 1;
}
.composer-hint {
  text-align: center;
  margin: 5px 0 0;
  font-size: 10px;
}
#error,
#gate-error {
  font-size: 13px;
  color: #a23836;
  max-height: 110px;
  overflow: auto;
}
body[data-theme="midnight"] #error,
body[data-theme="midnight"] #gate-error {
  color: #ffb5b1;
}
#draft-files {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
}
#draft-files button {
  font-size: 12px;
  padding: 4px 8px;
  min-height: 30px;
  margin-bottom: 8px;
}
dialog {
  width: min(620px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow-y: auto;
}
dialog::backdrop {
  background: #12201c80;
  backdrop-filter: blur(4px);
}
.dialog-head {
  position: sticky;
  top: -22px;
  z-index: 4;
  background: var(--panel);
  padding-block: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
}
.dialog-head h2 {
  margin: 0;
}
.dialog-head button {
  font-size: 22px;
  border: 0;
}
dialog section {
  border-bottom: 1px solid var(--line);
  padding: 20px 0;
}
.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}
.actions,
.themes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.themes button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--bubble);
}
#connection-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
#request-preview {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  max-height: 50dvh;
  overflow: auto;
  background: var(--bg);
  padding: 12px;
  border-radius: 10px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
@media (max-width: 720px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 5;
    box-shadow: var(--shadow);
  }
  .sidebar.open {
    display: flex;
  }
  #close-sidebar,
  #menu {
    display: block;
  }
  .topbar {
    height: 60px;
    padding: 8px 12px;
    gap: 8px;
  }
  .topbar button {
    padding: 7px 9px;
  }
  .title-stack strong {
    font-size: 13px;
  }
  .route-button {
    font-size: 12px;
    max-width: 40%;
  }
  .messages {
    padding: 24px 18px;
  }
  .message {
    margin-bottom: 24px;
  }
  .message.user {
    max-width: 92%;
  }
  .composer {
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  }
  .composer-hint {
    font-size: 10px;
  }
  .welcome h2 {
    font-size: 25px;
  }
  dialog {
    padding: 16px;
    border-radius: 16px;
  }
  .two {
    gap: 0 10px;
  }
  h1 {
    font-size: 40px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
/* Local appearance values follow the existing theme vocabulary; never model context. */
#wallpaper {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: var(--local-background, none);
  background-size: cover;
  background-position: calc(var(--local-backgroundX, 50) * 1%)
    calc(var(--local-backgroundY, 50) * 1%);
  opacity: calc(var(--local-backgroundOpacity, 25) / 100);
  filter: blur(calc(var(--local-backgroundBlur, 0) * 1px));
  transform: scale(calc(var(--local-backgroundScale, 100) / 100));
}
#app,
.gate {
  position: relative;
  z-index: 1;
}
body {
  font-family: var(--local-font, system-ui, sans-serif);
}
button.primary {
  color: var(--on-accent, var(--panel));
}
.messages {
  padding-inline: max(
    18px,
    calc((100% - var(--local-readingWidth, 780) * 1px) / 2)
  );
}
.message {
  margin-bottom: calc(var(--local-messageGap, 28) * 1px);
  font-size: calc(var(--local-fontSize, 16) * 1px);
}
.message .content {
  line-height: var(--local-lineHeight, 1.8);
}
.message.user {
  border-radius: calc(var(--local-radius, 18) * 1px);
}
.sidebar,
.composer form {
  background: color-mix(
    in srgb,
    var(--panel) calc(var(--local-panelOpacity, 96) * 1%),
    transparent
  );
}
body[data-message-style="bubbles"] .message.assistant {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--local-radius, 18) * 1px);
  padding: 14px 18px;
}
body[data-message-style="document"] .message.user {
  background: none;
  margin-left: 0;
  padding: 0 4px;
  max-width: 100%;
  width: 100%;
  border-radius: 0;
}
body[data-reduce-motion="true"] *,
body[data-reduce-motion="true"] *::before {
  transition: none !important;
  scroll-behavior: auto !important;
}
#appearance-ranges label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px;
}
#appearance-ranges input {
  grid-column: 1/-1;
  padding: 0;
}
#original-records details {
  border: 1px solid var(--line);
  padding: 8px;
  border-radius: 8px;
  margin: 8px 0;
}
#original-records pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 45dvh;
  overflow: auto;
  font-size: 12px;
}
#original-list button {
  margin: 5px 5px 5px 0;
}
.chat-shell {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
}

input[type="range"],
input[type="checkbox"] {
  accent-color: var(--accent);
}
.archive-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#original-files button {
  display: block;
  margin-block: 8px;
}
/* Long Chinese consent labels must not collapse their touch checkbox. */
.check input[type="checkbox"] {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
}

#library-list {
  max-height: 28dvh;
  overflow: auto;
  display: grid;
  gap: 8px;
  margin-block: 12px;
}
#library-version-preview {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 30dvh;
  overflow: auto;
  font: inherit;
}
#library-existing button {
  margin: 4px;
}
#library-dialog > details {
  margin-block: 16px;
}

.message-actions {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.message-actions button {
  margin: 6px 6px 0 0;
  padding: 5px 8px;
}
#versions-list pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 35dvh;
  overflow: auto;
}
