:root {
  color-scheme: light;
  --bg: #f3f1f7;
  --surface: #ffffff;
  --text: #2d2935;
  --muted: #696173;
  --line: #ded9e7;
  /* The active tab in data/richmenu/menu-main.png. */
  --brand: #7362a2;
  --brand-hover: #615187;
  --brand-ink: #ffffff;
  --focus: #7362a2;
  --control-line: #9c92ae;
  --selected: #e6e0f0;
  --glass: rgb(255 255 255 / .76);
  --glass-edge: rgb(255 255 255 / .9);
  --canvas-wash: #e9e4f1;
  --canvas-light: #faf9fc;
  --mark-bg: #e9e3f2;
  --disabled-bg: #e5e0ec;
  --disabled-ink: #746b80;
  --user-bubble: var(--brand);
  --user-ink: #ffffff;
  --assistant-bubble: #ffffff;
  --tool-bg: #eeebf3;
  --tool-ok: #2e7d32;
  --tool-err: #c62828;
  --danger-action: #b32632;
  --danger-hover: #96212c;
  --radius: 20px;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --content-width: 760px;
  --dialog-width: 440px;
  --drawer-width: 340px;
  --control-size: 44px;
  --icon-size: 20px;
  --icon-small: 16px;
  --mark-size: 88px;
  --mark-icon-size: 54px;
  --button-height: 48px;
  --composer-height: 68px;
  --page-gutter: 24px;
  --motion-fast: 160ms;
  --motion-enter: 380ms;
  --motion-dialog: 220ms;
  --blur-surface: 24px;
  --blur-scrim: 9px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  /* typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, monospace;
  --text-2xs: 12px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-base: 16px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 20px;
  --text-3xl: 22px;
  --text-display: 30px;
  /* spacing (4px scale) */
  --space-0-5: 2px;
  --space-1: 4px;
  --space-1-5: 6px;
  --space-2: 8px;
  --space-control-y: 9px;
  --space-2-5: 10px;
  --space-3: 12px;
  --space-3-5: 14px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  /* radii */
  --radius-2xs: 2px;
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 18px;
  --radius-card: 28px;
  --radius-full: 999px;
  /* overlays, shadows and neutral tints (work on light and dark backgrounds) */
  --on-danger: #ffffff;
  --scrim: rgb(37 29 51 / .32);
  --shadow-sm: 0 4px 16px rgb(49 37 73 / .06);
  --shadow-lg: 0 18px 50px rgb(49 37 73 / .12), inset 0 1px 0 var(--glass-edge);
  --shadow-drawer: 12px 0 40px rgb(49 37 73 / .14);
  --code-bg: rgb(127 127 127 / .15);
  --scrollbar-thumb: rgb(127 127 127 / .5);
  --scrollbar-track: rgb(127 127 127 / .12);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #19171f;
  --surface: #25222d;
  --text: #f1edf6;
  --muted: #b8afc8;
  --line: #40394e;
  --brand: #bdb0df;
  --brand-hover: #d0c4ec;
  --brand-ink: #241c35;
  --focus: #c5b6ed;
  --control-line: #7c708f;
  --selected: #393047;
  --glass: rgb(37 34 45 / .86);
  --glass-edge: rgb(218 205 245 / .12);
  --canvas-wash: #282134;
  --canvas-light: #1e1b26;
  --mark-bg: #342c44;
  --disabled-bg: #3c3548;
  --disabled-ink: #b0a5c0;
  --user-bubble: #7362a2;
  --assistant-bubble: #292530;
  --tool-bg: #302b3b;
  --tool-ok: #81c784;
  --tool-err: #ef9a9a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: var(--text-base)/1.7 var(--font-sans);
  letter-spacing: 0;
  color: var(--text);
  background: linear-gradient(125deg, var(--canvas-wash), var(--canvas-light) 48%, var(--bg));
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; }
button, a { touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: var(--icon-size); height: var(--icon-size); flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: var(--space-3); left: var(--space-3); z-index: 70; padding: var(--space-2) var(--space-4); background: var(--surface); color: var(--brand); border-radius: var(--radius-sm); transform: translateY(-200%); }
.skip-link:focus { transform: none; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
  overflow: hidden;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: calc(var(--space-3) + var(--sat)) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sar)) var(--space-3) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sal));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.title-group { flex: 1; min-width: 0; text-align: center; }
