* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); color: var(--ink); color-scheme: dark; }
html[data-theme="paper"] { color-scheme: light; }
body { margin: 0; min-width: 320px; min-height: 100dvh; background: var(--bg); color: var(--ink); font: 400 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; transition: background-color 300ms var(--ease), color 300ms var(--ease); }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
::selection { background: var(--ink); color: var(--bg); }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--bg); border-radius: 99px; }
#app { position: relative; width: 100%; max-width: var(--app-w); min-height: 100dvh; margin: 0 auto; background: var(--bg); overflow: hidden; }
.screen { height: 100dvh; padding: calc(20px + var(--safe-t)) 18px calc(var(--tabbar-h) + var(--safe-b) + 26px); overflow-y: auto; overscroll-behavior-y: contain; }
.screen[data-tab="read"] { padding: 0; overflow: hidden; }
.screen[hidden] { display: none; }
.shell-screen-active { animation: shell-screen-in 240ms var(--ease) both; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); color: var(--muted); font: 400 22px/1 var(--serif); z-index: 20; }
.icon { width: 22px; height: 22px; display: block; flex: none; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; padding: 0; border-radius: 50%; color: var(--ink); background: transparent; transition: background-color 160ms var(--ease), transform 160ms var(--ease); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.btn { min-height: 44px; padding: 11px 18px; border-radius: var(--r-sm); font-weight: 600; letter-spacing: -.01em; transition: background-color 160ms var(--ease), transform 160ms var(--ease); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { opacity: .88; }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.chip { min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 99px; background: transparent; color: var(--ink-2); }
.chip[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); background: var(--surface-2); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.section-label { margin: 0; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .12em; line-height: 1.2; text-transform: uppercase; }
#tabbar { position: absolute; right: 0; bottom: 0; left: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); min-height: var(--tabbar-h); padding: 5px 8px var(--safe-b); border-top: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.shell-tab { min-width: 44px; min-height: 48px; display: grid; place-items: center; align-content: center; gap: 2px; padding: 4px 2px; background: transparent; color: var(--muted); }
.shell-tab-icon { height: 23px; display: grid; place-items: center; }
.shell-tab-icon .icon { width: 20px; height: 20px; }
.shell-tab-label { font-size: 10px; line-height: 1; }
.shell-tab-active { color: var(--ink); }
.shell-tab:hover { color: var(--ink); }
dialog.sheet { width: min(100%, var(--app-w)); max-width: var(--app-w); max-height: 92dvh; margin: auto auto 0; padding: 0; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; background: var(--surface); color: var(--ink); box-shadow: 0 -12px 40px rgba(0,0,0,.16); animation: shell-sheet-up 280ms var(--ease) both; }
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet-grip { width: 34px; height: 4px; margin: 10px auto 2px; border-radius: 99px; background: var(--line); }
.sheet-head { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px 0 20px; }
.sheet-title { margin: 0; font: 500 22px/1 var(--serif); }
.sheet-close { margin: 0; }
.sheet-body { max-height: 85dvh; overflow-y: auto; padding: 0 20px calc(24px + var(--safe-b)); }
.toast { position: fixed; z-index: 30; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); left: 16px; max-width: 390px; margin: auto; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); box-shadow: 0 8px 24px rgba(0,0,0,.18); opacity: 0; transform: translateY(8px); transition: opacity 220ms var(--ease), transform 220ms var(--ease); }
.toast.show { opacity: 1; transform: translateY(0); }
#onboarding { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: calc(18px + var(--safe-t)) 18px calc(18px + var(--safe-b)); background: var(--bg); color: var(--ink); }
#onboarding[hidden] { display: none; }
.shell-onboard-panel { width: min(100%, 460px); min-height: min(720px, 100%); display: flex; flex-direction: column; }
.shell-onboard-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.shell-onboard-back { margin-left: -8px; }
.shell-onboard-step { color: var(--muted); font-size: 11px; letter-spacing: .08em; }
.shell-onboard-dots { display: flex; gap: 6px; position: absolute; left: 50%; transform: translateX(-50%); }
.shell-onboard-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line); }
.shell-onboard-dot-current { width: 18px; border-radius: 99px; background: var(--ink); }
.shell-onboard-dot-done { background: var(--muted); }
.shell-onboard-content { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 34px 0 12px; }
.shell-wordmark { margin: 0 0 32px; font: 500 20px/1 var(--serif); letter-spacing: -.02em; }
.shell-onboard-content h1 { max-width: 400px; margin: 10px 0 14px; font: 400 clamp(39px, 11vw, 62px)/.96 var(--serif); letter-spacing: -.035em; }
.shell-onboard-content h1 em { font-style: italic; }
.shell-onboard-intro { max-width: 330px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.shell-onboard-action { width: 100%; margin-top: 34px; }
.shell-onboard-actions { margin-top: auto; padding-top: 26px; }
.shell-onboard-actions .shell-onboard-action { margin-top: 0; }
.shell-topic-grid { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 28px; }
.shell-topic { text-align: left; }
.shell-topic-selected { border-color: var(--ink); }
.shell-start-list { display: grid; gap: 10px; margin-top: 25px; }
.shell-start-card { position: relative; min-height: 104px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 17px 14px 14px 18px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); text-align: left; transition: border-color 160ms var(--ease), transform 160ms var(--ease); }
.shell-start-card:hover { border-color: var(--muted); transform: translateY(-1px); }
.shell-start-card strong, .shell-start-card small { display: block; }
.shell-start-card strong { font: 500 22px/1 var(--serif); }
.shell-start-card small { margin-top: 5px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.shell-start-card > .icon { grid-column: 2; grid-row: 1; color: var(--muted); }
.shell-start-snippet { grid-column: 1 / -1; display: -webkit-box; overflow: hidden; color: var(--muted); font: italic 14px/1.25 var(--serif); -webkit-box-orient: vertical; -webkit-line-clamp: 1; }
.shell-size-block { margin-top: 28px; }
.shell-size-options { display: flex; gap: 8px; margin-top: 12px; }
.shell-size-option { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--r-sm); background: transparent; color: var(--ink); font: 400 calc(19px * var(--shell-size))/1 var(--serif); }
.shell-size-selected { border-color: var(--ink); background: var(--surface-2); }
.shell-size-sample { margin: 17px 0 0; color: var(--ink-2); font: 400 calc(20px * var(--text-scale))/1.2 var(--serif); transition: font-size 180ms var(--ease); }
.shell-onboard-leaving { animation: shell-onboard-out 320ms var(--ease) both; }
@keyframes shell-screen-in { from { opacity: .72; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shell-sheet-up { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shell-onboard-out { to { opacity: 0; transform: translateY(-8px); } }
@media (min-width: 700px) { #app { min-height: 100dvh; box-shadow: 0 0 0 1px var(--line); } .screen { padding-left: 28px; padding-right: 28px; } #onboarding { padding-left: 30px; padding-right: 30px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* iOS-style floating glass tab bar */
#tabbar { left: 12px; right: 12px; bottom: calc(var(--safe-b) + 10px); width: auto; max-width: calc(var(--app-w) - 24px); margin: 0 auto; min-height: 56px; padding: 4px; border: 1px solid var(--bar-edge); border-radius: 28px; background: var(--bar); backdrop-filter: blur(22px) saturate(180%); -webkit-backdrop-filter: blur(22px) saturate(180%); box-shadow: inset 0 1px 0 var(--bar-edge), 0 10px 30px rgba(0,0,0,.28); }
.shell-tab { min-height: 46px; border-radius: 22px; transition: background-color 200ms var(--ease-out), color 150ms ease, transform 150ms var(--ease-out); }
.shell-tab:active { transform: scale(.96); }

/* round 8: the glass pill under the active tab; drag across the bar and it follows your finger */
#tabbar { touch-action: none; user-select: none; -webkit-user-select: none; }
.tab-glass { position: absolute; left: 4px; top: 4px; bottom: 4px; width: calc((100% - 8px) / 5); border-radius: 22px; background: var(--bar-pill); box-shadow: inset 0 1px 0 var(--bar-edge); pointer-events: none; transition: transform 340ms var(--ease-out), scale 220ms var(--ease-out), background-color 220ms ease; }
#tabbar.is-dragging .tab-glass { transition: scale 220ms var(--ease-out), background-color 220ms ease; scale: 1.1 1.14; background: var(--bar-edge); box-shadow: inset 0 1px 0 var(--bar-edge), 0 6px 18px rgba(0,0,0,.25); }
.shell-tab { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) { .tab-glass { transition: none; } }

/* 5 tabs, Read in the middle */
#tabbar { grid-template-columns: repeat(var(--n, 5), 1fr); }
.tab-glass { width: calc((100% - 8px) / var(--n, 5)); }
