/* 小津助手 v2.1 — 对话 (js/views/chat.js). Owned by the chat view developer.
   B「温暖质感」 base with A's accents: centred title + model chip, the owner's photo beside every reply,
   answers on warm-white cards, the in-chat image card, the weather-scene welcome, the composer dock,
   the session drawer, the model sheet and the full-screen image viewer. Shared prose / code styles live
   in css/components.css; the overrides here are scoped to .msg-card so other views are untouched.
   Compatibility: no color-mix(), :has(), nesting, @container, @layer; aspect-ratio needs iOS 15+. */

/* ================================================================ top bar: title over the model chip */
.chat-top { height: calc(60px + var(--safe-top)); gap: 0; }
.chat-head { position: relative; flex: 1; min-width: 0; height: 60px; }
.chat-title {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 44px;
  padding: 4px 0 0;
}
.chat-title-text {
  display: inline-block;
  max-width: 100%;
  padding: 0 var(--sp-2);
  overflow: hidden;
  border-radius: var(--r-sm);
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: top;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: 22px;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.chat-title:active .chat-title-text, .chat-title.is-pressed .chat-title-text { background: var(--surface-2); transition-duration: var(--dur-press); }
.model-chip {
  position: absolute;
  top: 26px;
  left: 50%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  max-width: 100%;
  height: 34px;
  padding-top: 4px;
  transform: translateX(-50%);
  transition: transform var(--dur) var(--ease-out);
}
/* hit area: 44 px tall in total (the pill itself is 24 px) */
.model-chip::after { content: ""; position: absolute; top: 0; bottom: -10px; left: -4px; right: -4px; }
.model-chip-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  height: 24px;
  padding: 0 6px 0 9px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 18px;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.model-chip:active, .model-chip.is-pressed { transform: translateX(-50%) scale(var(--press-scale)); transition-duration: var(--dur-press); }
.model-chip:active .model-chip-pill, .model-chip.is-pressed .model-chip-pill { background: var(--surface-3); }
.model-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--teal); }
.model-chip-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-chip .icon { flex: none; color: var(--text-3); }
.model-chip.is-unavailable .model-dot { background: var(--text-disabled); }
.model-chip.is-unavailable .model-chip-name { color: var(--text-3); text-decoration: line-through; text-decoration-color: var(--text-3); }
.model-chip.is-loading .model-chip-name { min-width: 64px; color: transparent; border-radius: var(--r-xs); background: var(--surface-3); }
.model-chip.is-loading .model-dot { background: var(--surface-3); }

.model-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  max-width: var(--content-max);
  margin: 0 auto var(--sp-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-3);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  animation: view-in var(--dur) var(--ease-out);
}
.model-notice .inline-error { flex: 1; min-width: 0; }
.model-notice .btn { flex: none; max-width: 52%; overflow: hidden; text-overflow: ellipsis; }

/* ================================================================ message list */
.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-inner {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-2) var(--page-x) var(--sp-6);
}
.chat-error { flex: 1; }
.chat-error .btn .icon { width: 18px; height: 18px; }

.chat-inner .time-sep { margin: var(--sp-2) 0 var(--sp-4); color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; text-align: center; }
.chat-inner .msg + .time-sep { margin-top: var(--sp-6); }

.msg { animation: msg-in var(--dur-slow) var(--ease-out); }
.msg.no-enter { animation: none; }
.msg + .msg { margin-top: var(--sp-6); }
.msg-user + .msg-ai { margin-top: var(--sp-5); }
@keyframes msg-in { from { opacity: 0; transform: translate3d(0, 6px, 0); } to { opacity: 1; transform: none; } }

/* user: terracotta bubble, no avatar */
.msg-user { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2); padding-left: 15%; }
.bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--r-xl) var(--r-xl) var(--r-xs) var(--r-xl);
  background: var(--primary);
  color: var(--on-primary);
  font-size: var(--fs-base);
  line-height: var(--lh-prose);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-image {
  display: block;
  width: 64%;
  max-width: 240px;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow-1), var(--edge);
  transition: transform var(--dur) var(--ease-out), opacity var(--dur-fast) var(--ease-out);
}
.msg-image img { display: block; width: 100%; max-height: 300px; object-fit: cover; }
.msg-image:active, .msg-image.is-pressed { transform: scale(var(--press-scale)); opacity: .9; transition-duration: var(--dur-press); }