.title {
  margin: 0; font-size: var(--text-lg); font-weight: 600; line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
.title-caption { margin: var(--space-0-5) 0 0; font-size: var(--text-xs); color: var(--muted); }
.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: var(--control-size); height: var(--control-size); border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background var(--motion-fast), transform var(--motion-fast) var(--ease-out);
}
.icon-btn:active { background: var(--tool-bg); }
.icon-btn:disabled { color: var(--disabled-ink); background: var(--disabled-bg); }

/* ---- sidebar ---- */
.sidebar {
  position: absolute; inset: 0 auto 0 0; width: min(88vw, var(--drawer-width));
  background: var(--surface); border-right: 1px solid var(--line);
  transform: translateX(-105%); transition: transform var(--motion-enter) var(--ease-out);
  display: flex; flex-direction: column; z-index: 20;
  padding: var(--sat) 0 var(--sab); overflow-y: auto;
}
.sidebar.open { transform: none; box-shadow: var(--shadow-drawer); }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); font-weight: 600; border-bottom: 1px solid var(--line);
}
.session-list { list-style: none; margin: 0; padding: var(--space-3); overflow-y: auto; flex: 1; min-height: var(--button-height); }
.session-list li {
  display: flex; align-items: center; gap: var(--space-1); border-radius: var(--radius-md);
}
.session-list li.active { background: var(--selected); }
.session-list .sess-btn {
  flex: 1; min-width: 0; min-height: var(--button-height); text-align: left; border: 0; background: transparent; color: var(--text);
  padding: var(--space-2-5) var(--space-3); font: inherit; cursor: pointer; border-radius: var(--radius-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-list .del-btn {
  width: var(--control-size); height: var(--control-size); flex-shrink: 0; border: 0; background: transparent; color: var(--muted);
  font-size: var(--text-xl); cursor: pointer; border-radius: var(--radius-sm);
}
.session-list .del-btn:hover { color: var(--tool-err); }
.sidebar-note {
  margin: 0; padding: var(--space-2) var(--space-4); border-top: 1px solid var(--line);
  font-size: var(--text-xs); line-height: 1.5; color: var(--muted);
}
.sidebar-theme {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); flex-shrink: 0;
  font-size: var(--text-md);
}
.sidebar-theme select {
  width: 100%; min-width: 0; min-height: var(--button-height); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--control-line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.theme-status { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: var(--text-xs); overflow-wrap: anywhere; }
.user-box {
  display: flex; align-items: center; gap: var(--space-2-5); padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line); font-size: var(--text-sm); color: var(--muted);
}
.user-box img { width: 28px; height: 28px; border-radius: 50%; }
.backdrop { position: absolute; inset: 0; background: var(--scrim); z-index: 10; animation: scrim-in var(--motion-fast) ease-out; }

/* ---- messages ---- */
.messages {
  overflow-y: auto; overflow-x: hidden;
  padding: var(--space-6) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sar)) var(--space-6) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sal));
  display: flex; flex-direction: column; gap: var(--space-5); overflow-anchor: auto;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
}
.empty { margin: auto; width: 100%; max-width: var(--dialog-width); text-align: center; color: var(--muted); padding: var(--space-8) 0; }
.empty-mark { display: grid; place-items: center; width: var(--mark-size); height: var(--mark-size); margin: 0 auto var(--space-6); background: var(--mark-bg); color: var(--brand); border: 1px solid var(--glass-edge); border-radius: var(--radius-card); box-shadow: var(--shadow-sm); }
.empty-mark svg { width: var(--mark-icon-size); height: var(--mark-icon-size); fill: currentColor; }
.empty-title { font-size: var(--text-display); font-weight: 600; line-height: 1.35; color: var(--text); margin: 0 0 var(--space-8); overflow-wrap: anywhere; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.chip {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--button-height); min-width: 0; max-width: 100%;
  border: 1px solid var(--control-line); background: var(--surface); color: var(--text);
  border-radius: var(--radius-full); padding: var(--space-3) var(--space-4); font: inherit; font-size: var(--text-md); line-height: 1.5; cursor: pointer;
  overflow-wrap: anywhere; transition: background var(--motion-fast), border-color var(--motion-fast), transform var(--motion-fast) var(--ease-out), box-shadow var(--motion-fast);
}
.chip .icon { color: var(--brand); }

