:root {
  --sat: env(safe-area-inset-top, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --bg: #0A1622;
  --side: #0D1D2C;
  --surface: #0F2131;
  --surface-2: #102233;
  --raised: #16304A;
  --line: #1E3A55;
  --line-2: #2A4B6C;
  --text: #E8EEF4;
  --text-2: #D5DFE9;
  --text-3: #C4D2E0;
  --muted: #9FB3C8;
  --eyebrow: #8DA3B9;
  --accent: #F5B544;
  --accent-ink: #0A1622;
  --accent-soft: rgba(245, 181, 68, 0.12);
  --ok: #6FE0AE;
  --ok-soft: rgba(79, 211, 154, 0.12);
  --info: #7CC0FF;
  --info-soft: rgba(124, 192, 255, 0.08);
  --info-line: #2D5679;
  --viewer-bg: #1A2633;
  --radius: 14px;
  --side-w: 272px;
  --viewer-w: 560px;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", Inter, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info); text-decoration: none; }
a:hover { color: #A9D6FF; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

/* ---------- brand & buttons ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand-mark svg { width: 22px; height: 22px; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; }
.brand-mark.sm svg { width: 18px; height: 18px; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: transparent; color: var(--text-3); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.04); color: var(--text); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #F8C567; color: var(--accent-ink); }
.btn-block { width: 100%; height: 44px; font-size: 14px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--text-3); display: inline-grid; place-items: center; }
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.icon-btn.sq { width: 36px; height: 36px; border-radius: 8px; border-color: var(--line-2); }
.link-btn { background: none; border: none; color: var(--eyebrow); font-size: 12.5px; padding: 6px 10px; text-align: left; }
.link-btn:hover { color: var(--text); }
.eyebrow { margin: 0; font-size: 11.5px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--eyebrow); }

/* ---------- sign in ---------- */
.signin { min-height: 100%; display: grid; place-items: center; padding: calc(24px + var(--sat)) 24px 24px; background: radial-gradient(1200px 600px at 50% -10%, #132b44 0%, var(--bg) 60%); }
.signin-card { width: 100%; max-width: 420px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.signin-card .brand { margin-bottom: 14px; }
.field-label { font-size: 13px; color: var(--muted); }
.signin-card input { height: 46px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg); padding: 0 14px; font-size: 16px; }
.notice { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: 12px; background: rgba(245,181,68,.07); border: 1px solid #6B5226; margin-bottom: 6px; }
.notice-head { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.notice-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: #FFE2AE; letter-spacing: .2px; }
.notice p { margin: 0; font-size: 13px; line-height: 1.5; color: #D9C7A6; }
.ack { display: flex; gap: 10px; align-items: flex-start; margin-top: 4px; font-size: 13.5px; line-height: 1.45; color: var(--text); cursor: pointer; }
.ack input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.form-error { margin: 0; min-height: 18px; color: #FFB4A8; font-size: 13px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { width: var(--side-w); flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 26px; padding: 24px 18px 14px; overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.side-section { display: flex; flex-direction: column; gap: 4px; }
.side-section .eyebrow { padding: 0 10px 6px; }
.side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-list button { width: 100%; text-align: left; background: none; border: none; border-radius: 8px; padding: 9px 10px; color: var(--text-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
.side-list button span { overflow: hidden; text-overflow: ellipsis; }
.side-list button:hover { background: rgba(255,255,255,.04); }
.side-list button[aria-current="true"] { background: var(--raised); color: #fff; }
.side-list .saved-mark { width: 13px; height: 13px; color: var(--accent); }
.side-empty { padding: 6px 10px; color: var(--eyebrow); font-size: 13px; }
.library li { padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.library .lib-name { font-size: 13.5px; font-weight: 500; }
.library .lib-meta { font-size: 12px; color: var(--muted); }
.library .lib-meta.future { color: var(--accent); }
.sync-card { margin-top: auto; padding: 14px; border-radius: 12px; background: #11263A; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.sync-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: #4FD39A; }
.sync-card.stale .dot { background: var(--accent); }
.sync-sub { font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { height: 72px; flex-shrink: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 32px; }
.add-wrap { position: relative; }
.home-btn { height: 40px; padding: 0 14px 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: transparent; color: var(--text-3); display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 500; }
.home-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.home-btn svg { width: 19px; height: 19px; }
.side-settings { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: none; border-radius: 10px; background: transparent; color: var(--text-3); font-size: 14px; font-weight: 500; text-align: left; }
.side-settings:hover { background: rgba(255,255,255,.04); color: var(--text); }
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(3,8,14,.6); display: grid; place-items: center; padding: 16px; }
.sheet { width: 100%; max-width: 440px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.5); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-family: var(--display); font-size: 22px; font-weight: 600; }
.sheet-head .icon-btn { width: 38px; height: 38px; }
.set-group { display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; }
.set-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 14px; border: none; background: transparent; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row:hover { background: rgba(255,255,255,.04); }
.set-row strong { display: block; font-size: 15px; font-weight: 600; color: var(--text); }
.set-row span span { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.set-ic { width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.05); color: var(--text-3); display: grid; place-items: center; flex-shrink: 0; }
.set-row.danger strong { color: #FFB4A8; }
.set-row.danger .set-ic { background: rgba(255,120,100,.1); color: #FFB4A8; }
.set-note { margin: 0; display: flex; gap: 10px; font-size: 12.5px; line-height: 1.5; color: #D9C7A6; }
.set-note svg { width: 16px; height: 16px; color: var(--accent); margin-top: 1px; }
.set-admin { align-self: flex-start; font-size: 13px; }
.set-meta { margin: 0; font-size: 12px; color: var(--eyebrow); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding-right: 4px; }
.side-head .eyebrow { padding-bottom: 6px; }
.link-btn.sm { font-size: 12px; padding: 0 6px 6px; }
.add-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.add-btn:hover, .add-btn[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); }
.add-btn svg { width: 20px; height: 20px; stroke-width: 2.4; }
.add-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 300px; padding: 6px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: 0 24px 60px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px; }
.add-menu button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px; border: none; border-radius: 10px; background: transparent; }
.add-menu button:hover, .add-menu button:focus-visible { background: rgba(255,255,255,.05); }
.add-menu strong { display: block; font-size: 14px; font-weight: 600; color: var(--text); }
.add-menu span span { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.add-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.edition-toggle { display: flex; align-items: center; gap: 8px; }
.edition-label { font-size: 12.5px; color: var(--muted); }
.seg { display: flex; background: var(--surface-2); border: 1px solid #22405E; border-radius: 10px; padding: 3px; }
.seg button { height: 32px; padding: 0 12px; border-radius: 8px; border: none; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: #1D3A58; color: var(--text); }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- home ---------- */
.home { overflow-y: auto; align-items: center; padding: 0 48px 24px; }
.home-inner { width: 100%; max-width: 820px; margin-top: clamp(24px, 10vh, 110px); display: flex; flex-direction: column; gap: 28px; }
.hero { display: flex; flex-direction: column; gap: 12px; }
.hero h1 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 44px; letter-spacing: -.8px; line-height: 1.1; }
.hero p { margin: 0; font-size: 17px; color: var(--muted); line-height: 1.5; }
.ask { display: flex; flex-direction: column; gap: 14px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 16px; padding: 18px 18px 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.ask:focus-within { border-color: #3D6A94; }
.ask textarea { resize: none; background: transparent; border: none; outline: none; font-size: 18px; line-height: 1.5; min-height: 54px; }
.ask textarea::placeholder, .followup input::placeholder { color: #7F95AB; }
.ask-row { display: flex; align-items: flex-end; gap: 10px; }
.picker { position: relative; flex: 1; min-width: 0; display: flex; }
.picker-btn { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 40px; padding: 0 12px 0 12px; border-radius: 20px; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); font-size: 13.5px; font-weight: 500; }
.picker-btn.none { border-color: #9a4b45; background: rgba(255,120,100,.08); color: #FFB4A8; }
.picker-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-btn svg { width: 16px; height: 16px; }
.picker-btn .chev { transition: transform .15s; }
.picker-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.picker-menu { position: absolute; left: 0; top: calc(100% + 8px); z-index: 45; width: 360px; max-width: calc(100vw - 32px); padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line-2); box-shadow: 0 24px 60px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 10px; }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px; }
.picker-head .link-btn.sm { padding: 4px 6px; color: var(--info); }
.picker-acts { display: flex; gap: 2px; }
.picker-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; }
.pick:hover { background: rgba(255,255,255,.04); }
.pick input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }
.pick strong { display: block; font-size: 14.5px; font-weight: 500; color: var(--text); }
.pick span span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.pick span span.future { color: var(--accent); }
.send { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: none; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send svg { width: 20px; height: 20px; stroke-width: 2.4; }
.mic { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--line-2); background: transparent; color: var(--text-3); display: grid; place-items: center; position: relative; }
.mic:hover { color: var(--text); background: rgba(255,255,255,.04); }
.mic svg { width: 20px; height: 20px; }
.mic.on { background: #E5484D; border-color: #E5484D; color: #fff; }
.mic.on::after { content: ""; position: absolute; inset: -5px; border-radius: 15px; border: 2px solid #E5484D; animation: micpulse 1.2s ease-out infinite; }
@keyframes micpulse { from { opacity: .8; transform: scale(.92); } to { opacity: 0; transform: scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .mic.on::after { animation: none; opacity: .6; } }
.listening-hint { font-size: 12.5px; color: #FF9EA1; display: flex; align-items: center; gap: 6px; }
.followup .mic { width: 40px; height: 40px; border-radius: 10px; }
.send:disabled { opacity: .5; cursor: default; }
.photo-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--line-2); background: transparent; color: var(--text-3); display: grid; place-items: center; }
.photo-btn:hover { color: var(--text); background: rgba(255,255,255,.04); }
.photo-btn svg { width: 20px; height: 20px; }
.photo-card { width: 100%; text-align: left; display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-radius: 14px; background: var(--surface); border: 1px dashed #355b80; color: var(--text); }
.photo-card:hover, .photo-card.drag { border-color: var(--accent); background: #112538; }
.photo-ic { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.photo-ic svg { width: 22px; height: 22px; }
.photo-text { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.photo-text strong { font-size: 15px; font-weight: 600; }
.photo-text span { font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.photo-go { color: var(--eyebrow); }
.home.drag .ask { border-color: var(--accent); }

/* questions from a photo */
.batch-head { display: flex; gap: 16px; align-items: flex-start; }
.batch-thumb { width: 88px; height: 88px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line-2); flex-shrink: 0; background: var(--surface); }
.batch-head .q-block { flex: 1; min-width: 0; }
.batch-list { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.bq { padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 10px; }
.bq-top { display: flex; gap: 12px; align-items: flex-start; }
.bq-n { font: 600 12px var(--mono); color: var(--accent-ink); background: var(--accent); border-radius: 6px; min-width: 24px; height: 22px; display: grid; place-items: center; flex-shrink: 0; margin-top: 1px; }
.bq-q { margin: 0; font-size: 15.5px; font-weight: 500; line-height: 1.5; white-space: pre-line; color: var(--text); }
.bq-a { margin: 0; font-size: 14.5px; line-height: 1.6; color: var(--text-2); }
.bq-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bq-foot .btn { height: 34px; padding: 0 12px; font-size: 13px; }
.bq.pending .bq-a { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.badge.miss { background: rgba(255,255,255,.06); color: var(--text-3); }
.badge.err { background: rgba(255,120,100,.1); color: #FFB4A8; }
.back-link { align-self: flex-start; background: none; border: none; padding: 4px 0; color: var(--info); font-size: 13.5px; display: inline-flex; align-items: center; gap: 4px; }
.back-link svg { width: 16px; height: 16px; }
.q-block h1 { white-space: pre-line; }
.foot-note { margin: 32px 0 0; font-size: 12.5px; color: var(--eyebrow); display: flex; align-items: center; gap: 8px; text-align: center; }
.foot-note svg { width: 14px; height: 14px; }

/* ---------- answer ---------- */
.answer-scroll { flex: 1; overflow-y: auto; }
.answer-inner { max-width: 860px; margin: 0 auto; padding: 8px 40px 24px; display: flex; flex-direction: column; gap: 22px; }
.q-block { display: flex; flex-direction: column; gap: 10px; }
.q-block h1 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 28px; line-height: 1.25; letter-spacing: -.3px; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; font-size: 12.5px; font-weight: 500; }
.badge svg { width: 14px; height: 14px; stroke-width: 2.4; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ed { background: var(--accent-soft); color: var(--accent); }
.badge.neutral { background: rgba(255,255,255,.06); color: var(--text-3); }
.banner { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--info-soft); border: 1px solid var(--info-line); }
.banner svg { width: 20px; height: 20px; color: var(--info); margin-top: 1px; }
.banner strong { display: block; font-size: 14.5px; color: #CFE6FF; margin-bottom: 3px; }
.banner span { font-size: 13.5px; color: #A9BED3; line-height: 1.5; }
.banner.warn { background: rgba(245,181,68,.07); border-color: #6B5226; }
.banner.warn svg { color: var(--accent); }
.banner.warn strong { color: #FFE2AE; }
.answer-text { font-size: 16.5px; line-height: 1.68; color: var(--text); }
.answer-text p { margin: 0 0 12px; }
.answer-text p:last-child { margin-bottom: 0; }
.cite { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; margin: 0 1px 0 3px; border-radius: 6px; border: none; background: var(--accent-soft); color: var(--accent); font: 600 11.5px var(--mono); vertical-align: 2px; }
.cite:hover { background: var(--accent); color: var(--accent-ink); }
.notfound { padding: 26px 28px; border-radius: 16px; background: var(--surface); border: 1px dashed #3B5F82; display: flex; flex-direction: column; gap: 14px; }
.notfound-head { display: flex; align-items: center; gap: 12px; }
.notfound-head .ic { width: 40px; height: 40px; border-radius: 20px; background: var(--raised); display: grid; place-items: center; color: var(--text-3); }
.notfound h2 { margin: 0; font-family: var(--display); font-size: 22px; font-weight: 600; }
.notfound .answer-text { font-size: 16px; color: var(--text-2); }
.notfound-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.source { margin: 0; padding: 18px 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 10px; scroll-margin: 16px; }
.source.primary, .source.active { border-color: var(--accent); }
.source-tag-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.source-n { font: 600 12px var(--mono); color: var(--accent); }
.tag { font: 500 13px var(--mono); color: var(--accent-ink); background: var(--accent); padding: 3px 8px; border-radius: 6px; }
.source:not(.primary) .tag { background: #1D3A58; color: var(--text); }
.source-meta { font-size: 13px; color: var(--muted); }
.source-ed { font-size: 12px; color: var(--muted); }
.source-ed.future { color: var(--accent); }
.source blockquote { margin: 0; font-size: 15px; line-height: 1.6; color: var(--text-2); }
.source blockquote + blockquote { padding-top: 8px; border-top: 1px solid var(--line); }
.source-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.source-actions .btn { height: 36px; padding: 0 12px; font-size: 13px; }
.related { display: flex; flex-direction: column; gap: 8px; }
.related-item { width: 100%; text-align: left; display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); font-size: 14px; }
.related-item:hover { border-color: var(--line-2); }
.related-item .p { font: 500 12.5px var(--mono); color: var(--accent); margin-right: 6px; }
.related-item .pg { color: var(--eyebrow); font-size: 12.5px; white-space: nowrap; }
.answer-tools { display: flex; gap: 8px; }
.fb { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); margin-top: -8px; }
.fb .btn { height: 34px; padding: 0 12px; font-size: 13px; }
.fb .btn[aria-pressed="true"][data-v="1"] { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.fb .btn[aria-pressed="true"][data-v="-1"] { border-color: #FFB4A8; color: #FFB4A8; background: rgba(255,120,100,.08); }
.followup { flex-shrink: 0; margin: 12px auto 24px; width: calc(100% - 80px); max-width: 780px; display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 14px; padding: 8px 8px 8px 18px; }
.followup input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; height: 40px; font-size: 16px; }
.followup .send { width: 40px; height: 40px; border-radius: 10px; }

/* loading */
.thinking { display: flex; flex-direction: column; gap: 14px; }
.thinking-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14.5px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.skel { height: 14px; border-radius: 7px; background: linear-gradient(90deg, #12283c, #1a3550, #12283c); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .spinner, .skel { animation: none; } }

/* ---------- viewer ---------- */
.viewer { width: var(--viewer-w); flex-shrink: 0; background: var(--viewer-bg); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.viewer-head { min-height: 64px; flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--side); border-bottom: 1px solid var(--line); }
.viewer-doc-icon { color: var(--muted); }
.viewer-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.viewer-title span:first-child { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title span:last-child { font-size: 12px; }
.viewer-tools { display: flex; gap: 4px; }
.viewer-body { flex: 1; overflow: auto; padding: 22px; position: relative; }
.page-wrap { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 12px 40px rgba(0,0,0,.45); border-radius: 3px; }
.page-wrap canvas { display: block; border-radius: 3px; }
.viewer-status { color: var(--muted); font-size: 13.5px; text-align: center; margin: 24px 0; }
.textLayer { position: absolute; text-align: initial; inset: 0; overflow: clip; opacity: 1; line-height: 1; text-size-adjust: none; -webkit-text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; caret-color: CanvasText; z-index: 0; }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer span.hl { background: rgba(245, 181, 68, .42); border-radius: 2px; }
.textLayer ::selection { background: rgba(0, 100, 255, .25); }
.viewer-foot { display: flex; gap: 8px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--side); border-top: 1px solid var(--line); }
.viewer-foot .btn { flex: 1; height: 46px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #1D3A58; color: var(--text); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.only-mobile { display: none !important; }
.seg .short { display: none; }

/* ---------- tablet: viewer overlays the answer ---------- */
@media (max-width: 1280px) {
  .viewer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--viewer-w), 100vw); z-index: 30; box-shadow: -20px 0 60px rgba(0,0,0,.5); }
}

/* ---------- phone ---------- */
@media (max-width: 860px) {
  .only-mobile { display: inline-flex !important; }
  .not-mobile { display: none !important; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .22s ease; padding-top: calc(24px + var(--sat)); padding-left: calc(18px + var(--sal)); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
  .topbar { height: calc(64px + var(--sat)); padding: var(--sat) calc(12px + var(--sar)) 0 calc(8px + var(--sal)); justify-content: space-between; border-bottom: 1px solid var(--line); }
  .topbar .brand { gap: 10px; }
  .topbar .brand-name { font-size: 18px; }
  .edition-label { display: none; }
  .sheet-wrap { place-items: end stretch; padding: 0; }
  .sheet { max-width: none; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .topbar .home-btn { margin-left: auto; width: 40px; padding: 0; justify-content: center; }
  .add-menu { position: fixed; left: 12px; right: 12px; top: calc(70px + var(--sat)); width: auto; }
  .seg .long { display: none; }
  .seg .short { display: inline; }
  .seg button { padding: 0 9px; font-size: 12px; }
  .home { padding: 0 16px 16px; }
  .home-inner { margin-top: 24px; gap: 22px; }
  .hero h1 { font-size: 32px; }
  .hero p { font-size: 15px; }
  .ask { padding: 14px; }
  .ask textarea { font-size: 17px; }
  .picker-btn { height: 44px; border-radius: 22px; font-size: 14.5px; }
  .picker-menu { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; max-width: none; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 61; }
  .picker-menu .pick { padding: 12px 8px; }
  .picker.open::before { content: ""; position: fixed; inset: 0; background: rgba(3,8,14,.6); z-index: 60; }
  .photo-card { padding: 14px; gap: 12px; }
  .batch-thumb { width: 64px; height: 64px; }
  .foot-note { margin-top: 24px; text-align: left; align-items: flex-start; }
  .answer-inner { padding: 16px 16px 20px; gap: 16px; }
  .q-block h1 { font-size: 22px; }
  .answer-text { font-size: 16px; }
  .sources { grid-template-columns: 1fr; }
  .followup { width: calc(100% - 32px); margin: 8px 16px calc(12px + env(safe-area-inset-bottom)); padding: 6px 6px 6px 14px; }
  .followup .send { width: 44px; height: 44px; }
  .viewer { width: 100vw; border-left: none; }
  .viewer-head { padding: calc(8px + var(--sat)) 8px 8px; }
  .viewer-body { padding: 14px 10px; }
}

@media (max-width: 420px) {
  .topbar .brand .brand-name { display: none; }
}

/* ---------- phone keyboard: keep the screen still ----------
   iOS pans the page up when the keyboard opens. On phones the app is pinned to the
   visible area (app.js keeps --app-top/--app-h in step with the keyboard), so the
   top bar stays put and only the content area shrinks. */
@media (max-width: 860px) {
  html, body { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; }
  .app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); }
  .signin { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); min-height: 0; overflow-y: auto; }
  input, textarea, select { font-size: max(16px, 1em); }   /* under 16px makes iOS zoom in */
}

/* account screens */
.auth-view { display: flex; flex-direction: column; gap: 10px; }
.auth-title { margin: 4px 0 2px; font-family: var(--display, inherit); font-size: 20px; font-weight: 600; color: var(--text); }
.auth-note { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.auth-links .link-btn { font-size: 13.5px; padding: 8px 0; color: #9CCBFF; }
.field-label .hint { color: var(--eyebrow); font-size: 12px; margin-left: 4px; }
.auth-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; line-height: 1.5; color: var(--text-2, var(--text)); }
.qr { align-self: center; background: #fff; border-radius: 12px; padding: 10px; line-height: 0; }
.qr svg, .qr img { width: 184px; height: 184px; display: block; }
.secret { font-size: 13px; color: var(--muted); }
.secret summary { cursor: pointer; padding: 4px 0; }
.secret .mono { display: block; margin-top: 6px; font-family: var(--mono, monospace); font-size: 14px; letter-spacing: 1px; color: var(--text); word-break: break-all; user-select: all; }
.signin-card input.code-input { font-size: 22px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.signin-card input { width: 100%; min-width: 0; }
.signin { grid-template-columns: minmax(0, 420px); justify-content: center; }