/* assistant: the owner's photo + 小津 + model, then the answer card */
.msg-head { display: flex; align-items: center; gap: var(--sp-2); min-height: 30px; margin-bottom: var(--sp-2); }
.msg-head .avatar { width: 28px; height: 28px; }
.msg-name { flex: none; font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: 18px; }
.msg-meta { min-width: 0; overflow: hidden; color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; white-space: nowrap; text-overflow: ellipsis; }

.msg-card {
  padding: 12px var(--sp-4);
  border-radius: var(--r-xs) var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

/* waiting for the first token (and for the image/text decision on drawing requests) */
.msg-ai .typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-xs) var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.msg-ai .typing[hidden] { display: none; }
.msg-ai .typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: typing 1.2s var(--ease-in-out) infinite; }
.msg-ai .typing i:nth-child(2) { animation-delay: .15s; }
.msg-ai .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translate3d(0, -3px, 0); } }

/* reasoning disclosure: a quiet pill, the body opens under it */
.reasoning { margin-bottom: var(--sp-2); }
.reasoning-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 var(--sp-2) 0 10px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 18px;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out);
}
.reasoning-toggle::after { content: ""; position: absolute; top: -7px; bottom: -7px; left: 0; right: 0; }
.reasoning-toggle:active, .reasoning-toggle.is-pressed { background: var(--surface-3); transform: scale(var(--press-scale)); transition-duration: var(--dur-press); }
.reasoning-icon { color: var(--amber-text); --dt: .22; }
.reasoning-chev { color: var(--text-3); transition: transform var(--dur) var(--ease-out); }
.reasoning.is-open .reasoning-chev { transform: rotate(180deg); }
.reasoning.is-live .reasoning-icon { animation: think-pulse 1.4s var(--ease-in-out) infinite; }
@keyframes think-pulse { 50% { opacity: .45; } }
.reasoning-body {
  max-height: 300px;
  overflow-y: auto;
  margin: var(--sp-2) 0 var(--sp-1);
  padding: 2px 0 2px var(--sp-3);
  border-left: 2px solid var(--line-strong);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: var(--lh-prose);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: view-in var(--dur) var(--ease-out);
}

/* markdown inside the answer card (B: headings with a terracotta bar, terracotta bullets) */
.msg-card.prose h1, .msg-card.prose h2, .msg-card.prose h3 { display: flex; align-items: baseline; gap: var(--sp-2); }
.msg-card.prose h2, .msg-card.prose h3 { font-size: var(--fs-lg); }
.msg-card.prose h1::before, .msg-card.prose h2::before, .msg-card.prose h3::before {
  content: "";
  flex: none;
  align-self: center;
  width: 4px;
  height: 15px;
  border-radius: 2px;
  background: var(--primary);
}
.msg-card.prose li::marker { color: var(--primary); }
.msg-card.prose ol > li::marker { font-weight: var(--fw-semibold); }
.msg-card .code-block { margin: .9em -8px; }
.msg-card .code-block:first-child { margin-top: 4px; }
.msg-card .code-block:last-child { margin-bottom: 4px; }
.msg-card .table-wrap { margin: .9em -8px; border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--line); }
.msg-card.prose th { background: var(--surface-2); }
.msg-card.prose tr > :first-child { padding-left: 12px; }
.msg-card.prose tr > :last-child { padding-right: 12px; }
.msg-card.prose tr:last-child > td { border-bottom: 0; }
.msg-card.prose .math-display { margin: .6em -4px; padding: 8px 4px; }
/* keep answers on the type scale: inline code 13 px, formulas 17 px */
.msg-card.prose :not(pre) > code { font-size: var(--fs-sm); }
.msg-card.prose td code, .msg-card.prose th code { font-size: var(--fs-xs); }
.msg-card.prose .katex { font-size: var(--fs-lg); }