.msg { display: flex; flex-direction: column; flex-shrink: 0; min-width: 0; max-width: 88%; }
.msg.arriving { animation: message-in var(--motion-enter) var(--ease-out); }
.msg .suggestions { display: flex; flex-wrap: wrap; gap: var(--space-1-5); margin-top: var(--space-1-5); }
.msg .suggestions .chip { font-size: var(--text-sm); padding: var(--space-1-5) var(--space-3); border-color: var(--brand); color: var(--brand); }
.msg .suggestions.used .chip { opacity: .5; pointer-events: none; border-color: var(--line); color: var(--muted); }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble {
  /* flex item: min-width:0 stops wide tables / code lines from inflating the bubble
     past the message width; those elements scroll horizontally inside it instead */
  min-width: 0; max-width: 100%;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--assistant-bubble); border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble { background: var(--user-bubble); color: var(--user-ink); border-color: transparent; border-bottom-right-radius: var(--radius-xs); }
.msg.assistant .bubble { border-bottom-left-radius: var(--radius-xs); white-space: normal; }
.msg.assistant .bubble.streaming { white-space: pre-wrap; }
.bubble code { font-family: var(--font-mono); font-size: .92em; background: var(--code-bg); padding: 1px var(--space-1); border-radius: var(--radius-xs); }
.bubble a { color: var(--brand); text-underline-offset: .2em; }
.msg.user .bubble a { color: inherit; }

/* rendered markdown (assistant only) */
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .6em; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: .8em 0 .3em; line-height: 1.3; }
.bubble h1 { font-size: 1.15em; } .bubble h2 { font-size: 1.1em; } .bubble h3, .bubble h4 { font-size: 1em; }
.bubble ul, .bubble ol { margin: 0 0 .6em; padding-left: 1.4em; }
.bubble li { margin: .15em 0; }
.bubble li > p { margin: 0; }
.bubble blockquote { margin: .4em 0; padding: .2em .8em; border-left: 3px solid var(--brand); color: var(--muted); }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: .6em 0; }
.bubble pre { margin: 0; padding: var(--space-2) var(--space-2-5); font-size: .88em; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; font-size: .92em; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: var(--space-1) var(--space-2); text-align: left; white-space: nowrap; }
.bubble th { background: var(--tool-bg); }

/* horizontal scroll wrapper for tables / code: thin persistent scrollbar + "more to the right" fade */
.scroll-x { position: relative; margin: .4em 0 .6em; border-radius: var(--radius-sm); --fade: var(--assistant-bubble); }
.scroll-x:has(pre) { background: var(--tool-bg); --fade: var(--tool-bg); }
.scroll-x-inner {
  overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
.scroll-x-inner::-webkit-scrollbar { height: 4px; }
.scroll-x-inner::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: var(--radius-2xs); }
.scroll-x-inner::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: var(--radius-2xs); }
.scroll-x::after {
  content: "›"; position: absolute; top: 0; right: 0; bottom: 6px; width: 34px;
  display: flex; align-items: center; justify-content: flex-end; padding-right: var(--space-1);
  font-size: var(--text-xl); line-height: 1; color: var(--muted);
  background: linear-gradient(270deg, var(--fade) 35%, transparent);
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
.scroll-x.more-right::after { opacity: 1; }
.msg.error .bubble { border-color: var(--tool-err); color: var(--tool-err); }

.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; opacity: .7; }
@keyframes blink { to { opacity: 0; } }

