:root {
  color-scheme: light;
  font-family: system-ui, "Microsoft YaHei UI", sans-serif;
  color: var(--ink);
  background: var(--surface);
  --ink: #222a25;
  --muted: #58615b;
  --line: #dbe1da;
  --surface: #f8f9f6;
  --paper: #fdfefa;
  --soft: #edf1ea;
  --accent: #276345;
  --action: #234d39;
  --action-text: #f7fbf7;
  --action-hover: #173b2a;
  --notice: #6c501d;
  --gutter: clamp(14px, 4vw, 32px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 880px);
  height: 100%;
  height: 100dvh;
  margin-inline: auto;
  border-inline: 1px solid var(--line);
  background: var(--paper);
}

.masthead {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: max(4px, env(safe-area-inset-top)) var(--gutter) 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; white-space: nowrap; font-size: 14px; font-weight: 720; }
.mark {
  display: inline-grid;
  place-content: center;
  width: 27px;
  height: 27px;
  border-radius: 7px;
  background: var(--soft);
  color: var(--accent);
  font: 700 14px ui-monospace, monospace;
}
.connection { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.signal { width: 7px; height: 7px; border-radius: 50%; background: #a66c2b; }
body[data-connected="true"] .signal { background: var(--accent); }
.quiet { min-height: 44px; padding-inline: 8px; border: 0; border-radius: 6px; background: transparent; color: var(--accent); font-size: 13px; }
.quiet:hover { background: var(--soft); }
.masthead .quiet { flex: none; white-space: nowrap; }
.theme-select { min-width: 0; min-height: 44px; max-width: 90px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: inherit; font-size: 12px; }
.theme-select:hover { background: var(--soft); }

#pair { display: grid; align-content: center; min-height: 0; flex: 1; padding: clamp(20px, 6vw, 58px); }
.pair-panel { width: min(100%, 420px); margin-inline: auto; padding-bottom: 6vh; }
.pair-panel h1 { margin: 0; font-size: clamp(28px, 6vw, 36px); letter-spacing: -.04em; }
.pair-panel > p { margin: 10px 0 28px; color: var(--muted); line-height: 1.6; }
.pair-panel label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 700; }
.pair-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
.access-key-field { margin-bottom: 14px; }
.pair-panel .remember-pairing { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 5px 0 0; font-weight: 500; }
.remember-pairing input { width: 17px; min-height: auto; height: 17px; margin: 0; accent-color: var(--accent); }
input, textarea { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); color: var(--ink); font-size: 16px; }
input { min-height: 50px; padding-inline: 12px; letter-spacing: .16em; font-family: ui-monospace, monospace; }
textarea { min-height: 48px; max-height: min(24dvh, 160px); resize: none; field-sizing: content; padding: 9px 10px; line-height: 1.45; }
textarea::placeholder, input::placeholder { color: var(--muted); opacity: 1; }
.primary { min-height: 44px; padding: 8px 16px; border: 1px solid transparent; border-radius: 9px; background: var(--action); color: var(--action-text); font-weight: 700; }
.primary:hover:not(:disabled) { background: var(--action-hover); }