.msg-note { margin-top: var(--sp-2); color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; }
.msg-note .note-link { position: relative; color: var(--primary-text); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.msg-note .note-link::after { content: ""; position: absolute; top: -13px; bottom: -13px; left: -8px; right: -8px; }
.msg-note .note-link:active, .msg-note .note-link.is-pressed { opacity: .65; }
.msg-error {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-xs) var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.msg-error[hidden] { display: none; }
.msg-actions { display: flex; margin: var(--sp-1) 0 calc(-1 * var(--sp-2)) -10px; }
.msg-actions[hidden] { display: none; }

/* Touch screens: long-press opens the message menu (WeChat-style), so the bubbles don't start a text
   selection; 「选择文字」 in the menu opens a selectable copy. Desktop keeps normal selection. */
@media (pointer: coarse) {
  .msg-user .bubble, .msg-ai .msg-card, .msg-ai .msg-head { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .chat-inner:not(.is-wechat) .img-card .img-pic, .chat-inner:not(.is-wechat) .msg-image img { -webkit-touch-callout: none; }
}

/* ================================================================ image card (in-chat generation) */
.img-card {
  width: 316px;
  max-width: 100%;
  margin: 0;
  padding: var(--sp-2);
  border-radius: var(--r-xs) var(--r-lg) var(--r-lg) var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.img-card[hidden] { display: none; }
.img-card .img-frame {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: var(--r-md);
  background: var(--surface-2);
  isolation: isolate;
  transition: transform var(--dur) var(--ease-out);
}
.img-card[data-state="stopped"] .img-frame { aspect-ratio: 16 / 10; }
.img-card .img-frame[role="button"] { cursor: zoom-in; }
.img-card .img-frame[role="button"]:active, .img-card .img-frame[role="button"].is-pressed { transform: scale(.985); transition-duration: var(--dur-press); }
/* painted-canvas pattern: soft pigment blobs on a woven canvas, drifting while the picture is painted */
.img-card .img-paint, .chat-welcome .draw-card .draw-art {
  background-color: var(--surface-2);
  background-image:
    repeating-linear-gradient(45deg, var(--press-tint) 0, var(--press-tint) 1px, rgba(0, 0, 0, 0) 1px, rgba(0, 0, 0, 0) 7px),
    repeating-linear-gradient(-45deg, var(--press-tint) 0, var(--press-tint) 1px, rgba(0, 0, 0, 0) 1px, rgba(0, 0, 0, 0) 7px);
}
.img-card .img-paint { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; }
/* blobs stay inside the frame (the blur softens their edges); they breathe in place while painting */
.img-card .img-paint i, .chat-welcome .draw-card .draw-art i { position: absolute; border-radius: 50%; filter: blur(18px); }
.img-card .img-paint i:nth-child(1), .chat-welcome .draw-card .draw-art i:nth-child(1) { left: 4%; top: 4%; width: 58%; height: 52%; background: var(--primary-soft-press); }
.img-card .img-paint i:nth-child(2), .chat-welcome .draw-card .draw-art i:nth-child(2) { right: 4%; top: 12%; width: 52%; height: 48%; background: var(--paint-soft); }
.img-card .img-paint i:nth-child(3), .chat-welcome .draw-card .draw-art i:nth-child(3) { left: 10%; bottom: 4%; width: 56%; height: 46%; background: var(--teal-soft); }
.img-card .img-paint i:nth-child(4), .chat-welcome .draw-card .draw-art i:nth-child(4) { right: 6%; bottom: 6%; width: 40%; height: 38%; background: var(--amber-soft); }
.img-card[data-state="loading"] .img-paint i { animation: paint-breathe 5.6s var(--ease-in-out) infinite alternate; }
.img-card[data-state="loading"] .img-paint i:nth-child(2) { animation-duration: 6.4s; animation-delay: -1.8s; }
.img-card[data-state="loading"] .img-paint i:nth-child(3) { animation-duration: 7.2s; animation-delay: -3.1s; }
.img-card[data-state="loading"] .img-paint i:nth-child(4) { animation-duration: 4.8s; animation-delay: -.9s; }
@keyframes paint-breathe { from { transform: scale(.9); opacity: .75; } to { transform: scale(1.06); opacity: 1; } }
/* shimmer sweep: a moving gradient on a layer that never leaves the frame */
.img-card .img-frame::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  background-image: linear-gradient(100deg, var(--sheen-0) 35%, var(--sheen) 50%, var(--sheen-0) 65%);
  background-size: 260% 100%;
  background-repeat: no-repeat;
  background-position: 130% 0;
  pointer-events: none;
  opacity: 0;
}
.img-card[data-state="loading"] .img-frame::after, .img-card[data-state="done"]:not(.is-loaded):not([data-failed]) .img-frame::after {
  opacity: 1;
  animation: img-sheen 1.9s var(--ease-in-out) infinite;
}
@keyframes img-sheen { 0% { background-position: 130% 0; } 70%, 100% { background-position: -30% 0; } }
.img-card .img-loading {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--sp-4);
  text-align: center;
  transition: opacity var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
}
.img-card .img-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: var(--sp-2);
  border-radius: 16px;
  background: var(--surface);
  color: var(--paint-ink);
  box-shadow: var(--shadow-1);
}
.img-card .img-badge .icon { --dt: .24; }
.img-card[data-state="loading"] .img-badge .icon { animation: brush 1.6s var(--ease-in-out) infinite; }
@keyframes brush { 0%, 100% { transform: rotate(0); } 40% { transform: rotate(-12deg); } 70% { transform: rotate(6deg); } }
.img-card .img-status { color: var(--text); font-size: var(--fs-base); font-weight: var(--fw-semibold); line-height: 22px; }
.img-card .img-elapsed { max-width: 240px; color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh-wrap); }
.img-card .img-elapsed:empty { display: none; }
.img-card .img-progress {
  position: absolute;
  left: var(--sp-4);
  right: var(--sp-4);
  bottom: var(--sp-4);
  z-index: 2;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface);
  opacity: 0;
}
.img-card .img-progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 38%;
  border-radius: 2px;
  background: var(--primary);
  animation: img-indet 1.6s var(--ease-in-out) infinite;
}
@keyframes img-indet { from { transform: translateX(-100%); } to { transform: translateX(265%); } }
.img-card[data-state="loading"] .img-progress { opacity: .9; }
.img-card .img-pic {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 420ms var(--ease-out), transform 640ms var(--ease-out);
  -webkit-user-drag: none;
}
.img-card.is-loaded .img-pic { opacity: 1; transform: none; }
.img-card.is-loaded .img-loading, .img-card.is-loaded .img-progress { opacity: 0; visibility: hidden; }
.img-card[data-failed] .img-pic { display: none; }
.img-card[data-state="stopped"] .img-badge, .img-card[data-failed] .img-badge { color: var(--text-3); }
.img-card .img-cap { display: block; padding: 10px 6px 2px; }
.img-card .img-cap[hidden] { display: none; }
.img-card .img-caption { display: block; color: var(--text); font-size: var(--fs-base); line-height: var(--lh-wrap); overflow-wrap: anywhere; }
.img-card .img-caption:empty { display: none; }
.img-card .img-meta { display: block; margin-top: 2px; color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; }
.img-card .img-meta[hidden] { display: none; }
.img-card .img-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: var(--sp-2) 0 0; }
.img-card .img-actions:empty { display: none; }
.img-card .img-actions .btn { flex: 1 1 auto; padding: 0 var(--sp-3); }

