:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #4e3540; background: #f9eeef; font-synthesis: none;
  --page: #fff8f6; --rose: #b94f71; --muted: #87626e; --line: #f5dce3; --bubble: #f6cbd5;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--rose); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.shell { position: relative; isolation: isolate; max-width: 780px; margin: 0 auto; height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: var(--page); border-inline: 1px solid var(--line); }
.shell::before { content: ""; position: absolute; z-index: -1; right: 14px; bottom: 76px; width: 145px; height: 145px; background: url('/static/assets/peach.4053b7d854468d80.webp') center / contain no-repeat; opacity: .045; pointer-events: none; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 26px; min-height: 76px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.identity { display: flex; gap: 12px; align-items: center; min-width: 0; }
.avatar { width: 44px; height: 44px; object-fit: contain; flex-shrink: 0; }
h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: .5px; }
#connection { font-size: 12px; color: var(--muted); margin: 5px 0 0; line-height: 1.5; }
.quiet { background: transparent; border: 0; color: var(--rose); font-size: 13px; padding: 12px; min-height: 44px; }
.welcome { margin: auto; width: min(400px, 100%); padding: 32px 28px 64px; overflow-y: auto; }
.page-loading { position: absolute; inset: 76px 0 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 24px; text-align: center; color: var(--muted); font-size: 14px; background: var(--page); }
.page-loading p { margin: 0; line-height: 1.7; }
.portrait { position: relative; width: 214px; height: 176px; margin: 0 auto; display: flex; align-items: center; justify-content: center; padding-right: 30px; }
.portrait > img:first-child { width: 160px; height: 160px; object-fit: contain; }
.portrait .flower { position: absolute; right: 0; bottom: 13px; width: 43px; height: 65px; transform: rotate(9deg); }
.portrait::before, .portrait::after { content: ""; position: absolute; left: 0; top: 72px; width: 17px; height: 5px; background: #f3adc6; border-radius: 4px; transform: rotate(13deg); }
.portrait::after { top: 54px; left: 8px; width: 13px; transform: rotate(49deg); }
.welcome form { margin-top: 40px; }
.welcome label { font-size: 14px; font-weight: 550; display: block; margin-bottom: 10px; }
.login-row { display: flex; flex-direction: column; gap: 14px; }
.password-field { display: flex; gap: 14px; align-items: center; padding: 0 17px; border: 1px solid #eec1cf; background: #fffdfd; border-radius: 19px; }
.password-field:focus-within { border-color: var(--rose); box-shadow: 0 0 0 2px #b94f7114; }
.lock { position: relative; width: 15px; height: 13px; margin-top: 5px; border: 1.7px solid #bd8195; border-radius: 3px; flex-shrink: 0; }
.lock::before { content: ""; position: absolute; left: 2px; top: -8px; width: 7px; height: 8px; border: 1.7px solid #bd8195; border-bottom: 0; border-radius: 6px 6px 0 0; }
.login-row input { width: 100%; min-width: 0; padding: 15px 0; border: 0; background: transparent; border-radius: 8px; color: inherit; font-size: 16px; }
input::placeholder, textarea::placeholder { color: #917781; opacity: 1; }
.primary { border: 0; border-radius: 25px; min-height: 50px; background: var(--rose); color: white; padding: 13px 20px; font-size: 16px; font-weight: 550; }
.primary span { margin-left: 6px; }
.primary:hover, .send:hover, .stop:hover { background: #a94163; }
.error { font-size: 13px; color: #ac3554; line-height: 1.6; margin: 9px 0; overflow-wrap: anywhere; }
.error:empty { display: none; }
#chat-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#chat-panel.preparing { visibility: hidden; }
#chat-panel.preparing #timeline { scroll-behavior: auto; }
#notice { font-size: 12px; background: #fcecef; color: #79525f; padding: 10px 24px; line-height: 1.6; flex-shrink: 0; }
#timeline { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 20px 26px; scroll-behavior: smooth; }
#older { display: block; margin: 0 auto 18px; color: var(--muted); font-size: 12px; }
#older::before, #older::after { content: ""; display: inline-block; width: 24px; height: 1px; background: #dca9ba; vertical-align: middle; margin: 0 12px; }
.empty { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 30px 0 65px; }
.turn { margin: 0 0 25px; }
.conversation-time { display: block; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.5; margin: 19px 0; font-variant-numeric: tabular-nums; }
.message { max-width: 82%; width: fit-content; font-size: 16px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.message a { color: #a03760; text-decoration: underline; text-underline-offset: 3px; }
.message.user { margin-left: auto; background: var(--bubble); border-radius: 21px 21px 5px 21px; padding: 11px 16px; }
.reply-block { position: relative; margin-top: 21px; padding-left: 44px; min-height: 36px; }
.reply-avatar { position: absolute; top: 2px; left: 0; width: 34px; height: 34px; object-fit: contain; }
.reply-messages { display: flex; flex-direction: column; gap: 8px; }
.reply-messages .message.assistant { max-width: 90%; background: #fffdfd; border: 1px solid #f7e2e8; border-radius: 5px 21px 21px 21px; padding: 10px 15px; }
.reply-messages .message.assistant + .message.assistant { border-top-left-radius: 17px; }
.turn-status { font-size: 13px; color: var(--muted); line-height: 1.7; margin-top: 8px; }
.turn-status:empty { display: none; }
.turn-status button { font-size: 13px; color: var(--rose); background: transparent; border: 0; min-height: 44px; padding: 8px 10px; text-decoration: underline; text-underline-offset: 3px; }
.reply-typing { display: flex; gap: 6px; align-items: center; width: fit-content; min-height: 43px; padding: 14px 17px; background: #fffdfd; border: 1px solid #f7e2e8; border-radius: 5px 19px 19px 19px; }
.reply-messages:not(:empty) + .reply-typing { margin-top: 8px; }
.typing-dot { width: 7px; height: 7px; background: #e697b1; border-radius: 50%; animation: breathe 1.4s ease-in-out infinite; }
.typing-dot:nth-of-type(2) { animation-delay: .16s; }
.typing-dot:nth-of-type(3) { animation-delay: .32s; }
.composer-wrap { flex-shrink: 0; padding: 10px 22px max(20px, env(safe-area-inset-bottom)); background: var(--page); }
#composer { display: flex; gap: 10px; align-items: flex-end; padding: 6px 7px 6px 18px; border: 1px solid #edbccd; border-radius: 29px; background: #fffdfd; }
#composer:focus-within { border-color: var(--rose); box-shadow: 0 0 0 1px var(--rose); }
textarea { flex: 1; min-width: 0; resize: none; max-height: 130px; border: 0; background: transparent; line-height: 1.6; padding: 9px 0; font-size: 16px; color: inherit; border-radius: 6px; }
textarea:focus-visible { outline: none; }
.send, .stop { border: 0; background: var(--rose); color: white; min-width: 44px; height: 44px; border-radius: 24px; flex-shrink: 0; }
.send { font-size: 29px; line-height: 1; }
.stop { padding: 0 14px; font-size: 13px; }
.stop span { font-size: 13px; margin-right: 3px; }
@keyframes breathe { 50% { opacity: .35; transform: translateY(-2px); } }
@media (max-width: 600px) {
  .shell { border: 0; }
  .topbar { padding: 12px 18px; min-height: 72px; }
  #timeline { padding: 18px 16px; }
  .composer-wrap { padding: 10px 12px max(15px, env(safe-area-inset-bottom)); }
  .topbar .quiet { padding-right: 2px; }
  .message { max-width: 85%; }
  .reply-messages .message.assistant { max-width: 96%; }
}
@media (max-height: 550px) {
  .welcome { padding: 16px 28px 24px; }
  .welcome .portrait { height: 108px; }
  .welcome .portrait > img:first-child { width: 105px; height: 105px; }
  .welcome form { margin-top: 14px; }
  .empty { padding: 10px 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}


/* Shared sticker picker and image messages. */
.header-actions { display: flex; align-items: center; gap: 6px; }
#voice-toggle { font-size: 12px; white-space: nowrap; padding: 9px 7px; border-radius: 16px; }
#voice-toggle[aria-pressed="true"] { background: #f6e3db; color: #93523e; }
.voice-status-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; flex-shrink: 0; gap: 4px; font-size: 12px; color: #897b72; }
#voice-status:not([hidden]) { padding: 5px 10px; }
.voice-menu { position: fixed; z-index: 20; width: 156px; padding: 5px; background: #fffaf7; border: 1px solid #efddd0; border-radius: 14px; box-shadow: 0 8px 30px #58382a26; }
.voice-menu button { display: block; width: 100%; border: 0; border-radius: 10px; padding: 12px; background: transparent; color: #664e42; text-align: left; }
.voice-menu button:hover,.voice-menu button:focus-visible { background: #f6e3db; }
.assistant[data-speech-turn] { cursor: pointer; }
.assistant.voice-playing { outline: 2px solid #d4a286; outline-offset: 3px; }
.composer-wrap { flex-shrink: 0; }
.sticker-toggle { flex: 0 0 36px; width: 36px; height: 36px; padding: 6px; border: 0; border-radius: 50%; background: transparent; color: #837f74; }
.sticker-toggle svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.sticker-toggle[aria-expanded="true"] { background: #f6e3db; color: #a66e55; }
#sticker-panel { max-height: min(310px, 38dvh); overflow-y: auto; padding: 8px 0 0; overscroll-behavior: contain; }
.sticker-heading { display: flex; align-items: center; justify-content: space-between; color: #8b7568; font-size: 12px; padding: 0 4px; }
.sticker-heading .quiet { padding: 9px; }
.sticker-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 6px; }
.sticker-choice { min-width: 0; border: 1px solid transparent; background: transparent; border-radius: 14px; padding: 5px 2px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: #897b72; font-size: 11px; }
.sticker-choice:hover:not(:disabled),.sticker-choice:focus-visible { background: #fff3eb; border-color: #efddd0; }
.sticker-choice img { width: min(100%,72px); height: auto; aspect-ratio: 1; border-radius: 10px; object-fit: contain; }
.sticker-hint { text-align: center; font-size: 11px; color: #a19489; margin: 9px 0 3px; }
.message.user.sticker-message,.reply-messages .message.assistant.sticker-message { padding: 0; background: transparent; border: 0; box-shadow: none; line-height: 0; }
.chat-sticker { display: block; width: 148px; height: 148px; max-width: 100%; object-fit: contain; border-radius: 14px; }
@media (min-width: 601px) { .sticker-grid { grid-template-columns: repeat(8,minmax(0,1fr)); } }
@media (max-height: 550px) { #sticker-panel { max-height: 30dvh; } }

.user-input + .user-input { margin-top: 10px; }

#stop { display: block; margin: 6px 0 0 auto; height: 36px; }
#stop[hidden] { display: none; }

/* Two fixed contacts share the same conversation layout. Crop only at display time. */
.back-link { font-size: 32px; text-decoration: none; line-height: 1; padding: 2px 10px 5px 0; }
#contacts-panel { flex: 1; overflow-y: auto; padding: 22px 20px; }
.contact-row { display: flex; align-items: center; gap: 14px; padding: 22px 8px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.contact-row:hover { background: #ffffff88; }
.contact-image { width: 58px; height: 58px; object-fit: contain; flex-shrink: 0; }
.contact-copy { min-width: 0; flex: 1; }
.contact-copy strong { font-size: 17px; font-weight: 600; }
.contact-copy p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 9px 0 0; }
.contact-meta { display: flex; align-items: flex-end; flex-direction: column; gap: 10px; flex-shrink: 0; }
.contact-meta time { font-size: 11px; color: var(--muted); }
.unread { border-radius: 20px; background: var(--rose); color: white; font-size: 11px; padding: 2px 6px; min-width: 19px; text-align: center; }
img.xiayan, [data-character="xiayan"] .reply-avatar { object-fit: cover; object-position: 50% 28%; border-radius: 50%; }
[data-character="xiayan"]::before, [data-character="list"]::before { background-image: none; }
[data-character="xiayan"] .portrait .flower, [data-character="xiayan"] .portrait::before, [data-character="xiayan"] .portrait::after { display: none; }
@media (max-width: 420px) {
  #contacts-panel { padding: 18px 12px; }
  .contact-row { gap: 11px; }
  .contact-meta time { font-size: 10px; }
  .topbar { gap: 6px; }
  .header-actions .quiet { padding: 10px 6px; }
  .identity { gap: 7px; }
}

a:focus-visible { outline: 2px solid var(--rose); outline-offset: 3px; }

/* Storyteller portrait: square source with a circular face crop. */
img.maishu, [data-character="maishu"] .reply-avatar { object-fit: cover; object-position: center; border-radius: 50%; }
[data-character="maishu"]::before { background-image: none; }
[data-character="maishu"] .portrait .flower, [data-character="maishu"] .portrait::before, [data-character="maishu"] .portrait::after { display: none; }

.story-card { width: min(320px, 100%); padding: 14px 16px; border: 1px solid var(--line); border-radius: 18px; background: #fffcf7; }
.story-controls { display: flex; align-items: center; min-height: 48px; }
.story-play { display: flex; align-items: center; gap: 12px; min-width: 48px; min-height: 48px; border: 0; border-radius: 24px; background: transparent; color: #89654e; padding: 0; text-align: left; }
.story-indicator { display: grid; place-items: center; flex: 0 0 44px; height: 44px; border-radius: 50%; background: #f2e4d8; font-size: 18px; }
.story-label { font-size: 13px; line-height: 1.6; }
.story-card.is-loading .story-indicator { color: transparent; background: transparent; border: 3px solid #eddfd3; border-top-color: #a87c5f; animation: story-spin 1s linear infinite; }
.story-card.is-playing .story-indicator { background: #a87c5f; color: white; }
.story-original { margin-top: 10px; }
.story-original summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 7px 0; }
.story-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; font-size: 15px; padding-top: 9px; }
@keyframes story-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .story-card.is-loading .story-indicator { animation: none; } }