/* ---- tool calls ---- */
.tools { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-1-5); width: 100%; min-width: 0; }
.tools[hidden] { display: none; }
.tool {
  font-size: var(--text-xs); background: var(--tool-bg); border-radius: var(--radius-md); padding: var(--space-1-5) var(--space-2-5); color: var(--muted);
}
.tool summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--space-1-5); }
.tool summary { min-height: var(--space-8); }
.tool .thought {
  margin: var(--space-1-5) 0 0; white-space: pre-wrap; font-size: var(--text-xs); line-height: 1.5; color: var(--muted);
  max-height: 200px; overflow: auto;
}
.tool summary::-webkit-details-marker { display: none; }
.tool .label { white-space: nowrap; }
.tool .name { font-family: var(--font-mono); color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .dur { margin-left: auto; font-variant-numeric: tabular-nums; }
.tool pre {
  margin: var(--space-1-5) 0 0; white-space: pre-wrap; word-break: break-all; font-size: var(--text-2xs);
  max-height: 160px; overflow: auto; color: var(--text);
}

/* status icon: a ring that spins while running, then closes and draws a check (or a cross) */
.tool-icon { width: 16px; height: 16px; flex: none; }
.tool-icon svg { width: 100%; height: 100%; display: block; overflow: visible; }
.tool-icon .ring, .tool-icon .mark {
  fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.tool-icon .ring {
  stroke: var(--brand);
  stroke-dasharray: 40 17;            /* r=9 → circumference ≈ 56.5; show ~70% arc */
  transform-origin: 50% 50%;
  animation: tool-spin .9s linear infinite;
  transition: stroke-dasharray .35s ease, stroke .35s ease;
}
.tool-icon .mark {
  stroke-dasharray: 20; stroke-dashoffset: 20;   /* hidden until drawn */
}
/* keep spinning while the arc closes: a full circle rotating is invisible, so no snap */
.tool.ok .tool-icon .ring, .tool.err .tool-icon .ring { stroke-dasharray: 57 0; }
.tool.ok .tool-icon .ring { stroke: var(--tool-ok); }
.tool.err .tool-icon .ring { stroke: var(--tool-err); }
.tool.ok .tool-icon .check { stroke: var(--tool-ok); animation: tool-draw .3s ease-out .2s forwards; }
.tool.err .tool-icon .cross { stroke: var(--tool-err); animation: tool-draw .3s ease-out .2s forwards; }
.tool.ok .label, .tool.err .label { color: var(--muted); }
/* history items: final state, no replay */
.tool.static .tool-icon .ring { animation: none; transform: none; }
.tool.static .tool-icon .mark { animation: none; }
.tool.static.ok .tool-icon .check, .tool.static.err .tool-icon .cross { stroke-dashoffset: 0; }

@keyframes tool-spin { to { transform: rotate(360deg); } }
@keyframes tool-draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .tool-icon .ring { animation: none; }
  .tool-icon .mark { transition: none; }
}

/* ---- composer ---- */
.composer-dock { min-width: 0; }
.composer-note {
  margin: 0 max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sar)) var(--space-2) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sal));
  padding-inline: var(--space-2); color: var(--muted); font-size: var(--text-xs); line-height: 1.6;
  text-align: center; overflow-wrap: anywhere;
}
.composer {
  display: flex; gap: var(--space-2); align-items: flex-end; min-width: 0;
  margin: 0 max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sar)) calc(var(--space-4) + var(--sab)) max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sal));
  padding: var(--space-2); background: var(--surface); border: 1px solid var(--control-line); border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg); transition: border-color var(--motion-fast);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; border-radius: var(--radius-lg);
  padding: var(--space-2-5) var(--space-3); font: inherit; background: transparent; color: var(--text);
  width: 100%; height: auto; field-sizing: content; min-block-size: var(--button-height); max-block-size: 6lh;
  max-height: min(6lh, 30dvh);
}
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.composer:focus-within { border-color: var(--focus); }
.composer textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.send-btn {
  display: inline-grid; place-items: center; flex-shrink: 0; align-self: flex-end;
  width: var(--button-height); height: var(--button-height); border: 0; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
  transition: background var(--motion-fast), transform var(--motion-fast) var(--ease-out);
}
.send-btn:disabled { background: var(--disabled-bg); color: var(--disabled-ink); cursor: not-allowed; }
.composer.busy .send-btn .icon { display: none; }
.composer.busy .send-btn::after { content: ""; width: var(--icon-size); height: var(--icon-size); border: 2px solid var(--disabled-ink); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- overlay / dialog ---- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: calc(var(--space-5) + var(--sat)) max(var(--space-5), var(--sar)) calc(var(--space-5) + var(--sab)) max(var(--space-5), var(--sal));
  background: var(--bg); z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay-card { max-width: var(--dialog-width); text-align: center; color: var(--muted); padding: var(--space-8); background: var(--surface); border: 1px solid var(--glass-edge); border-radius: var(--radius-card); box-shadow: var(--shadow-lg); overflow-wrap: anywhere; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto var(--space-3); border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
.btn {
  min-height: var(--button-height); border: 0; border-radius: var(--radius-full); padding: var(--space-3) var(--space-6); font: inherit; font-size: var(--text-md); font-weight: 600; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
  transition: background var(--motion-fast), transform var(--motion-fast) var(--ease-out);
}
.btn.ghost { background: var(--tool-bg); color: var(--text); }
.btn.danger { background: var(--danger-action); color: var(--on-danger); }
.btn:disabled { background: var(--disabled-bg); color: var(--disabled-ink); }
.dialog { border: 1px solid var(--glass-edge); border-radius: var(--radius-card); padding: var(--space-7); background: var(--surface); color: var(--text); width: min(var(--dialog-width), calc(100% - var(--space-8))); max-width: calc(100% - var(--space-8)); max-height: calc(100dvh - var(--space-10)); overflow-y: auto; box-shadow: var(--shadow-lg); overflow-wrap: anywhere; }
.dialog[open] { animation: dialog-in var(--motion-dialog) var(--ease-out); }
.dialog::backdrop { background: var(--scrim); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-5); }

/* ---- privacy & data ---- */
.sidebar-section { display: flex; flex-direction: column; gap: var(--space-0-5); padding: var(--space-2); border-top: 1px solid var(--line); }
.side-link {
  display: block; width: 100%; min-height: var(--control-size); text-align: left; padding: var(--space-2) var(--space-2-5); border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font: inherit; font-size: var(--text-md); text-decoration: none; cursor: pointer;
}
.side-link:hover, .side-link:focus-visible { background: var(--tool-bg); }
.side-link.danger { color: var(--tool-err); }
.consent { background: var(--scrim); z-index: 60; }
.consent-card {
  background: var(--surface); color: var(--text); border-radius: var(--radius-card);
  max-width: var(--dialog-width); width: 100%; max-height: 100%; overflow-y: auto; padding: var(--space-7);
  border: 1px solid var(--glass-edge); box-shadow: var(--shadow-lg); animation: dialog-in var(--motion-dialog) var(--ease-out);
}
.consent-card h2 { font-size: var(--text-xl); margin: 0 0 var(--space-3); }
.consent-points { padding-left: var(--space-5); margin: 0 0 var(--space-3); line-height: 1.6; font-size: var(--text-md); }
.consent-card a { color: var(--brand); }
.consent-card .btn { width: 100%; margin-top: var(--space-1); }
.consent-note { color: var(--muted); font-size: var(--text-sm); margin: var(--space-3) 0 0; text-align: center; }

/* ---- profile ---- */
.profile-dialog { width: min(var(--dialog-width), calc(100% - var(--space-8))); }
.profile-dialog h2 { font-size: var(--text-xl); margin: 0 0 var(--space-2); }
.profile-dialog h3 { font-size: var(--text-md); margin: var(--space-4) 0 var(--space-1-5); color: var(--muted); font-weight: 600; }
.profile-intro { font-size: var(--text-md); color: var(--muted); margin: 0 0 var(--space-2); line-height: 1.6; }
.field { display: flex; flex-direction: column; gap: var(--space-1); margin: var(--space-2-5) 0; font-size: var(--text-md); }
.field input {
  font: inherit; min-width: 0; min-height: var(--button-height); padding: var(--space-control-y) var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--control-line);
  background: var(--bg); color: var(--text);
}
.field input:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.field-error { color: var(--tool-err); font-size: var(--text-sm); margin: var(--space-1) 0; }
.memory-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.memory-list li {
  display: flex; align-items: center; gap: var(--space-2); padding: var(--space-1-5) var(--space-2-5); border-radius: var(--radius-sm);
  background: var(--tool-bg); font-size: var(--text-md);
}
.memory-list li span { flex: 1; overflow-wrap: anywhere; }
.memory-list button { width: var(--control-size); height: var(--control-size); flex-shrink: 0; border: 0; background: none; color: var(--muted); font-size: var(--text-xl); cursor: pointer; }
.memory-list button:hover { color: var(--tool-err); }
.memory-empty { font-size: var(--text-sm); color: var(--muted); margin: 0; }
.memory-note { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-1); }