/* ================================================================ welcome: weather scene + suggestions */
.chat-scroll.is-empty .chat-inner { padding-top: var(--sp-2); }
.chat-welcome { display: flex; flex-direction: column; padding-bottom: var(--sp-2); }
.chat-hero {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 176px;
  padding: var(--sp-4) var(--sp-4) 14px;
  overflow: hidden;
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-1);
  isolation: isolate;
  animation: view-in var(--dur-slow) var(--ease-out);
}
.chat-hero .hero-row { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; }
.chat-hero .hero-avatar { position: relative; flex: none; }
.chat-hero .hero-avatar .avatar-ring { display: block; width: 68px; height: 68px; animation: hero-pop 520ms var(--ease-spring) both; }
.chat-hero .hero-sticker {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--sticker-bg);
  color: var(--tone-ink);
  box-shadow: 0 2px 4px rgba(84, 48, 24, 0.08), 0 6px 14px rgba(84, 48, 24, 0.14);
  animation: hero-bob 4.4s var(--ease-in-out) infinite;
}
.chat-hero .hero-sticker .icon { --dt: .26; }
.chat-hero .hero-sticker.s1 { --rot: 10deg; top: -6px; right: -12px; }
.chat-hero .hero-sticker.s2 { --rot: -9deg; bottom: -6px; left: -10px; animation-duration: 5s; animation-delay: -1.7s; }
[data-theme="dark"] .chat-hero .hero-sticker { box-shadow: inset 0 1px 0 rgba(255, 236, 220, 0.08), 0 0 0 1px rgba(255, 230, 210, 0.07), 0 6px 14px rgba(0, 0, 0, 0.4); }
@keyframes hero-bob { 0%, 100% { transform: translate3d(0, 0, 0) rotate(var(--rot, 0deg)); } 50% { transform: translate3d(0, -4px, 0) rotate(var(--rot, 0deg)); } }
@keyframes hero-pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
.chat-hero .hero-text { flex: 1; min-width: 0; }
.chat-hello {
  color: var(--scene-ink, var(--text));
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  overflow-wrap: anywhere;
}
.chat-hello-sub { margin-top: var(--sp-1); color: var(--scene-ink-2, var(--text-2)); font-size: var(--fs-sm); line-height: var(--lh-wrap); }
.chat-hero[data-ink="light"] .chat-hello, .chat-hero[data-ink="light"] .chat-hello-sub { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22); }
.chat-hero[data-ink="dark"] .chat-hello-sub { text-shadow: 0 0 6px rgba(255, 253, 250, 0.5); }
/* in the flow (not absolute) so a larger text size grows the hero instead of overlapping */
.chat-hero .hero-pill { position: relative; z-index: 1; display: flex; max-width: 100%; margin-top: auto; padding-top: var(--sp-3); }
.chat-hero .hero-pill:empty { display: none; }