.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.masthead, .chat-header, .composer { flex-shrink: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 42px; padding: 4px var(--gutter); border-bottom: 1px solid var(--line); }
.chat-header h1 { min-width: 0; overflow: hidden; margin: 0; font-size: 14px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.view-switch { flex: none; white-space: nowrap; }
.sessions-button { display: inline-flex; flex: none; align-items: center; gap: 4px; white-space: nowrap; padding-inline: 8px; margin-inline-start: -5px; }
.unread-count {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding-inline: 4px;
  border-radius: 999px;
  background: var(--action);
  color: var(--action-text);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chat-header h1 { flex: 1; }
.desktop-preview { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding-inline: var(--gutter); background: var(--surface); }
.preview-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.preview-toolbar button { flex: none; }
.preview-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; background: var(--surface); }
.preview-scroll img { display: block; max-width: 100%; height: auto; margin-inline: auto; }
.actual-size img { max-width: none; }
.transcript { position: relative; flex: 1; min-height: 0; overflow: auto; padding: 18px max(var(--gutter), calc((100% - 680px) / 2)) 5px; overscroll-behavior: contain; }
.message { min-width: 0; margin: 0 0 18px; font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.message.user { width: fit-content; max-width: 88%; margin-left: auto; padding: 9px 12px; border-radius: 12px 12px 4px 12px; background: var(--soft); }
.message-time { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.user .message-time { text-align: right; }
.message p, .message li { white-space: pre-wrap; }
.message p, .message ul, .message pre { margin: 0; }
.message :is(p, ul, pre) + :is(p, ul, pre) { margin-top: 7px; }
.message ul { padding-inline-start: 1.35em; }
.message a { color: var(--accent); text-underline-offset: 2px; }
.message .link-preview { display: grid; gap: 2px; max-width: 100%; width: fit-content; min-width: 120px; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; background: var(--surface); color: var(--ink); font-size: 13px; text-decoration: none; }
.link-preview span { color: var(--muted); font-size: 11px; }
.message a.link-preview:hover { background: var(--soft); }
.message pre { overflow: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font: 13px/1.55 ui-monospace, monospace; overflow-wrap: normal; }
.message pre code { font: inherit; }
.message .activity-time { color: var(--muted); font-size: 12px; }
.inline-detail, .change-summary { margin: 9px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; }
.inline-detail summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px; cursor: pointer; font-weight: 650; }
.inline-detail summary::-webkit-details-marker { display: none; }
.inline-detail summary::before { content: ""; flex: 0 0 6px; height: 6px; margin-inline: 1px 3px; border: solid var(--muted); border-width: 0 1px 1px 0; transform: rotate(-45deg); }
.inline-detail[open] summary::before { transform: rotate(45deg); }
.inline-detail[open] summary { border-bottom: 1px solid var(--line); }
.inline-detail summary:hover { background: var(--soft); }
.activity-list { margin: 0; padding: 8px 12px 10px 30px; }
.activity-list li + li { margin-top: 5px; }
.message .change-list { padding: 0; list-style: none; }
.change-list li { display: flex; align-items: baseline; gap: 8px; padding: 7px 10px; }
.change-list li + li { border-top: 1px solid var(--line); }
.change-list code { min-width: 0; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, monospace; }
.line-counts { display: flex; flex: none; gap: 7px; margin-inline-start: auto; font: 650 12px/1.5 ui-monospace, monospace; white-space: nowrap; }
.added { color: var(--accent); }
.removed { color: #a23938; }
.change-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 7px 10px; }
.message .detail-note { padding: 7px 10px; color: var(--muted); font-size: 12px; }
.change-summary .detail-note { flex-basis: 100%; padding: 0; }
.empty { margin: 24px auto; color: var(--muted); text-align: center; }
.composer { position: relative; margin: 0; border-top: 1px solid var(--line); background: var(--surface); padding: 9px var(--gutter) max(9px, env(safe-area-inset-bottom)); }
.compose-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.compose-controls:focus-within { border-color: var(--accent); }
.compose-controls textarea { border: 0; }
.compose-controls textarea:focus-visible { outline: 0; }
.compose-toolbar { display: flex; align-items: center; gap: 6px; min-width: 0; }
.compose-toolbar .primary { margin-inline-start: auto; flex: none; }
.add-image { flex: none; padding-inline: 6px; white-space: nowrap; }
.attachment-list { display: flex; gap: 8px; overflow-x: auto; list-style: none; margin: 0; padding: 6px; }
.attachment-list li { position: relative; flex: 0 0 68px; height: 68px; }
.attachment-list img { display: block; width: 100%; height: 100%; object-fit: cover; border: 1px solid var(--line); border-radius: 9px; background: var(--soft); }
.remove-image { position: absolute; top: 0; right: 0; min-width: 36px; min-height: 36px; border: 0; border-radius: 4px 9px 4px 8px; background: var(--action); color: var(--action-text); font-size: 20px; line-height: 1; }
.composer-meta { display: flex; gap: 2px; min-width: 0; }
.model-trigger { min-width: 0; min-height: 44px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.model-trigger::after { content: ""; display: inline-block; width: 4px; height: 4px; margin-inline: 6px 2px; border: solid currentColor; border-width: 0 1px 1px 0; transform: translateY(-2px) rotate(45deg); }
.model-trigger:hover { background: var(--soft); color: var(--ink); }
.live-turn { display: flex; align-items: center; gap: 8px; margin: 8px 0 16px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.live-turn::before { content: ""; flex: 0 0 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.live-turn-text { background: linear-gradient(105deg, var(--muted) 32%, var(--ink) 48%, var(--muted) 64%) 100% 0 / 220% 100%; background-clip: text; color: transparent; animation: pocket-live 2s linear infinite; }
@keyframes pocket-live { to { background-position: -100% 0; } }
.latest { position: absolute; z-index: 1; right: var(--gutter); bottom: calc(100% + 8px); min-height: 44px; padding-inline: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--accent); font-size: 13px; }
.latest:hover { background: var(--soft); }
.notice, .pair-panel .notice { margin: 0 0 8px; color: var(--notice); line-height: 1.45; font-size: 13px; }
.pair-panel .notice { margin-top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.session-drawer { position: fixed; inset: 0 auto 0 0; width: min(100%, 410px); height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-inline-end: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.session-drawer[open] { display: flex; flex-direction: column; }
.session-drawer::backdrop { background: rgb(16 22 18 / 60%); }
.drawer-header { display: flex; align-items: center; gap: 5px; padding: max(5px, env(safe-area-inset-top)) 14px 5px; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0 auto 0 0; font-size: 17px; }
.drawer-scroll { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 12px 14px max(18px, env(safe-area-inset-bottom)); }
.session-new { width: 100%; margin-bottom: 10px; }
.drawer-note { margin-bottom: 10px; }
.session-active { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.session-active-title { display: grid; gap: 3px; }
.session-active-title span { color: var(--muted); font-size: 12px; }
.session-active-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.session-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.session-group { margin-top: 6px; border-bottom: 1px solid var(--line); }
.session-group-header { display: flex; align-items: center; gap: 5px; }
.session-group-toggle, .session-row { min-height: 44px; padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); text-align: left; }
.session-group-toggle { display: flex; flex: 1; align-items: center; gap: 9px; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.session-group-toggle::before { content: ""; flex: 0 0 6px; height: 6px; border: solid var(--muted); border-width: 0 1px 1px 0; transform: rotate(-45deg); }
.session-group-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
.session-group ul { margin: 0 0 5px; padding: 0; list-style: none; }
.session-row { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; padding-inline-start: 24px; }
.session-row.with-state { display: flex; align-items: center; gap: 8px; }
.session-row-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.session-state { flex: none; width: 12px; height: 12px; margin-inline-start: auto; border-radius: 50%; }
.session-state.running { border: 2px solid var(--line); border-top-color: var(--accent); animation: pocket-spin .9s linear infinite; }
.session-state.waiting { background: var(--notice); width: 7px; height: 7px; }
.session-state.unread { background: var(--accent); width: 8px; height: 8px; }
.session-group-toggle .session-state { margin-inline-start: 0; }
@keyframes pocket-spin { to { transform: rotate(360deg); } }
.session-row:hover, .session-group-toggle:hover, .session-row[aria-current] { background: var(--soft); }
.session-more { margin-inline-start: 16px; }
.group-empty { margin: 0 0 9px 24px; color: var(--muted); font-size: 13px; }
.session-editor { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 10px; }
.session-editor label { font-size: 13px; }
.session-editor input { min-height: 44px; margin-block: 5px; font-family: inherit; letter-spacing: normal; }
.session-editor p { margin: 0 0 6px; font-size: 13px; overflow-wrap: anywhere; }
.quiet.danger { color: #a23938; }
.primary.danger-button { background: #a23938; color: #fff4f1; }
.primary.danger-button:hover:not(:disabled) { background: #842d2c; }

.model-picker { position: fixed; inset: auto auto var(--picker-bottom, 80px) var(--picker-left, 12px); width: min(calc(100% - 24px), 320px); max-width: none; max-height: min(380px, var(--picker-height, 60dvh)); margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); overflow: auto; box-shadow: 0 4px 18px rgb(13 20 16 / 18%); }
.model-picker::backdrop { background: rgb(16 22 18 / 12%); }
.model-picker-header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--line); background: var(--paper); }
.model-picker-header h2 { margin: 0; font-size: 14px; }
.model-state { margin: 8px 12px 4px; color: var(--muted); }
.model-options { margin: 0; padding: 4px; list-style: none; }
.model-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 44px; padding: 7px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; color: var(--ink); font-size: 14px; }
.model-option:hover:not(:disabled), .model-option[aria-pressed="true"] { background: var(--soft); }
.model-current { flex: none; color: var(--accent); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .session-state.running, .live-turn-text { animation: none; }
  .live-turn-text { background: none; color: var(--muted); }
}

@media (max-width: 354px) {
  .masthead { gap: 6px; }
  .mark { display: none; }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf1ed;
  --muted: #a9b6ad;
  --line: #39423b;
  --surface: #1b201d;
  --paper: #202521;
  --soft: #2d3831;
  --accent: #9dd6b5;
  --action: #b1d9bd;
  --action-text: #1b3224;
  --action-hover: #c2e6cc;
  --notice: #e2c48e;
}
:root[data-theme="dark"] .removed { color: #f1aaa5; }
:root[data-theme="dark"] .quiet.danger { color: #f1aaa5; }
