:root {
  color-scheme: var(--tg-color-scheme, light dark);
  --base-page: #fbfcfc;
  --base-side: #edf1f1;
  --base-panel: #ffffff;
  --base-text: #182c32;
  --base-muted: #586b70;
  --base-line: #cdd6d7;
  --base-accent: #086f6a;
  --base-on-accent: #ffffff;
  --base-error: #a33d35;
  --base-chart-b: #a35437;
  --page: var(--tg-theme-bg-color, var(--base-page));
  --side: var(--tg-theme-secondary-bg-color, var(--base-side));
  --panel: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--base-panel)));
  --text: var(--tg-theme-text-color, var(--base-text));
  --muted: var(--tg-theme-subtitle-text-color, var(--base-muted));
  --line: var(--tg-theme-section-separator-color, var(--base-line));
  --accent: var(--tg-theme-button-color, var(--base-accent));
  --on-accent: var(--tg-theme-button-text-color, var(--base-on-accent));
  --danger: var(--tg-theme-destructive-text-color, var(--base-error));
  --tint: color-mix(in srgb, var(--accent) 9%, var(--panel));
  --chart-a: var(--accent);
  --chart-b: var(--base-chart-b);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --column: 52rem;
  --rail: clamp(15rem, 22vw, 19rem);
  --gutter: clamp(1.1rem, 3.6vw, 4rem);
  --safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
  --safe-left: max(env(safe-area-inset-left, 0px), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
  --safe-right: max(env(safe-area-inset-right, 0px), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)));
}
@media (prefers-color-scheme: dark) {
  :root {
    --base-page: #111a1e;
    --base-side: #172327;
    --base-panel: #1c292e;
    --base-text: #e7eeef;
    --base-muted: #a2b4b7;
    --base-line: #36464c;
    --base-accent: #78d7ca;
    --base-on-accent: #102c2a;
    --base-error: #ffa79b;
    --base-chart-b: #efa883;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  font: 1rem/1.6 var(--sans); color: var(--text); background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button, select, input:not([type=file]), textarea {
  border: 1px solid var(--line); border-radius: .65rem; background: var(--panel);
}
button, select { min-height: 2.45rem; padding: .42rem .82rem; }
button { cursor: pointer; font-size: .9rem; font-weight: 560; line-height: 1.4; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .52; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, summary:focus-visible, [tabindex="0"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px;
}
a { color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .18em; }
h1, h2, h3, h4, p, pre, figure, dl { margin: 0; }
code, pre, output { font-family: var(--mono); }
pre {
  max-width: 100%; padding: .8rem 1rem; overflow: auto;
  border-radius: .55rem; background: var(--side); font-size: .82rem; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
.primary {
  border-color: transparent; background: var(--accent); color: var(--on-accent);
  font-weight: 650;
}
.primary:hover:not(:disabled) { filter: brightness(.94); border-color: transparent; }
.muted { color: var(--muted); }
.error, [data-state="error"] { color: var(--danger); }
.wordmark { display: flex; align-items: center; gap: .55rem; }
.brand-mark {
  display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 2px;
  width: 2.1rem; height: 2.1rem; border-radius: .68rem;
  background: var(--accent); color: var(--on-accent);
}
.brand-mark i { display: block; width: 3px; height: .5rem; border-radius: 2px; background: currentColor; }
.brand-mark i:nth-child(2) { height: 1.12rem; }
.brand-mark i:nth-child(3) { height: .82rem; }
.brand-mark i:nth-child(4) { height: .36rem; }
.brand-cn { margin-inline-start: .16rem; font-weight: 720; font-size: 1.14rem; }
.brand-name { font-family: var(--sans); font-weight: 620; letter-spacing: -.035em; }

/* The browser and Telegram share the same authenticated workspace. */
.login-page {
  display: grid; min-height: 100vh; min-height: 100dvh; place-items: center;
  padding: max(1.2rem, var(--safe-top)) max(1.2rem, var(--safe-right)) max(1.2rem, var(--safe-bottom)) max(1.2rem, var(--safe-left));
  background: var(--side);
}
.login-card {
  width: min(100%, 27rem); padding: clamp(1.5rem, 5vw, 2.7rem); border: 1px solid var(--line);
  border-radius: 1.2rem; background: var(--panel); box-shadow: 0 12px 45px -35px rgb(0 28 32 / .5);
}
.login-card .wordmark { margin-bottom: 2rem; font-size: 1.18rem; }
.login-card h1 { font-size: 1.85rem; line-height: 1.2; letter-spacing: -.04em; }
.login-intro { margin: .8rem 0 1.45rem; color: var(--muted); }
#pair-start { width: 100%; min-height: 2.85rem; }
#pair-code {
  display: block; margin-top: 1.1rem; border: 1px solid var(--line); border-radius: .65rem;
  padding: .5rem 1rem; background: var(--side); text-align: center;
  font-size: 1.35rem; font-weight: 650; letter-spacing: .12em; overflow-wrap: anywhere;
}
#pair-status { margin-top: .8rem; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
#pair-link { display: inline-block; margin-top: .65rem; }
#pair-code:empty, #pair-status:empty, #pair-link:not([href]), #pair-link[href=""] { display: none; }

.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100vh; height: var(--tg-viewport-height, 100dvh); overflow: hidden; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  padding-inline-start: var(--safe-left); padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
  border-inline-end: 1px solid var(--line); background: var(--side);
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 1.5rem 1.25rem .95rem; }
.sidebar .brand-name { align-self: baseline; color: var(--muted); font-size: .87rem; }
#new-session {
  display: flex; flex: none; align-items: center; gap: .66rem; margin: .55rem 1rem 1.25rem;
  padding: .65rem .82rem; border-radius: .72rem; text-align: start; background: var(--panel);
}
.icon-plus, .icon-close, .icon-nav { position: relative; display: inline-block; width: 1.1rem; height: 1.1rem; }
.icon-plus::before, .icon-plus::after, .icon-close::before, .icon-close::after, .icon-nav::before, .icon-nav::after {
  position: absolute; content: ""; height: 2px; border-radius: 2px; background: currentColor;
}
.icon-plus::before, .icon-plus::after, .icon-close::before, .icon-close::after { top: calc(50% - 1px); left: .1rem; right: .1rem; }
.icon-plus::after { transform: rotate(90deg); }
.icon-close::before { transform: rotate(45deg); }
.icon-close::after { transform: rotate(-45deg); }
.icon-nav::before, .icon-nav::after { left: 0; right: 0; top: .28rem; }
.icon-nav::after { top: .69rem; right: .18rem; }
.icon-button { display: inline-grid; place-items: center; min-width: 2.55rem; min-height: 2.55rem; padding: .4rem; }
.drawer-control, .drawer-scrim { display: none; }
.sidebar-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 .75rem 1.1rem; }
.side-section + .side-section { margin-top: 1.4rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.side-section h2 { margin: 0 .55rem .45rem; color: var(--muted); font-size: .88rem; font-weight: 620; }
.side-list { display: grid; gap: .2rem; min-width: 0; }
.side-list button {
  display: block; min-width: 0; width: 100%; min-height: 2.5rem; padding: .54rem .65rem;
  overflow: hidden; text-overflow: ellipsis; text-align: start; border: 1px solid transparent;
  background: transparent; font-weight: 480; overflow-wrap: anywhere;
}
.side-list button:hover { background: var(--panel); border-color: var(--line); }
.side-list button.selected, .side-list [aria-current="true"], .side-list [aria-current="page"] {
  background: var(--panel); border-color: var(--line); box-shadow: inset 3px 0 var(--accent); font-weight: 650;
}
.side-list small { display: block; margin-top: .12rem; color: var(--muted); font-size: .8rem; }
.side-list:empty::after { margin: .35rem .55rem .55rem; color: var(--muted); font-size: .83rem; }
#sessions:empty::after { content: "暂无会话"; }
#files:empty::after { content: "暂无音频"; }

.workspace { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--page); }
.session-header {
  display: flex; align-items: center; gap: .8rem; min-width: 0; min-height: calc(4.4rem + var(--safe-top));
  padding: calc(.75rem + var(--safe-top)) max(var(--gutter), var(--safe-right)) .75rem var(--gutter);
  border-bottom: 1px solid var(--line);
}
.session-header h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.08rem; font-weight: 650; }
#connection { flex: none; max-width: 35%; font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
#connection:empty { display: none; }
.conversation { position: relative; min-height: 0; min-width: 0; }
.stream {
  height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable;
  padding: 1.4rem max(var(--gutter), var(--safe-right)) 1.4rem var(--gutter);
}
.stream > * { max-width: var(--column); margin-inline: auto; }
.stream:focus { outline-offset: -3px; }
.empty-state {
  display: none; position: absolute; inset: 0; flex-direction: column; align-items: center; justify-content: center;
  gap: .65rem; padding: 1.2rem; text-align: center; pointer-events: none;
}
.stream:empty + .empty-state { display: flex; }
.empty-state .brand-mark { width: 2.8rem; height: 2.8rem; margin-bottom: .4rem; background: var(--tint); color: var(--accent); }
.empty-state h2 { font-size: clamp(1.35rem, 3vw, 1.8rem); letter-spacing: -.04em; }
.empty-state p { color: var(--muted); }
.turn { min-width: 0; overflow-wrap: anywhere; }
.turn + .turn { margin-top: 1.5rem; }
.turn.user { display: flex; flex-direction: column; align-items: flex-end; }
.turn.user .bubble {
  max-width: min(87%, 43rem); padding: .65rem 1rem; white-space: pre-wrap;
  border: 1px solid var(--line); border-radius: 1rem 1rem .25rem 1rem; background: var(--tint);
}
.turn.assistant .bubble, .prose { white-space: pre-wrap; line-height: 1.72; }
.parts { display: grid; gap: .75rem; min-width: 0; }
.turn p + p { margin-top: .72em; }
.card, .file-card, .tool, .job {
  min-width: 0; padding: clamp(.82rem, 2vw, 1.15rem); border: 1px solid var(--line);
  border-radius: .9rem; background: var(--panel); overflow-wrap: anywhere;
}
.turn > :is(.card,.tool,.job) + *, .turn .bubble + .parts { margin-top: .7rem; }
.card h3, .job h3 { font-size: 1rem; }
.card h4 { font-size: .92rem; }
.card > * + *, .job > * + * { margin-top: .68rem; }
.card small, .tool small, .file-card small { color: var(--muted); }
.card :is(input,select,textarea) { max-width: 100%; padding: .48rem .65rem; min-height: 2.45rem; }
.card textarea { width: 100%; min-height: 4rem; font-family: var(--mono); }
.card label { display: grid; gap: .32rem; color: var(--muted); font-size: .9rem; }
.card progress { width: 100%; height: .45rem; accent-color: var(--accent); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%, 8.5rem), 1fr)); gap: .45rem; font-variant-numeric: tabular-nums; }
.metrics > * { min-width: 0; padding: .55rem .65rem; border-radius: .5rem; background: var(--side); }
.metrics dt, .metrics small { display: block; color: var(--muted); font-size: .82rem; }
.metrics dd { margin: 0; font-weight: 620; }
.actions, .ab { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.actions > *, .ab > * { max-width: 100%; }
button[aria-pressed="true"], button.selected { background: var(--tint); border-color: var(--accent); }
.tool { font-size: .92rem; }
.tool summary { cursor: pointer; font-weight: 560; }
.tool details { margin: .55rem 0; }
.tool[open] > summary, .tool details[open] > summary { margin-bottom: .6rem; }
.chart, .card canvas, .card svg, audio { display: block; max-width: 100%; }
.chart, .card canvas, audio { width: 100%; }
.chart { color: var(--chart-a); }
.card table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.card th, .card td { padding: .42rem .52rem; text-align: start; border-bottom: 1px solid var(--line); }

.composer-wrap { padding: .55rem max(var(--gutter), var(--safe-right)) max(1.15rem, var(--safe-bottom)) var(--gutter); }
.composer {
  max-width: var(--column); margin: auto; padding: .75rem; border: 1px solid var(--line);
  border-radius: 1rem; background: var(--panel); box-shadow: 0 4px 18px -14px rgb(0 30 30 / .4);
}
.composer:focus-within { border-color: var(--accent); }
#message {
  display: block; width: 100%; max-height: min(28dvh, 12rem); min-height: 2.4rem; padding: .1rem .25rem;
  resize: vertical; border: 0; border-radius: .25rem; background: transparent; line-height: 1.5;
}
#message:focus { outline: none; }
#message::placeholder { color: var(--muted); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-top: .45rem; }
.attachment {
  display: inline-flex; align-items: center; gap: .5rem; padding-inline: .5rem .66rem;
  border-color: transparent; background: transparent; color: var(--muted);
}
.attachment:hover { background: var(--side); border-color: transparent; color: var(--text); }
.icon-clip {
  display: inline-block; position: relative; width: .64rem; height: 1.1rem;
  border: 1.7px solid currentColor; border-top-color: transparent; border-radius: .35rem; transform: rotate(37deg);
}
.icon-clip::before { content: ""; position: absolute; left: .09rem; top: -.15rem; width: .27rem; height: .84rem; border: 1.5px solid currentColor; border-radius: .22rem; }
#send { min-width: 4rem; }
.picked-file { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin: 0 .2rem .55rem; font-size: .88rem; overflow-wrap: anywhere; }
.picked-file:empty { display: none; }
.toast {
  position: fixed; z-index: 4; bottom: max(1rem, var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  max-width: min(90%, 38rem); border: 1px solid var(--line); border-radius: .72rem; padding: .65rem 1rem;
  background: var(--text); color: var(--page); box-shadow: 0 4px 18px rgb(0 0 0 / .12);
  overflow-wrap: anywhere; font-size: .9rem; pointer-events: none;
}
.toast:empty { display: none; }

@media (max-width: 48rem) {
  :root { --gutter: .85rem; }
  .app { grid-template-columns: minmax(0,1fr); }
  .workspace { padding-inline-start: var(--safe-left); }
  .sidebar {
    position: fixed; z-index: 3; inset-block: 0; inset-inline-start: 0;
    width: min(20rem, 86vw); visibility: hidden; transform: translateX(-100%);
    transition: transform .18s ease, visibility .18s;
  }
  .sidebar.open { visibility: visible; transform: none; }
  .sidebar.open + .drawer-scrim {
    display: block; position: fixed; inset: 0; z-index: 2; padding: 0; border: 0;
    border-radius: 0; background: rgb(8 21 24 / .5);
  }
  .drawer-control { display: inline-grid; }
  .session-header { min-height: calc(3.65rem + var(--safe-top)); padding-block: calc(.45rem + var(--safe-top)) .45rem; gap: .55rem; }
  .session-header h1 { font-size: 1rem; }
  .session-header .icon-button, #drawer-close { background: transparent; border-color: transparent; }
  .stream { padding-block: 1.1rem; scrollbar-gutter: auto; }
  .turn.user .bubble { max-width: 93%; }
  .composer-wrap { padding-top: .3rem; padding-bottom: max(.6rem,var(--safe-bottom)); }
  .composer { padding: .55rem; }
  #message { resize: none; }
  .attachment, #send, .side-list button { min-height: 2.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}
.attachment-picker { width: min(29rem, 92vw); max-height: min(34rem, 82dvh); margin: auto; padding: 1.2rem; overflow: auto; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; }
.attachment-picker::backdrop { background: rgb(8 21 24 / .5); }
.attachment-picker > * + * { margin-block-start: .9rem; }
.attachment-picker > .actions { justify-content: space-between; }
.waveform { display: block; width: 100%; height: 2rem; }
.player { margin-block-start: .4rem; }