.chat-welcome .welcome-head { display: flex; align-items: center; justify-content: space-between; margin: var(--sp-5) 0 10px; }
.chat-welcome .welcome-label { color: var(--text); font-size: var(--fs-base); font-weight: var(--fw-semibold); line-height: 22px; }
.chat-welcome .welcome-more {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  margin-right: -6px;
  padding: 0 6px;
  border-radius: var(--r-full);
  color: var(--text-3);
  font-size: var(--fs-sm);
  transition: background-color var(--dur-fast) var(--ease-out);
}
.chat-welcome .welcome-more::after { content: ""; position: absolute; top: -6px; bottom: -6px; left: 0; right: 0; }
.chat-welcome .welcome-more:active, .chat-welcome .welcome-more.is-pressed { background: var(--surface-2); transition-duration: var(--dur-press); }

.chat-welcome .suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chat-welcome .suggest-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  padding: 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  text-align: left;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.chat-welcome .suggest-card:active, .chat-welcome .suggest-card.is-pressed { transform: scale(var(--press-scale)); box-shadow: var(--shadow-press); background: var(--bg-elev); transition-duration: var(--dur-press); }
/* one line each at the normal text size (copy is written to fit 360 px); they wrap at larger sizes */
.chat-welcome .suggest-title {
  display: block;
  max-width: 100%;
  margin-top: 10px;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-wrap);
  overflow-wrap: anywhere;
}
.chat-welcome .suggest-sub {
  display: block;
  max-width: 100%;
  margin-top: 2px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  line-height: var(--lh-wrap);
  overflow-wrap: anywhere;
}

.chat-welcome .draw-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: 10px;
  padding: 12px 10px 12px 12px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  text-align: left;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.chat-welcome .draw-card:active, .chat-welcome .draw-card.is-pressed { transform: scale(var(--press-scale)); box-shadow: var(--shadow-press); background: var(--bg-elev); transition-duration: var(--dur-press); }
