:root { color-scheme: light; font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; background: #f4ede3; color: #4e392d; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; overflow: hidden; background: #f4ede3; }
button, textarea, input, select { font: inherit; }
.hidden { display: none !important; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.card { width: min(420px, 100%); padding: 32px; border: 1px solid #ffffff99; border-radius: 28px; background: #ffffffb8; box-shadow: 0 24px 70px #655b4d22; backdrop-filter: blur(18px); }
h1 { margin: 0 0 8px; font-weight: 500; letter-spacing: .04em; }
.muted { color: #71808b; }
form { display: flex; gap: 10px; }
input, textarea { width: 100%; border: 1px solid #9cabb755; border-radius: 16px; background: #ffffffcc; padding: 13px 15px; color: inherit; outline: none; }
input:focus, textarea:focus { border-color: #5f7588; box-shadow: 0 0 0 3px #5f75881c; }
button { border: 0; border-radius: 16px; padding: 0 18px; background: #344b60; color: white; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
#loginForm button { min-width: 72px; flex-shrink: 0; white-space: nowrap; }
.error { min-height: 1.4em; margin: 10px 0 0; color: #a14c45; }
.memory-toast { position: fixed; z-index: 20; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px; background: #526c58ed; color: white; box-shadow: 0 10px 28px #28313a33; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; }
.memory-toast-visible { opacity: 1; transform: translate(-50%, 0); }
.memory-toast-failed { background: #9a554fed; }
.chat-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid #8c79652b; background: #fffaf2e8; backdrop-filter: blur(14px); }
.route-controls, .header-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.header-actions { justify-content: flex-end; }
.new-chat { padding: 8px 10px; border: 1px solid #768a9a44; border-radius: 12px; background: transparent; color: #344b60; }
#status { font-size: .76rem; color: #788879; }
dialog { width: min(430px, calc(100% - 28px)); max-height: min(78dvh, 680px); padding: 0; border: 0; border-radius: 22px; background: #faf8f4; color: inherit; box-shadow: 0 24px 70px #28313a44; }
dialog::backdrop { background: #28313a66; backdrop-filter: blur(3px); }
.dialog-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid #768a9a2b; background: #faf8f4; }
.dialog-head strong { font-weight: 500; }
.dialog-head button { padding: 6px 10px; background: transparent; color: #344b60; }
.conversation-list { padding: 8px; overflow-y: auto; }
.conversation-row { display: flex; align-items: flex-start; position: relative; }
.conversation-item { display: block; flex: 1; min-width: 0; margin-bottom: 6px; padding: 12px; text-align: left; border: 1px solid transparent; background: transparent; color: inherit; }
.conversation-actions summary { cursor: pointer; list-style: none; padding: 12px; }
.conversation-actions summary::-webkit-details-marker { display: none; }
.conversation-actions nav { position: absolute; z-index: 1; right: 0; padding: 6px; background: #fffdf9; border: 1px solid #768a9a44; border-radius: 12px; box-shadow: 0 6px 18px #28313a22; }
.conversation-actions button { display: block; padding: 10px; width: 100%; background: transparent; color: #344b60; text-align: left; }
.conversation-item[aria-current="true"] { border-color: #71889c55; background: #dce5ed88; }
.conversation-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-meta { display: block; margin-top: 5px; color: #71808b; font-size: .78rem; }
@media (max-width: 350px) { .header-actions { grid-column: 1 / -1; } }
.dialog-body { padding: 16px; }
.dialog-footer { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid #768a9a2b; }
#settingsForm, #memoryWriterForm, #personalizationForm { display: grid; gap: 12px; }
#settingsForm label, #memoryWriterForm label, #personalizationForm label { display: grid; gap: 6px; }
#settingsForm label.privacy-confirm { display: flex; align-items: center; gap: 10px; }
#settingsForm label.privacy-confirm input[type="checkbox"] { flex: none; width: 18px; height: 18px; margin: 0; }
#settingsForm label.privacy-confirm span { min-width: 0; flex: 1; }
#settingsForm select, #memoryWriterForm select { width: 100%; padding: 10px; border: 1px solid #768a9a44; border-radius: 12px; background: #fffdf9; color: inherit; }
#apiFields { display: grid; gap: 12px; border: 0; padding: 0; margin: 0; min-width: 0; }
#memoryWriterDedicated { display: grid; gap: 12px; border: 0; padding: 0; margin: 0; min-width: 0; }
#memoryWriterConsent { grid-template-columns: auto 1fr; align-items: start; padding: 12px; border: 1px solid #b9856552; border-radius: 12px; background: #fbf2e9; line-height: 1.55; }
#memoryWriterConsent input { width: auto; margin: 4px 0 0; }
#settingsMessage, #memoryWriterMessage { margin: 0; font-size: .85rem; overflow-wrap: anywhere; }
#messages { overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 12px; }
#messages.messages-loading { visibility: hidden; }
.empty { margin: auto; text-align: center; color: #77848e; line-height: 1.8; }
.message { max-width: 78%; padding: 11px 15px; border-radius: 19px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 7px 22px #53677912; }
.human { align-self: flex-end; background: #dce5ed; border-bottom-right-radius: 6px; }
.ai { align-self: flex-start; background: #fffdf9; border-bottom-left-radius: 6px; }
.message-group { max-width: 78%; min-width: 0; }
.message-group .message { max-width: 100%; }
.human-group { align-self: flex-end; }
.ai-reply { align-self: flex-start; }
.message-tools { min-height: 40px; display: flex; align-items: center; gap: 1px; opacity: 0; visibility: hidden; transition: opacity .15s ease; }
.human-group .message-tools { justify-content: flex-end; }
.message-group:hover .message-tools, .message-tools:focus-within { opacity: 1; visibility: visible; }
.message-tool { width: 40px; height: 40px; min-width: 40px; display: grid; place-items: center; padding: 0; background: transparent; color: #71808b; }
.message-tool:hover, .message-tool:focus-visible { background: #71808b14; color: #4e392d; }
.message-tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: none) { .message-tools { opacity: 1; visibility: visible; } }
.attachment { display: block; margin-top: 8px; color: #344b60; font-size: .9rem; white-space: normal; }
.attachment img { display: block; width: min(280px, 100%); max-height: 320px; margin-top: 6px; border-radius: 12px; object-fit: contain; background: #ffffff88; }
.pending-upload { opacity: .78; }
.upload-state { display: block; margin-top: 7px; color: #687985; font-size: .82rem; }
.upload-failed { color: #a14c45; }
.composer { position: relative; display: block; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: #f7f3edee; border-top: 1px solid #768a9a2b; }
.scroll-to-latest { position: absolute; z-index: 2; left: 50%; top: -46px; width: 38px; height: 38px; min-width: 38px !important; padding: 0; border: 1px solid #8c796545; border-radius: 50%; background: #fffaf2e8; color: #654d3f; box-shadow: 0 7px 20px #655b4d26; backdrop-filter: blur(10px); opacity: .72; transform: translateX(-50%); transition: opacity .15s ease, transform .15s ease; }
.scroll-to-latest:hover, .scroll-to-latest:focus-visible, .composer:hover .scroll-to-latest { opacity: 1; transform: translateX(-50%) translateY(-2px); }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 48px; max-height: 132px; }
.composer button { min-width: 74px; }
.attach-button { display: grid; place-items: center; width: 48px; height: 48px; min-width: 48px; flex: 0 0 48px; border: 1px solid #9cabb755; border-radius: 16px; background: #ffffffcc; color: #344b60; cursor: pointer; font-size: 1.35rem; }
.pending { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #5e6d78; font-size: .84rem; }
.pending span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending button { min-width: auto; padding: 2px 8px; background: transparent; color: #7b5550; }
.pending-list { display:flex; min-width:0; gap:8px; overflow-x:auto; padding:3px 2px; }
.pending-item { display:flex; flex:none; align-items:center; gap:6px; max-width:240px; padding:5px 7px; border:1px solid rgba(156,185,205,.35); border-radius:14px; background:rgba(239,247,252,.92); }
.pending-item img { width:38px; height:38px; flex:none; border-radius:9px; object-fit:cover; }
.pending-item span { max-width:110px; }
.pending-item button { min-height:36px; min-width:36px; padding:4px; color:#527895; }
.attachment-menu { position:relative; }
.attachment-menu > summary { list-style:none; }
.attachment-menu > summary::-webkit-details-marker { display:none; }
.attachment-menu-options { position:absolute; z-index:8; left:0; bottom:calc(100% + 8px); display:flex; gap:6px; padding:8px; border:1px solid rgba(255,255,255,.9); border-radius:18px; background:#edf5fb; box-shadow:0 12px 30px rgba(45,75,98,.2); }
.attachment-menu-options button { min-width:58px; min-height:44px; padding:8px; border-radius:12px; background:rgba(255,255,255,.75); color:#466c88; white-space:nowrap; }
.image-crop-dialog { width:min(620px,calc(100% - 24px)); max-height:90dvh; overflow-y:auto; }
.image-crop-hint { margin:12px 16px; color:#638198; font-size:.8rem; }
#imageCropCanvas { display:block; width:auto; max-width:calc(100% - 24px); max-height:45dvh; margin:0 auto; touch-action:none; object-fit:contain; }
.image-crop-controls { display:grid; grid-template-columns:1fr 1fr; gap:6px 12px; padding:12px 16px; }
.image-crop-controls label { display:flex; gap:6px; align-items:center; color:#638198; font-size:.78rem; }
.image-crop-controls input { min-width:0; width:100%; }

:where(button, summary, .attach-button, [role="tab"]) { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
:where(button, summary, .attach-button, [role="tab"]):focus-visible { outline: 2px solid #778c78; outline-offset: 2px; }
.message, .memory-text, .memory-quotes, textarea, input, code, pre { -webkit-user-select: text; user-select: text; }

.shell { height: 100dvh; max-width: 760px; margin: auto; background: #fffaf4; box-shadow: 0 0 70px #655b4d1f; }
.view { height: 100%; }
.home-view { position: relative; overflow: hidden; padding: calc(20px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); background:
  radial-gradient(circle at 18% 8%, #fff 0 4%, transparent 19%),
  radial-gradient(circle at 86% 30%, #dfe5d8aa, transparent 29%),
  linear-gradient(150deg, #fffdf9 0%, #f6ecdf 56%, #e8dccd 100%); }
.home-view::before, .home-view::after { content: ""; position: absolute; border: 1px solid #9dad983d; border-radius: 50%; pointer-events: none; }
.home-view::before { width: 280px; height: 280px; right: -150px; top: 22%; }
.home-view::after { width: 180px; height: 180px; left: -105px; bottom: 8%; }
.home-topbar { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: flex-start; }
.home-date, .home-time, .home-kicker, .home-copy p, .lucien-name, .lucien-note { margin: 0; }
.home-date { font-family: "Songti SC", "STSong", "SimSun", Georgia, serif; font-size: .9rem; letter-spacing: .06em; }
.home-time { margin-top: 2px; font-family: Georgia, "Songti SC", serif; font-size: clamp(2.5rem, 13vw, 4rem); line-height: 1; font-variant-numeric: tabular-nums; }
.icon-button, .plain-button { min-width: 44px; min-height: 44px; padding: 0 10px; background: transparent; color: #583a2a; }
.icon-button { font-size: 1.25rem; }
.home-content { position: relative; z-index: 1; min-height: calc(100% - 82px); display: grid; align-content: center; gap: clamp(26px, 6vh, 52px); }
.home-kicker { color: #879182; font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; }
.home-copy h1 { margin: 8px 0 10px; font-family: "Songti SC", "STSong", "SimSun", Georgia, serif; font-size: clamp(2.45rem, 12vw, 4.6rem); font-weight: 400; letter-spacing: .04em; line-height: 1.15; }
.home-copy p:last-child { color: #765f50; font-family: "Songti SC", "STSong", "SimSun", Georgia, serif; font-size: 1rem; line-height: 1.85; }
.lucien-presence { width: 100%; padding: 0; display: grid; justify-items: center; gap: 8px; background: transparent; color: inherit; }
.lucien-portrait { width: min(54vw, 230px); aspect-ratio: 1; display: grid; place-items: center; border: 2px solid #fffaf2; border-radius: 50%; background:
  radial-gradient(circle at 36% 28%, #fffdf9 0 9%, transparent 24%),
  linear-gradient(145deg, #d9c8b8, #8c9f8e); box-shadow: 0 18px 44px #715b4930, 0 0 0 1px #8d745643; }
.lucien-portrait span { font-family: Georgia, serif; font-size: clamp(4rem, 20vw, 7rem); font-style: italic; color: #fffaf2dd; text-shadow: 0 2px 18px #5a47383d; transform: translateX(-.05em); }
.lucien-name { font-family: Georgia, "Songti SC", serif; font-size: 1.55rem; font-style: italic; }
.lucien-note { color: #7b6252; font-family: "Songti SC", "STSong", serif; letter-spacing: .08em; }
.enter-label { width: min(100%, 340px); min-height: 58px; margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 14px; border: 1px solid #ffffffaa; border-radius: 999px; background: linear-gradient(135deg, #8c9f8e, #6f836f); color: white; box-shadow: 0 12px 28px #65776438; font-size: 1.05rem; }
.chat-view { display: grid; grid-template-rows: auto 1fr auto; background: linear-gradient(180deg, #fffcf7, #f8f0e7); }
.chat-identity { display: grid; justify-items: center; gap: 2px; }
.chat-identity strong { font-family: Georgia, "Songti SC", serif; font-size: 1.12rem; font-weight: 500; }
.chat-header > :last-child { justify-self: end; }
.chat-header .plain-button { justify-self: start; }
.settings-view { overflow-y: auto; background: linear-gradient(180deg, #fffdf9, #f3e9dc); }
.memory-view { overflow-y: auto; background: linear-gradient(180deg, #fffdf9, #f3e9dc); }
.page-header { position: sticky; top: 0; z-index: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid #8c79652b; background: #fffaf2e8; backdrop-filter: blur(14px); }
.page-header .plain-button { justify-self: start; padding: 0; }
.page-header h1 { margin: 0; font-family: "Songti SC", "STSong", serif; font-size: 1.35rem; font-weight: 500; }
.settings-content { display: grid; gap: 16px; padding: 20px 16px calc(28px + env(safe-area-inset-bottom)); }
.settings-section { padding: 18px; border: 1px solid #a28b7038; border-radius: 20px; background: #fffdf9d9; box-shadow: 0 12px 30px #655b4d10; }
.settings-section h2 { margin: 0; font-family: "Songti SC", "STSong", serif; font-size: 1.1rem; font-weight: 500; }
.settings-section > .muted, .settings-row .muted { margin: 6px 0 16px; line-height: 1.6; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-row .muted { margin-bottom: 0; }
.primary-button, .secondary-button { min-height: 44px; padding: 10px 16px; }
.primary-button { background: #778c78; }
.secondary-button { flex-shrink: 0; border: 1px solid #8c796554; background: transparent; color: #583a2a; white-space: nowrap; }
#settingsForm, #personalizationForm { margin-top: 14px; }
#messages { padding: 20px 14px; }
.message { max-width: 84%; font-size: 16px; box-shadow: 0 7px 22px #53677910; }
.human { background: #dce3d8; }
.ai { background: #fffdf9; }
.composer { background: #fffaf2ed; border-color: #8c79652b; }
.composer textarea, .attach-button { border-color: #9b897052; background: #fffdf9; }
.composer #send { min-width: 48px; width: 48px; height: 48px; flex: 0 0 48px; border-radius: 50%; padding: 0; background: #778c78; font-size: 1.35rem; }

.memory-content { display: grid; gap: 14px; padding: 18px 16px calc(30px + env(safe-area-inset-bottom)); }
.memory-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 4px; border: 1px solid #a28b7038; border-radius: 16px; background: #eee4d8a8; }
.memory-tabs button { min-height: 44px; padding: 8px 9px; background: transparent; color: #765f50; font-size: .86rem; }
.memory-intro { margin: -3px 1px 0; font-size: .8rem; color: #71808b; line-height: 1.6; }
.memory-tabs button[aria-selected="true"] { background: #fffdf9; color: #4e392d; box-shadow: 0 5px 14px #655b4d16; }
#memoryListStatus { min-height: 1.4em; margin: 0; font-size: .86rem; }
.memory-list { display: grid; gap: 11px; }
.memory-record { min-height: 44px; display: grid; gap: 6px; padding: 15px 16px; border: 1px solid #a28b7038; border-radius: 18px; background: #fffdf9dd; color: inherit; text-align: left; box-shadow: 0 9px 24px #655b4d0d; }
.memory-record:hover, .memory-record:focus-visible { border-color: #778c7888; background: #fff; }
.memory-record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.memory-record-title { min-width: 0; display: grid; gap: 3px; }
.memory-record-kind { color: #7691a9; font-size: .72rem; font-weight: 500; }
.memory-record-head strong { min-width: 0; font-family: "Songti SC", "STSong", serif; font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
.memory-record-time, .memory-record-meta { display: block; color: #71808b; font-size: .8rem; line-height: 1.5; overflow-wrap: anywhere; }
.memory-pill { flex-shrink: 0; display: inline-flex; align-items: center; min-height: 25px; padding: 3px 8px; border-radius: 999px; background: #e2eadf; color: #526c58; font-size: .72rem; font-weight: 500; }
.memory-pill.danger { background: #f4dfdc; color: #994f48; }
#memoryLoadMore { justify-self: center; }
.memory-detail-dialog { width: min(680px, calc(100% - 24px)); max-height: min(88dvh, 820px); }
.memory-detail-dialog[open] { display: flex; flex-direction: column; height: min(88dvh, 820px); overflow: hidden; }
.memory-detail-dialog > .dialog-head { position: relative; top: auto; z-index: 1; flex: 0 0 auto; }
.memory-detail-body { flex: 1 1 auto; height: 0; min-height: 0; display: grid; align-content: start; gap: 14px; padding: 14px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; touch-action: pan-y; }
.memory-technical { margin-top: 12px; border-top: 1px solid rgba(145,190,229,.36); }
.memory-technical > summary { padding: 11px 0 7px; color: #597fa0; font-size: .83rem; cursor: pointer; }
.memory-technical > .memory-facts { padding: 6px 0 10px; }
.memory-detail-section { padding: 15px; border: 1px solid #a28b7038; border-radius: 16px; background: #fffdf9; }
.memory-detail-section > h3 { margin: 0 0 12px; font-family: "Songti SC", "STSong", serif; font-size: 1.05rem; font-weight: 600; }
.memory-card-heading, .memory-card-summary strong { font-family: "Songti SC", "STSong", serif; font-size: 1.05rem; font-weight: 600; }
.memory-card-heading { margin-bottom: 12px; }
.memory-card-summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.memory-module-card > .memory-facts { margin-top: 12px; }
.memory-module-card > .memory-text-block, .memory-module-card > .muted { margin-top: 12px; }
.memory-readable-space { display: grid; gap: 10px; margin: 16px 12px 12px; }
.memory-readable-space > .memory-facts { margin-bottom: 4px; }
.memory-readable-space > .memory-subheading { margin: 8px 0 0; }
.memory-readable-part-note { margin: 0 14px 14px; color: #72838e; font-size: .8rem; line-height: 1.7; overflow-wrap: anywhere; }
.memory-readable-continuity { display: grid; gap: 10px; margin: 16px 12px 12px; }
.memory-readable-continuity > .memory-subheading { margin-bottom: 2px; }
.memory-readable-part { overflow: hidden; border: 1px solid rgba(120,151,173,.22); border-radius: 13px; background: rgba(236,245,250,.76); }
.memory-detail-body .memory-readable-part > summary { display: grid; align-items: stretch; justify-content: stretch; gap: 6px; padding: 12px 14px; cursor: pointer; list-style: none; }
.memory-readable-part > summary::-webkit-details-marker { display: none; }
.memory-readable-part > summary::after { content: "展开"; color: #65859b; font-size: .75rem; justify-self: end; }
.memory-readable-part[open] > summary::after { content: "收起"; }
.memory-readable-part-name { font-size: .87rem; font-weight: 600; color: #44667d; overflow-wrap: anywhere; }
.memory-readable-part-preview { font-size: .8rem; line-height: 1.65; color: #72838e; overflow-wrap: anywhere; }
.memory-readable-part[open] .memory-readable-part-preview { display: none; }
.memory-readable-part-body { margin: 0 14px 14px; padding-top: 12px; border-top: 1px solid rgba(120,151,173,.18); font-size: .88rem; line-height: 1.9; white-space: pre-wrap; overflow-wrap: anywhere; color: #43586a; }
.memory-readable-raw { margin: 12px 0 0; border-top: 1px solid rgba(120,151,173,.18); }
.memory-readable-raw > summary { padding: 10px 0; color: #65849a; font-size: .81rem; cursor: pointer; }
.memory-readable-raw > .memory-facts, .memory-readable-raw > .memory-text-block { margin: 8px 0 12px; }
.memory-technical-card .memory-item > .memory-readable-continuity { margin-inline: 12px; }
.memory-module-source { margin: 14px 12px 0; padding-top: 12px; border-top: 1px solid #a28b7038; }
.memory-module-source h4, .memory-subheading { margin: 0 0 10px; color: #765f50; font-size: .86rem; font-weight: 600; }
.memory-facts { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 7px 12px; margin: 0; font-size: .82rem; line-height: 1.5; }
.memory-facts dt { color: #71808b; }
.memory-facts dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.memory-note, .memory-error, .memory-evidence-note { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: #f3eee6; font-size: .84rem; line-height: 1.6; }
.memory-error { background: #f7e7e4; color: #984c46; }
.memory-evidence-note { color: #71808b; }
.memory-item { margin-top: 10px; border: 1px solid #a28b7038; border-radius: 14px; background: #fffaf4; overflow: hidden; }
.memory-item summary { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; cursor: pointer; }
.memory-item > :not(summary) { margin-inline: 12px; }
.memory-item > :last-child { margin-bottom: 12px; }
.memory-text-block { margin-top: 12px; }
.memory-text-block h4, .memory-quotes h4 { margin: 0 0 6px; color: #765f50; font-size: .82rem; font-weight: 600; }
.memory-text { margin: 0; padding: 11px; border-radius: 11px; background: #f3eee6; color: #4e392d; font: inherit; font-size: .84rem; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-quotes { margin-top: 12px; }
.memory-quotes blockquote { margin: 7px 0; padding: 9px 11px; border-left: 3px solid #9aad98; background: #f3eee6; font-size: .84rem; line-height: 1.6; }

@media (max-width: 480px) {
  .settings-row { align-items: flex-start; }
  .memory-detail-dialog { width: calc(100% - 16px); max-height: 92dvh; border-radius: 18px; }
  .memory-detail-dialog[open] { height: 92dvh; }
  .memory-detail-body { padding: 10px; }
  .memory-detail-section { padding: 12px; }
  .memory-facts { grid-template-columns: 1fr; gap: 2px; }
  .memory-facts dd { margin-bottom: 7px; }
}

@media (min-width: 761px) {
  .home-view, .chat-view, .settings-view, .memory-view { border-inline: 1px solid #ad9a8426; }
}

/* Ice-blue home desktop V1: scoped to the home screen. */
.visually-hidden{position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
.home-view{isolation:isolate;display:flex;flex-direction:column;min-height:100%;padding:calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));color:#345c81;background:radial-gradient(ellipse at 15% 14%,#fff 0%,transparent 40%),radial-gradient(ellipse at 92% 55%,#b4d4ff99 0%,transparent 45%),linear-gradient(155deg,#f7fbff 0%,#e5f3ff 52%,#d9ecf8 100%)}
.home-view::before,.home-view::after{display:none}
.home-atmosphere{position:absolute;inset:0;z-index:-1;pointer-events:none;background:radial-gradient(circle at 70% 25%,#ffffffaa 0 11%,transparent 33%),radial-gradient(circle at 20% 77%,#c6e6e88c 0 12%,transparent 36%)}
.home-topbar{display:flex;align-items:center;justify-content:space-between}
.home-brand{font-family:Georgia,serif;font-size:.83rem;letter-spacing:.12em;color:#557a9b}
.home-brand span{font-family:system-ui,sans-serif;font-size:.57rem;letter-spacing:.25em;margin-left:5px}
.home-top-dot{width:8px;height:8px;border-radius:50%;background:#87ceeb;box-shadow:0 0 0 5px #ffffff8c}
.home-clock{margin-top:clamp(36px,8vh,90px);text-align:center}
.home-time{font-family:Georgia,serif;font-weight:400;font-size:clamp(4.6rem,21vw,7.5rem);letter-spacing:-.07em;line-height:1.08;color:#416d98;text-shadow:0 5px 25px #ffffffc9;font-variant-numeric:tabular-nums}
.home-date{margin-top:10px;font-family:inherit;font-size:.95rem;letter-spacing:.12em;color:#6289a9}
.home-desktop{margin:auto 0;position:relative;z-index:1}
.desktop-caption{margin:0 0 20px;text-align:center;color:#7395b2;letter-spacing:.26em;font-size:.64rem}
.home-icons{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:22px 16px;max-width:380px;margin:auto}
.desktop-app{display:flex;flex-direction:column;align-items:center;gap:10px;min-width:0;padding:0;background:transparent;color:#476d8e;font-size:.86rem;cursor:pointer}
.desktop-icon{display:grid;place-items:center;width:min(21vw,76px);height:min(21vw,76px);min-width:62px;min-height:62px;border:1px solid #ffffffd9;border-radius:23px;background:linear-gradient(145deg,#ffffffd9,#b4d4ff6e);box-shadow:0 12px 28px #4a90e21b,inset 0 1px 0 #fff;backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px);transition:transform .18s ease,box-shadow .18s ease}
.desktop-icon svg,.home-dock svg{width:29px;height:29px;fill:none;stroke:#4a90e2;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.desktop-app:active .desktop-icon{transform:scale(.94);box-shadow:0 5px 12px #4a90e21b}
.desktop-app:focus-visible{outline:2px solid #4a90e2;outline-offset:6px}
.home-subnote{margin:30px 0 0;text-align:center;font-family:"Songti SC","STSong",serif;color:#7698b1;font-size:.86rem;letter-spacing:.06em}
.home-dock{align-self:center;display:flex;align-items:center;justify-content:center;gap:22px;width:min(240px,85%);min-height:64px;border:1px solid #fff;border-radius:24px;background:#ffffff8a;box-shadow:0 14px 40px #4a90e21c,inset 0 1px 0 #fff;backdrop-filter:blur(22px);-webkit-backdrop-filter:blur(22px)}
.home-dock button{display:grid;place-items:center;width:48px;height:48px;padding:0;background:transparent}
.home-dock svg{width:25px;height:25px}
.dock-divider{width:1px;height:24px;background:#a7c8e0}
.dock-label{font-family:Georgia,serif;letter-spacing:.17em;color:#618eb3;font-size:1rem}
@media(max-height:620px){.home-clock{margin-top:15px}.home-time{font-size:4.2rem}.home-desktop{margin:22px 0}.home-subnote{margin-top:12px}.desktop-icon{min-width:54px;min-height:54px}}
@media(prefers-reduced-motion:reduce){.desktop-icon{transition:none}}

/* Desktop / tablet responsive home layout. Mobile rules above remain unchanged. */
@media (min-width: 900px) {
  body { background: linear-gradient(135deg,#edf7ff,#dbeafa); }
  .shell { max-width: none; width: 100%; box-shadow: none; }
  .home-view { padding: 36px clamp(48px,6vw,112px) 38px; }
  .home-topbar { width: 100%; max-width: 1500px; margin-inline: auto; }
  .home-brand { font-size: 1rem; }
  .home-clock { margin-top: clamp(24px,5vh,68px); }
  .home-time { font-size: clamp(6.5rem,10vw,10rem); }
  .home-date { font-size: 1.1rem; }
  .home-desktop { width: min(100%,1050px); margin: auto; }
  .desktop-caption { margin-bottom: 34px; font-size: .78rem; }
  .home-icons { max-width: 700px; gap: 30px 60px; }
  .desktop-icon { width: 106px; height: 106px; min-width: 106px; min-height: 106px; border-radius: 30px; }
  .desktop-icon svg { width: 40px; height: 40px; }
  .desktop-app { gap: 14px; font-size: 1rem; }
  .desktop-app:hover .desktop-icon { transform: translateY(-5px); box-shadow: 0 20px 38px #4a90e22c,inset 0 1px 0 #fff; }
  .home-subnote { margin-top: 40px; font-size: 1rem; }
  .home-dock { width: 300px; min-height: 74px; border-radius: 28px; }
  .home-dock button { width: 54px; height: 54px; }
  .home-view, .chat-view, .settings-view, .memory-view { border-inline: 0; }
  .chat-view { max-width: 1100px; margin-inline: auto; box-shadow: 0 0 50px #4a90e212; }
  .settings-view, .memory-view { max-width: 1100px; margin-inline: auto; }
  .settings-content, .memory-content { max-width: 880px; margin-inline: auto; width: 100%; }
}
@media (min-width: 900px) and (max-height: 760px) {
  .home-clock { margin-top: 12px; }
  .home-time { font-size: clamp(5rem,8vw,7rem); }
  .home-desktop { margin: 16px auto; }
  .desktop-caption { margin-bottom: 16px; }
  .desktop-icon { width: 80px; height: 80px; min-width: 80px; min-height: 80px; }
  .home-subnote { margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .desktop-app:hover .desktop-icon { transform: none; }
}


/* Shared ice-blue / pearl-white glass theme for existing functional views.
   Overrides only presentation; chat, memory and provider logic stay intact. */
:root {
  --ice-ink: #294c70;
  --ice-muted: #62839e;
  --ice-accent: #4a90e2;
  --ice-line: rgba(255,255,255,.75);
  --ice-glass: rgba(255,255,255,.68);
  --ice-shadow: 0 14px 38px rgba(62,119,174,.12);
  --motion-fast: .18s;
  --motion-base: .22s;
  --motion-ease-out: cubic-bezier(.2,.75,.25,1);
  background: #eaf4ff;
  color: var(--ice-ink);
  color-scheme: light;
}
body {
  color: var(--ice-ink);
  background: linear-gradient(145deg, #f6fbff, #dfefff);
}
.muted, .conversation-meta, .memory-record-time, .memory-record-meta,
.memory-facts dt, .memory-evidence-note {
  color: var(--ice-muted);
}
:where(button, summary, .attach-button, [role="tab"]):focus-visible {
  outline-color: var(--ice-accent);
}
button:not(:disabled) { transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  border-color: var(--ice-accent) !important;
  outline: 2px solid rgba(74,144,226,.30);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(74,144,226,.10);
}
input[type="checkbox"] { accent-color: var(--ice-accent); }
:where(input, textarea, select) { color: var(--ice-ink); }
:where(input, textarea)::placeholder { color: #7c9db8; }

/* Login: the same atmosphere before entering the home. */
.login {
  background: radial-gradient(circle at 17% 15%, #ffffff 0, transparent 40%),
              radial-gradient(circle at 85% 75%, #b4d4ffb8 0, transparent 47%),
              linear-gradient(155deg,#f7fcff,#dcefff 70%,#c6e6e8);
}
.login .card {
  border: 1px solid rgba(255,255,255,.90);
  color: var(--ice-ink);
  background: rgba(255,255,255,.62);
  box-shadow: 0 26px 64px rgba(70,130,184,.16), inset 0 1px 0 #fff;
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
}
.login .card h1 { color: #416f9e; }
.login #secret {
  background: rgba(255,255,255,.82);
  border-color: rgba(137,183,226,.42);
}
#loginForm button, .primary-button {
  background: linear-gradient(140deg,#66a8ec,#427fc8);
  color: #fff;
  box-shadow: 0 8px 20px rgba(74,144,226,.23);
}
#loginForm button:hover, .primary-button:not(:disabled):hover {
  background: linear-gradient(140deg,#75b6f7,#3e79c5);
}
.error { color: #a94f5f; }

/* Chat: a quiet ice-blue conversation canvas. */
.chat-view {
  background: radial-gradient(ellipse at 8% 20%, rgba(255,255,255,.92), transparent 47%),
              radial-gradient(ellipse at 94% 76%, rgba(180,212,255,.57), transparent 52%),
              linear-gradient(155deg,#f5fbff,#eaf5ff 55%,#dbecf8);
  color: var(--ice-ink);
}
.chat-header, .page-header {
  border-bottom: 1px solid rgba(255,255,255,.82);
  background: rgba(248,252,255,.73);
  box-shadow: 0 7px 22px rgba(72,129,182,.055);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.chat-identity strong, .page-header h1 { color: #356898; }
#status { color: #507d9f; }
.icon-button, .plain-button {
  color: #47779f;
  border-radius: 14px;
}
.icon-button:hover, .plain-button:hover {
  background: rgba(180,212,255,.32);
}
#messages {
  min-height: 0;
  scrollbar-color: #a9cde8 transparent;
}
.empty { color: #7393ac; }
.message {
  color: #284963;
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 9px 28px rgba(77,134,183,.105);
}
.human {
  background: rgba(180,212,255,.76);
  border-color: rgba(255,255,255,.67);
}
.ai {
  background: rgba(255,255,255,.81);
  border-color: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.message-tool { color: #678dac; }
.message-tool:hover, .message-tool:focus-visible {
  color: #316da5;
  background: rgba(180,212,255,.28);
}
.attachment { color: #326eab; }
.attachment img { background: rgba(255,255,255,.54); }
.upload-state, .pending { color: #5c829e; }
.upload-failed { color: #a94f5f; }
.composer {
  border-top: 1px solid rgba(255,255,255,.87);
  background: rgba(247,252,255,.81);
  box-shadow: 0 -7px 27px rgba(70,127,178,.06);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.composer textarea, .attach-button {
  color: var(--ice-ink);
  background: rgba(255,255,255,.83);
  border: 1px solid rgba(139,185,226,.46);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.95);
}
.attach-button { color: #4e86bd; }
.attach-button:hover { background: #fff; }
.composer #send {
  background: linear-gradient(145deg,#75b7f7,#4a90e2);
  color: #fff;
  box-shadow: 0 6px 16px rgba(74,144,226,.28);
}
.composer #send:not(:disabled):hover { background: #387ec8; }
.pending button { color: #a55869; }
.scroll-to-latest {
  border: 1px solid rgba(255,255,255,.88);
  background: rgba(255,255,255,.88);
  color: #477aa7;
  box-shadow: 0 8px 22px rgba(74,144,226,.18);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
/* Settings and memory: frosted panels over the same light landscape. */
.settings-view, .memory-view {
  background: radial-gradient(ellipse at 85% 15%, rgba(255,255,255,.95), transparent 48%),
              radial-gradient(ellipse at 12% 90%, rgba(198,230,232,.7), transparent 50%),
              linear-gradient(150deg,#eef8ff,#dceeff);
  color: var(--ice-ink);
  scrollbar-color: #abcde7 transparent;
}
.settings-section,
.memory-record, .memory-detail-section {
  border: 1px solid rgba(255,255,255,.87);
  background: rgba(255,255,255,.68);
  box-shadow: var(--ice-shadow), inset 0 1px 0 rgba(255,255,255,.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.settings-section h2, .memory-record-head strong, .memory-detail-section > h3 {
  color: #356893;
}
#settingsForm label, #memoryWriterForm label { color: #3f6888; }
#settingsForm select, #memoryWriterForm select,
#settingsForm input:not([type="checkbox"]),
#memoryWriterForm input:not([type="checkbox"]) {
  background: rgba(255,255,255,.84);
  border: 1px solid rgba(130,177,220,.48);
  color: var(--ice-ink);
}
.secondary-button, .new-chat {
  border: 1px solid rgba(139,185,226,.52);
  background: rgba(255,255,255,.53);
  color: #3d79af;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72);
}
.secondary-button:not(:disabled):hover, .new-chat:not(:disabled):hover {
  background: rgba(225,243,255,.91);
  border-color: #88b9e2;
}
.privacy-confirm, #memoryWriterConsent {
  border-color: rgba(120,173,222,.38);
  background: rgba(225,240,255,.65);
  color: #426985;
}
.memory-tabs {
  border: 1px solid rgba(255,255,255,.9);
  background: rgba(186,216,244,.44);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.memory-tabs button { color: #557f9f; }
.memory-tabs button[aria-selected="true"] {
  color: #2c669b;
  background: rgba(255,255,255,.94);
  box-shadow: 0 5px 15px rgba(71,137,197,.15);
}
.memory-record:hover, .memory-record:focus-visible {
  border-color: #91bce3;
  background: rgba(255,255,255,.92);
}
.memory-pill {
  background: rgba(198,230,232,.76);
  color: #386f7e;
}
.memory-pill.danger { background: #f9e0e6; color: #9c5063; }
.memory-item {
  border: 1px solid rgba(145,190,229,.36);
  background: rgba(248,252,255,.72);
}
.memory-note, .memory-evidence-note, .memory-text {
  background: rgba(229,242,255,.82);
  color: #355976;
}
.memory-text-block h4, .memory-quotes h4 { color: #497d9d; }
.memory-quotes blockquote {
  border-left: 3px solid #86b9e4;
  background: rgba(224,240,255,.72);
  color: #355976;
}
.memory-error { background: #f9e5e9; color: #984c61; }

/* All existing modal dialogs share the frosted treatment. */
dialog {
  border: 1px solid rgba(255,255,255,.92);
  background: rgba(241,249,255,.94);
  color: var(--ice-ink);
  box-shadow: 0 25px 80px rgba(24,71,115,.26);
}
dialog::backdrop {
  background: rgba(33,80,121,.31);
}
.dialog-head {
  background: rgba(245,251,255,.89);
  border-bottom: 1px solid rgba(155,196,231,.37);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.dialog-head strong { color: #356893; }
.dialog-head button, .conversation-actions button {
  color: #4078aa;
}
.dialog-head button:hover, .conversation-actions button:hover {
  background: rgba(180,212,255,.35);
}
.dialog-footer { border-top: 1px solid rgba(150,192,229,.35); }
.conversation-actions nav {
  background: rgba(249,253,255,.97);
  border-color: rgba(134,185,229,.45);
  box-shadow: var(--ice-shadow);
}
.conversation-item[aria-current="true"] {
  border-color: rgba(123,177,226,.49);
  background: rgba(201,227,252,.56);
}
.memory-toast {
  background: rgba(49,112,165,.94);
  box-shadow: 0 10px 27px rgba(36,94,146,.25);
}
.memory-toast-failed { background: rgba(156,72,91,.94); }

@media (min-width: 900px) {
  .chat-view { box-shadow: 0 0 60px rgba(74,144,226,.09); }
  .settings-content, .memory-content { padding-top: 32px; padding-bottom: 54px; }
  .settings-section { padding: 24px 28px; }
  .composer { padding-inline: max(22px, calc((100% - 940px)/2)); }
  #messages { padding-inline: max(24px, calc((100% - 960px)/2)); }
}
@media (max-width: 480px) {
  .login .card { padding: 28px 20px; }
  .settings-section { background: rgba(255,255,255,.76); }
  .message { box-shadow: 0 6px 20px rgba(67,126,178,.10); }
}
@media (prefers-reduced-motion: reduce) {
  button:not(:disabled) { transition: none; }
}


/* Jude-like chat appearance: multiple visual segments share one message ID. */
.chat-display-setting { display:grid; gap:8px; color:#426784; font-size:.9rem; }
.chat-display-setting select { width:100%; min-height:44px; padding:10px 12px; border:1px solid #a9c3d455; border-radius:12px; background:rgba(255,255,255,.72); color:inherit; }
/* WeChat-like paragraph bubbles: several visual bubbles, one real reply. */
.message-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
}
.message-group.human-group { align-items: flex-end; }
.message-group .message {
  width: fit-content;
  max-width: 100%;
  margin: 0;
}
.message-group .message-tools {
  align-self: flex-start;
  margin-top: 0;
}
.message-group.human-group .message-tools { align-self: flex-end; }
@media (max-width: 480px) {
  .message-group { gap: 8px; }
}


.chat-identity strong {
  display: none;
}

/* Co-reading room: quiet paper, pearl-blue glass, two-person discussion. */
.home-icons { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 440px; gap: 18px 8px; }
.reading-view {
  display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden;
  color: #365779;
  background: radial-gradient(ellipse at 10% 4%, #fff 0%, transparent 46%),
    radial-gradient(ellipse at 92% 74%, #bdd9f8a0 0%, transparent 58%),
    linear-gradient(140deg, #f4f9ff, #e7f2ff 57%, #dbeaff);
}
.reading-header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid #8aa7c22b; background: #ffffff8c;
  backdrop-filter: blur(18px);
}
.reading-header .plain-button { width: max-content; font-size: 1.5rem; }
.reading-header-mark { justify-self: end; letter-spacing: .2em; color: #7b9ab6; font-size: .7rem; }
.reading-identity { display: flex; flex-direction: column; align-items: center; gap: 2px; white-space: nowrap; }
.reading-identity strong { font-weight: 600; font-size: .98rem; }
.reading-identity span { font-size: .57rem; letter-spacing: .24em; color: #89a2ba; }
.reading-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 13px 18px 8px; }
.reading-shelf-label { display: grid; gap: 5px; font-size: .71rem; color: #637f99; flex: 1; min-width: 150px; }
.reading-shelf-label select {
  width: 100%; max-width: 390px; min-height: 38px; padding: 6px 28px 6px 11px;
  border: 1px solid #a3bbd37d; border-radius: 12px; color: #365779; background: #ffffffd9;
}
.reading-toolbar .secondary-button { min-height: 38px; }
.reading-toggle {
  min-height: 38px; padding: 6px 15px; border: 1px solid #acc5db9e;
  background: #ffffffce; color: #426e90; white-space: nowrap;
}
.reading-toggle[aria-pressed="true"] {
  background: #4478a6; color: white; border-color: #4478a6; box-shadow: 0 8px 24px #548bbb35;
}
.reading-notice { min-height: 28px; padding: 2px 20px 8px; font-size: .76rem; color: #6d89a2; }
.reading-layout {
  flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr);
  gap: 14px; padding: 3px 18px calc(16px + env(safe-area-inset-bottom));
}
.reading-book-panel, .reading-companion {
  min-width: 0; min-height: 0; display: flex; flex-direction: column;
  border: 1px solid #ffffffb9; border-radius: 23px; overflow: hidden;
  background: #ffffffbf; backdrop-filter: blur(18px);
  box-shadow: 0 14px 36px #477eaf1a, inset 0 1px 0 #fff;
}
.reading-book-panel { background: #fffefaed; }
.reading-paper-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 19px 24px 12px; border-bottom: 1px solid #b5c9dd49;
}
.reading-paper-top h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; font-weight: 600; }
.reading-paper-top span { flex-shrink: 0; color: #8497a8; font-size: .75rem; }
.reading-page {
  flex: 1; min-height: 0; overflow-y: auto; padding: 22px clamp(20px,4vw,40px);
  color: #404f5b; white-space: pre-wrap; overflow-wrap: anywhere;
  line-height: 2.05; font-size: 1.02rem; letter-spacing: .025em;
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif; scrollbar-width: thin;
}
.reading-page:focus-visible { outline: 2px solid #8dbae1; outline-offset: -3px; }
.reading-companion-top { padding: 16px 18px 12px; border-bottom: 1px solid #b5c9dd49; }
.reading-companion-top strong { display: block; font-size: 1rem; }
.reading-companion-top p { margin: 5px 0 0; font-size: .78rem; color: #7790a7; }
.reading-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 17px 15px; display: flex; flex-direction: column; gap: 12px; }
.reading-thread-empty { margin: auto; font-size: .85rem; line-height: 1.75; text-align: center; color: #8ba0b5; }
.reading-comment {
  max-width: 95%; padding: 11px 13px; border-radius: 16px;
  box-shadow: 0 5px 15px #4d7d9a10; white-space: pre-wrap; overflow-wrap: anywhere;
}
.reading-comment strong { font-size: .73rem; opacity: .75; font-weight: 600; }
.reading-comment p { margin: 5px 0 0; font-size: .9rem; line-height: 1.65; }
.reading-lucien { align-self: flex-start; background: #fffdf9; border-bottom-left-radius: 5px; }
.reading-sienna { align-self: flex-end; background: #dcecff; border-bottom-right-radius: 5px; }
.reading-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #b5c9dd49; }
.reading-form textarea {
  flex: 1; min-width: 0; min-height: 48px; max-height: 110px; resize: vertical;
  padding: 10px 12px; line-height: 1.55; font-size: .88rem;
}
.reading-form button { align-self: flex-end; min-width: 58px; min-height: 46px; padding: 0 12px; border-radius: 13px; background: #4478a6; }
@media (min-width: 900px) {
  .home-icons { max-width: 760px; }
  .reading-layout { gap: 20px; padding-inline: clamp(24px,4vw,70px); }
  .reading-toolbar, .reading-notice { padding-inline: clamp(24px,4vw,70px); }
}
@media (max-width: 760px) {
  .home-icons { gap: 14px 6px; }
  .desktop-icon { width: min(65px, 100%); height: 65px; min-width: 0; }
  .reading-toolbar { padding-inline: 12px; gap: 8px; }
  .reading-notice { padding-inline: 14px; }
  .reading-layout { grid-template-columns: 1fr; grid-template-rows: minmax(185px, 1fr) minmax(190px, .7fr); padding: 2px 10px calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  .reading-book-panel, .reading-companion { border-radius: 17px; }
  .reading-paper-top { padding: 12px 15px 10px; }
  .reading-page { padding: 12px 17px; line-height: 1.85; font-size: .94rem; }
  .reading-companion-top { padding: 9px 13px; }
  .reading-thread { padding: 10px 12px; gap: 8px; }
  .reading-comment { padding: 8px 10px; }
  .reading-form { padding: 8px; }
  .reading-form textarea { min-height: 38px; }
  .reading-form button { min-height: 40px; }
}
@media (max-width: 390px) {
  .reading-header { padding-inline: 12px; }
  .reading-toolbar .secondary-button { padding-inline: 9px; }
  .reading-toggle { padding-inline: 9px; }
  .home-icons .desktop-app { font-size: .72rem; }
}

.reading-privacy { margin: 0; padding: 0 18px 3px; color: #7790a7; font-size: .72rem; line-height: 1.4; }
#readingDeleteButton { color: #8a6670; }
@media (max-width: 760px) { .reading-privacy { padding-inline: 12px; } }
@media (max-height: 660px) and (max-width: 760px) {
  .reading-layout { grid-template-rows: minmax(115px,1fr) minmax(145px,.78fr); }
}


/* Reading V2: actual visual bookshelf and full-height reading canvas. */
.reading-view { position: relative; }
.reading-library { min-height: 0; overflow-y: auto; flex: 1; padding: clamp(18px,3vw,38px); scrollbar-width: thin; }
.reading-library-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.reading-library-heading h2 { font-size: 1.35rem; margin: 0 0 7px; font-weight: 600; }
.reading-library-heading p { margin: 0; font-size: .83rem; color: #819cb3; }
.reading-shelf-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(145px,1fr)); gap: 25px 19px; align-items: start; max-width: 1250px; margin-inline: auto; }
.reading-shelf-empty { grid-column: 1/-1; padding: 65px 20px; text-align: center; color: #7c98b1; line-height: 1.8; border-radius: 24px; background: #ffffff8f; }
.reading-book-card { min-width: 0; display: flex; flex-direction: column; padding: 0; text-align: left; color: #3d5f7b; background: transparent; border-radius: 14px; }
.reading-book-card:focus-visible { outline: 2px solid #6ba0d3; outline-offset: 6px; }
.reading-cover { position: relative; width: 100%; aspect-ratio: 3/4; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; overflow: hidden; border-radius: 8px 15px 15px 8px; padding: 13px 12px 14px 17px; background: linear-gradient(147deg,#dce6f3,#8faac8 65%,#688ab1); color: white; box-shadow: 3px 9px 18px #53749933,inset 5px 0 0 #ffffff34; transition: transform .18s,box-shadow .18s; }
.reading-book-card:hover .reading-cover { transform: translateY(-4px); box-shadow: 3px 15px 28px #5374993b,inset 5px 0 0 #ffffff34; }
.reading-cover::after { content: ""; position: absolute; top: 0; bottom: 0; left: 7px; width: 1px; background: #ffffff73; pointer-events: none; }
.reading-cover.with-art { padding: 0; background: #e7edf4; }
.reading-cover img { width: 100%; height: 100%; display: block; object-fit: cover; }
.reading-cover-mark { font-size: .55rem; letter-spacing: .17em; opacity: .85; }
.reading-cover-title { font: 600 clamp(.95rem,2.3vw,1.45rem)/1.5 "Songti SC","SimSun",serif; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.reading-cover-author { font-size: .65rem; opacity: .85; }
.reading-book-card-title { display: block; max-width: 100%; margin-top: 12px; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reading-book-card-author { display: block; width: 100%; margin-top: 3px; font-size: .74rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #7993aa; }
.reading-book-card-status { font-size: .76rem; color: #6b88a3; margin: 9px 0 7px; }
.reading-progress-track { display: block; height: 4px; width: 100%; overflow: hidden; border-radius: 100px; background: #adc6df66; }
.reading-progress-track > span { display: block; height: 100%; border-radius: inherit; background: #5b90c1; }
.reading-reader { display: flex; flex: 1; min-height: 0; flex-direction: column; }
.reading-reader .reading-layout { flex: 1; min-height: 0; }
.reading-reader .reading-toolbar { align-items: center; padding-top: 12px; padding-bottom: 8px; }
.reading-back-shelf, .reading-book-edit { border: 1px solid #a3bbd37d; border-radius: 12px; padding: 9px 13px; min-height: 36px; background: #ffffffd9; color: #537b9e; white-space: nowrap; }
.reading-reader .reading-toolbar .reading-toggle { margin-left: auto; }
.reading-close-chat { margin-left: auto; border: 0; background: transparent; color: #5a7897; font-size: 1.5rem; padding: 4px 9px; }
.reading-companion-top { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.reading-companion-top p { order: 2; flex: 0 0 100%; }
.reading-companion-top .reading-close-chat { display: none; }
.reading-comment small { font-weight: 400; font-size: .69rem; }
.reading-float-zone { display: none; }
.reading-chat-backdrop { display: none; }
.reading-edit-dialog { width: min(440px,calc(100% - 28px)); padding: 20px; color: #385e7d; background: #f5f9ff; }
.reading-edit-form { display: grid; gap: 13px; }
.reading-edit-form h2 { margin: 0; font-size: 1.1rem; }
.reading-edit-form label { display: grid; gap: 5px; font-size: .85rem; }
.reading-edit-form input { background: white; }
.reading-edit-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.reading-edit-actions button { padding: 10px 12px; }
.reading-notice { position: absolute; left: 50%; bottom: calc(8px + env(safe-area-inset-bottom)); transform: translateX(-50%); pointer-events: none; z-index: 30; max-width: calc(100% - 30px); min-height: 0; padding: 0; font-size: .75rem; text-align: center; text-shadow: 0 1px 2px white; }
.reading-notice:empty { display: none; }
@media (max-width: 760px) {
  .reading-library { padding: 20px 16px 85px; }
  .reading-library-heading { margin-bottom: 22px; }
  .reading-library-heading h2 { font-size: 1.2rem; }
  .reading-library-heading p { font-size: .76rem; max-width: 200px; }
  .reading-library-heading button { padding-inline: 10px; white-space: nowrap; font-size: .8rem; }
  .reading-shelf-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px 18px; }
  .reading-cover { padding: 11px 10px 12px 15px; }
  .reading-cover-title { font-size: 1.05rem; }
  .reading-reader .reading-layout { display: flex; padding: 4px 10px calc(14px + env(safe-area-inset-bottom)); }
  .reading-reader .reading-book-panel { flex: 1; min-height: 0; }
  .reading-reader .reading-companion {
    position: absolute; z-index: 42; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
    height: min(57dvh,520px); min-height: 245px; flex: none; border-radius: 22px; box-shadow: 0 20px 60px #274c7790;
    transform: translateY(calc(100% + 35px)); opacity: 0; pointer-events: none;
    transition: transform .22s ease,opacity .22s ease;
  }
  .reading-reader .reading-companion.reading-chat-open { transform: translateY(0); opacity: 1; pointer-events: auto; }
  .reading-companion-top .reading-close-chat { display: block; }
  .reading-chat-backdrop:not(.hidden) { display: block; position: absolute; inset: 0; z-index: 38; background: #324e6d30; }
  .reading-float-zone { display: flex; position: absolute; right: 16px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 39; flex-direction: column; align-items: end; gap: 11px; pointer-events: none; }
  .reading-bubble, .reading-fab { pointer-events: auto; }
  .reading-fab { position: relative; width: 55px; height: 55px; padding: 0; border-radius: 50%; background: #477daf; color: white; font: 600 1.45rem Georgia,serif; box-shadow: 0 6px 24px #305b86a0, inset 0 1px 0 #ffffff59; }
  .reading-unread { position: absolute; right: -2px; top: -4px; border: 2px solid white; background: #d96f78; color: white; border-radius: 99px; min-width: 18px; height: 18px; padding: 0 4px; font: 600 10px/15px system-ui; }
  .reading-bubble { max-width: min(275px,calc(100vw - 45px)); padding: 12px 15px; text-align: left; line-height: 1.4; border: 1px solid #a9c3df; border-radius: 17px 17px 6px 17px; background: #ffffffef; color: #3d6384; box-shadow: 0 9px 28px #335b8030; font-size: .84rem; }
  .reading-reader .reading-toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
  .reading-back-shelf, .reading-book-edit { padding: 7px 10px; font-size: .85rem; }
  .reading-toggle { font-size: .85rem; padding: 7px 10px; }
  .reading-privacy { font-size: .68rem; line-height: 1.25; }
  .reading-page { padding: 18px; font-size: 1.04rem; line-height: 1.95; }
  .reading-notice { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .reading-companion .reading-form { padding-bottom: max(10px,env(safe-area-inset-bottom)); }
}
@media (min-width: 761px) {
  .reading-layout { grid-template-columns: minmax(0,1.4fr) minmax(290px,.6fr); }
}
@media (prefers-reduced-motion: reduce) {
  .reading-book-card .reading-cover, .reading-companion { transition: none !important; }
}

/* Draggable companion stays small; the preview floats above without changing its hitbox. */
@media (max-width: 760px) {
  .reading-float-zone {
    right: 10px; bottom: auto; top: 56%;
    width: 55px; height: 55px; display: block;
    touch-action: none;
  }
  .reading-fab { touch-action: none; user-select: none; -webkit-user-select: none; }
  .reading-bubble {
    position: absolute; right: 0; bottom: 65px;
    width: max-content; max-width: min(275px,calc(100vw - 45px));
  }
  .reading-float-zone:has(.reading-fab[aria-expanded="true"]) { z-index: 44; }
}
@media (max-width: 760px) { .reading-float-zone.at-left .reading-bubble { right: auto; left: 0; border-radius: 17px 17px 17px 6px; } }

/* Co-reading immersion, lightweight status and reader-owned selection UI. */
.reading-has-book > .reading-header { display: none; }
.reading-reader { position: relative; }
.reading-reader .reading-toolbar { transition: max-height .2s ease,opacity .2s ease,padding .2s ease; max-height: 120px; overflow: hidden; }
.reading-reader.reading-immersive .reading-toolbar {
  max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0;
  margin: 0; pointer-events: none;
}
.reading-reader.reading-immersive .reading-privacy { display: none; }
.reading-privacy { padding-bottom: 4px; }
.reading-notice {
  position: absolute; z-index: 55;
  bottom: calc(82px + env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100% - 32px);
  padding: 9px 14px; border: 1px solid #ffffffc9;
  border-radius: 20px; background: #eaf4ffeb;
  box-shadow: 0 6px 22px #5f91bd31;
  color: #436b8e; font-size: .77rem;
}
.reading-selection-tools {
  position: absolute; z-index: 22; left: 50%; bottom: 62px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 5px; padding: 7px;
  width: max-content; max-width: calc(100% - 20px);
  border: 1px solid #ffffffdb; border-radius: 18px;
  background: #eef7ffed; backdrop-filter: blur(18px);
  box-shadow: 0 9px 30px #6088a344;
}
.reading-selection-tools button { padding: 8px 10px; white-space: nowrap; border-radius: 11px; color: #466e90; background: #ffffffb7; font-size: .8rem; }
.reading-highlight { background: #bde1ffb0; color: inherit; border-radius: 3px; cursor: pointer; }
.reading-highlight:focus-visible { outline: 2px solid #6f9aca; }
.reading-side-dialog, .reading-note-dialog {
  border: 1px solid #ffffffdf; border-radius: 22px;
  width: min(520px, calc(100vw - 24px)); max-height: 80dvh;
  padding: 18px; background: #eff7ff; color: #3e6080;
  box-shadow: 0 24px 65px #273f6680;
}
.reading-side-dialog::backdrop, .reading-note-dialog::backdrop { background: #2138516b; }
.reading-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid #a5c1d566; padding-bottom: 12px; margin-bottom: 12px; }
.reading-dialog-head button, .reading-add-chapter button,.reading-note-dialog button { border-radius: 12px; padding: 9px 12px; background: #dcebf9; color: #416d93; }
.reading-dialog-body { max-height: min(57dvh,570px); overflow: auto; display: grid; gap: 8px; }
.reading-chapter { text-align: left; padding: 12px 14px; background: #ffffffba; border-radius: 12px; color: #3e6080; }
.reading-add-chapter { display: flex; gap: 8px; margin-top: 14px; }
.reading-add-chapter input { min-width: 0; flex: 1; background: white; }
.reading-note-card { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; border: 1px solid #d5e5f5; border-radius: 12px; background: #fffdf9ba; }
.reading-note-card > button:first-child { width: 100%; padding: 4px; color: #416d93; text-align: left; line-height: 1.5; background: transparent; }
.reading-note-card p { flex: 1; min-width: 100%; margin: 0; font-size: .83rem; white-space: pre-wrap; }
.reading-note-card > button:not(:first-child) { padding: 6px 10px; background: #e4f0ff; color: #416d93; border-radius: 9px; }
.reading-note-dialog form { display: grid; gap: 13px; }
.reading-note-dialog blockquote { padding: 10px 14px; border-left: 3px solid #93bbe0; margin: 0; max-height: 100px; overflow: auto; background: #fffefa; font-size: .83rem; white-space: pre-wrap; }
.reading-note-dialog textarea { background: white; width: 100%; }
@media (max-width: 760px) {
  .reading-reader .reading-companion { height: min(78dvh, 780px); min-height: 240px; }
  .reading-reader .reading-companion.reading-chat-open { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .reading-fab {
    background: linear-gradient(140deg, #ffffffdc, #d2e9facd 60%, #bbdafaac);
    color: #517a9c; border: 1px solid #fffffff2;
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 5px 20px #668fb34d, inset 0 1px 0 #ffffff;
  }
  .reading-fab.reading-thinking { animation: reading-breath 2.5s ease-in-out infinite; }
  .reading-float-zone:has(.reading-fab[aria-expanded="true"]) .reading-fab { visibility: hidden; pointer-events: none; }
  .reading-privacy { padding-top: 0; }
  .reading-float-zone { z-index: 36; }
  .reading-note-dialog { width: calc(100vw - 24px); }
}
@keyframes reading-breath {
  0%, 100% { box-shadow: 0 4px 16px #7bb1d644, 0 0 0 0 #b1dafe35, inset 0 1px 0 white; opacity: .88; }
  50% { box-shadow: 0 5px 25px #64a9dfa0, 0 0 0 8px #c0e5fb39, inset 0 1px 0 white; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .reading-fab.reading-thinking { animation: none; outline: 2px solid #8bc3e9; }
}

/* Reading V3.1: one-row controls, edge-peeking Lucien and native ebook drawer. */
.reading-toc-drawer {
  position: fixed; inset: 0 auto 0 0; margin: 0;
  width: min(80vw,370px); max-width: none; height: 100dvh; max-height: none;
  border-radius: 0 22px 22px 0;
  padding: max(16px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: #edf6ffed; backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  box-shadow: 15px 0 45px #25497144;
}
.reading-toc-drawer[open] { animation: reading-drawer-in .22s ease-out both; }
.reading-toc-drawer::backdrop { background: #1b35484d; }
.reading-toc-drawer .reading-dialog-body { max-height: calc(100dvh - 170px); }
.reading-toc-drawer .reading-chapter.is-current {
  color: #3b6890; background: #bcdaf4bc; font-weight: 650;
  border-left: 3px solid #6b9dcc;
}
@keyframes reading-drawer-in { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.reading-reader .reading-toolbar {
  display: flex; align-items: center; flex-wrap: nowrap; gap: 7px;
  min-width: 0; padding: 9px 12px 7px; max-height: 72px;
}
.reading-reader .reading-back-shelf, .reading-reader .reading-book-edit {
  min-width: 0; flex: 0 0 auto; padding: 7px 9px; min-height: 34px;
  font-size: .78rem; border-radius: 11px;
}
.reading-reader .reading-toolbar .reading-toggle {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto;
  margin-left: auto; padding: 5px; min-height: 34px;
  border: none; background: transparent; color: #60819d;
  box-shadow: none; font-size: .75rem; white-space: nowrap;
}
.reading-toggle-track {
  display: flex; align-items: center; width: 33px; height: 19px;
  border-radius: 20px; padding: 2px; background: #b8c9d6;
  transition: background .18s;
}
.reading-toggle-knob {
  width: 15px; height: 15px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px #3c61763a; transition: transform .18s;
}
.reading-toggle[aria-checked="true"] .reading-toggle-track { background: #6b9dc3; }
.reading-toggle[aria-checked="true"] .reading-toggle-knob { transform: translateX(14px); }
.reading-reader .reading-layout { padding-top: 0; }
.reading-privacy { display: none !important; }
@media (max-width:760px) {
  .reading-reader .reading-toolbar {
    gap: clamp(3px,1.5vw,8px); padding: 7px 6px 6px; max-height: 54px;
  }
  .reading-reader .reading-back-shelf, .reading-reader .reading-book-edit {
    padding: 6px 5px; min-height: 32px; font-size: clamp(.69rem, 2.7vw, .82rem);
    border-radius: 9px;
  }
  .reading-reader .reading-toolbar .reading-toggle {
    padding: 3px 2px; gap: 4px; min-height: 32px; font-size: .7rem;
  }
  .reading-toggle-track { width: 29px; height: 18px; }
  .reading-toggle-knob { width: 14px; height: 14px; }
  .reading-toggle[aria-checked="true"] .reading-toggle-knob { transform: translateX(11px); }
  .reading-reader .reading-layout { padding: 0 6px calc(7px + env(safe-area-inset-bottom)); }
  .reading-page { padding: 13px 15px; }
  .reading-paper-top { padding: 9px 13px; }
  .reading-float-zone {
    transition: transform .23s ease; will-change: transform;
  }
  .reading-float-zone.is-docked.at-right { transform: translateX(36px); }
  .reading-float-zone.is-docked.at-left { transform: translateX(-36px); }
  .reading-float-zone.is-docked .reading-fab { opacity: .86; }
  .reading-float-zone.reading-has-preview { transform: translateX(0) !important; }
  .reading-float-zone.at-right .reading-bubble { right: 0; left: auto; }
  .reading-float-zone.at-left .reading-bubble { left: 0; right: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .reading-toc-drawer[open] { animation: none; }
  .reading-float-zone { transition: none; }
}

/* Reader-only appearance: keep Home, shelf and Lucien conversation unchanged. */
.reading-reader {
  --reading-paper: #fffefaed;
  --reading-ink: #40556a;
  --reading-frame: #edf5fc;
  --reading-hairline: #b5c9dd60;
  --reading-muted: #71869a;
  --reading-control-bg: #edf5fce8;
  --reading-control-ink: #496a88;
  --reading-accent: #6b9dc3;
  --reading-track: #b8c9d6;
}
.reading-reader.reading-theme-day {
  --reading-paper: #f8f6ef;
  --reading-ink: #45413b;
  --reading-frame: #f1ede2;
  --reading-hairline: #ccc6b6;
  --reading-muted: #797165;
  --reading-control-bg: #efe9dc;
  --reading-control-ink: #63584b;
  --reading-accent: #8c7c67;
  --reading-track: #c7bcaa;
}
.reading-reader.reading-theme-warm {
  --reading-paper: #ded0b5;
  --reading-ink: #4a4035;
  --reading-frame: #d7c9ad;
  --reading-hairline: #b8a78a;
  --reading-muted: #72644f;
  --reading-control-bg: #e5d7bd;
  --reading-control-ink: #564938;
  --reading-accent: #856f4f;
  --reading-track: #b8a88e;
}
.reading-reader .reading-book-panel {
  background: var(--reading-paper);
  color: var(--reading-ink);
  transition: background-color .15s ease, color .15s ease;
}
.reading-reader .reading-paper-top {
  color: var(--reading-ink);
  border-color: var(--reading-hairline);
}
.reading-reader .reading-paper-top span { color: var(--reading-muted); }
.reading-reader .reading-page {
  color: var(--reading-ink);
  line-height: 1.87;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.reading-reader .reading-toolbar {
  color: var(--reading-ink);
  border-bottom: 1px solid var(--reading-hairline);
}
.reading-reader .reading-back-shelf,
.reading-reader .reading-book-edit,
.reading-reader .reading-appearance-button {
  background: color-mix(in srgb,var(--reading-control-bg) 82%,transparent);
  color: var(--reading-control-ink);
  border-color: var(--reading-hairline);
}
.reading-reader .reading-toolbar .reading-toggle { color: var(--reading-control-ink); }
.reading-reader .reading-toggle-track { background: var(--reading-track); }
.reading-reader .reading-toggle[aria-checked="true"] .reading-toggle-track { background: var(--reading-accent); }
.reading-reader .reading-highlight {
  background: transparent;
  border-bottom: 1px dashed #83b6d7;
  border-radius: 0;
}
.reading-reader .reading-appearance-button {
  flex: 0 0 auto;
  min-height: 34px; min-width: 34px;
  padding: 5px 6px;
  border: 1px solid var(--reading-hairline);
  border-radius: 9px;
  background: color-mix(in srgb,var(--reading-control-bg) 82%,transparent);
  color: var(--reading-control-ink);
  font: 600 .85rem/1 Georgia, serif;
  white-space: nowrap;
}
.reading-appearance-dialog {
  border: 1px solid #ffffffed;
  border-radius: 22px;
  padding: 19px;
  width: min(390px, calc(100vw - 24px));
  max-height: 82dvh;
  background: #f2f7fc;
  color: #425e79;
  box-shadow: 0 24px 70px #2e4f6a55;
}
.reading-appearance-dialog::backdrop { background: #1b35485c; }
.reading-appearance-description {
  font-size: .75rem; line-height: 1.6;
  margin: 9px 0 15px; color: #6e879d;
}
.reading-palette-options {
  display: grid; grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 9px;
}
.reading-palette-choice {
  display: grid; gap: 9px; justify-items: center;
  min-width: 0; padding: 8px 5px;
  border-radius: 12px; border: 2px solid transparent;
  background: #ffffff8c; color: #4b6178;
  font-size: .72rem; white-space: nowrap;
}
.reading-palette-choice[aria-pressed="true"] {
  border-color: #7badd1; box-shadow: 0 0 0 2px #ffffffba;
  font-weight: 650;
}
.reading-palette-swatch {
  display: grid; align-content: center; gap: 6px;
  width: 100%; height: 69px; padding: 12px 10px;
  border-radius: 8px; border: 1px solid #b4b5b324;
}
.reading-palette-swatch i {
  display: block; width: 90%; height: 3px;
  background: currentColor; opacity: .56; border-radius: 3px;
}
.reading-palette-swatch i:nth-child(2) { width: 72%; }
.reading-palette-swatch i:nth-child(3) { width: 84%; }
.reading-palette-blue .reading-palette-swatch { background: #e8f3fa; color: #405a70; }
.reading-palette-day .reading-palette-swatch { background: #f8f6ef; color: #45413b; }
.reading-palette-warm .reading-palette-swatch { background: #ded0b5; color: #4a4035; }
.reading-font-controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 21px; padding-top: 15px;
  border-top: 1px solid #c6d7e8; font-size: .87rem; font-weight: 600;
}
.reading-font-buttons { display: flex; align-items: center; gap: 13px; }
.reading-font-buttons button {
  min-width: 34px; min-height: 34px; padding: 3px;
  border-radius: 10px; background: #e0edf8; color: #4c7293;
  font-size: 1.25rem;
}
.reading-font-buttons button:disabled { opacity: .35; cursor: default; }
.reading-font-buttons output { min-width: 39px; text-align: center; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .reading-reader .reading-toolbar { gap: 3px; }
  .reading-reader .reading-appearance-button {
    min-height: 32px; min-width: 30px; padding: 5px 4px;
    font-size: .76rem;
  }
  .reading-appearance-dialog { padding: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .reading-reader .reading-book-panel { transition: none; }
}

/* Reading V4: light-touch note dates and conversation bubble groups. */
.reading-highlight { background: transparent; border-bottom: 1.5px dashed #92bee4; border-radius: 0; }
.reading-mark-date { display: inline; vertical-align: baseline; margin: 0 2px 0 3px; padding: 0 3px;
  border: 0; border-radius: 5px; background: #e7f1fb; color: #658ba9; font-size: .65em; line-height: 1.5; cursor: pointer; }
.reading-highlight-target { background: #b9dfff70; border-bottom-color: #4d91c5; border-radius: 3px; }
.reading-note-date { flex-basis: 100%; font-size: .71rem; color: #849bb1; }
.reading-thread .reading-followup { margin-top: -7px; }
.reading-thread .reading-comment { max-width: 83%; }
.reading-thread .reading-comment p { margin-top: 0; }
.reading-thread .reading-comment strong + p { margin-top: 5px; }
.reading-thread .reading-comment.reading-new-bubble { animation: readingBubbleIn .24s ease both; }
@keyframes readingBubbleIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }

/* Co-reading V4.1: quiet status, bottom jump and typing indicator. */
.reading-companion { position: relative; }
.reading-companion-top { gap: 8px; flex-wrap: nowrap; }
.reading-connection { display: inline-flex; width: 14px; height: 14px; align-items: center; justify-content: center;
  font-size: .72rem; color: #9aafbe; line-height: 1; flex: none; }
.reading-connection[data-state="connected"] { color: #58a889; }
.reading-connection[data-state="connecting"] { color: #d0a75d; animation: readingPulse 1.15s infinite; }
.reading-connection[data-state="disconnected"],.reading-connection[data-state="failed"] { color: #c77979; }
.reading-companion-top .reading-close-chat { margin-left: auto; }
.reading-auto-marker { display: block; color: #90aac0; font-size: .73rem; opacity: .75; line-height: 1; margin-bottom: 5px; }
.reading-thread .reading-comment p { margin: 0; }
.reading-thread .reading-retry { display: block; margin-top: 7px; border: 0; background: #edf2f6; color: #567c9d;
  border-radius: 9px; padding: 5px 9px; font-size: .76rem; }
.reading-pending-bubble { display: flex; align-items: center; gap: 5px; min-width: 60px; width: fit-content; min-height: 37px; }
.reading-pending-dot { display: block; width: 6px; height: 6px; border-radius: 50%; background: #90aec6;
  animation: readingPulse 1.15s infinite ease-in-out; }
.reading-pending-dot:nth-child(2) { animation-delay: .18s; }
.reading-pending-dot:nth-child(3) { animation-delay: .36s; }
@keyframes readingPulse { 0%,65%,100% { opacity: .32; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
.reading-to-latest { position: absolute; z-index: 8; bottom: 77px; left: 50%; transform: translateX(-50%);
  display: flex; justify-content: center; align-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: #fcffffc7; border: 1px solid #ccdfedb3; color: #5b88ae; box-shadow: 0 3px 13px #3f6b8c19;
  backdrop-filter: blur(8px); cursor: pointer; font-size: 1.25rem; transition: opacity .18s; }
.reading-to-latest.hidden { display: none; }
@media (max-width:760px) { .reading-to-latest { bottom: 70px; } }

/* Chat polish: soft glass and compact mobile status indicator. */
.chat-view { background: radial-gradient(ellipse at 90% 80%,rgba(185,207,232,.22),transparent 52%),linear-gradient(155deg,#f7faff,#edf4fb 65%,#e7eff8); }
.chat-header { position: relative; z-index: 2; }
.composer #send { border-radius: 50%; transition: transform .16s ease,box-shadow .16s ease; }
.composer #send:not(:disabled):active { transform:scale(.92); box-shadow:0 2px 8px rgba(74,144,226,.2); }
@media (prefers-reduced-motion:reduce) { .composer #send { transition:none; } }

/* Chat message rhythm and time landmarks. */
.message-group { position:relative; display:flex; flex-direction:row; align-items:flex-start; gap:8px; max-width:min(92%,760px); }
.message-group.human-group { flex-direction:row-reverse; align-items:flex-start; }
.message-content { min-width:0; max-width:calc(100% - 42px); display:flex; flex-direction:column; align-items:flex-start; gap:4px; }
.voice-player { width:min(100%, 350px); min-width:0; margin-top:6px; color:#536d80; font-size:.82rem; white-space:normal; }
.voice-bubble .voice-player { margin-top:0; }
.voice-bubble { display:flex; align-items:flex-start; gap:6px; width:fit-content; min-width:0; max-width:100%; }
.voice-bubble > .message-tool { width:28px; min-width:28px; height:30px; }
.voice-bubble > .voice-player { flex:1; }
.voice-bubble:has(> .voice-extra:not(.voice-collapsed)) { min-width:min(300px,100%); }
.voice-bubble > .voice-extra.voice-collapsed { flex:0 1 auto; width:auto; }
.message-tool.is-playing { color:#407b9c; background:#cce2ef60; }
.voice-controls { display:flex; align-items:center; gap:10px; }
.voice-wave-track { position:relative; flex:1; min-width:50px; height:28px; }
.voice-inline.voice-collapsed .voice-controls { display:none; }
.voice-extra.voice-collapsed .voice-controls, .voice-extra.voice-collapsed .voice-caption { display:none; }
.voice-extra.voice-ended .voice-note, .voice-extra.voice-ended .voice-direction { display:none; }
.voice-waveform { display:block; width:100%; height:28px; }
.voice-time { white-space:nowrap; font-variant-numeric:tabular-nums; font-size:.74rem; }
.voice-progress, .voice-progress:focus { position:absolute; inset:0; appearance:none; -webkit-appearance:none; width:100%; height:28px; margin:0; padding:0; border:0; border-radius:4px; background:transparent; box-shadow:none; cursor:pointer; }
.voice-progress::-webkit-slider-runnable-track { height:2px; background:transparent; }
.voice-progress::-moz-range-track { height:2px; background:transparent; }
.voice-progress::-webkit-slider-thumb { -webkit-appearance:none; width:7px; height:7px; margin-top:-2.5px; border-radius:50%; background:#8db4cc; }
.voice-progress::-moz-range-thumb { width:7px; height:7px; border:0; border-radius:50%; background:#8db4cc; }
.voice-progress:disabled { opacity:0; cursor:default; }
.voice-progress:focus-visible { outline:2px solid #7ca3bc; outline-offset:2px; }
.voice-caption { line-height:1.7; white-space:pre-wrap; overflow-wrap:anywhere; }
.voice-caption .voice-unit { border-radius:3px; transition:color .12s ease,background-color .12s ease; }
.voice-caption .voice-unit.heard { color:#356f94; background:#dcecf5; }
.voice-note { display:block; margin-top:3px; color:#6d8492; line-height:1.4; font-size:.7rem; }
.voice-note:empty, #voiceSettingsStatus:empty { display:none; }
.voice-direction { margin-top:3px; color:#6d8492; font-size:.72rem; line-height:1.5; }
.voice-direction[hidden] { display:none; }
.voice-direction summary { cursor:pointer; color:#587e98; }
.voice-direction-item { display:flex; flex-wrap:wrap; gap:6px; margin-top:3px; overflow-wrap:anywhere; }
.voice-direction-item code { color:#426d88; }
#voiceSettings { align-self:start; display:grid; gap:14px; min-width:0; }
#voiceSettings form { display:grid; gap:12px; min-width:0; }
#voiceSettings label { display:grid; gap:6px; min-width:0; font-size:.88rem; }
#voiceSettings input:not([type="range"]), #voiceSettings select { width:100%; min-width:0; padding:10px 12px; border:1px solid #a9c3d455; border-radius:12px; background:#ffffffb3; color:inherit; }
#voicePreferences { padding-bottom:14px; border-bottom:1px solid #b9d0dd55; }
#voicePreferences label { display:flex; align-items:center; justify-content:space-between; }
#voicePreferences label.privacy-confirm { justify-content:flex-start; gap:10px; font-size:1rem; }
#voicePreferences input[type="checkbox"] { width:18px; height:18px; margin:0; accent-color:#7ca3bc; }
#voicePreferences input[type="number"] { width:100px; }
#voiceProfiles { display:grid; gap:10px; min-width:0; }
.voice-profile { border:1px solid #b9d0dd70; border-radius:14px; padding:12px; min-width:0; background:#ffffff55; }
.voice-profile-head { display:flex; align-items:center; gap:8px; }
.voice-default { flex-shrink:0; border-radius:8px; padding:2px 7px; background:#dcebf3; color:#527a94; font-size:.7rem; }
.voice-profile strong, .voice-profile small { display:block; overflow-wrap:anywhere; }
.voice-profile small { color:#728695; margin-top:4px; }
.voice-settings-actions { display:flex; align-items:center; flex-wrap:wrap; gap:6px; }
.voice-settings-actions .secondary-button { min-height:36px; padding:6px 11px; font-size:.82rem; }
.voice-settings-actions .muted { margin-right:auto; font-size:.78rem; }
.voice-profile .voice-settings-actions { margin-top:8px; }
#voiceTagLibrary summary { cursor:pointer; color:#456b83; }
#voiceTags { display:grid; gap:10px; margin-top:12px; min-width:0; }
.voice-tag-filters { display:grid; grid-template-columns:repeat(auto-fit,minmax(125px,1fr)); gap:6px; }
.voice-tag-list { display:grid; gap:6px; max-height:420px; overflow:auto; }
.voice-tag-card { padding:10px; border:1px solid #b9d0dd70; border-radius:12px; background:#fff9; overflow-wrap:anywhere; }
.voice-tag-card strong, .voice-tag-card small, .voice-tag-preview small { display:block; }
.voice-tag-card small, .voice-tag-preview small { color:#728695; margin:4px 0; }
.voice-tag-card .voice-settings-actions { margin-top:6px; }
.voice-tag-import { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
.voice-tag-import input[type="file"] { max-width:260px; }
.voice-tag-import select { max-width:140px; }
.voice-tag-preview { max-height:240px; overflow:auto; }
#voiceSettings .voice-tag-active { display:flex; align-items:center; gap:8px; }
#voiceSettings .voice-tag-active input { width:18px; height:18px; margin:0; accent-color:#7ca3bc; }
.human-group .message-content { align-items:flex-end; }
.cross-space-card { width:min(360px,100%); margin-top:5px; border:1px solid rgba(151,185,213,.48); border-radius:18px; background:rgba(247,251,255,.8); color:#40566a; box-shadow:0 10px 28px rgba(71,115,152,.1); backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); }
.reading-invite-card { display:grid; grid-template-columns:58px minmax(0,1fr); gap:11px; padding:12px; }
.cross-space-book-cover { grid-row:1 / span 2; width:58px; aspect-ratio:2/3; display:grid; place-items:center; border-radius:8px; object-fit:cover; background:linear-gradient(145deg,#d9e9f7,#eef6fc); color:#68839a; }
.reading-invite-card > div { min-width:0; display:grid; gap:2px; }
.reading-invite-card small,.reading-invite-card span,.source-quote-card small { color:#72889a; font-size:.76rem; }
.reading-invite-card strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.reading-invite-card p { margin:5px 0 0; color:#566f83; font-size:.84rem; line-height:1.45; }
.reading-invite-card > button { grid-column:2; justify-self:start; min-height:34px; padding:0 14px; border-radius:12px; background:#607f99; }
.source-quote-card { padding:0 13px 12px; }
.source-quote-card summary { padding:12px 0; cursor:pointer; font-size:.84rem; color:#59748a; }
.source-quote-card blockquote { margin:0 0 8px; padding-left:11px; border-left:2px solid #9ab7ce; color:#40566a; white-space:pre-wrap; line-height:1.55; }
.source-quote-card > button { display:block; min-height:32px; margin-top:10px; padding:0 12px; border-radius:11px; background:rgba(96,127,153,.12); color:#4c6c86; }
.cross-space-source-focus { animation:crossSpaceSourceFocus 1.8s ease; }
@keyframes crossSpaceSourceFocus { 0%,100% { filter:none; } 25% { filter:drop-shadow(0 0 11px rgba(78,138,184,.5)); } }
.message-group .message { margin:0; }
.message-group.same-speaker { margin-top:-8px; }
.time-separator { align-self:center; margin:8px 0 4px; padding:4px 10px; border-radius:999px; color:#7891a6; background:rgba(255,255,255,.5); font-size:.7rem; line-height:1.4; cursor:pointer; user-select:none; -webkit-user-select:none; }
.composer textarea { overflow-y:hidden; }
.edit-notice { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px; padding:7px 10px 7px 13px; border:1px solid rgba(139,185,226,.42); border-radius:13px; background:rgba(229,242,253,.88); color:#4f7899; font-size:.82rem; }
.edit-notice button { min-width:auto; padding:4px 9px; background:transparent; color:#477aa7; }

/* Typing indicator, shown only until streamed text arrives. */
.typing-bubble { padding:10px 15px; background:rgba(255,255,255,.84); border:1px solid rgba(255,255,255,.9); border-radius:19px; border-bottom-left-radius:6px; box-shadow:0 8px 24px rgba(77,134,183,.08); width:max-content; }
.typing-dots { display:flex; align-items:center; gap:5px; height:18px; }
.typing-dots i { display:block; width:6px; height:6px; border-radius:50%; background:#8baac5; animation:typing-bob 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay:.16s; }
.typing-dots i:nth-child(3) { animation-delay:.32s; }
@keyframes typing-bob { 0%,65%,100% { opacity:.45; transform:translateY(0); } 30% { opacity:1; transform:translateY(-4px); } }
@media(prefers-reduced-motion:reduce) { .typing-dots i { animation:none; opacity:.8; } }

/* Touch: always-visible, icon-only actions; long press remains for text selection. */
@media (hover:none) and (pointer:coarse) {
  .message-tools { display:flex; flex-wrap:wrap; gap:1px; min-height:36px; opacity:1; visibility:visible; padding:0; margin-top:2px; border:0; background:transparent; box-shadow:none; }
  .message-group .message-tools { align-self:flex-start; justify-content:flex-start; }
  .message-group.human-group .message-tools { align-self:flex-end; justify-content:flex-end; }
  .message-tools .message-tool { display:grid; place-items:center; width:36px; min-width:36px; height:36px; padding:0; border-radius:11px; color:#7392aa; }
  .message-tools .message-tool::after { content:none; }
  .message-tools .message-tool svg { width:18px; height:18px; }
}

/* Mobile visual viewport: composer stays within the visible area when keyboard opens. */
@media (max-width: 760px) {
  .shell { position:fixed; top:var(--visual-viewport-offset,0px); right:0; left:0; height:var(--visual-viewport-height,100dvh); transform:none; }
  .chat-view { min-height:0; overflow:hidden; }
  #messages { min-height:0; padding-inline:10px; overscroll-behavior-y:contain; touch-action:pan-y; -webkit-overflow-scrolling:touch; }
  .message-group { max-width:min(100%,800px); }
  .memory-detail-dialog { position:fixed; inset:auto 0 0; width:100%; max-width:none; max-height:86dvh; margin:0; border-radius:24px 24px 0 0; }
  .memory-detail-dialog[open] { height:min(86dvh,760px); }
  .memory-detail-dialog::backdrop { background:rgba(47,69,88,.38); }
}

.memory-conclusion { background:linear-gradient(145deg,rgba(241,249,255,.96),rgba(255,255,255,.9)); }
.memory-conclusion-text { margin:0 0 12px; color:#315f83; font-size:.96rem; line-height:1.65; }
.memory-source-summary { display:grid; gap:3px; padding:10px 0; border-top:1px solid rgba(145,190,229,.25); }
.memory-source-summary:first-of-type { border-top:0; padding-top:0; }
.memory-source-summary strong { font-size:.88rem; font-weight:600; }
.memory-source-summary span { color:#71889d; font-size:.78rem; }

/* Sienna × Lucien Home · Gray-Blue Liquid Glass */
:root {
  --home-ink:#334f68;
  --home-muted:#6f879a;
  --home-line:rgba(188,207,222,.58);
  --home-glass:rgba(239,246,251,.72);
  --home-glass-strong:rgba(245,249,252,.9);
  --home-shadow:0 18px 48px rgba(50,78,102,.16),inset 0 1px 0 rgba(255,255,255,.88);
}
body { background:linear-gradient(145deg,#edf3f7,#dfe9f0); color:var(--home-ink); }
.chat-view {
  position:relative;
  grid-template-rows:minmax(0,1fr) auto;
  overflow:hidden;
  background:radial-gradient(ellipse at 88% 86%,rgba(177,198,216,.28),transparent 52%),linear-gradient(155deg,#f4f8fb,#eaf1f6 66%,#e1eaf1);
}
#messages { grid-row:1; padding-top:calc(82px + env(safe-area-inset-top)); }
.composer { grid-row:2; }
.chat-header {
  position:absolute;
  z-index:4;
  inset:0 0 auto;
  grid-template-columns:auto 1fr auto;
  min-height:60px;
  padding:calc(8px + env(safe-area-inset-top)) 12px 8px;
  background:transparent;
  border:0;
  box-shadow:none;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}
.chat-header::after { display:none; }
.conversation-trigger,.drawer-trigger,.chat-header .icon-button {
  width:44px;
  height:44px;
  min-width:44px;
  display:grid;
  place-items:center;
  padding:0;
  border:1px solid rgba(188,207,222,.42);
  border-radius:15px;
  background:linear-gradient(145deg,rgba(255,255,255,.54),rgba(220,233,242,.32));
  color:#54758f;
  box-shadow:0 5px 16px rgba(62,91,113,.08),inset 0 1px 0 rgba(255,255,255,.88);
  backdrop-filter:blur(18px) saturate(135%);
  -webkit-backdrop-filter:blur(18px) saturate(135%);
}
.conversation-entry { display:flex; align-items:center; gap:7px; min-width:0; }
.conversation-trigger svg,.drawer-trigger svg { width:25px; height:25px; fill:rgba(132,163,188,.26); stroke:currentColor; stroke-width:1.9; stroke-linejoin:round; }
#status.conversation-status {
  display:none;
  width:6px;
  height:6px;
  flex:0 0 6px;
  border-radius:50%;
  color:transparent;
  font-size:0;
  overflow:hidden;
}
#status.conversation-status[data-state="connecting"] { display:block; background:#d3a94f; box-shadow:0 0 0 3px rgba(211,169,79,.11); animation:status-soft-pulse 1.8s ease-in-out infinite; }
#status.conversation-status[data-state="error"] { display:block; background:#cf6d72; box-shadow:0 0 0 3px rgba(207,109,114,.12); animation:status-soft-pulse 1.5s ease-in-out 2; }
@keyframes status-soft-pulse { 50% { opacity:.55; transform:scale(.84); } }
.chat-header-actions { justify-self:end; display:flex; gap:6px; }
.chat-header .icon-button svg { width:23px; height:23px; fill:rgba(132,163,188,.12); stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
.cabin-target-button[aria-pressed="true"] { border-color:rgba(103,148,181,.58); background:linear-gradient(145deg,rgba(222,239,249,.82),rgba(181,211,231,.58)); color:#3f7194; box-shadow:0 5px 18px rgba(62,112,148,.17),inset 0 1px 0 rgba(255,255,255,.92); }
.cabin-target-button[aria-pressed="true"] svg { fill:rgba(92,143,178,.28); }

.side-drawer {
  position:fixed;
  top:var(--visual-viewport-offset,0px);
  width:min(80vw,320px);
  height:var(--visual-viewport-height,100dvh);
  max-height:none;
  margin:0;
  border:1px solid rgba(255,255,255,.72);
  background:linear-gradient(155deg,rgba(245,250,252,.44),rgba(199,220,234,.28));
  box-shadow:0 0 64px rgba(41,65,85,.2),inset 0 1px 0 rgba(255,255,255,.92);
  backdrop-filter:blur(24px) saturate(150%);
  -webkit-backdrop-filter:blur(24px) saturate(150%);
  touch-action:pan-y;
}
.side-drawer[data-drawer-side="left"] { right:auto; bottom:auto; left:0; border-radius:0 28px 28px 0; box-shadow:24px 0 60px rgba(41,65,85,.2),inset -1px 0 0 rgba(255,255,255,.76); }
.side-drawer[data-drawer-side="right"] { right:0; bottom:auto; left:auto; border-radius:28px 0 0 28px; box-shadow:-24px 0 60px rgba(41,65,85,.2),inset 1px 0 0 rgba(255,255,255,.76); }
.side-drawer[open] { display:flex; flex-direction:column; }
.side-drawer[data-drawer-side="left"][open] { animation:drawer-in-left var(--motion-base) var(--motion-ease-out) both; }
.side-drawer[data-drawer-side="right"][open] { animation:drawer-in-right var(--motion-base) var(--motion-ease-out) both; }
.side-drawer[open].drawer-ready { animation:none; }
.side-drawer[open].drawer-dragging,.side-drawer[open].drawer-settling { animation:none; transform:translateX(var(--drawer-x,0)); will-change:transform; }
.side-drawer[open].drawer-dragging { transition:none; }
.side-drawer[open].drawer-settling { transition:transform .21s var(--motion-ease-out); }
.side-drawer[open].drawer-settling::backdrop { transition:background .21s var(--motion-ease-out); }
.side-drawer::backdrop { background:rgb(39 57 72 / var(--drawer-backdrop,.1)); }
@keyframes drawer-in-left { from { transform:translateX(-100%); } to { transform:translateX(0); } }
@keyframes drawer-in-right { from { transform:translateX(100%); } to { transform:translateX(0); } }
.side-drawer .dialog-head { display:grid; grid-template-columns:44px 1fr 44px; align-items:center; gap:8px; padding:calc(8px + env(safe-area-inset-top)) 12px 8px; background:rgba(241,248,252,.34); border-color:rgba(255,255,255,.58); backdrop-filter:blur(18px) saturate(140%); -webkit-backdrop-filter:blur(18px) saturate(140%); }
.side-drawer .dialog-head strong { text-align:center; }
#conversationDialog .conversation-list { flex:1; min-height:0; overscroll-behavior:contain; touch-action:pan-y; }
#conversationDialog .conversation-item { min-height:54px; border-color:rgba(255,255,255,.32); border-radius:16px; background:rgba(244,249,252,.18); }
#conversationDialog .conversation-actions summary { min-width:44px; min-height:44px; display:grid; place-items:center; padding:0; border-radius:14px; color:#577791; }
#conversationDialog .dialog-footer { padding-bottom:calc(12px + env(safe-area-inset-bottom)); }
#conversationDialog .new-chat { width:100%; min-height:46px; border-radius:15px; }
#settingsDrawer .drawer-settings-categories { flex:1; min-height:0; align-content:start; overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y; padding:14px 12px calc(18px + env(safe-area-inset-bottom)); }
#settingsDrawer .settings-categories > button { min-height:72px; background:linear-gradient(145deg,rgba(250,253,255,.32),rgba(216,231,241,.14)); border-color:rgba(255,255,255,.62); box-shadow:0 10px 24px rgba(52,79,100,.08),inset 0 1px 0 rgba(255,255,255,.78); backdrop-filter:blur(14px); -webkit-backdrop-filter:blur(14px); }

.composer {
  padding:7px 10px calc(10px + env(safe-area-inset-bottom));
  border-top:0;
  background:transparent;
  box-shadow:none;
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}
.composer-row {
  display:grid;
  grid-template-rows:auto auto;
  gap:2px;
  align-items:stretch;
  padding:5px 6px;
  border:1px solid rgba(255,255,255,.46);
  border-radius:26px;
  background:linear-gradient(145deg,rgba(255,253,249,.76),rgba(242,243,239,.66));
  box-shadow:0 8px 24px rgba(55,78,96,.08),inset 0 1px 0 rgba(255,255,255,.66);
  backdrop-filter:blur(22px) saturate(112%);
  -webkit-backdrop-filter:blur(22px) saturate(112%);
}
.composer-row > textarea {
  display:block;
  width:100%;
  min-height:44px;
  max-height:132px;
  padding:10px 11px;
  border-color:transparent !important;
  border-radius:19px;
  background:transparent;
  box-shadow:none;
  outline:none;
  line-height:1.5;
  text-align:left;
}
.composer-row > textarea:focus-visible { border-color:transparent !important; outline:0; box-shadow:none; }
.composer-toolbar { min-width:0; min-height:44px; display:flex; align-items:flex-end; gap:5px; }
.model-pill {
  position:static;
  max-width:min(calc(100% - 98px),230px);
  min-width:0 !important;
  min-height:29px;
  margin:auto auto 7px 0;
  display:flex;
  align-items:center;
  gap:5px;
  padding:4px 9px;
  border:1px solid rgba(177,199,216,.32);
  border-radius:999px;
  background:rgba(224,234,240,.42);
  color:#4c6e87;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.76);
  font-size:.76rem;
  line-height:1.2;
  backdrop-filter:blur(10px);
  -webkit-backdrop-filter:blur(10px);
}
#modelPillLabel { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.attach-button,.composer #send {
  width:44px;
  height:44px;
  min-width:44px !important;
  flex:0 0 44px;
  align-self:flex-end;
  border-radius:16px;
}
.attach-button { border:0; background:transparent; box-shadow:none; color:#5f8098; }
.composer #send { display:grid; place-items:center; padding:0; background:linear-gradient(145deg,#7898b0,#587b96); box-shadow:0 7px 17px rgba(63,91,113,.25),inset 0 1px 0 rgba(255,255,255,.35); }
.composer #send svg { width:23px; height:23px; fill:none; stroke:currentColor; stroke-width:2.1; stroke-linecap:round; stroke-linejoin:round; }
.composer #send:not(:disabled):hover { background:linear-gradient(145deg,#83a2b9,#52758f); }

#messages { scroll-behavior:auto; }
.message-enter { animation:message-enter-ai .18s ease-out both; }
.human-group.message-enter { animation-name:message-enter-human; }
.ai-reply.message-enter .message-content > .message.ai:not(:first-child) { animation:message-enter-ai .2s ease-out .18s both; }
@keyframes message-enter-ai { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes message-enter-human { from { opacity:0; transform:translate(8px,8px); } to { opacity:1; transform:translate(0,0); } }

.model-sheet {
  --sheet-drag:0px;
  position:fixed;
  inset:auto 0 0;
  width:min(100%,760px);
  height:min(75dvh,680px);
  max-height:75dvh;
  margin:0 auto;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.84);
  border-bottom:0;
  border-radius:30px 30px 0 0;
  background:linear-gradient(155deg,rgba(242,248,252,.9),rgba(216,229,239,.88));
  box-shadow:0 -24px 70px rgba(38,62,82,.23),inset 0 1px 0 rgba(255,255,255,.96);
  transform:translateY(var(--sheet-drag));
}
.model-sheet[open] { display:flex; flex-direction:column; animation:sheet-in var(--motion-base) var(--motion-ease-out) both; }
.model-sheet[open].dialog-closing { animation:sheet-out var(--motion-fast) ease-in both; }
.model-sheet::backdrop { background:rgba(38,57,74,.28); }
@keyframes sheet-in { from { transform:translateY(100%); } to { transform:translateY(var(--sheet-drag)); } }
@keyframes sheet-out { to { transform:translateY(100%); } }
.sheet-handle-zone { flex:0 0 27px; display:grid; place-items:center; touch-action:none; cursor:grab; }
.sheet-handle { width:42px; height:5px; border-radius:999px; background:rgba(90,118,140,.35); }
.model-sheet-head { display:flex; align-items:center; justify-content:space-between; padding:0 18px 10px; }
.model-sheet-head h2 { margin:0; color:#3c607b; font-size:1.15rem; font-weight:600; }
.model-sheet-head button { width:44px; height:44px; min-width:44px; padding:0; border-radius:50%; background:rgba(203,220,232,.55); color:#55758d; font-size:1.3rem; }
.model-sheet-scroll { flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain; padding:0 14px 14px; }
.model-search { display:block; margin:0 2px 10px; }
.model-search input { min-height:44px; border-color:rgba(168,193,212,.48); background:rgba(249,252,253,.72); }
.model-choice-list { display:grid; gap:6px; }
.model-choice {
  width:100%;
  min-height:58px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:9px 13px;
  border:1px solid transparent;
  border-radius:17px;
  background:rgba(249,252,253,.47);
  color:var(--home-ink);
  text-align:left;
}
.model-choice > span:first-child { min-width:0; display:grid; gap:3px; }
.model-choice strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.94rem; font-weight:600; }
.model-choice small { color:var(--home-muted); font-size:.75rem; }
.model-choice[aria-selected="true"] { border-color:rgba(122,157,183,.48); background:rgba(211,226,237,.72); box-shadow:inset 0 1px 0 rgba(255,255,255,.82); }
.model-check { flex:0 0 24px; color:#4e7d9d; font-weight:700; text-align:center; }
.reasoning-section { margin-top:14px; padding:14px; border-top:1px solid rgba(153,181,202,.28); }
.reasoning-section h3 { margin:0; color:#42667f; font-size:.92rem; }
.reasoning-section p { margin:5px 0 10px; font-size:.76rem; line-height:1.5; }
.reasoning-choices { display:flex; flex-wrap:wrap; gap:7px; }
.reasoning-choice { min-height:40px; padding:7px 13px; border:1px solid rgba(153,181,202,.44); border-radius:999px; background:rgba(248,251,253,.56); color:#526f85; }
.reasoning-choice.selected { border-color:rgba(91,133,164,.55); background:#6f91aa; color:#fff; box-shadow:0 6px 15px rgba(62,92,115,.18); }
.manage-models { flex:0 0 auto; min-height:54px; display:flex; align-items:center; justify-content:space-between; margin:0 14px calc(10px + env(safe-area-inset-bottom)); padding:0 15px; border-top:1px solid rgba(255,255,255,.66); border-radius:17px; background:rgba(246,250,252,.62); color:#496e89; }

.message.ai {
  background:rgba(248,251,253,.94);
  backdrop-filter:none;
  -webkit-backdrop-filter:none;
}
/* Divider and fenced code are standalone in Jude paragraph mode. */
.message-group.bubble-style-paragraph .message-code-segment,
.message-group.bubble-style-paragraph .message-divider-segment {
  width:100%; padding:0; border:0; border-radius:0; background:transparent; box-shadow:none;
}
.message-group.bubble-style-paragraph .message-divider-segment hr { width:100%; margin:10px 0; border:0; border-top:1px solid rgba(120,153,176,.42); }
/* No-background mode keeps Markdown and reply actions, not a bubble shell. */
.message-group.bubble-style-plain .message:not(.voice-bubble) {
  padding:0; border:0; border-radius:0; background:transparent; box-shadow:none;
}

.message-avatar,.avatar-current {
  position:relative;
  flex:0 0 34px;
  width:34px;
  height:34px;
  display:grid;
  place-items:center;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.72);
  border-radius:50%;
  background:linear-gradient(145deg,rgba(229,239,246,.96),rgba(178,201,219,.9));
  color:#55758e;
  box-shadow:0 5px 14px rgba(52,79,100,.11),inset 0 1px 0 rgba(255,255,255,.8);
  font:600 .78rem/1 Georgia,serif;
}
.message-avatar { margin-top:2px; }
.message-avatar img,.avatar-current img { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; }
.message-avatar:not(.has-image) img,.avatar-current:not(.has-image) img { display:none; }

.avatar-profiles { display:grid; gap:14px; margin-top:14px; }
.avatar-profile { display:grid; gap:10px; padding:14px; border:1px solid rgba(180,202,218,.4); border-radius:18px; background:rgba(249,252,253,.5); }
.avatar-profile-head { display:grid; grid-template-columns:52px minmax(0,1fr) auto; align-items:center; gap:10px; }
.avatar-current { width:52px; height:52px; flex-basis:52px; font-size:1.05rem; }
.avatar-profile-head > div { min-width:0; display:grid; gap:3px; }
.avatar-profile-head strong { color:#3f627d; font-size:.95rem; }
.avatar-profile-head small,.avatar-ai-entry small,.avatar-tool-note { color:var(--home-muted); font-size:.74rem; line-height:1.5; }
.avatar-upload-button { min-height:44px; display:grid; place-items:center; padding:8px 12px; border:1px solid rgba(151,183,207,.48); border-radius:14px; color:#4c7493; background:rgba(245,250,252,.58); cursor:pointer; white-space:nowrap; }
.avatar-status { min-height:1.2em; margin:0; font-size:.78rem; }
.avatar-gallery { display:flex; gap:9px; min-height:42px; overflow-x:auto; padding:2px 1px 5px; overscroll-behavior-x:contain; }
.avatar-gallery:empty::after { content:"收藏夹还是空的"; color:var(--home-muted); font-size:.78rem; line-height:40px; }
.avatar-favorite { position:relative; flex:0 0 54px; }
.avatar-favorite-select { width:48px; height:48px; min-width:48px; padding:0; overflow:hidden; border:2px solid transparent; border-radius:50%; background:#dfeaf1; }
.avatar-favorite-select[aria-pressed="true"] { border-color:#6287a2; box-shadow:0 0 0 3px rgba(98,135,162,.12); }
.avatar-favorite-select img { width:100%; height:100%; display:block; object-fit:cover; }
.avatar-favorite-delete { position:absolute; top:-5px; right:0; width:24px; height:24px; min-width:24px; padding:0; border-radius:50%; background:rgba(69,93,111,.88); font-size:.78rem; }
.avatar-ai-entry { display:grid; gap:8px; padding-top:10px; border-top:1px solid rgba(175,199,216,.34); }
.avatar-ai-entry label { display:grid; gap:6px; color:#4b708d; font-size:.8rem; }
.avatar-ai-entry textarea { min-height:64px; resize:vertical; background:rgba(255,255,255,.58); }
.avatar-ai-entry button { width:100%; }
.avatar-tool-note { margin:0; }

.avatar-editor { width:min(420px,calc(100% - 24px)); overflow:hidden; background:rgba(239,246,250,.96); }
.avatar-editor-body { display:grid; gap:10px; padding:14px 18px; }
#avatarCropCanvas { width:min(100%,320px); aspect-ratio:1; justify-self:center; display:block; border-radius:50%; background:#dfe9ef; box-shadow:0 8px 28px rgba(48,74,94,.16); touch-action:none; cursor:grab; }
#avatarCropCanvas:active { cursor:grabbing; }
.avatar-editor-body p { margin:0; text-align:center; font-size:.78rem; }
.avatar-zoom { display:grid; grid-template-columns:auto 1fr; align-items:center; gap:10px; color:#4b708d; font-size:.82rem; }
.avatar-zoom input { padding:0; }

.avatar-editor[open],.memory-detail-dialog[open] {
  transform-origin:var(--dialog-origin,50% 50%);
  animation:surface-dialog-in var(--motion-base) var(--motion-ease-out) both;
}
.avatar-editor[open].dialog-closing,.memory-detail-dialog[open].dialog-closing {
  animation:surface-dialog-out var(--motion-fast) ease-in both;
}
.avatar-editor[open]::backdrop,.memory-detail-dialog[open]::backdrop,.model-sheet[open]::backdrop {
  animation:surface-backdrop-in var(--motion-base) ease-out both;
}
.avatar-editor[open].dialog-closing::backdrop,.memory-detail-dialog[open].dialog-closing::backdrop,.model-sheet[open].dialog-closing::backdrop {
  animation:surface-backdrop-out var(--motion-fast) ease-in both;
}
@keyframes surface-dialog-in { from { opacity:.55; transform:translateY(8px) scale(.97); } }
@keyframes surface-dialog-out { to { opacity:0; transform:translateY(6px) scale(.98); } }
@keyframes surface-backdrop-in { from { background:transparent; } }
@keyframes surface-backdrop-out { to { background:transparent; } }

.settings-view { background:radial-gradient(ellipse at 86% 15%,rgba(255,255,255,.78),transparent 48%),linear-gradient(150deg,#eef4f8,#dde8ef); }
.settings-content { min-height:calc(100% - 60px); align-content:start; }
.settings-categories { display:grid; gap:10px; }
.settings-categories > button {
  width:100%;
  min-height:76px;
  display:grid;
  grid-template-columns:48px 1fr auto;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  border:1px solid rgba(255,255,255,.82);
  border-radius:22px;
  background:rgba(241,247,250,.72);
  color:var(--home-ink);
  text-align:left;
  box-shadow:0 12px 30px rgba(56,83,105,.1),inset 0 1px 0 rgba(255,255,255,.92);
}
.settings-categories > button > span:nth-child(2) { min-width:0; display:grid; gap:4px; }
.settings-categories strong { color:#3f627d; font-size:.98rem; font-weight:600; }
.settings-categories small { color:var(--home-muted); font-size:.77rem; }
.settings-categories > button > span:last-child { color:#7390a5; font-size:1.45rem; }
.settings-category-icon { width:46px; height:46px; display:grid; place-items:center; border-radius:16px; background:linear-gradient(145deg,rgba(202,220,233,.76),rgba(236,244,249,.9)); box-shadow:inset 0 1px 0 #fff,0 6px 15px rgba(65,94,117,.09); color:#567b96; }
.settings-category-icon svg { width:25px; height:25px; fill:rgba(125,157,181,.13); stroke:currentColor; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
.settings-section { border-color:rgba(255,255,255,.8); background:rgba(245,249,251,.72); box-shadow:0 13px 34px rgba(56,83,105,.1),inset 0 1px 0 rgba(255,255,255,.92); }

@supports not ((backdrop-filter:blur(1px)) or (-webkit-backdrop-filter:blur(1px))) {
  .conversation-trigger,.drawer-trigger,.chat-header .icon-button { background:#eef4f8; }
  .side-drawer { background:#e4edf3; }
  .model-sheet { background:#e7f0f6; }
  .composer-row { background:#f7f6f2; }
  .model-pill { background:#dce8f0; }
  .settings-categories > button,.settings-section { background:#f3f7fa; }
}

@media (prefers-reduced-motion:reduce) {
  .side-drawer[open],.model-sheet[open],#status.conversation-status,.message-enter,.ai-reply.message-enter .message-content > .message.ai { animation:none; }
  .side-drawer[open].drawer-settling { transition:none; }
  .avatar-editor[open],.memory-detail-dialog[open],
  .avatar-editor[open]::backdrop,.memory-detail-dialog[open]::backdrop,.model-sheet[open]::backdrop { animation:none; }
}

@media (max-width:420px) {
  .avatar-profile-head { grid-template-columns:48px minmax(0,1fr); }
  .avatar-profile-head .avatar-upload-button { grid-column:1 / -1; }
}
/* Co-reading V5: fit chat into the visible mobile viewport and soften notes. */
@media (max-width: 760px) {
  .reading-reader .reading-companion {
    min-height: 0;
    max-height: max(150px, calc(var(--visual-viewport-height, 100dvh) - 20px - env(safe-area-inset-bottom)));
  }
  .reading-companion .reading-thread { overscroll-behavior: contain; }
  .reading-note-dialog {
    position: fixed;
    inset: auto 0 max(0px, calc(100dvh - var(--visual-viewport-height, 100dvh) - var(--visual-viewport-offset, 0px))) 0;
    margin: 0;
    width: 100%;
    max-width: none;
    max-height: min(86dvh, calc(var(--visual-viewport-height, 100dvh) - 12px));
    overflow: auto;
    overscroll-behavior: contain;
    padding: 18px 18px max(18px, env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
    background: rgba(239, 247, 255, .97);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .reading-note-dialog[open] { animation: reading-note-sheet-in .22s cubic-bezier(.2,.75,.25,1) both; }
  .reading-note-dialog::backdrop { background: rgba(31, 52, 72, .32); }
}
@keyframes reading-note-sheet-in {
  from { opacity: .8; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .reading-note-dialog[open] { animation: none; }
}

/* Reading V6 — adapted for personal use from NEST ShelfView, BookDetailView,
   ReaderView, ShelfSoftEdge, AnnotationSheet and TocDrawer by nonchaiovo (Chai).
   Full source notice: docs/licenses/NEST-UI-LICENSE.txt */
.reading-view { position:relative; overflow:hidden; }
.reading-library { position:relative; overflow-y:auto; overscroll-behavior:contain; scrollbar-width:none; padding:0; }
.reading-library::-webkit-scrollbar,.reading-viewport::-webkit-scrollbar,.reading-detail-scroll::-webkit-scrollbar { display:none; }
.reading-library-heading { position:relative; z-index:7; padding:clamp(18px,4vw,34px) clamp(20px,5vw,48px) 12px; background:linear-gradient(#eef7ff 72%,transparent); }
.reading-library-heading h2 { margin:0; font:700 clamp(1.22rem,3vw,1.7rem)/1.2 Georgia,"Noto Serif SC",serif; color:#345b7d; }
.reading-library-heading p { margin:5px 0 0; letter-spacing:.16em; font-size:.65rem; color:#86a0b8; }
.reading-continue { display:flex; align-items:center; gap:clamp(18px,4vw,34px); width:min(720px,calc(100% - 40px)); margin:18px auto 26px; padding:22px clamp(20px,4vw,34px); border:1px solid #d4e5f2; border-radius:22px; background:#f7fbfebd; box-shadow:0 12px 34px #315d7b12; cursor:pointer; }
.reading-continue-cover { width:94px; height:135px; flex:none; transform:rotate(-4deg); box-shadow:8px 12px 22px #31516d2a; }
.reading-continue-copy { flex:1; min-width:0; color:#496783; }
.reading-continue-copy>span { font-size:.68rem; letter-spacing:.1em; color:#7894ab; }
.reading-continue-copy h3 { margin:7px 0 4px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font:700 clamp(1.08rem,3vw,1.42rem)/1.3 Georgia,"Noto Serif SC",serif; }
.reading-continue-copy p { margin:0; color:#7890a6; font-size:.78rem; }
.reading-continue-copy>div { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:20px; font-size:.72rem; color:#7790a6; }
.reading-continue-copy button,.reading-detail-copy button { padding:9px 18px; border-radius:999px; background:#466f93; color:white; box-shadow:none; }
.reading-shelf-section { display:flex; justify-content:space-between; align-items:center; width:min(980px,calc(100% - 40px)); margin:0 auto 15px; color:#66839b; font-size:.76rem; }
.reading-shelf-grid { width:min(980px,calc(100% - 40px)); margin:0 auto; padding:0 0 80px; grid-template-columns:repeat(auto-fill,minmax(132px,1fr)); gap:30px clamp(18px,4vw,38px); }
.reading-book-card { align-items:center; padding:0; background:transparent; border:0; box-shadow:none; }
.reading-book-card .reading-cover { width:min(132px,100%); aspect-ratio:124/178; height:auto; transition:transform .24s cubic-bezier(.2,.8,.2,1),box-shadow .24s; box-shadow:8px 10px 20px #31516d24; }
.reading-book-card:hover .reading-cover { transform:translateY(-4px) rotate(-1deg); box-shadow:10px 16px 28px #31516d30; }
.reading-book-card-title { margin-top:15px; }
.reading-nest-credit { display:block; padding:0 20px calc(22px + env(safe-area-inset-bottom)); color:#8ea5b8; text-align:center; font-size:.62rem; }
.reading-soft-edge,.reading-reader-soft-edge { position:absolute; left:0; right:0; z-index:6; height:58px; pointer-events:none; opacity:0; transition:opacity .12s linear; overflow:hidden; }
.reading-soft-edge::before,.reading-reader-soft-edge::before { content:""; position:absolute; inset:0; backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px); mask-image:linear-gradient(to bottom,#000 0 12%,transparent 68%); -webkit-mask-image:linear-gradient(to bottom,#000 0 12%,transparent 68%); }
.reading-soft-edge::after,.reading-reader-soft-edge::after { content:""; position:absolute; inset:0; background:linear-gradient(to bottom,#edf7ff 0%,#edf7fff0 18%,#edf7ff68 58%,transparent); }
.reading-soft-edge-top { top:0; opacity:var(--soft-top,0); }
.reading-soft-edge-bottom { bottom:0; opacity:var(--soft-bottom,0); transform:rotate(180deg); }
.reading-detail { position:absolute; inset:0; z-index:20; display:flex; flex-direction:column; background:#edf6fe; color:#44637e; animation:reading-surface-in .24s cubic-bezier(.2,.75,.25,1); }
.reading-detail-header { display:grid; grid-template-columns:70px 1fr 70px; align-items:center; padding:calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom:1px solid #c7dceb78; }
.reading-detail-header strong { text-align:center; }
.reading-detail-header button { padding:8px 4px; background:transparent; box-shadow:none; color:#557795; }
.reading-detail-scroll { overflow-y:auto; overscroll-behavior:contain; padding:30px max(22px,calc((100% - 760px)/2)) calc(50px + env(safe-area-inset-bottom)); }
.reading-detail-hero { display:flex; align-items:center; gap:clamp(24px,6vw,58px); padding:18px 4px 30px; }
.reading-detail-hero .reading-cover { width:clamp(116px,25vw,164px); height:auto; aspect-ratio:124/178; box-shadow:14px 18px 32px #31516d32; }
.reading-detail-copy { min-width:0; flex:1; }
.reading-detail-copy h2 { margin:0 0 8px; font:700 clamp(1.35rem,4vw,2rem)/1.28 Georgia,"Noto Serif SC",serif; }
.reading-detail-copy p { margin:0 0 12px; color:#7790a5; }
.reading-detail-copy>span { display:block; margin-bottom:20px; font-size:.76rem; color:#7895ad; }
.reading-detail-stats { display:grid; grid-template-columns:repeat(3,1fr); padding:17px 0; border-block:1px solid #c9dce9; }
.reading-detail-stats span { display:grid; gap:4px; text-align:center; color:#879eaf; font-size:.68rem; }
.reading-detail-stats span+span { border-left:1px solid #c9dce9; }
.reading-detail-stats strong { color:#426481; font-size:1rem; }
.reading-detail-section { margin-top:28px; }
.reading-detail-section>strong { display:block; margin-bottom:12px; font-size:.78rem; color:#7892a8; }
.reading-detail-section-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.reading-detail-section-head>strong { font-size:.78rem; color:#7892a8; }
.reading-detail-section-head button { padding:7px 10px; border-radius:10px; background:#e5f0f8; color:#567a98; font-size:.72rem; }
.reading-detail-toc,.reading-detail-annotations { display:grid; gap:8px; }
.reading-detail-toc button { display:grid; grid-template-columns:38px 1fr; gap:8px; width:100%; padding:13px 15px; border:1px solid #d6e5f0; border-radius:13px; background:#f8fbfdbd; color:#4d6c87; text-align:left; }
.reading-detail-toc button span { color:#9ab0c0; font-size:.7rem; }
.reading-detail-note-carousel { min-width:0; padding:5px 10px 18px; overflow:hidden; }
.reading-detail-note-stack { position:relative; min-height:184px; perspective:900px; touch-action:pan-y; }
.reading-detail-note-card { position:absolute; inset:0; width:100%; min-height:174px; display:flex; flex-direction:column; align-items:stretch; gap:12px; overflow:hidden; padding:22px clamp(82px,29%,112px) 26px 22px; border:1px solid #d9e0e2; border-radius:17px 17px 22px 17px; background-color:#F5F7F7; background-image:radial-gradient(circle at 16% 25%,#718a9610 0 .7px,transparent .9px),radial-gradient(circle at 72% 68%,#fff 0 .8px,transparent 1px),linear-gradient(145deg,#fafcfc,#F5F7F7 58%,#edf2f3); background-size:11px 11px,13px 13px,auto; color:#536d7e; text-align:left; box-shadow:0 15px 28px #48617624,0 3px 7px #48617618,inset 0 1px 0 #fff; transform-origin:50% 8%; transition:transform .24s cubic-bezier(.2,.75,.25,1),opacity .2s ease,box-shadow .2s ease; will-change:transform; }
.reading-detail-note-card::after { content:""; position:absolute; z-index:4; top:-1px; right:-1px; width:38px; height:38px; border-radius:0 16px 0 12px; background:linear-gradient(225deg,#d6e0e3 0 45%,#f9fbfb 47% 60%,transparent 62%); filter:drop-shadow(-2px 3px 2px #62798820); pointer-events:none; }
.reading-detail-note-card[data-note-depth="0"] { z-index:3; transform:translate3d(0,0,20px) rotateZ(.15deg); }
.reading-detail-note-card[data-note-depth="1"] { z-index:2; pointer-events:none; transform:translate3d(-7px,10px,0) rotateZ(-1.15deg) scale(.986); background-color:#e8edef; opacity:.94; }
.reading-detail-note-card[data-note-depth="2"] { z-index:1; pointer-events:none; transform:translate3d(7px,18px,-12px) rotateZ(1.25deg) scale(.97); background-color:#dde6e9; opacity:.82; }
.reading-detail-note-card.reading-detail-note-dragging { z-index:5; transition:none; transform:translate3d(var(--note-drag-x,0),var(--note-drag-y,0),42px) rotateZ(var(--note-drag-rotate,0deg)) rotateY(var(--note-drag-tilt,0deg)); box-shadow:0 22px 38px #405a7036,0 6px 12px #405a7026; }
.reading-detail-note-card.reading-detail-note-flip-left { z-index:5; transform:translate3d(-118%,-12px,55px) rotateZ(-9deg) rotateY(12deg); opacity:0; }
.reading-detail-note-card.reading-detail-note-flip-right { z-index:5; transform:translate3d(118%,-12px,55px) rotateZ(9deg) rotateY(-12deg); opacity:0; }
.reading-detail-note-card q { position:relative; z-index:2; display:-webkit-box; overflow:hidden; color:#748b9a; font:italic .78rem/1.65 Georgia,"Noto Serif SC",serif; -webkit-box-orient:vertical; -webkit-line-clamp:2; }
.reading-detail-note-card>span { position:relative; z-index:2; display:-webkit-box; overflow:hidden; color:#456477; font:.9rem/1.72 Georgia,"Noto Serif SC",serif; white-space:pre-wrap; -webkit-box-orient:vertical; -webkit-line-clamp:3; }
.reading-detail-note-flower { position:absolute; z-index:1; right:-14px; bottom:-11px; width:154px; height:154px; object-fit:cover; opacity:.3; mix-blend-mode:multiply; filter:saturate(.64) contrast(.9); pointer-events:none; -webkit-user-drag:none; }
.reading-detail-note-signature { position:absolute; z-index:3; right:16px; bottom:14px; display:grid; place-items:center; width:25px; height:25px; border-radius:50%; background:#d9e8efdc; color:#56778d; box-shadow:inset 0 1px 0 #fff9; font:700 .68rem/1 Georgia,serif; }
@keyframes reading-surface-in { from { opacity:0; transform:translateX(18px); } to { opacity:1; transform:none; } }
::view-transition-old(reading-book-cover),::view-transition-new(reading-book-cover) { animation-duration:.32s; animation-timing-function:cubic-bezier(.2,.75,.25,1); }
.reading-reader { position:absolute; inset:0; z-index:20; background:var(--reading-frame); }
.reading-reader .reading-layout { position:absolute; inset:0; padding:0; display:grid; }
.reading-reader .reading-layout { grid-template-columns:1fr; grid-template-rows:1fr; }
.reading-reader .reading-book-panel { position:relative; min-width:0; min-height:0; border-radius:0; overflow:hidden; }
.reading-reader .reading-companion { position:fixed; z-index:42; left:auto; right:20px; bottom:calc(16px + env(safe-area-inset-bottom)); width:min(410px,calc(100vw - 24px)); height:min(76dvh,720px); min-height:260px; border-radius:22px; box-shadow:0 20px 60px #274c7766; transform:translateY(calc(100% + 40px)); opacity:0; pointer-events:none; transition:transform .24s cubic-bezier(.2,.75,.25,1),opacity .2s; }
.reading-reader .reading-companion.reading-chat-open { transform:translateY(0); opacity:1; pointer-events:auto; }
.reading-companion-top .reading-close-chat { display:block; }
.reading-chat-backdrop:not(.hidden) { display:block; position:fixed; inset:0; z-index:38; background:#324e6d30; backdrop-filter:blur(1px); }
.reading-float-zone { display:flex; position:absolute; right:16px; bottom:calc(22px + env(safe-area-inset-bottom)); z-index:39; flex-direction:column; align-items:end; gap:11px; pointer-events:none; }
.reading-bubble,.reading-fab { pointer-events:auto; }
.reading-reader .reading-toolbar { position:absolute; z-index:35; top:0; left:0; right:0; max-height:none; padding:calc(8px + env(safe-area-inset-top)) 12px 9px; background:color-mix(in srgb,var(--reading-paper) 82%,transparent); box-shadow:0 8px 24px color-mix(in srgb,var(--reading-ink) 8%,transparent); backdrop-filter:blur(18px) saturate(125%); -webkit-backdrop-filter:blur(18px) saturate(125%); transition:transform .25s cubic-bezier(.2,0,.2,1),opacity .2s,background-color .15s ease,color .15s ease; }
.reading-reader.reading-immersive .reading-toolbar { display:flex; transform:translateY(-105%); opacity:0; pointer-events:none; padding:calc(8px + env(safe-area-inset-top)) 12px 9px; }
.reading-paper-top { position:absolute; z-index:4; top:calc(12px + env(safe-area-inset-top)); left:24px; right:24px; padding:0; border:0; background:transparent; pointer-events:none; opacity:.68; }
.reading-paper-top h2 { display:none; }
.reading-paper-top span { margin-left:auto; font-size:.68rem; }
.reading-viewport { position:absolute; inset:0; padding:calc(42px + env(safe-area-inset-top)) clamp(20px,5vw,54px) calc(48px + env(safe-area-inset-bottom)); overflow:hidden; overscroll-behavior:contain; overflow-anchor:none; touch-action:pan-y pinch-zoom; }
.reading-page { box-sizing:border-box; width:100%; height:100%; min-height:0; padding:0; margin:0; overflow:visible; column-gap:64px; column-fill:auto; white-space:normal; will-change:transform; color:var(--reading-ink); line-height:1.9; text-align:justify; }
.reading-page p { margin:0 0 1.08em; white-space:pre-wrap; overflow-wrap:anywhere; text-wrap:pretty; }
.reading-page p.reading-empty-paragraph { min-height:.7em; margin:0; }
.reading-viewport[data-reading-mode="scroll"] { overflow-y:auto; padding-top:calc(70px + env(safe-area-inset-top)); }
.reading-viewport[data-reading-mode="scroll"] .reading-page { height:auto; min-height:100%; column-width:auto!important; column-count:auto; transform:none!important; padding-bottom:20px; }
.reading-page-edge { position:absolute; z-index:11; top:45px; bottom:48px; width:19px; display:grid; place-items:center; padding:0; border:0; border-radius:0; background:transparent; color:var(--reading-control-ink); box-shadow:none; opacity:0; }
.reading-page-edge::before { display:none; }
.reading-page-edge-previous::before { content:"‹"; }
.reading-page-edge-next::before { content:"›"; }
.reading-page-edge:disabled { opacity:0; pointer-events:none; }
.reading-page-edge-previous { left:0; }
.reading-page-edge-next { right:0; }
.reading-scroll-mode .reading-page-edge { display:none; }
@media (hover:hover) and (pointer:fine) {
  .reading-page-edge { width:34px; transition:opacity .16s ease; }
  .reading-page-edge::before { display:grid; place-items:center; width:28px; height:46px; border:1px solid var(--reading-hairline); border-radius:999px; background:color-mix(in srgb,var(--reading-control-bg) 72%,transparent); box-shadow:0 5px 18px color-mix(in srgb,var(--reading-ink) 9%,transparent); backdrop-filter:blur(10px) saturate(120%); -webkit-backdrop-filter:blur(10px) saturate(120%); font:400 1.45rem/1 Georgia,serif; }
  .reading-page-edge:hover,.reading-page-edge:focus-visible { opacity:.82; }
}
.reading-reader-soft-edge { z-index:10; }
.reading-reader-soft-edge-top { top:0; height:calc(58px + env(safe-area-inset-top)); opacity:var(--reading-soft-top,0); }
.reading-reader-soft-edge-bottom { bottom:0; height:calc(40px + env(safe-area-inset-bottom)); opacity:var(--reading-soft-bottom,0); transform:rotate(180deg); }
.reading-reader-soft-edge::after { background:linear-gradient(to bottom,var(--reading-paper) 0%,color-mix(in srgb,var(--reading-paper) 90%,transparent) 20%,transparent); }
.reading-selection-tools { z-index:45; }
.reading-highlight { border:0; border-bottom:2px solid #78aeda; background:#c9e6fb70; cursor:pointer; }
.reading-highlight-yellow { background:#f5dfa872; border-bottom-color:#d3ad55; }
.reading-highlight-pink { background:#f3c9d074; border-bottom-color:#ce8797; }
.reading-highlight-green { background:#cce5d27a; border-bottom-color:#7eaf8b; }
.reading-highlight-dual { box-shadow:inset 0 -4px 0 #d8a5c4aa; }
.reading-mark-date { font-size:.58em; }
.reading-mark-lucien { background:#d7eafd; color:#4e7ea6; }
.reading-mark-sienna { background:#edf2f6; color:#738da3; }
.reading-side-dialog { max-height:var(--reading-visual-height,100dvh); }
.reading-notes-drawer { position:fixed; inset:0 auto 0 0; margin:0; width:min(88vw,410px); max-width:none; height:100dvh; max-height:var(--reading-visual-height,100dvh); padding:max(16px,env(safe-area-inset-top)) 14px max(14px,env(safe-area-inset-bottom)); border-radius:0 22px 22px 0; background:#edf6fff3; backdrop-filter:blur(24px); box-shadow:15px 0 45px #25497144; touch-action:pan-y; }
.reading-notes-drawer[open] { display:flex; flex-direction:column; animation:reading-drawer-in .24s cubic-bezier(.2,.75,.25,1); }
.reading-notes-drawer .reading-dialog-body { flex:1; min-height:0; max-height:none; align-content:start; grid-auto-rows:max-content; touch-action:pan-y; }
.reading-notes-drawer[open].drawer-ready { animation:none; }
.reading-notes-drawer[open].drawer-dragging,.reading-notes-drawer[open].drawer-settling { animation:none; transform:translateX(var(--drawer-x,0)); will-change:transform; }
.reading-notes-drawer[open].drawer-dragging { transition:none; }
.reading-notes-drawer[open].drawer-settling { transition:transform .21s ease-out; }
.reading-notes-drawer[open].drawer-settling::backdrop { transition:background .21s ease-out; }
.reading-notes-drawer::backdrop { background:rgb(33 56 81 / var(--drawer-backdrop,.1)); }
.reading-toc-drawer.reading-dialog-closing { animation:reading-drawer-left-out .22s ease-in both; }
@keyframes reading-drawer-left-out { to { transform:translateX(-100%); } }
.reading-note-group { border-bottom:1px solid #cbddea; }
.reading-note-group summary { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 4px; color:#466d8d; cursor:pointer; }
.reading-note-group summary small { color:#8199ad; font-size:.7rem; }
.reading-note-group-list { display:grid; gap:7px; padding:0 0 10px; }
.reading-note-group-empty { margin:0; padding:8px 10px 12px; color:#849caf; font-size:.78rem; }
.reading-note-card { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:5px; padding:8px 9px; }
.reading-note-card-main { display:grid; min-width:0; padding:0!important; background:transparent!important; color:#416d93; text-align:left; box-shadow:none; }
.reading-note-card-meta { color:#527b9e; font-size:.7rem; }
.reading-note-card-main q,.reading-note-card-preview { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.reading-note-card-main q { margin-top:3px; font-size:.8rem; }
.reading-note-card-preview { margin-top:2px; color:#738ba0; font-size:.72rem; }
.reading-note-locate { padding:6px 8px!important; border-radius:9px!important; background:#e4f0ff!important; color:#527b9e!important; font-size:.7rem; }
.reading-note-card-lucien { border-left:3px solid #82b5dc; }
.reading-note-dialog { inset:auto 0 max(0px,calc(100dvh - var(--visual-viewport-height,100dvh) - var(--visual-viewport-offset,0px))); margin:0 auto; width:min(660px,100%); max-width:none; max-height:min(82dvh,calc(var(--visual-viewport-height,100dvh) - 12px)); padding:0; border:0; border-radius:24px 24px 0 0; background:#eef7fe; overflow:hidden; }
.reading-note-dialog[open] { animation:reading-note-sheet-in .25s cubic-bezier(.2,.75,.25,1); }
.reading-note-dialog.reading-dialog-closing { animation:reading-note-sheet-out .22s ease-in both; }
@keyframes reading-note-sheet-out { to { transform:translateY(100%); opacity:.6; } }
.reading-note-sheet { display:flex; flex-direction:column; max-height:min(82dvh,var(--reading-visual-height,82dvh)); overflow:hidden; }
.reading-note-sheet>.reading-dialog-head { flex:none; margin:0; padding:14px 20px 12px; background:#eef7fefa; backdrop-filter:blur(16px); -webkit-backdrop-filter:blur(16px); }
.reading-note-content { min-height:0; overflow-y:auto; overscroll-behavior:contain; padding:12px 20px calc(20px + env(safe-area-inset-bottom)); }
.reading-note-author { margin:-3px 0 10px; color:#6f8ca4; font-size:.72rem; }
.reading-note-colors { display:flex; gap:3px; margin:9px 0; }
.reading-note-colors button { width:34px; height:34px; padding:6px; border:0; border-radius:9px; background:transparent; }
.reading-note-colors button::before { content:""; display:block; width:22px; height:22px; border-radius:50%; background:#cbe6fa; border:1.5px solid transparent; }
.reading-note-colors button[data-note-color="yellow"]::before { background:#f5dfa8; }
.reading-note-colors button[data-note-color="pink"]::before { background:#f3c9d0; }
.reading-note-colors button[data-note-color="green"]::before { background:#cce5d2; }
.reading-note-colors button[aria-pressed="true"]::before { border-color:#486b87; box-shadow:0 0 0 2px #fff; }
.reading-note-replies { display:grid; gap:9px; margin-top:16px; }
.reading-note-reply { max-width:88%; padding:10px 13px; border:1px solid #d2e2ee; border-radius:14px; background:#f9fcfe; }
.reading-note-reply-lucien { justify-self:start; border-bottom-left-radius:5px; }
.reading-note-reply-sienna { justify-self:end; border-bottom-right-radius:5px; background:#dfeefa; }
.reading-note-reply strong { color:#66839b; font-size:.68rem; }
.reading-note-reply p { margin:4px 0 0; white-space:pre-wrap; }
.reading-reply-form { display:flex; gap:9px; margin-top:14px; }
.reading-reply-form textarea { flex:1; min-width:0; background:white; }
.reading-discuss-note { width:100%; margin-top:10px; background:transparent; color:#527c9f; box-shadow:none; }
.reading-mode-controls { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:16px; padding-top:15px; border-top:1px solid #c6d7e8; font-size:.87rem; font-weight:600; }
.reading-mode-controls>div { display:flex; padding:3px; border-radius:11px; background:#e0edf8; }
.reading-mode-controls button { padding:8px 10px; border-radius:8px; background:transparent; color:#66839b; box-shadow:none; font-size:.72rem; }
.reading-mode-controls button[aria-pressed="true"] { background:white; color:#426b8d; }
.reading-appearance-dialog.reading-dialog-closing { animation:reading-note-sheet-out .22s ease-in both; }
@media (max-width:760px) {
  .reading-library-heading { padding:16px 17px 8px; }
  .reading-continue { width:calc(100% - 26px); margin:12px auto 22px; padding:18px 16px; gap:17px; }
  .reading-continue-cover { width:76px; height:109px; }
  .reading-shelf-grid,.reading-shelf-section { width:calc(100% - 30px); }
  .reading-shelf-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:26px 20px; }
  .reading-detail-scroll { padding:20px 20px calc(42px + env(safe-area-inset-bottom)); }
  .reading-detail-hero { gap:22px; align-items:flex-start; }
  .reading-detail-hero .reading-cover { width:112px; }
  .reading-detail-copy h2 { font-size:1.25rem; }
  .reading-viewport { padding-inline:20px; }
  .reading-reader .reading-toolbar { overflow-x:auto; scrollbar-width:none; }
  .reading-reader .reading-layout { display:grid; }
  .reading-reader .reading-companion { position:fixed; left:12px; right:12px; bottom:calc(8px + env(safe-area-inset-bottom)); width:auto; max-height:calc(var(--reading-visual-height,100dvh) - 16px); }
  .reading-page { text-align:left; }
}
@media(prefers-reduced-motion:reduce) {
  .reading-detail,.reading-notes-drawer[open],.reading-note-dialog[open],.reading-dialog-closing { animation:none!important; }
  .reading-page,.reading-book-card .reading-cover,.reading-soft-edge,.reading-reader-soft-edge { transition:none!important; }
}

/* Shared safe Markdown presentation for saved chat and co-reading messages. */
.message.markdown-body,.reading-comment .markdown-body { white-space:normal; }
.markdown-body > :first-child { margin-top:0; }
.markdown-body > :last-child { margin-bottom:0; }
.markdown-body p { margin:0 0 .65em; white-space:pre-wrap; }
.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6 { margin:.2em 0 .55em; line-height:1.35; color:inherit; }
.markdown-body h1 { font-size:1.22em; }
.markdown-body h2 { font-size:1.15em; }
.markdown-body h3 { font-size:1.08em; }
.markdown-body h4,.markdown-body h5,.markdown-body h6 { font-size:1em; }
.markdown-body ul,.markdown-body ol { margin:.25em 0 .7em; padding-left:1.45em; }
.markdown-body li + li { margin-top:.2em; }
.markdown-body blockquote { margin:.3em 0 .75em; padding:.2em 0 .2em .8em; border-left:3px solid rgba(101,139,169,.42); color:#607b92; }
.markdown-body a { color:#3e78a6; text-decoration-color:rgba(62,120,166,.45); text-underline-offset:2px; }
.markdown-body code { padding:.1em .32em; border-radius:5px; background:rgba(73,103,128,.1); font: .88em/1.45 ui-monospace,SFMono-Regular,Consolas,monospace; }
.markdown-table-wrap { max-width:100%; margin:.35em 0 .75em; overflow-x:auto; }
.markdown-table-wrap table { width:max-content; min-width:100%; border-collapse:collapse; font-size:.9em; }
.markdown-table-wrap th,.markdown-table-wrap td { padding:.42em .58em; border:1px solid rgba(117,148,172,.28); }
.markdown-table-wrap th { background:rgba(224,236,245,.52); font-weight:650; }
.markdown-code-block { max-width:100%; margin:.4em 0 .75em; overflow:hidden; border:1px solid rgba(116,145,168,.28); border-radius:12px; background:rgba(39,56,70,.94); color:#e8f0f6; }
.markdown-code-toolbar { display:flex; align-items:center; justify-content:space-between; min-height:34px; padding:3px 6px 3px 11px; color:#adc1d1; background:rgba(255,255,255,.055); font-size:.7rem; }
.markdown-code-toolbar button { width:auto; min-width:44px; min-height:30px; padding:4px 8px; border:0; border-radius:8px; background:transparent; box-shadow:none; color:#d9e7f1; font-size:.7rem; }
.markdown-code-block pre { max-width:100%; margin:0; padding:12px 13px; overflow:auto; white-space:pre; -webkit-overflow-scrolling:touch; }
.markdown-code-block pre code { padding:0; background:transparent; color:inherit; font: .82rem/1.55 ui-monospace,SFMono-Regular,Consolas,monospace; }


/* Runtime Bridge turns are inbound context, not Sienna or Lucien chat bubbles. */
.message.bridge {
  align-self: center;
  border: 1px solid rgba(92, 118, 137, .18);
  border-radius: 14px;
  background: rgba(236, 242, 246, .78);
  color: #5f7080;
  box-shadow: none;
  font-size: .9rem;
}
.message-group.bridge-group {
  align-self: center;
  align-items: center;
  max-width: min(88%, 640px);
}
.message-group.bridge-group .message-tools {
  align-self: center;
  justify-content: center;
}


/* Memory detail: compact diagnostics with stronger contrast. */
.memory-detail-body .memory-detail-section { background:#f8fbfe; border:1px solid #b8cfde; box-shadow:0 6px 20px rgba(39,69,91,.08); }
.memory-detail-body .memory-conclusion { background:#f1f7fb; }
.memory-detail-body .memory-card-summary strong { color:#294c65; font-weight:650; }
.memory-detail-body .memory-facts dt { color:#526e83; }
.memory-detail-body .memory-facts dd { color:#2c475c; }
.memory-detail-body .memory-item { background:#f3f8fc; border-color:#c7d9e6; }
.memory-detail-body .memory-readable-part { background:#edf5fa; border-color:#bdd4e3; }
.memory-detail-body .memory-readable-part-preview { color:#4b667c; }
.memory-detail-body .memory-readable-raw > summary { color:#365f7d; }
.memory-overview-table-wrap { overflow:hidden; margin-top:10px; border:1px solid #bfd4e2; border-radius:12px; background:#fff; }
.memory-overview-table { width:100%; table-layout:fixed; border-spacing:0; border-collapse:separate; color:#2e4b62; }
.memory-overview-table tr > :first-child { width:33%; text-align:left; }
.memory-overview-table th,.memory-overview-table td { padding:10px 8px; font-size:.8rem; text-align:center; line-height:1.45; overflow-wrap:anywhere; }
.memory-overview-table thead th { background:#e2edf5; color:#3c5c75; font-size:.76rem; font-weight:650; }
.memory-overview-table tbody th { font-weight:600; color:#294c65; }
.memory-overview-table tbody tr:nth-child(even) { background:#f1f6fa; }
.memory-overview-table tbody tr + tr > * { border-top:1px solid #dbe6ee; }
.memory-overview-status { display:inline-block; border-radius:7px; padding:4px 6px; font-size:.76rem; font-weight:600; white-space:normal; }
.memory-overview-ok { color:#275c47; background:#dceee4; }
.memory-overview-neutral { color:#506477; background:#e7edf2; }
.memory-overview-unknown { color:#775c2c; background:#f6edd8; }
.memory-overview-danger { color:#914244; background:#f8e0df; }
.memory-overview-meta { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; margin-top:12px; }
.memory-overview-meta-item { display:grid; gap:4px; min-width:0; padding:10px 12px; border:1px solid #d3e1eb; border-radius:10px; background:#fff; }
.memory-overview-meta-label { color:#5d768a; font-size:.75rem; line-height:1.35; }
.memory-overview-meta-value { color:#294960; font-size:.84rem; font-weight:600; overflow-wrap:anywhere; }
@media (max-width:480px) {
  .memory-overview-table th,.memory-overview-table td { padding:9px 4px; font-size:.73rem; }
  .memory-overview-table tr > :first-child { width:34%; }
  .memory-overview-status { padding:4px 3px; font-size:.7rem; }
  .memory-overview-meta-item { padding:9px 10px; }
}


/* Consistent high-contrast styling for every memory detail level. */
.memory-detail-body .memory-module-card:not(.memory-technical-card) > .memory-facts {
  padding: 12px; border: 1px solid #d1e0ea; border-radius: 11px;
  background: #ffffff; color: #294960;
}
.memory-detail-body .memory-item > summary,
.memory-detail-body .memory-technical-group > summary {
  color: #294c65; font-weight: 600;
}
.memory-detail-body .memory-item > summary .memory-pill {
  background: #d5ece9; color: #225e60; font-weight: 600;
}
.memory-detail-body .memory-technical-card {
  background: #edf4f9; border-color: #acc7da;
}
.memory-detail-body .memory-technical-card > .memory-facts {
  padding: 12px; border: 1px solid #c8dce9; border-radius: 11px;
  background: #ffffff; margin-top: 10px;
}
.memory-detail-body .memory-technical-group {
  background: #e5f0f7; border-color: #bad0df;
}
.memory-detail-body .memory-technical-card .memory-item .memory-item {
  background: #ffffff; border-color: #c3d8e6;
}
.memory-detail-body .memory-technical-card .memory-item > .memory-facts,
.memory-detail-body .memory-technical-card .memory-readable-raw > .memory-facts {
  padding: 12px; border: 1px solid #d1e1eb; border-radius: 10px;
  background: #f9fcfe; color: #294960;
}
.memory-detail-body .memory-readable-raw { border-top-color: #c3d8e6; }
.memory-detail-body .memory-readable-raw > summary {
  color: #315d7c; font-weight: 600;
}
.memory-detail-body .memory-text-block h4,
.memory-detail-body .memory-subheading { color: #365b75; }
.memory-detail-body .memory-text {
  background: #e8f1f8; color: #263e52;
  border: 1px solid #d1e2ed; line-height: 1.78;
}
.memory-detail-body .memory-readable-part-name { color: #2b506b; }
.memory-detail-body .memory-readable-part-body { color: #2b455b; }
.memory-detail-body .memory-readable-part-note { color: #4c677b; }


/* Memory detail: restrained neutrals, with teal only as a small accent. */
.memory-detail-body {
  background: #ECEFEE;
  color: #334B61;
}
.memory-detail-body .memory-detail-section,
.memory-detail-body .memory-conclusion,
.memory-detail-body .memory-technical-card {
  background: #FEFDF8;
  color: #334B61;
  border: 1px solid #B6C0C4;
  box-shadow: 0 3px 12px rgba(51,75,97,.05);
}
.memory-detail-body .memory-card-summary strong,
.memory-detail-body .memory-item > summary,
.memory-detail-body .memory-readable-part-name,
.memory-detail-body .memory-subheading,
.memory-detail-body .memory-text-block h4 {
  color: #334B61;
}
.memory-detail-body .memory-module-card > .memory-facts,
.memory-detail-body .memory-technical-card > .memory-facts,
.memory-detail-body .memory-technical-card .memory-item > .memory-facts,
.memory-detail-body .memory-readable-raw > .memory-facts {
  background: #FEFDF8;
  color: #334B61;
  border: 1px solid #D3DCDE;
}
.memory-detail-body .memory-facts dt,
.memory-detail-body .memory-overview-meta-label { color: #526573; }
.memory-detail-body .memory-facts dd,
.memory-detail-body .memory-overview-meta-value { color: #334B61; }
/* Expanded cards stay white; only their headings use a soft tinted strip. */
.memory-detail-body .memory-module-card > .memory-item,
.memory-detail-body .memory-technical-card > .memory-item,
.memory-detail-body .memory-technical-card .memory-item .memory-item {
  background: #FEFDF8;
  color: #334B61;
  border: 1px solid #B8C5C8;
}
.memory-detail-body .memory-technical-group {
  background: #FEFDF8;
  color: #334B61;
  border: 1px solid #B8C5C8;
  border-left: 3px solid #A9C7D0;
}
.memory-detail-body .memory-item > summary {
  background: #EDF2F1;
}
.memory-detail-body .memory-readable-part {
  background: #FEFDF8;
  color: #334B61;
  border: 1px solid #B8C5C8;
}
.memory-detail-body .memory-readable-part > summary {
  background: #F0F3F1;
}
.memory-detail-body .memory-readable-part[open] > summary {
  background: #E7EFED;
}
.memory-detail-body .memory-readable-part-preview,
.memory-detail-body .memory-readable-part-note,
.memory-detail-body .memory-readable-part-body {
  color: #405767;
}
.memory-detail-body .memory-readable-raw { border-top-color: #D3DBDA; }
.memory-detail-body .memory-readable-raw > summary {
  color: #334B61;
}
.memory-detail-body .memory-text {
  background: #F6F7F5;
  color: #334B61;
  border: 1px solid #D3DBDA;
}
.memory-detail-body .memory-overview-table-wrap,
.memory-detail-body .memory-overview-meta-item {
  background: #FEFDF8;
  border-color: #919CA3;
}
.memory-detail-body .memory-overview-table thead th { background: #D7E4E6; color: #334B61; }
.memory-detail-body .memory-overview-table tbody tr:nth-child(even) { background: #F2F5F3; }
.memory-detail-body .memory-overview-table,
.memory-detail-body .memory-overview-table tbody th { color: #334B61; }
.memory-detail-body .memory-overview-table tbody tr + tr > * { border-top-color: #B3BDC1; }


/* Memory write details: compact OB receipt, closed nested drawers by default. */
.memory-detail-body .memory-write-drawer > .memory-card-summary { color: #334B61; }
.memory-detail-body .memory-write-receipt { margin: 12px; display: grid; gap: 10px; }
.memory-detail-body .memory-write-receipt > .memory-facts {
  padding: 12px; border: 1px solid #D3DCDE; border-radius: 11px;
  background: #FEFDF8; color: #334B61;
}
.memory-detail-body .memory-write-receipt > .memory-readable-raw { margin-top: 0; }


/* Model settings: separate current connection, saved configs and editable details. */
.model-settings { display: grid; align-content: start; gap: 14px; }
.model-settings > h2 { margin: 0 0 2px; color: #334B61; }
.model-manager-panel { padding: 16px; background: #FEFDF8; border: 1px solid #BDC8CA; border-radius: 16px; }
.model-manager-panel > h3, .model-manager-heading > h3 { margin: 0 0 12px; font-size: .98rem; color: #334B61; }
.model-manager-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.model-manager-heading > h3 { margin: 0; }
.model-manager-heading .secondary-button { margin: 0; flex: 0 0 auto; }
.model-current-summary { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.model-current-field { display: grid; align-content: start; gap: 5px; padding: 12px; background: #F1F4F3; border: 1px solid #D3DCDE; border-radius: 11px; min-width: 0; }
.model-current-field small { color: #5A6F78; }
.model-current-field strong { color: #334B61; overflow-wrap: anywhere; font-size: .91rem; }
.model-saved-profiles { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.model-profile-card { display: grid; align-content: start; gap: 6px; min-width: 0; min-height: 112px; text-align: left; padding: 13px; border: 1px solid #C4CFD0; border-radius: 12px; background: #F8FAF8; color: #334B61; cursor: pointer; }
.model-profile-card.selected { border: 2px solid #718F98; padding: 12px; background: #EAF2F0; }
.model-profile-card:hover { border-color: #718F98; }
.model-profile-type { font-size: .74rem; color: #546B75; }
.model-profile-card strong { color: #334B61; font-size: .92rem; overflow-wrap: anywhere; }
.model-profile-card small { color: #617580; overflow-wrap: anywhere; }
.model-profile-current { justify-self: start; padding: 3px 8px; border-radius: 99px; background: #DAE8E1; color: #355C4C; font-size: .73rem; }
.model-settings #settingsForm { margin: 0; gap: 12px; }
.model-settings #settingsForm label { color: #334B61; }
.model-settings #settingsForm fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.model-settings #codexModelFields:not(.hidden), .model-settings #apiFields:not(.hidden) { display: grid; gap: 12px; }
.model-settings #settingsForm input:not([type="checkbox"]), .model-settings #settingsForm select { border: 1px solid #BBC9CB; background: #fff; color: #334B61; border-radius: 10px; min-width: 0; }
.model-form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.model-form-actions > button { flex: 1 1 150px; }
.model-settings #useProvider { width: 100%; }
.model-settings .muted:empty { display: none; }
.model-settings #settingsProfile[hidden] { display: none !important; }
@media (max-width: 520px) {
  .model-current-summary { grid-template-columns: 1fr; gap: 7px; }
  .model-current-field { padding: 9px 11px; }
  .model-saved-profiles { grid-template-columns: 1fr; }
  .model-manager-panel { padding: 12px; }
}

/* Consistent connection/service hierarchy on desktop and mobile. */
.connection-hub { align-self: start; }
.connection-hub > h2 { margin-bottom: 14px; color: #334B61; }
.connection-service-links { display: grid; gap: 10px; }
.connection-service-links > button { display: grid; grid-template-columns: 42px minmax(0,1fr) auto; align-items: center; gap: 12px; width: 100%; min-height: 78px; padding: 13px; text-align: left; background: #FEFDF8; color: #334B61; border: 1px solid #C4CFD0; border-radius: 14px; cursor: pointer; }
.connection-service-links > button > span:nth-child(2) { min-width: 0; display: grid; gap: 5px; }
.connection-service-links strong { font-size: .98rem; font-weight: 600; }
.connection-service-links small { font-size: .78rem; line-height: 1.5; color: #5F737F; }
.connection-service-links > button > span:last-child { font-size: 1.4rem; color: #667E88; }
.connection-service-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: #507382; background: #E4EEEB; font-size: 1.3rem; }
.connection-service-links > button:hover, .connection-service-links > button:focus-visible { border-color: #7C9EA6; }
.model-settings .model-config-drawer > summary, #voiceSettings .voice-service-drawer > summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 45px; cursor: pointer; list-style: none; color: #334B61; font-weight: 600; }
.model-settings .model-config-drawer > summary::-webkit-details-marker, #voiceSettings .voice-service-drawer > summary::-webkit-details-marker { display: none; }
.model-settings .model-config-drawer > summary::after, #voiceSettings .voice-service-drawer > summary::after { content: "展开"; font-size: .8rem; color: #5D7580; font-weight: 400; }
.model-settings .model-config-drawer[open] > summary::after, #voiceSettings .voice-service-drawer[open] > summary::after { content: "收起"; }
.model-settings .model-config-drawer > summary strong { color: #334B61; font-weight: 600; font-size: .98rem; }
.model-settings .model-config-drawer > summary small { margin-left: auto; font-size: .76rem; color: #607683; font-weight: 400; }
.model-settings .model-config-drawer > .model-manager-heading, .model-settings .model-config-drawer > .model-saved-profiles, .model-settings .model-config-drawer > #settingsForm { margin-top: 14px; }
#voiceSettings .voice-service-card { background: #FEFDF8; border: 1px solid #C4CFD0; border-radius: 15px; padding: 15px; min-width: 0; color: #334B61; }
#voiceSettings .voice-service-card > h2 { margin: 0 0 14px; color: #334B61; font-size: .99rem; font-family: inherit; font-weight: 600; }
#voiceSettings .voice-service-drawer > form, #voiceSettings .voice-service-drawer > #voiceEmotionHint { margin-top: 14px; }
#voiceSettings #voicePreferences { padding-bottom: 0; border-bottom: 0; }
#voiceSettings #voiceTagLibrary { margin-top: 12px; padding-top: 12px; border-top: 1px solid #D7E0DE; }
#voiceSettings #voiceProfiles { gap: 9px; }
#voiceSettings .voice-profile { background: #F3F6F4; border-color: #CFDADB; }
@media (min-width: 760px) { .connection-service-links { grid-template-columns: repeat(2,minmax(0,1fr)); } }


/* Voice services: compact settings and an explicit voice-model picker. */
#voiceSettings .voice-toggle-line {
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding:4px 0 14px; color:#334B61; cursor:pointer;
}
#voiceSettings .voice-toggle-copy { font-size:.9rem; font-weight:500; line-height:1.45; }
#voiceSettings .voice-toggle-control { position:relative; flex:0 0 42px; width:42px; height:25px; }
#voiceSettings .voice-toggle-control input[type="checkbox"] {
  position:absolute; z-index:1; inset:0; width:100%; height:100%;
  padding:0; margin:0; opacity:0; cursor:pointer;
}
#voiceSettings .voice-toggle-track {
  display:block; height:25px; border-radius:99px; border:1px solid #B4C8CA;
  background:#DDE4E4; transition:background .15s; pointer-events:none;
}
#voiceSettings .voice-toggle-track::after {
  content:""; position:absolute; left:3px; top:3px; width:19px; height:19px;
  border-radius:50%; background:#fff; box-shadow:0 1px 4px #334B612B; transition:transform .15s;
}
#voiceSettings .voice-toggle-control input:checked + .voice-toggle-track { background:#7EA99E; border-color:#709A90; }
#voiceSettings .voice-toggle-control input:checked + .voice-toggle-track::after { transform:translateX(17px); }
#voiceSettings .voice-toggle-control input:focus-visible + .voice-toggle-track { outline:2px solid #48768B; outline-offset:3px; }
#voiceSettings .voice-limit-line {
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:13px 0 7px; border-top:1px solid #E0E7E5;
}
#voiceSettings .voice-limit-line > label { display:grid; gap:5px; font-weight:500; color:#334B61; }
#voiceSettings .voice-limit-line small { color:#637986; font-size:.78rem; font-weight:400; }
#voiceSettings .voice-limit-input { display:flex; align-items:center; gap:6px; flex:0 0 auto; }
#voiceSettings .voice-limit-input input[type="number"] { width:76px; max-width:76px; padding:8px; text-align:center; }
#voiceSettings .voice-limit-input > span { font-size:.84rem; color:#637986; }
#voiceSettings .voice-preferences-actions { justify-content:flex-end; margin-top:4px; }
#voiceSettings .voice-preferences-actions button { min-height:38px; }
#voiceSettings .voice-model-row { display:flex; align-items:center; gap:8px; min-width:0; }
#voiceSettings .voice-model-row input { flex:1; min-width:0; width:0; }
#voiceSettings .voice-model-row button { flex:0 0 auto; min-height:40px; white-space:nowrap; }
#voiceSettings #voiceModelOptions { margin-top:4px; }
#voiceSettings #voiceModelsStatus { display:block; font-size:.78rem; line-height:1.5; color:#607582; }
#voiceSettings #voiceModelsStatus:empty { display:none; }
@media(prefers-reduced-motion:reduce) {
  #voiceSettings .voice-toggle-track, #voiceSettings .voice-toggle-track::after { transition:none; }
}

/* Markdown task lists, nested lists, and common-language code tokens. */
.markdown-body .markdown-task-item { list-style:none; }
.markdown-body .markdown-task-item > input[type="checkbox"] { width:15px; height:15px; margin:0 7px 0 -20px; vertical-align:-2px; accent-color:#6c97b1; pointer-events:none; }
.markdown-body li > ul,.markdown-body li > ol { margin:.32em 0 .3em; }
.markdown-code-block .code-token-keyword { color:#a8c8ff; }
.markdown-code-block .code-token-string { color:#c6e1a2; }
.markdown-code-block .code-token-number { color:#eac291; }
.markdown-code-block .code-token-comment { color:#9faebc; }


/* Lightweight Jude-inspired reply diagnostics and lifetime usage statistics. */
.stats-view { overflow-y:auto; color:#334B61; background:linear-gradient(155deg,#f0f5fa,#e5eef5 66%,#e1ebf4); }
.stats-view .page-header { position:sticky; top:0; z-index:2; background:rgba(243,248,252,.84); backdrop-filter:blur(14px); }
.stats-body { width:min(940px,100%); padding:18px clamp(14px,4vw,30px) max(40px,env(safe-area-inset-bottom)); margin:auto; display:grid; gap:14px; }
.stats-filters { display:grid; grid-template-columns:1fr 1.5fr; gap:10px; }
.stats-filters label { display:grid; gap:5px; color:#5b758b; font-size:.76rem; }
.stats-filters select { width:100%; min-width:0; padding:10px; border:1px solid #c4d8e7; border-radius:12px; background:#f9fcff; color:#334B61; font:inherit; }
.stats-notice,.stats-footnote { color:#648096; font-size:.78rem; line-height:1.65; }
.stats-summary-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.stats-tile,.stats-panel,.reply-diagnostic-card { border:1px solid rgba(255,255,255,.8); background:linear-gradient(148deg,rgba(255,255,255,.84),rgba(240,247,252,.82)); border-radius:18px; box-shadow:0 6px 20px rgba(75,103,133,.08); }
.stats-tile { padding:15px; display:grid; gap:6px; min-width:0; }
.stats-tile small { color:#658197; font-size:.75rem; }
.stats-tile strong { color:#2f5776; font-size:clamp(1.12rem,3vw,1.55rem); font-weight:680; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }
.stats-panel { padding:16px; min-width:0; }
.stats-panel h2 { margin:0 0 8px; font-size:.96rem; color:#355773; font-weight:680; }
.stats-hint { margin:0 0 12px; color:#70889c; font-size:.73rem; line-height:1.55; }
.stats-chart { display:block; width:100%; height:auto; max-height:210px; overflow:visible; }
.stats-chart-label { fill:#6b8399; font-size:10px; }
.stats-empty { font-size:.82rem; color:#748b9b; padding:18px 0; text-align:center; }
.stats-model-row { display:grid; gap:5px; padding:12px 0; border-top:1px solid #dce8f1; }
.stats-model-head,.stats-model-detail { display:flex; justify-content:space-between; align-items:center; gap:8px; min-width:0; }
.stats-model-head strong { font-size:.79rem; min-width:0; overflow-wrap:anywhere; color:#355b78; }
.stats-model-head span,.stats-model-detail { font-size:.72rem; color:#687f90; }
.stats-bar { height:8px; border-radius:10px; background:#e1ebf4; overflow:hidden; }
.stats-bar>i { display:block; height:100%; background:linear-gradient(90deg,#8db6d8,#6096bf); border-radius:10px; }
.stats-heatmap-layout { display:flex; align-items:flex-end; gap:8px; min-width:0; }
.stats-heatmap-weekdays { display:grid; grid-template-rows:repeat(7,12px); gap:3px; flex:0 0 16px; color:#7a90a2; font-size:.65rem; line-height:12px; }
.stats-heatmap-scroll { overflow-x:auto; min-width:0; flex:1; scrollbar-width:thin; }
.stats-heatmap-calendar { width:max-content; }
.stats-heatmap-months { display:flex; gap:3px; height:18px; margin-bottom:5px; color:#71889c; font-size:.64rem; }
.stats-heatmap-months span { flex:0 0 12px; width:12px; white-space:nowrap; }
.stats-heatmap { display:flex; gap:3px; }
.stats-heatmap-week { width:12px; display:grid; grid-template-rows:repeat(7,12px); gap:3px; flex:none; }
.stats-heatmap-week span { width:12px; height:12px; border-radius:3px; background:#e6eef5; }
.stats-heatmap-week span.stats-heatmap-outside { background:#f1f6fa; opacity:.5; }
.stats-heatmap span[data-level="1"] { background:#c8dfef; }
.stats-heatmap span[data-level="2"] { background:#a7c9e3; }
.stats-heatmap span[data-level="3"] { background:#81add1; }
.stats-heatmap span[data-level="4"] { background:#568db7; }
.stats-daily-table { display:grid; gap:0; max-height:310px; overflow:auto; }
.stats-daily-row { display:grid; grid-template-columns:1fr 1fr 1fr; align-items:center; gap:8px; border-top:1px solid #e0eaf1; padding:10px 0; color:#55718a; font-size:.76rem; }
.stats-daily-row strong { color:#334B61; font-variant-numeric:tabular-nums; }
.usage-actions { display:flex; gap:10px; margin:10px 0; flex-wrap:wrap; }
.reply-diagnostics { display:grid; gap:12px; min-width:0; color:#334B61; }
.reply-diagnostics-more { border:1px solid rgba(164,194,213,.45); border-radius:15px; background:rgba(239,247,252,.68); }
.reply-diagnostics-more > summary { display:flex; align-items:center; justify-content:space-between; min-height:44px; padding:10px 14px; color:#527895; font-size:.82rem; cursor:pointer; list-style:none; }
.reply-diagnostics-more > summary::-webkit-details-marker { display:none; }
.reply-diagnostics-more > summary::after { content:"展开 ⌄"; color:#7794a9; }
.reply-diagnostics-more[open] > summary::after { content:"收起 ⌃"; }
.reply-diagnostics-more-list { display:grid; gap:10px; max-height: min(55dvh, 480px); overflow-y:auto; overscroll-behavior:contain; padding:0 10px 10px; }
.reply-diagnostic-card { padding:14px; }
.reply-diagnostic-head { display:flex; justify-content:space-between; align-items:flex-start; gap:10px; margin-bottom:11px; }
.reply-diagnostic-head strong { color:#355876; font-size:.82rem; overflow-wrap:anywhere; }
.reply-diagnostic-head time { color:#69849a; font-size:.72rem; white-space:nowrap; font-variant-numeric:tabular-nums; }
.reply-diagnostic-metrics { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:7px; }
.usage-data-field { display:grid; gap:5px; min-width:0; padding:9px; border-radius:11px; background:rgba(232,242,249,.65); }
.usage-data-field span { font-size:.7rem; color:#698297; }
.usage-data-field strong { font-size:.8rem; font-weight:660; color:#315471; overflow-wrap:anywhere; }
.usage-details { margin-top:12px; border-top:1px solid #d6e5ef; padding-top:9px; }
.usage-details summary { cursor:pointer; font-size:.78rem; color:#4c7595; list-style:none; }
.usage-details summary::after { content:"⌄"; float:right; }
.usage-details[open] summary::after { content:"⌃"; }
.usage-details-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; margin-top:12px; }
.usage-preferences { border-top:1px solid #d1e2ed; margin-top:15px; padding-top:12px; }
.usage-toggle { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:11px 0; color:#335775; }
.usage-toggle span { display:grid; gap:4px; }
.usage-toggle strong { font-size:.86rem; }
.usage-toggle small { font-size:.72rem; line-height:1.5; color:#7890a3; }
.usage-toggle input { width:19px; height:19px; flex-shrink:0; accent-color:#6e9fc3; }
.message-usage-line { margin:7px 4px 0; padding:5px 0; color:#71889d; font-size:.67rem; line-height:1.55; overflow-wrap:anywhere; }
@media(max-width:420px) {
  .stats-filters { grid-template-columns:1fr 1fr; }
  .reply-diagnostic-metrics .usage-data-field { padding:7px 5px; }
  .usage-data-field strong { font-size:.75rem; }
  .stats-body { padding-inline:12px; }
}

/* Personalization sections: shared pearl-blue cards without changing save behavior. */
.settings-section.personalization-card { padding:clamp(16px,3vw,24px); border-radius:20px; }
.personalization-card h2 { color:#365c78; font-size:1.05rem; font-weight:650; }
.personalization-card > .muted { margin:7px 0 14px; color:#6b8499; font-size:.8rem; line-height:1.65; }
.preference-card #personalizationForm { margin-top:0; gap:10px; }
.preference-card #personalizationForm > label { font-size:.82rem; color:#54738e; }
.preference-card #personalizationText {
  width:100%; min-height:96px; resize:vertical; padding:13px 14px;
  border:1px solid rgba(150,182,204,.54); border-radius:14px;
  background:rgba(255,255,255,.67); color:#34536d; line-height:1.7;
  box-shadow:inset 0 1px 2px rgba(50,79,101,.04);
}
.preference-card #personalizationText:focus-visible { outline:2px solid rgba(95,148,186,.53); outline-offset:1px; }
.personalization-form-actions { display:flex; justify-content:flex-end; }
.personalization-form-actions .primary-button { background:#719fbe; border-radius:12px; }
.preference-card #personalizationMessage:empty { display:none; }
.preference-card #personalizationMessage { margin:0; font-size:.78rem; }
.chat-display-card .chat-display-setting { color:#4b6d87; font-size:.8rem; }
.chat-display-card .chat-display-setting select {
  border:1px solid rgba(150,182,204,.55); border-radius:13px;
  color:#355875; background:rgba(255,255,255,.78);
}
.personalization-avatars .avatar-profiles { gap:12px; margin-top:4px; }
.personalization-avatars .avatar-profile {
  gap:11px; padding:14px; border-radius:17px;
  border:1px solid rgba(160,191,212,.4); background:rgba(255,255,255,.54);
}
.personalization-avatars .avatar-profile-head { gap:12px; }
.personalization-avatars .avatar-status { min-height:0; }
.personalization-avatars .avatar-status:empty { display:none; }
.personalization-avatars .avatar-upload-button { border-radius:12px; background:rgba(226,239,247,.72); }
.avatar-collection { display:grid; gap:7px; min-width:0; }
.avatar-collection-head { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.avatar-collection-head strong { font-size:.77rem; font-weight:550; color:#67859a; }
.avatar-gallery-expand {
  min-height:32px; padding:4px 8px; font-size:.75rem; color:#517b9a;
  background:transparent; border-radius:9px; white-space:nowrap;
}
.avatar-collection .avatar-gallery { min-height:52px; }
.avatar-collection.expanded .avatar-gallery {
  flex-wrap:wrap; align-content:start; max-height:268px;
  overflow-x:hidden; overflow-y:auto;
}
.avatar-collection .avatar-gallery:empty::after { line-height:48px; }
.avatar-extra { border-top:1px solid rgba(166,195,215,.36); padding-top:9px; }
.avatar-extra > summary { cursor:pointer; padding:7px 3px; color:#68869e; font-size:.77rem; }
.avatar-extra > summary:focus-visible { outline:2px solid #8db6d2; border-radius:8px; }
.avatar-extra-body { display:grid; gap:12px; padding:10px 2px 2px; }
.avatar-extra .avatar-ai-entry { padding-top:0; border-top:0; }
.avatar-extra .avatar-tool-note { font-size:.74rem; }
@media (min-width:850px) {
  .personalization-avatars .avatar-profiles { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:420px) {
  .personalization-avatars .avatar-profile-head { grid-template-columns:48px minmax(0,1fr); }
  .personalization-avatars .avatar-profile-head .avatar-upload-button { grid-column:1 / -1; }
}

/* Unified low-saturation switches; native checkboxes keep existing listeners. */
.usage-preferences .usage-toggle input[type="checkbox"] {
  position:relative; appearance:none; -webkit-appearance:none;
  flex:0 0 46px; width:46px; height:27px; margin:0; padding:0;
  border:1px solid #bed0de; border-radius:999px;
  background:#dce7ee; cursor:pointer; transition:background-color .18s,border-color .18s;
}
.usage-preferences .usage-toggle input[type="checkbox"]::before {
  content:""; position:absolute; top:3px; left:3px;
  width:19px; height:19px; border-radius:50%; background:#fff;
  box-shadow:0 1px 4px rgba(44,76,98,.2); transition:transform .18s;
}
.usage-preferences .usage-toggle input[type="checkbox"]:checked { background:#7da8c7; border-color:#7da8c7; }
.usage-preferences .usage-toggle input[type="checkbox"]:checked::before { transform:translateX(19px); }
.usage-preferences .usage-toggle input[type="checkbox"]:focus-visible { outline:2px solid #5687a7; outline-offset:3px; }
.usage-preferences .usage-toggle input[type="checkbox"]:disabled { opacity:.55; cursor:wait; }
@media(prefers-reduced-motion:reduce) {
  .usage-preferences .usage-toggle input[type="checkbox"],
  .usage-preferences .usage-toggle input[type="checkbox"]::before { transition:none; }
}
/* Conversation summary management lives beside Memory Center in settings. */
.summary-dialog { width: min(620px, calc(100% - 28px)); max-height: 90dvh; overflow-y: auto; }
.summary-global-settings { margin: 12px 16px 4px; padding: 11px 12px; border: 1px solid rgba(145,185,211,.38); border-radius: 14px; background: rgba(245,250,253,.66); }
.summary-global-settings > summary { cursor: pointer; color: #4c6e88; font-size: .87rem; font-weight: 600; }
.summary-global-settings .summary-form { padding: 12px 0 0; max-height: none; }
.summary-control-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
.summary-control-grid label { min-width: 0; font-size: .8rem; }
.summary-control-grid input { width: 100%; min-width: 0; box-sizing: border-box; }
.summary-form textarea { width: 100%; box-sizing: border-box; border-radius: 12px; }
#summaryText { min-height: 220px; line-height: 1.65; }
#summaryModelSettings label { display: grid; gap: 8px; margin: 12px 0; }
#summaryModelSelect { max-width: 100%; }
.summary-conversation-picker { display: grid; gap: 6px; padding: 10px 16px 0; font-size: .85rem; color: #526a7c; }
.summary-conversation-picker select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid rgba(128,169,198,.35); border-radius: 12px; color: #344b60; background: rgba(246,250,253,.9); }
.summary-form { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px 0; max-height: calc(78dvh - 60px); overflow-y: auto; }

.summary-item { display: grid; gap: 6px; font-size: .84rem; color: #526a7c; }
.summary-item textarea { min-height: 78px; resize: vertical; line-height: 1.55; font-size: .91rem; color: #344b60; }
.summary-hint { font-size: .78rem; line-height: 1.55; margin: 0; }
.summary-form > .dialog-footer { padding: 12px 0; }
.summary-form > .dialog-footer button { flex: 1; }
#summaryStatus { margin: 0; line-height: 1.55; font-size: .84rem; }

/* Summary manager follows the existing Home dialog and conversation-row patterns. */
.summary-dialog-head { display:grid; grid-template-columns:44px minmax(0,1fr) 58px; align-items:center; gap:8px; }
.summary-dialog-head strong { text-align:center; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.summary-dialog-head #summaryBack { font-size:1.45rem; padding:4px; }
.summary-list-view { padding:10px 16px 18px; }
.summary-list-view > .summary-hint { margin:4px 0 12px; }
.summary-list-view > #summaryListStatus:empty { display:none; }
.summary-list-group { margin:12px 0; }
.summary-list-group h3, .summary-preview h3 { margin:0 0 8px; font-size:.9rem; font-weight:600; color:#526e85; }
.summary-list-group .conversation-list { padding:0; }
.summary-list-item { position:relative; width:100%; padding:12px 34px 12px 14px; margin:0 0 6px; border:1px solid rgba(145,185,211,.32); border-radius:14px; background:rgba(246,250,253,.7); cursor:pointer; }
.summary-list-item:focus-visible { outline:2px solid #80aaca; outline-offset:2px; }
.summary-list-item .summary-list-chevron { position:absolute; right:13px; top:50%; transform:translateY(-50%); color:#7c9ab0; font-size:1.3rem; }
.summary-list-view .summary-global-settings { margin:18px 0 0; }
.summary-detail-view { padding:10px 4px 16px; }
.summary-detail-view > .summary-hint { margin:4px 16px 0; }
.summary-detail-view .summary-form { max-height:none; overflow:visible; }
.summary-preview { padding:14px; border:1px solid rgba(145,185,211,.38); border-radius:14px; background:rgba(245,250,253,.75); }
.summary-preview textarea { min-height:210px; }
.summary-preview .dialog-footer { padding:12px 0 0; }

/* Compact image messages: keep the existing text bubbles untouched. */
.message.image-message { padding: 0; background: transparent; box-shadow: none; border: 0; max-width: 100%; }
.chat-image-gallery { display: grid; width: min(208px, 57vw); gap: 4px; overflow: hidden; border-radius: 13px; }
.chat-image-gallery.image-count-1 { width: min(112px, 34vw); }
.chat-image-gallery.image-count-2 { grid-template-columns: repeat(2, 1fr); }
.chat-image-gallery.image-count-3, .chat-image-gallery.image-count-4, .chat-image-gallery.image-count-5 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 96px); }
.chat-image-gallery.image-count-3 .chat-image-slot:first-child { grid-row: span 2; }
.chat-image-slot { position: relative; min-width: 0; overflow: hidden; border-radius: 9px; }
.chat-image { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: #cbddea55; cursor: zoom-in; overflow: hidden; border-radius: inherit; }
.chat-image img { display: block; width: 100%; height: 100%; max-height: none; object-fit: cover; border-radius: inherit; }
.image-count-1 .chat-image { max-height: 152px; }
.image-count-1 .chat-image img { height: auto; max-height: 152px; object-fit: contain; }
.image-count-2 .chat-image-slot { height: 104px; }
.chat-image-more { position: absolute; inset: 0; display: grid; place-items: center; background: #203c57a3; color: white; font-size: 1.35rem; pointer-events: none; }
.image-load-error { min-height: 70px; background: #e7edf3; }
.image-viewer { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; background: #111b27ed; touch-action: pan-y; }
.image-viewer img { max-width: 96vw; max-height: 86dvh; object-fit: contain; }
.image-viewer img.zoomed { max-width: none; max-height: none; width: auto; height: auto; transform: scale(1.8); }
.image-viewer button { position: absolute; z-index: 1; color: white; border: 0; background: #243b56a8; border-radius: 50%; width: 42px; height: 42px; font-size: 26px; }
.image-viewer-close { top: max(18px, env(safe-area-inset-top)); right: 18px; }
.image-viewer-prev { left: 8px; top: 50%; }
.image-viewer-next { right: 8px; top: 50%; }
.image-viewer-count { position: absolute; bottom: 27px; color: white; }
.image-viewer-save { position: absolute; bottom: 22px; right: 18px; color: white; font-size: .85rem; }
.pending { flex-wrap: wrap; padding: 6px 0; }
.pending-list { display: flex; flex: 1 1 auto; gap: 8px; overflow-x: auto; padding: 4px; }
.pending-item { position: relative; flex: 0 0 70px; height: 76px; border-radius: 12px; overflow: hidden; background: #d8e6f2; }
.pending-item img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }
.pending-file-icon { display: grid; place-items: center; height: 100%; font-size: .8rem; }
.pending-item .pending-remove { position: absolute; top: 2px; right: 2px; min-width: 23px; width: 23px; height: 23px; padding: 0; border-radius: 50%; background: #1b324bbd; color: white; font-size: 18px; }
.pending-add { flex: 0 0 62px; height: 76px; border: 1px dashed #8faec5; border-radius: 12px; background: #d9e8f466; color: #577993; font-size: 26px; }
.pending-upload { opacity: 1; }
.pending-upload .chat-image-gallery { opacity: .74; }
.pending-upload .image-message { position: relative; }
.pending-upload .upload-state { display: grid; place-items: center; pointer-events: none; }
.pending-upload .image-upload-state { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; }
.upload-spinner { display: block; width: 34px; height: 34px; border: 3px solid #ffffffa0; border-top-color: #6f99b8bb; border-radius: 50%; animation: image-upload-spin .9s linear infinite; }
@keyframes image-upload-spin { to { transform: rotate(360deg); } }
.pending-upload .upload-state.upload-failed { position: relative; width: auto; height: auto; margin: 6px 0; pointer-events: auto; }

/* Caramel Pudding: replace (rather than stack with) existing non-drag popup motion. */
dialog.cp-pop[open]:not(.cp-out) { animation:cp-pop calc(580ms / var(--cp-speed,1)) backwards; }
dialog.cp-pop[open].cp-out { animation:cp-out calc(170ms / var(--cp-speed,1)) cubic-bezier(.4,0,1,1) forwards; pointer-events:none; }
.reading-selection-tools.cp-menu { --cp-radius:18px; }
.memory-toast.cp-pop { transition:none; }
@media (prefers-reduced-motion:reduce) {
  dialog.cp-pop[open]:not(.cp-out) { animation:none; }
  dialog.cp-pop[open].cp-out { animation-duration:1ms; }
}