/* ---- message actions, loading, scroll ---- */
.msg-actions { display: flex; gap: var(--space-1); margin-top: var(--space-1); }
.msg-action {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: var(--text-xs);
  min-height: var(--control-size); padding: var(--space-1) var(--space-3); border-radius: var(--radius-full); cursor: pointer;
}
.msg-action:hover, .msg-action:focus-visible { background: var(--tool-bg); color: var(--text); }
.msg.error .retry-btn { color: var(--tool-err); }
.loading-msgs { display: flex; flex-direction: column; gap: var(--space-2-5); padding: var(--space-2) 0; }
.loading-msgs[hidden] { display: none; }
.skeleton {
  height: 38px; width: 70%; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--tool-bg) 25%, var(--line) 50%, var(--tool-bg) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite;
}
.skeleton.short { width: 45%; align-self: flex-end; }
@keyframes shimmer { to { background-position: -200% 0; } }
.scroll-btn {
  display: flex; align-items: center; gap: var(--space-1); min-height: var(--control-size);
  position: absolute; right: max(var(--page-gutter), calc((100% - var(--content-width)) / 2), var(--sar)); bottom: calc(var(--composer-height) + var(--space-3)); z-index: 5;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius-full); padding: var(--space-1-5) var(--space-3); font: inherit; font-size: var(--text-sm); cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.scroll-btn[hidden] { display: none; }