.chat-welcome .draw-card .draw-art {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 56px;
  height: 56px;
  overflow: hidden;
  border-radius: 14px;
  color: var(--paint-ink);
  isolation: isolate;
}
.chat-welcome .draw-card .draw-art i { filter: blur(8px); }
.chat-welcome .draw-card .draw-art .icon { position: relative; z-index: 1; --dt: .3; }
.chat-welcome .draw-card .draw-main { flex: 1; min-width: 0; }
.chat-welcome .draw-card .draw-kicker { display: flex; align-items: center; gap: 4px; color: var(--paint-text); font-size: var(--fs-sm); font-weight: var(--fw-semibold); line-height: 18px; }
.chat-welcome .draw-card .draw-kicker .icon { --dt: .24; }
.chat-welcome .draw-card .draw-kicker .badge { margin-left: 2px; }
.chat-welcome .draw-card .draw-text { display: block; margin-top: 2px; color: var(--text); font-size: var(--fs-base); line-height: var(--lh-wrap); }
/* the idea wraps at its comma (each clause is an inline-block that only breaks inside when it must) */
.chat-welcome .draw-card .draw-seg { display: inline-block; max-width: 100%; }
.chat-welcome .draw-card .draw-chev { flex: none; color: var(--text-3); }
.shortcut-row { margin-top: 10px; }

/* ================================================================ loading skeleton */
.chat-loading { display: flex; flex-direction: column; padding-top: var(--sp-4); }
.chat-loading .sk-bubble { align-self: flex-end; width: 56%; height: 44px; border-radius: var(--r-xl) var(--r-xl) var(--r-xs) var(--r-xl); }
.chat-loading .sk-head { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-6); }
.chat-loading .sk-avatar { width: 28px; height: 28px; margin: 0; border-radius: 50%; }
.chat-loading .sk-name { width: 88px; margin: 0; }
.chat-loading .sk-card { display: block; margin-top: var(--sp-3); padding: var(--sp-4); border-radius: var(--r-xs) var(--r-lg) var(--r-lg) var(--r-lg); background: var(--surface); box-shadow: var(--shadow-1); }

/* ================================================================ composer dock */
.composer-wrap { position: relative; flex: none; padding: 6px var(--page-x) 10px; background: var(--bg); }
.composer-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -18px;
  height: 18px;
  background: linear-gradient(180deg, var(--bg-fade) 0%, var(--bg) 100%);
  pointer-events: none;
}
html.composer-focus[data-tab="chat"] .composer-wrap { padding-bottom: max(var(--sp-2), var(--safe-bottom)); }
html.kb-open .composer-wrap { padding-bottom: var(--sp-2) !important; }
.composer {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 4px 6px 6px;
  border-radius: var(--r-2xl);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transition: box-shadow var(--dur) var(--ease-out);
}
.composer:focus-within { box-shadow: var(--shadow-2), 0 0 0 1.5px var(--primary-soft-press); }
.composer-input {
  display: block;
  width: 100%;
  min-height: 44px;
  max-height: 148px;
  padding: 10px 12px 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-input);
  line-height: var(--lh-wrap);
  resize: none;
  overflow-y: hidden;
}
.composer-input::placeholder { color: var(--text-3); }
.composer-input:focus { box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 4px; }
.composer-tool { color: var(--text-2); }
.composer-tool.is-dim { color: var(--text-3); }
.think-chip[hidden] { display: none; }
.composer-gap { flex: 1; }
.send-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  margin: 2px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-3);
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out), transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.send-btn::before { content: ""; position: absolute; top: -2px; right: -2px; bottom: -2px; left: -2px; }
.send-btn.is-ready, .send-btn.is-stop { box-shadow: var(--lip); }
.send-btn.is-ready { background: var(--primary); color: var(--on-primary); }
.send-btn.is-stop { background: var(--text); color: var(--bg); box-shadow: none; }
.send-btn:active:not(:disabled), .send-btn.is-pressed:not(:disabled) { transform: scale(.9); transition-duration: var(--dur-press); }
.send-btn.is-ready:active, .send-btn.is-ready.is-pressed { background: var(--primary-press); box-shadow: none; }
.send-btn:disabled { color: var(--text-disabled); cursor: default; }
.attach-row { padding: 6px 6px 2px; }
.attach-row[hidden] { display: none; }
.attach-thumb { position: relative; width: 64px; height: 64px; }
.attach-thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--r-md); box-shadow: var(--shadow-1), var(--edge); }
.attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 0 0 2px var(--surface);
}
.attach-remove::before { content: ""; position: absolute; top: -11px; right: -11px; bottom: -11px; left: -11px; }
.attach-remove:active, .attach-remove.is-pressed { opacity: .75; }
.to-bottom {
  position: absolute;
  top: -44px;
  left: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  transform: translateX(-50%);
  animation: view-in var(--dur) var(--ease-out);
  transition: background-color var(--dur-fast) var(--ease-out);
}
.to-bottom::after { content: ""; position: absolute; top: -5px; bottom: -5px; left: 0; right: 0; }
.to-bottom:active, .to-bottom.is-pressed { background: var(--surface-2); transform: translateX(-50%) scale(var(--press-scale)); }
.to-bottom[hidden] { display: none; }

