/* Keep orientation changes from triggering mobile text inflation. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
:root{color-scheme:light;--bg:#fff;--panel:#fff;--input:#f4f4f4;--hover:#ececec;--ink:#171717;--muted:#737373;--line:#e5e5e5;--soft:#f4f4f4;--green:#171717;--button:#171717;--button-ink:#fff;--shadow:0 12px 48px #0002;--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px)}
:root[data-theme=dark]{color-scheme:dark;--bg:#212121;--panel:#2f2f2f;--input:#303030;--hover:#3b3b3b;--ink:#ececec;--muted:#aaa;--line:#444;--soft:#303030;--green:#ececec;--button:#ececec;--button-ink:#171717;--shadow:0 12px 48px #0006}
*{box-sizing:border-box}html,body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;background:var(--bg);color:var(--ink);font-size:15px}button,input,textarea,select{font:inherit}button{cursor:pointer;color:inherit}button:disabled{opacity:.4;cursor:default}button,input,textarea,select{-webkit-tap-highlight-color:transparent}button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible{outline:2px solid var(--muted);outline-offset:2px}button[hidden]{display:none!important}
svg{display:block;width:21px;height:21px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
.app-root,.app-page{height:100%;overflow:hidden;overscroll-behavior:none}
#viewport-probe{position:fixed;top:0;left:0;width:1px;height:1px;visibility:hidden;pointer-events:none}
.shell{position:fixed;top:var(--viewport-top,0px);left:0;right:0;height:var(--viewport-height,100dvh);background:var(--bg);isolation:isolate}
.shell:before{content:'';position:absolute;top:0;left:0;right:0;height:calc(var(--safe-top) + 10px);background:var(--bg);z-index:4;pointer-events:none}
main{position:relative;display:flex;flex-direction:column;width:100%;height:100%;min-height:0;max-width:940px;margin:0 auto;padding:calc(var(--safe-top) + 10px) max(20px,env(safe-area-inset-right,0px)) calc(var(--safe-bottom) + 12px) max(20px,env(safe-area-inset-left,0px))}
.ios-installed main{padding-top:calc(var(--safe-top) + 22px)}.ios-installed .shell:before{height:calc(var(--safe-top) + 22px)}
header{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-shrink:0;min-height:44px;margin-bottom:8px;background:var(--bg)}
.chat-brand{display:flex;align-items:center;gap:9px;min-width:0}.reading-logo{width:30px;height:30px;flex-shrink:0}.reading-brand-name{font-size:17px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
.header-actions{display:flex;gap:2px;flex-shrink:0}.action-icon{display:grid;place-items:center;flex-shrink:0;width:40px;height:40px;padding:0;border:0;border-radius:12px;background:transparent;color:var(--ink)}.action-icon:hover,.action-icon:active{background:var(--hover)}.header-actions .action-icon{width:44px;height:44px}
.auth{display:none}.auth.error{display:block;color:#dc6b59;font-size:12px;margin:0 0 8px}
.conversation-title{flex-shrink:0;font-size:12px;line-height:20px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:0 0 8px}
.chat{flex:1;min-height:0;overflow:auto;padding:8px 4px 20px;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;scroll-behavior:smooth;scrollbar-width:thin}
.welcome{max-width:620px;margin:clamp(24px,8vh,90px) auto}.welcome-icon,.welcome p:empty{display:none}.welcome h2{font-size:28px;line-height:1.4;font-weight:600;margin:0 0 24px}.welcome p{color:var(--muted)}.suggestions{display:grid;gap:8px}.suggestions button{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:14px 16px;text-align:left;background:var(--bg);border:1px solid var(--line);border-radius:16px;font-size:14px;min-height:48px}.suggestions button:hover{background:var(--soft)}
#composer{flex-shrink:0;background:var(--input);border:1px solid transparent;border-radius:26px;padding:10px 12px 8px;transition:padding .25s ease,background .25s ease;box-shadow:none}
.composer-reveal{display:grid;grid-template-rows:1fr;opacity:1;transition:grid-template-rows .25s ease,opacity .2s ease}#composer-body{min-height:0;overflow:hidden}
textarea{display:block;width:100%;min-height:38px;max-height:160px;padding:4px 6px;resize:none;border:0;outline:none;background:transparent;color:var(--ink);font-size:16px;line-height:1.6;overflow:auto}textarea::placeholder{color:var(--muted)}
.composer-toolbar{display:flex;align-items:center;gap:4px;height:40px;margin-top:4px;min-width:0;transition:height .25s ease,margin .25s ease}
.scope-picker{display:flex;align-items:center;gap:7px;min-width:0;max-width:calc(100% - 132px);min-height:36px;padding:6px 10px;border:1px solid var(--line);border-radius:20px;color:var(--ink);background:transparent}.scope-picker svg{width:18px;height:18px;flex-shrink:0}#scope{display:block;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}.scope-picker:hover{background:var(--hover)}
#send{margin-left:auto}#send{display:grid;place-items:center;width:36px;height:36px;flex-shrink:0;border:0;border-radius:50%;padding:0;background:var(--button);color:var(--button-ink)}#send svg{width:20px;height:20px}#send.is-busy svg{animation:busy-pulse 1s infinite alternate}@keyframes busy-pulse{to{opacity:.3}}
.message{margin:12px 0 28px}.message.user{display:flex;justify-content:flex-end}.user-bubble{background:var(--soft);border-radius:20px;padding:12px 16px;white-space:pre-wrap;max-width:88%;line-height:1.7}.answer-label{display:flex;justify-content:space-between;align-items:center;color:var(--muted);font-size:12px;margin-bottom:5px}.answer-meta{color:var(--muted);font-size:11px;line-height:1.5;margin:0 0 14px}.text-button{border:0;padding:4px 0;color:var(--muted);background:none;font-size:12px}.text-button:hover{color:var(--ink)}
.prose{font-size:16px;line-height:1.85;overflow-wrap:anywhere}.prose p{margin:12px 0}.prose h1{font-size:27px}.prose h2{font-size:24px}.prose h3{font-size:21px}.prose h4,.prose h5,.prose h6{font-size:18px}.prose h1,.prose h2,.prose h3,.prose h4,.prose h5,.prose h6{font-weight:650;line-height:1.5;margin:24px 0 12px}.prose strong,.prose b{font-weight:700}.prose ul,.prose ol{padding-left:1.6em;margin:12px 0}.prose li{margin:6px 0}.prose hr{border:0;border-top:1px solid var(--line);margin:20px 0}.prose a{color:var(--ink);text-underline-offset:3px}.prose table{display:block;overflow:auto;border-collapse:collapse;max-width:100%;font-size:14px}.prose td,.prose th{border:1px solid var(--line);padding:8px 12px}.prose th{background:var(--soft)}.prose pre{background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:16px;overflow:auto;font-size:13px;line-height:1.6}.prose code{font-size:.88em}.prose blockquote{margin-left:0;border-left:3px solid var(--line);padding-left:16px;color:var(--muted)}.katex-display{overflow:auto;padding:4px 0}
.sources{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px}.sources button{border:1px solid var(--line);background:var(--soft);border-radius:18px;padding:8px 12px;font-size:11px;max-width:100%;text-align:left}.pending,.muted,.empty{color:var(--muted);font-size:13px;line-height:1.6}.error-message{color:#dc6b59}.note-media{margin:18px 0;padding:12px;border:1px solid var(--line);border-radius:16px;background:var(--panel)}.note-media figcaption{color:var(--muted);font-size:12px;line-height:1.6;margin-bottom:10px}.note-media img{display:block;max-width:100%;max-height:600px;object-fit:contain;margin:auto;border-radius:6px}.media-download{display:inline-block;font-size:12px;color:var(--ink);margin-top:8px;padding:6px 0}
/* Every sheet uses the current visual viewport, including landscape and keyboard height. */
dialog{position:fixed;top:calc(var(--dialog-viewport-top,0px) + var(--safe-top) + 12px);left:50%;right:auto;bottom:auto;transform:translateX(-50%);margin:0;width:min(640px,calc(100vw - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px) - 24px));max-width:none;max-height:calc(var(--viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 24px);border:1px solid var(--line);border-radius:24px;padding:20px;background:var(--panel);color:var(--ink);box-shadow:var(--shadow);overflow:hidden}
dialog[open]{display:flex;flex-direction:column}dialog::backdrop{background:#0006;backdrop-filter:blur(2px)}.dialog-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-shrink:0;margin-bottom:12px;min-height:40px}.dialog-head>div{min-width:0}.dialog-head h2{font-size:18px;font-weight:600;line-height:1.5;margin:0}.dialog-head .muted{font-size:12px;margin:6px 0 0;overflow-wrap:anywhere}.secondary{border:0;background:var(--soft);color:var(--ink);border-radius:20px;min-height:36px;padding:8px 14px;font-size:13px;white-space:nowrap}.secondary:hover{background:var(--hover)}
#library-dialog{height:min(760px,calc(var(--viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 24px))}#library-dialog aside{display:flex;flex-direction:column;min-height:0;flex:1}.library-heading{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-shrink:0;margin-bottom:8px}.library-heading .action-icon{height:32px;width:32px}#stats{font-size:12px}.selection-head{display:flex;align-items:center;justify-content:space-between;gap:8px;color:var(--muted);font-size:12px;margin:10px 0;flex-shrink:0}
input[type=search],input[type=password]{width:100%;padding:11px 14px;min-height:44px;border:1px solid transparent;border-radius:14px;outline:none;color:var(--ink);background:var(--input);font-size:16px;flex-shrink:0}input[type=search]:focus,input[type=password]:focus{border-color:var(--muted)}
.notes{min-height:0;flex:1;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}.note{display:grid;grid-template-columns:20px minmax(0,1fr);align-items:start;gap:12px;padding:12px 10px;margin:2px 0;border-radius:14px}.note:hover,.note.selected{background:var(--soft)}.note input{width:18px;height:18px;padding:0;margin:4px 0;accent-color:var(--ink)}.note>div{min-width:0}.note button{width:100%;text-align:left;border:0;background:none;padding:0;line-height:1.5;font-size:14px;color:var(--ink)}.note .path{font-size:11px;color:var(--muted);margin-top:5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.note .badge{font-size:11px;color:var(--muted);margin-top:4px}.folder-row{background:var(--soft);cursor:pointer}.folder-row strong{font-size:14px;font-weight:600;overflow-wrap:anywhere}.folder-group{margin-bottom:10px}.folder-group summary{padding:10px 6px;font-size:13px;color:var(--muted);cursor:pointer}.empty{padding:20px 8px}
#history-list,#preview-body,.settings-body{min-height:0;overflow:auto;overscroll-behavior:contain}#history-list{max-height:650px}.history-item{display:flex;flex-direction:column;gap:6px;padding:14px 10px;width:100%;border:0;border-bottom:1px solid var(--line);border-radius:0;background:none;color:var(--ink);text-align:left;line-height:1.5}.history-item:hover{background:var(--soft);border-radius:10px}.history-item small{font-size:11px;color:var(--muted)}#preview{width:min(840px,calc(100vw - 24px))}
.settings-body{display:flex;flex-direction:column;gap:8px}.settings-body label{display:flex;align-items:center;justify-content:space-between;gap:16px;font-size:14px;padding:12px 0;border-bottom:1px solid var(--line)}.controls{display:contents}.settings-body select{min-width:0;max-width:64%;min-height:40px;padding:8px 10px;border:1px solid var(--line);border-radius:10px;background:var(--input);color:var(--ink);font-size:16px}.settings-body .text-button{align-self:flex-end;margin-top:6px;min-height:32px}#settings-dialog{max-width:520px}
#toast{position:fixed;left:50%;bottom:calc(var(--safe-bottom) + 20px);transform:translateX(-50%);padding:10px 16px;border-radius:20px;max-width:calc(100vw - 24px);background:var(--button);color:var(--button-ink);z-index:12;display:none;font-size:13px}
.login-page{min-height:100dvh}.login-page main{display:block;height:auto!important}.brand{display:flex;align-items:center;gap:12px;font-size:22px;font-weight:600}.logo{width:40px;height:40px}.login-page form{background:var(--input);padding:20px;border-radius:24px}.login-page h1{font-size:25px}.login-page #login-send{background:var(--button);color:var(--button-ink);width:100%}
@media(max-width:650px){main{padding-left:max(12px,env(safe-area-inset-left,0px));padding-right:max(12px,env(safe-area-inset-right,0px))}.reading-brand-name{font-size:16px}.reading-logo{width:28px;height:28px}.conversation-title{font-size:11px;margin-bottom:4px}.welcome h2{font-size:24px}.prose{font-size:15px}.user-bubble{max-width:94%}dialog{padding:14px;border-radius:20px}.note{padding:10px 4px}.settings-body select{font-size:16px;max-width:68%}.note-media img{max-height:65dvh}}
@media(max-width:360px){.chat-brand{gap:6px}.reading-brand-name{font-size:14px}.header-actions{gap:0}.scope-picker{max-width:calc(100% - 126px);padding:6px 8px}}
@media(max-height:500px){main{padding-top:calc(var(--safe-top) + 4px);padding-bottom:calc(var(--safe-bottom) + 6px)}.ios-installed main{padding-top:calc(var(--safe-top) + 8px)}.shell:before,.ios-installed .shell:before{height:calc(var(--safe-top) + 4px)}header{min-height:36px;margin-bottom:0}.header-actions .action-icon{height:36px}.reading-logo{width:26px;height:26px}.conversation-title{display:none}.welcome{margin:14px auto}.welcome h2{font-size:22px;margin-bottom:16px}#composer{padding:6px 10px;border-radius:22px}.composer-toolbar{height:36px;margin-top:0}.composer-toolbar .action-icon{height:36px}textarea{min-height:36px;padding:2px 6px}dialog{top:calc(var(--dialog-viewport-top,0px) + var(--safe-top) + 6px);max-height:calc(var(--viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 12px);padding:10px 14px;border-radius:18px}#library-dialog{height:calc(var(--viewport-height,100dvh) - var(--safe-top) - var(--safe-bottom) - 12px)}.dialog-head{min-height:36px;margin-bottom:6px}.library-heading{display:none}.selection-head{margin:6px 0}.settings-body label{padding:8px 0}}
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important}.composer-reveal,#composer,.composer-toolbar{transition:none}#send.is-busy svg{animation:none}}
/* Transparent diagrams retain a light canvas for legible labels. */
.note-media img{background:#fff}

/* Status stays in the modal top layer, with refresh accessible in every orientation. */
.dialog-actions{display:flex;align-items:center;gap:6px}
#library-status{font-size:12px;line-height:1.5;padding:0 0 8px;flex-shrink:0;color:var(--muted)}
#library-status[hidden]{display:none}#library-status.error-message{color:#dc6b59}
#refresh.is-refreshing svg{animation:refresh-spin 1s linear infinite}@keyframes refresh-spin{to{transform:rotate(360deg)}}
dialog #toast{position:absolute;bottom:12px;max-width:calc(100% - 24px)}
.keyboard-docked{--safe-bottom:0px}
.short-viewport header{min-height:36px;margin-bottom:0}.short-viewport .conversation-title{display:none}
.short-viewport #composer{padding:6px 10px;border-radius:22px}.short-viewport .composer-toolbar{height:36px;margin-top:0}
.short-viewport .header-actions .action-icon,.short-viewport .composer-toolbar .action-icon{height:36px}
.short-viewport textarea{min-height:36px;padding:2px 6px}
.keyboard-docked.short-viewport main{padding-top:6px;padding-bottom:6px}
@media(prefers-reduced-motion:reduce){#refresh.is-refreshing svg{animation:none}}


/* Keyboard layout uses visual height, not layout-viewport media queries. */
.keyboard-docked .shell:before{height:6px}
.keyboard-docked main,.ios-installed.keyboard-docked main{padding-top:6px;padding-bottom:6px}
.keyboard-docked .conversation-title,.keyboard-docked .library-heading{display:none}
.keyboard-docked dialog{top:calc(var(--dialog-viewport-top,0px) + 6px);max-height:calc(var(--viewport-height,100dvh) - 12px);padding:10px 14px}
.keyboard-docked #library-dialog{height:calc(var(--viewport-height,100dvh) - 12px)}
.keyboard-docked .dialog-head{min-height:36px;margin-bottom:6px}
.keyboard-docked .selection-head{margin:6px 0}

.keyboard-docked.short-viewport .selection-head{display:none}

/* Reading fills the old composer footprint, including the bottom safe area. */


/* Browsing follows the actual folder hierarchy; searching produces two result groups. */
.library-section-title{font-size:12px;color:var(--muted);padding:12px 6px 4px}
.library-folder{margin:2px 0}.library-folder>summary{display:flex;align-items:center;gap:10px;padding:12px 6px;cursor:pointer;list-style:none;border-radius:12px;min-height:44px}
.library-folder>summary::-webkit-details-marker{display:none}.library-folder>summary:hover{background:var(--soft)}
.library-folder>summary input{width:18px;height:18px;flex-shrink:0;margin:0;accent-color:var(--ink)}
.folder-title{min-width:0;flex:1;font-size:14px;overflow-wrap:anywhere}.library-folder>summary small{font-size:11px;color:var(--muted);white-space:nowrap}
.folder-arrow{font-size:22px;line-height:18px;width:12px;flex-shrink:0;transition:transform .15s}.library-folder[open]>summary>.folder-arrow{transform:rotate(90deg)}
.folder-children{margin-left:12px;padding-left:6px;border-left:1px solid var(--line)}
.preview-tools{flex-shrink:0;min-width:0}.preview-modes{display:flex;gap:4px;margin-bottom:8px}.preview-modes[hidden]{display:none}
.preview-modes button{border:0;border-radius:10px;background:transparent;padding:7px 12px;font-size:12px;color:var(--muted)}.preview-modes button.active{background:var(--soft);color:var(--ink)}
.preview-find-status{display:flex;align-items:center;justify-content:space-between;gap:6px;font-size:11px;color:var(--muted);min-height:32px}.preview-find-status>div{display:flex}.preview-find-status .action-icon{width:32px;height:32px;font-size:18px}
#preview-body{flex:1}.preview-line{display:grid;grid-template-columns:52px minmax(0,1fr);gap:8px;min-height:24px;padding:3px 4px;border-radius:6px;line-height:1.65;font-size:14px}
.preview-line-number{font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums;user-select:none;white-space:nowrap}.preview-line-text{white-space:pre-wrap;overflow-wrap:anywhere;min-width:0}
.preview-hit{background:var(--soft)}.preview-line mark{background:#ffe68a;color:#222;border-radius:2px}.preview-gap{padding:6px;color:var(--muted)}
.keyboard-docked.short-viewport .preview-modes{margin-bottom:2px}.keyboard-docked.short-viewport .preview-modes button{padding:3px 8px}.keyboard-docked.short-viewport .preview-find-status{min-height:24px}.keyboard-docked.short-viewport .preview-find-status .action-icon{height:24px}

.library-folder>summary:has(input:checked){background:var(--soft)}
#preview .dialog-head h2{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.keyboard-docked.short-viewport #preview-path,.keyboard-docked.short-viewport #preview-modes{display:none}
.keyboard-docked.short-viewport #preview .dialog-head{min-height:32px;margin-bottom:2px}
.keyboard-docked.short-viewport #preview .dialog-head .action-icon{height:32px;width:32px}

.preview-current{box-shadow:inset 3px 0 0 var(--muted)}

/* Compact phone layouts use the same body size in both orientations. */
@media(max-width:650px),(max-height:500px){.prose{font-size:15px}}

.history-tabs{display:flex;gap:6px;margin:0 0 12px;flex-shrink:0}.history-tabs button{border:0;background:transparent;color:var(--muted);padding:8px 14px;border-radius:10px}.history-tabs button[aria-pressed="true"]{background:var(--soft);color:var(--ink)}.history-row{display:flex;align-items:center;gap:6px;border-bottom:1px solid var(--line)}.history-row .history-item{flex:1;min-width:0;border-bottom:0;overflow-wrap:anywhere}.history-action{flex-shrink:0;margin-right:4px}.suggestions button>span:first-child{min-width:0;overflow-wrap:anywhere}.suggestions button>span:last-child{flex-shrink:0}

.prose .inline-citation{display:inline;padding:1px 5px;margin:0 2px;border:0;border-radius:6px;background:var(--soft);color:var(--ink);font:inherit;font-size:.85em;line-height:inherit;cursor:pointer;vertical-align:baseline;white-space:nowrap}.prose .inline-citation:hover{background:var(--line)}.inline-citation:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.answer-progress{font-size:14px;line-height:1.6;color:var(--muted)}.progress-current{display:flex;flex-wrap:wrap;align-items:center;gap:12px}.progress-current::before{content:'';width:7px;height:7px;border-radius:50%;background:currentColor;animation:progress-pulse 1.5s infinite}.progress-elapsed{font-size:12px}.progress-detail{margin-top:6px;overflow-wrap:anywhere}.progress-events{margin-top:10px}.progress-events summary{cursor:pointer;font-size:12px}.progress-events ol{padding-left:20px;font-size:12px;max-height:180px;overflow:auto}.progress-events li{margin:6px 0;overflow-wrap:anywhere}@keyframes progress-pulse{50%{opacity:.3}}@media(prefers-reduced-motion:reduce){.progress-current::before{animation:none}}

.history-purge{flex-shrink:0;color:#c03939;background:transparent;border:0;border-radius:8px;font-size:12px;padding:9px 8px;min-height:40px}.history-purge:hover{background:var(--soft)}.history-purge:disabled{opacity:.45}.history-row .history-action{margin-right:0}#purge-dialog{width:min(420px,calc(100vw - 24px));padding:24px;overflow:auto}#purge-dialog h2{font-size:20px;margin:0 0 16px}#purge-title{overflow-wrap:anywhere;max-height:100px;overflow:auto}#purge-warning{font-size:14px;color:var(--muted);line-height:1.6}.purge-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}.purge-actions button{padding:10px 16px;min-height:42px;border-radius:12px}.purge-actions .history-purge{background:#c03939;color:white;font-size:14px}.purge-actions .history-purge:hover{background:#a52d2d}[data-theme="dark"] .history-row .history-purge{color:#f08080}

.login-page #access-code{display:block;width:100%;min-height:48px;padding:12px 14px;border:1.5px solid #8a9691;border-radius:12px;background:var(--panel);color:var(--ink);font-size:16px;outline:none}.login-page #access-code:focus{border-color:var(--ink);box-shadow:0 0 0 3px color-mix(in srgb,var(--ink) 14%,transparent)}