.scroll-btn .icon { transform: rotate(180deg); width: var(--icon-small); height: var(--icon-small); }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar, .composer, .sidebar, .scroll-btn {
    background: var(--glass);
    -webkit-backdrop-filter: blur(var(--blur-surface)) saturate(150%);
    backdrop-filter: blur(var(--blur-surface)) saturate(150%);
  }
  .dialog::backdrop, .consent {
    -webkit-backdrop-filter: blur(var(--blur-scrim));
    backdrop-filter: blur(var(--blur-scrim));
  }
}
@media (hover: hover) {
  .icon-btn:hover:not(:disabled), .chip:hover:not(:disabled) { background: var(--selected); border-color: var(--brand); }
  .chip:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
  .send-btn:hover:not(:disabled), .btn:not(.ghost):not(.danger):hover:not(:disabled) { background: var(--brand-hover); }
  .btn.danger:hover:not(:disabled) { background: var(--danger-hover); }
  .btn.ghost:hover:not(:disabled), .session-list .sess-btn:hover { background: var(--selected); }
}
.chip:active:not(:disabled), .icon-btn:active:not(:disabled), .btn:active:not(:disabled), .send-btn:active:not(:disabled) { transform: scale(.97); }
@keyframes message-in {
  from { opacity: .45; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@keyframes dialog-in {
  from { opacity: .5; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes scrim-in { from { opacity: .4; } to { opacity: 1; } }
@media (max-width: 800px) {
  :root { --page-gutter: 24px; }
}
@media (max-width: 620px) {
  :root { --page-gutter: 16px; --text-display: 25px; }
  .topbar { padding-top: calc(var(--space-2) + var(--sat)); padding-bottom: var(--space-2); }
  .messages { padding-top: var(--space-5); padding-bottom: var(--space-5); gap: var(--space-4); }
  .msg { max-width: 94%; }
  .empty { padding-block: var(--space-5); }
  .empty-title { margin-bottom: var(--space-6); }
  .chips { gap: var(--space-2); }
  .chips .chip { padding-inline: var(--space-2); font-size: var(--text-sm); }
  .composer { margin-bottom: calc(var(--space-3) + var(--sab)); }
  .dialog, .consent-card { padding: var(--space-5); }
}
@media (max-height: 500px) {
  .empty { padding-block: var(--space-2); }
  .empty-mark { display: none; }
  .empty-title { margin-bottom: var(--space-4); }
  .sidebar-head, .sidebar-note, .sidebar-section, .user-box { flex-shrink: 0; }
}

/* Respect the OS "reduce motion" setting. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .tool.ok .tool-icon .check, .tool.err .tool-icon .cross { stroke-dashoffset: 0; }
}