/* ================================================================ session drawer */
.drawer-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; flex: none; height: var(--topbar-h); padding: 0 var(--sp-1) 0 var(--page-x); }
.drawer-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
.drawer-search { flex: none; margin: 0 var(--page-x) var(--sp-2); }
.drawer-search .input { min-height: 40px; height: 40px; }
.drawer-search .input::-webkit-search-cancel-button { -webkit-appearance: none; }
.drawer-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 var(--sp-2) var(--sp-4); }
.drawer-skeleton { padding: var(--sp-4) var(--sp-2); }
.drawer-skeleton .skeleton { height: 18px; margin-bottom: var(--sp-5); }
.drawer-skeleton .skeleton:nth-child(2n) { width: 72%; }
.drawer-group-label { display: flex; align-items: center; gap: 4px; padding: var(--sp-4) var(--sp-2) var(--sp-1); color: var(--text-3); font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 18px; }
.drawer-group-label .icon { --dt: .2; }
.session-row { display: flex; align-items: center; border-radius: var(--r-md); transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out); }
.session-row:active, .session-row.is-pressed { background: var(--surface-2); }
.session-row.is-current { background: var(--primary-soft); }
.session-row.is-holding { background: var(--surface-2); }
.session-main { display: flex; flex: 1; align-items: center; gap: var(--sp-2); min-width: 0; min-height: var(--tap); padding: var(--sp-2) 0 var(--sp-2) var(--sp-2); text-align: left; }
.session-title {
  display: -webkit-box;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh-wrap);
  overflow-wrap: anywhere;
}
.session-row.is-current .session-title { color: var(--primary-text); font-weight: var(--fw-semibold); }
.session-time { flex: none; color: var(--text-3); font-size: var(--fs-xs); }
.session-row .icon-btn { width: 44px; }
.drawer-tip { flex: none; padding: var(--sp-2) var(--page-x) calc(var(--sp-3) + var(--safe-bottom)); color: var(--text-3); font-size: var(--fs-xs); line-height: 18px; text-align: center; }

/* ================================================================ model sheet */
.model-row { gap: var(--sp-3); }
.model-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.model-row .tag { height: 20px; padding: 0 7px; }
.model-row.is-unavailable .row-title { color: var(--text-disabled); }
.model-row.is-unavailable .tag { opacity: .55; }
.model-row.is-unavailable .row-sub { color: var(--danger); }
.model-row.is-unavailable .row-icon { opacity: .6; }
.sheet .model-row .row-icon.tone-quiet { background: var(--surface-3); }
.model-skeleton { padding-top: var(--sp-4); }
.model-skeleton .skeleton { height: 52px; border-radius: var(--r-lg); }

/* 「选择文字」 sheet */
.select-sheet .select-text {
  max-height: 52vh;
  overflow-y: auto;
  margin-bottom: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh-prose);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* ================================================================ full-screen image viewer
   Always dark, in both themes (photo viewer), so it uses fixed near-black / white-alpha values. */
