:root {
  color-scheme: light;
  --paper: #f5f3ed;
  --panel: #fffefa;
  --ink: #222928;
  --muted: #596562;
  --edge: #dedfd7;
  --accent: #295b51;
  --accent-hover: #1e483f;
  --mint: #e1eee8;
  --warn: #8a432a;
  font-family: 'Instrument Sans', 'Microsoft YaHei', 'PingFang SC', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button, a, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #679b8a; outline-offset: 3px; }
a { color: var(--accent); }
.primary, .secondary, .text-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border: 1px solid transparent;
  border-radius: 12px; font-weight: 650; text-decoration: none; white-space: nowrap;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover:enabled, a.primary:hover { background: var(--accent-hover); }
.secondary { color: var(--ink); background: var(--panel); border-color: var(--edge); }
.secondary:hover:enabled, .secondary:hover:is(a) { background: var(--mint); }
.text-button { background: transparent; color: var(--muted); padding-inline: 8px; }
.text-button:hover { color: var(--ink); text-decoration: underline; }
.small { min-height: 42px; padding-inline: 12px; font-size: 14px; }
.brand-icon {
  display: inline-grid; place-items: center; flex: none; width: 50px; height: 50px;
  font: 700 22px Consolas, monospace; letter-spacing: -.08em;
  color: #fff; background: var(--accent); border-radius: 15px;
}
.brand-icon.mini { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
.connection { display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 13px; }
.connection::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #ab8355; flex: none; }
.connection[data-online="true"]::before { background: #45846a; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.setup-shell { max-width: 1030px; margin: auto; padding: 28px 34px 32px; }
.setup-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: clamp(28px, 8vh, 90px); }
.wordmark { display: flex; align-items: center; gap: 11px; font-size: 17px; font-weight: 750; }
.setup-card {
  display: grid; grid-template-columns: 1.25fr 1fr; align-items: stretch; border: 1px solid var(--edge);
  background: var(--panel); border-radius: 25px; overflow: hidden; box-shadow: 0 14px 40px #2337310b;
}
.setup-copy { padding: clamp(28px, 5vw, 62px); align-self: center; }
.setup-copy h1 { margin: 0 0 14px; font-size: clamp(28px, 4vw, 45px); letter-spacing: -.06em; line-height: 1.2; }
.setup-copy p { color: var(--muted); margin: 0; max-width: 25em; line-height: 1.75; }
.details { margin: 28px 0 22px; border-top: 1px solid var(--edge); }
.details div { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--edge); }
.details dt { flex: none; color: var(--muted); font-size: 14px; }
.details dd { min-width: 0; margin: 0; font-weight: 680; overflow-wrap: anywhere; text-align: right; }
.scan-panel { display: grid; justify-items: center; align-content: center; background: #e8efe9; padding: 34px 20px; text-align: center; }
.scan-panel p { color: var(--muted); margin: 16px 0 12px; max-width: 22em; font-size: 14px; line-height: 1.5; }
.qr-frame { width: min(242px, 100%); aspect-ratio: 1; display: grid; place-items: center; background: #fff; border: 1px solid #d4e1d9; border-radius: 16px; padding: 9px; }
.qr-frame img { width: 100%; height: auto; image-rendering: pixelated; }
.manual-setup { margin-top: 14px; max-width: 100%; color: var(--muted); font-size: 14px; }
.manual-setup summary { cursor: pointer; }
.manual-setup bdi, .manual-setup strong { display: block; overflow-wrap: anywhere; }
.manual-setup strong { margin-top: 8px; font: 700 20px Consolas, monospace; color: var(--ink); }
.manual-pair { display: grid; gap: 10px; margin: 24px auto 0; max-width: 270px; }
.manual-pair label { font-size: 14px; color: var(--muted); }
.manual-pair input { width: 100%; min-height: 44px; text-align: center; border: 1px solid var(--edge); border-radius: 10px; font: 18px Consolas, monospace; text-transform: uppercase; }
.qr-placeholder { width: 72%; height: 72%; display: grid; grid-template: 1fr 1fr / 1fr 1fr; gap: 35%; }
.qr-placeholder span { border: 5px solid var(--edge); border-radius: 6px; }
.setup-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.setup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 650px) {
  .setup-shell { padding: 20px 16px; }
  .setup-card { grid-template-columns: 1fr; }
  .setup-footer { flex-direction: column; align-items: flex-start; }
}

.pair-screen { display: grid; place-items: center; min-height: 100dvh; padding: 22px; }
.pair-panel { width: min(100%, 400px); text-align: center; padding: 44px 22px; background: var(--panel); border: 1px solid var(--edge); border-radius: 23px; }
.pair-panel h1 { font-size: 25px; margin: 18px 0 10px; }
.pair-panel p { color: var(--muted); margin: 0; line-height: 1.55; }
.chat-shell { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-header {
  display: grid; grid-template-columns: 1fr minmax(0, 2fr) 1fr; gap: 8px; align-items: center;
  background: var(--panel); border-bottom: 1px solid var(--edge);
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
}
.chat-header button:first-child { justify-self: start; }
.chat-header button:last-child { justify-self: end; }
.chat-heading { display: grid; justify-items: center; gap: 3px; text-align: center; min-width: 0; }
.chat-heading strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-scroll { overflow-y: auto; overscroll-behavior: contain; }
.chat-content, .composer-wrap { width: min(100%, 780px); margin-inline: auto; }
.chat-content { padding: 22px clamp(12px, 4vw, 30px) 26px; }
.thread-heading { display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--edge); padding-bottom: 14px; margin-bottom: 22px; }
.thread-heading h1 { font-size: 17px; margin: 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.older { display: flex; margin: 0 auto 18px; font-size: 14px; }
.empty { text-align: center; padding: clamp(42px, 16vh, 146px) 12px 24px; }
.empty h1 { font-size: clamp(20px, 4vw, 27px); margin: 15px 0 7px; }
.empty button { margin-top: 10px; }
.history-status, .readonly-note { color: var(--muted); font-size: 14px; line-height: 1.5; }
.readonly-note { margin: 4px 0; }
.messages { display: grid; gap: 17px; }
.bubble { min-width: 0; overflow-wrap: anywhere; line-height: 1.65; }
.bubble.user { justify-self: end; max-width: min(92%, 590px); background: var(--mint); border-radius: 17px 17px 4px 17px; padding: 11px 15px; white-space: pre-wrap; }
.bubble.assistant { justify-self: start; max-width: 100%; background: var(--panel); border: 1px solid var(--edge); border-radius: 5px 17px 17px; padding: 12px 15px; }
.role-label { display: block; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p { margin-block: 9px; }
.message-body ul, .message-body ol { padding-inline-start: 24px; }
.message-body blockquote { margin: 8px 0; border-left: 3px solid var(--edge); color: var(--muted); padding-left: 12px; }
.message-body pre { max-width: 100%; overflow-x: auto; background: #eeeFE9; border-radius: 10px; padding: 12px; }
.message-body code { font: .88em Consolas, monospace; background: #eeefe9; border-radius: 4px; padding: 2px 4px; }
.message-body pre code { padding: 0; }
.message-body table { display: block; max-width: 100%; overflow: auto; border-collapse: collapse; }
.message-body td, .message-body th { border: 1px solid var(--edge); padding: 4px 8px; }
.working { width: fit-content; display: flex; gap: 8px; align-items: center; margin-top: 17px; font-size: 14px; color: var(--muted); }
.working i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite alternate; }
@keyframes pulse { to { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .working i { animation: none; } }
.composer-area { background: var(--paper); border-top: 1px solid var(--edge); padding: 9px 12px calc(10px + env(safe-area-inset-bottom)); }
.model-settings { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 5px; font-size: 13px; color: var(--muted); }
.attention { padding: 10px 14px; margin-bottom: 8px; color: #583b16; background: #fff1d8; border: 1px solid #dbbc81; border-radius: 10px; font-size: 14px; }
.attention p { margin: 4px 0; }
.attention summary { cursor: pointer; }
.thread-attention { color: #795014; font-weight: 650; }
.model-settings select { font: inherit; min-height: 38px; max-width: 100%; border: 1px solid var(--edge); border-radius: 8px; padding: 0 6px; color: var(--ink); background: var(--panel); }
.composer { display: flex; align-items: flex-end; gap: 8px; border: 1px solid #c9d3c9; background: var(--panel); padding: 7px; border-radius: 17px; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  min-width: 0; width: 100%; min-height: 44px; max-height: 130px; resize: none;
  border: 0; border-radius: 9px; background: var(--panel); color: var(--ink); padding: 11px 8px; font-size: 16px; line-height: 22px;
}
.composer textarea:focus { outline: none; }
.inline-status { font-size: 13px; line-height: 1.5; margin: 0 0 7px; color: var(--accent); overflow-wrap: anywhere; }
.inline-status.error { color: var(--warn); }
.thread-drawer {
  position: fixed; inset: 0 auto 0 0; margin: 0; padding: 0; border: 0; width: min(88vw, 365px);
  height: 100dvh; max-height: 100dvh; background: var(--panel); color: var(--ink);
}
.thread-drawer[open] { display: flex; flex-direction: column; }
.thread-drawer::backdrop { background: #18272270; }
.drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px; border-bottom: 1px solid var(--edge); }
.drawer-header h2 { font-size: 16px; margin: 0; }
.thread-list { flex: 1; overflow: auto; padding: 8px; }
.thread-list > p { margin: 12px; }
.history-status.error { color: var(--warn); }
.history-action { margin: 8px 10px; }
.thread-row { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); border: 0; border-radius: 11px; padding: 11px 10px; }
.thread-row:hover, .thread-row[aria-current="true"] { background: var(--mint); }
.thread-row strong { display: block; overflow-wrap: anywhere; margin-bottom: 3px; }
.thread-row-meta { display: flex; flex-wrap: wrap; gap: 3px 12px; font-size: 12px; color: var(--muted); }
.thread-row-meta span { overflow-wrap: anywhere; }
.drawer-footer { padding: 8px 12px; border-top: 1px solid var(--edge); }
