:root {
  color-scheme: light dark;
  font-family: "Microsoft YaHei UI", system-ui, sans-serif;
  --body: #f7f7f5;
  --card: #ffffff;
  --raised: #f5f5f2;
  --line: #e2e2db;
  --ink: #262622;
  --muted: #6b6a64;
  --solid: #2c2c28;
  --inverse: #ffffff;
  --link: #2861bb;
  --good: #23834b;
  --warn: #9a5a12;
  --bad: #bc4536;
}
@media (prefers-color-scheme: dark) {
  :root {
    --body: #1c1c1b;
    --card: #242422;
    --raised: #2c2c29;
    --line: #3c3c36;
    --ink: #f0f0eb;
    --muted: #adaca3;
    --solid: #ecebe4;
    --inverse: #242422;
    --link: #91b9ff;
    --good: #6ccb8c;
    --warn: #edb67d;
    --bad: #ff9588;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--body); color: var(--ink); font-size: 15px; line-height: 1.5; }
h1, h2, p, pre { margin: 0; }
h1 { font-size: 24px; letter-spacing: -.04em; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.app { display: flex; flex-direction: column; width: min(100%, 55rem); height: 100%; height: 100dvh; margin: 0 auto; }
.topbar {
  min-height: 60px; padding: max(9px, env(safe-area-inset-top)) 16px 9px;
  display: flex; align-items: center; gap: 10px; flex: none; border-bottom: 1px solid var(--line); background: var(--card);
}
.topbar-title { min-width: 0; flex: 1; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 750; letter-spacing: -.03em; }
.brand-mark {
  display: grid; width: 27px; height: 27px; place-items: center; background: var(--solid); color: var(--inverse);
  border-radius: 8px; font-size: 16px; font-weight: 800;
}
.topbar h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; letter-spacing: 0; }
.connection { display: inline-flex; align-items: center; gap: 6px; flex: none; color: var(--muted); font-size: 12px; }
.connection i, .status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.connection[data-state="online"] i, .status-dot.running { color: var(--good); }
.connection[data-state="offline"] i { color: var(--warn); }
.button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 42px;
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; background: var(--card);
  color: var(--ink); font-size: 14px; font-weight: 550; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.button:not(:disabled):hover, .icon-button:not(:disabled):hover { background: var(--raised); }
.button.primary, .button.primary:not(:disabled):hover { border-color: var(--solid); background: var(--solid); color: var(--inverse); }
.button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button.stop { color: var(--bad); }
.icon-button { width: 42px; padding: 0; font-size: 24px; background: transparent; border-color: transparent; }
.icon-button.back { font-size: 32px; line-height: .85; }
.muted { color: var(--muted); font-size: 13px; }
.notice {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--raised);
  color: var(--muted); font-size: 13px; overflow-wrap: anywhere;
}
.notice[data-error="true"] { color: var(--bad); }
.pair-page { display: grid; flex: 1; min-height: 0; overflow: auto; align-items: start; justify-items: center; padding: clamp(24px, 7vh, 68px) 14px 28px; }
.pair-card {
  width: min(100%, 395px); padding: clamp(18px, 6vw, 27px); border: 1px solid var(--line);
  border-radius: 18px; background: var(--card); box-shadow: 0 10px 32px #2323210a;
}
.pair-card > p:not(.notice) { color: var(--muted); margin: 4px 0 20px; }
.pair-icon { display: grid; place-items: center; width: 46px; height: 46px; background: var(--raised); border-radius: 13px; margin-bottom: 12px; }
.pair-icon i { position: relative; width: 15px; height: 23px; border: 2px solid var(--ink); border-radius: 4px; }
.pair-icon i::after { content: ""; position: absolute; width: 4px; height: 2px; border-radius: 2px; bottom: 2px; left: 4px; background: var(--ink); }
.pair-card form { display: grid; gap: 14px; }
.pair-card label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; }
.pair-card input, textarea, .question input[type="text"] {
  width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink); padding: 10px 11px; font-size: 16px;
}
.pair-card .pair-code { letter-spacing: .24em; font-variant-numeric: tabular-nums; }
.pair-card .notice { margin-top: 14px; }
.pair-card .pair-retry { margin-top: 6px; }
.pair-pending { display: grid; justify-items: start; gap: 12px; padding-top: 6px; }
.spinner { display: block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--link); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.home-page { min-height: 0; flex: 1; overflow: auto; padding: 19px 16px max(16px, env(safe-area-inset-bottom)); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 16px; }
.session-list { display: grid; gap: 7px; margin-top: 12px; }
.session-row {
  display: flex; width: 100%; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  padding: 11px 12px; border-radius: 11px; text-align: left; cursor: pointer;
}
.session-row:hover { background: var(--raised); }
.session-row > span { min-width: 0; flex: 1; display: grid; gap: 2px; }
.session-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 620; }
.session-row small { color: var(--muted); font-size: 12px; }
.session-row .chevron { color: var(--muted); font-size: 20px; line-height: 1; }
.empty { padding: 24px 11px; text-align: center; color: var(--muted); }
.home-footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }
.chat-page { min-height: 0; flex: 1; display: flex; flex-direction: column; background: var(--card); }
.message-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 10px; overscroll-behavior: contain; }
.earlier { display: flex; margin: 0 auto 14px; }
.turn { display: grid; gap: 12px; margin-bottom: 20px; }
.msg { min-width: 0; }
.msg.user {
  justify-self: end; max-width: min(85%, 38rem); padding: 9px 12px; border-radius: 13px 13px 4px 13px; background: var(--raised);
}
.msg > p { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { margin-top: 5px; color: var(--muted); font-size: 11px; }
.msg-attachments { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.msg.step { border-left: 2px solid var(--line); padding-left: 10px; color: var(--muted); font-size: 13px; }
.msg.step summary { cursor: pointer; overflow-wrap: anywhere; }
.msg.step > pre {
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 13rem; overflow-y: auto; padding-top: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
.files { padding: 9px 10px; border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.files h2 { font-size: 13px; margin-bottom: 6px; }
.artifact { display: flex; align-items: center; gap: 7px; min-height: 38px; border-top: 1px solid var(--line); }
.artifact strong { min-width: 0; flex: 1; color: var(--link); overflow-wrap: anywhere; font-size: 14px; }
.artifact .button { min-height: 34px; border-color: transparent; font-size: 12px; padding: 4px 7px; }
.question { display: grid; gap: 8px; background: var(--raised); padding: 11px; border-radius: 11px; min-width: 0; }
.question p { overflow-wrap: anywhere; }
.question label { display: flex; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.question .button { justify-self: start; }
.composer { flex: none; padding: 9px 12px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.composer .notice { margin-bottom: 7px; }
.composer form { display: grid; gap: 7px; }
.composer textarea { display: block; min-height: 52px; max-height: 120px; resize: vertical; }
.composer-actions { display: flex; justify-content: space-between; gap: 6px; }
.send-actions { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.attach-button { position: relative; cursor: pointer; }
.attach-button:focus-within { outline: 2px solid var(--link); outline-offset: 2px; }
.attach-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.attachments { display: flex; gap: 5px; overflow-x: auto; }
.attachment {
  display: inline-flex; align-items: center; flex: none; gap: 4px; max-width: min(76vw, 300px);
  padding-left: 7px; border-radius: 7px; background: var(--raised); font-size: 12px;
}
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment button { flex: none; width: 32px; min-height: 32px; font-size: 19px; }
.preview {
  padding: 0; color: var(--ink); width: min(calc(100% - 16px), 49rem);
  max-height: min(calc(100% - 16px), 82vh); border: 1px solid var(--line); border-radius: 14px; background: var(--card);
}
.preview::backdrop { background: #0008; }
.preview[open] { display: grid; grid-template-rows: auto minmax(42px, 1fr) auto; }
.preview header, .preview footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; }
.preview header { border-bottom: 1px solid var(--line); }
.preview footer { justify-content: flex-end; border-top: 1px solid var(--line); }
.preview h2 { font-size: 15px; overflow-wrap: anywhere; }
.preview-body { min-height: 0; padding: 12px; overflow: auto; }
.preview-body img { display: block; max-width: 100%; max-height: 58vh; object-fit: contain; margin: auto; }
.preview-body iframe { display: block; width: 100%; height: min(58vh, 650px); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.preview-body pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, Consolas, monospace; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
@media (max-width: 359px) {
  .topbar, .home-page, .message-scroll { padding-left: 10px; padding-right: 10px; }
  .composer-actions .button { padding-left: 8px; padding-right: 8px; }
}