.iv { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: calc(var(--z-sheet) + 10); }
.iv-bg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(10, 8, 7, 0.97); opacity: 0; transition: opacity 260ms var(--ease-out); }
.iv.is-open .iv-bg { opacity: 1; }
.iv.is-closing .iv-bg { transition-duration: 220ms; }
.iv-stage { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; touch-action: none; }
.iv-img {
  position: absolute;
  max-width: none;
  transform-origin: 50% 50%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
  will-change: transform;
}
.iv.is-open .iv-img { opacity: 1; }
.iv.is-closing .iv-img { opacity: 0; transition: opacity 240ms var(--ease-in), transform 240ms var(--ease-sheet); }
.iv-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 6px 0;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
  pointer-events: none;
}
.iv.is-open .iv-bar { opacity: 1; }
.iv-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.94);
  pointer-events: auto;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out);
}
.iv-btn:active, .iv-btn.is-pressed { background: rgba(255, 255, 255, 0.24); transform: scale(.92); transition-duration: var(--dur-press); }
.iv-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--sp-6) var(--page-x) calc(var(--safe-bottom) + var(--sp-4));
  background: linear-gradient(180deg, rgba(10, 8, 7, 0) 0%, rgba(10, 8, 7, 0.55) 100%);
  text-align: center;
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
  pointer-events: none;
}
.iv.is-open .iv-foot { opacity: 1; }
.iv.is-zoomed .iv-foot, .iv.is-closing .iv-foot, .iv.is-closing .iv-bar { opacity: 0; }
.iv-cap { margin-bottom: var(--sp-1); color: rgba(255, 255, 255, 0.92); font-size: var(--fs-base); line-height: var(--lh-wrap); }
.iv-hint { color: rgba(255, 255, 255, 0.62); font-size: var(--fs-xs); line-height: 18px; }

/* ================================================================ narrow phones */
@media (max-width: 374px) {
  .chat-welcome .suggest-card { padding: 12px; }
}
/* short screens (360×640, WeChat's shorter webview): a lower hero so the first cards show */
@media (max-height: 700px) {
  .chat-hero { min-height: 150px; }
  .chat-welcome .welcome-head { margin-top: var(--sp-4); }
}

/* ================================================================ reduced motion: opacity only */
@media (prefers-reduced-motion: reduce) {
  .msg { animation: fade-in var(--dur) linear; }
  .msg-ai .typing i { animation: typing-fade 1.4s linear infinite; }
  .msg-ai .typing i:nth-child(2) { animation-delay: .2s; }
  .msg-ai .typing i:nth-child(3) { animation-delay: .4s; }
  .img-card[data-state="loading"] .img-paint i, .img-card[data-state="loading"] .img-badge .icon, .chat-hero .hero-sticker, .chat-hero .hero-avatar .avatar-ring { animation: none; }
  .img-card[data-state="loading"] .img-frame::after, .img-card[data-state="done"]:not(.is-loaded):not([data-failed]) .img-frame::after {
    background-position: 50% 0;
    animation: img-pulse 2.4s linear infinite alternate;
  }
  .img-card .img-progress::after { width: 100%; animation: img-pulse 2.4s linear infinite alternate; }
  .img-card .img-pic, .img-card.is-loaded .img-pic { transform: none; transition: opacity var(--dur) linear; }
  .model-chip:active, .model-chip.is-pressed { transform: translateX(-50%); }
  .to-bottom:active, .to-bottom.is-pressed { transform: translateX(-50%); }
  .chat-welcome .suggest-card:active, .chat-welcome .suggest-card.is-pressed, .chat-welcome .draw-card:active, .chat-welcome .draw-card.is-pressed,
  .send-btn:active:not(:disabled), .send-btn.is-pressed:not(:disabled), .reasoning-toggle:active, .reasoning-toggle.is-pressed,
  .img-card .img-frame[role="button"]:active, .img-card .img-frame[role="button"].is-pressed, .msg-image:active, .msg-image.is-pressed, .iv-btn:active, .iv-btn.is-pressed { transform: none; }
  .reasoning.is-live .reasoning-icon { animation: none; }
}
@keyframes typing-fade { 50% { opacity: 1; } 0%, 100% { opacity: .35; } }
@keyframes img-pulse { from { opacity: .35; } to { opacity: 1; } }
