/* Surface tokens cover the original book skins as well as the application chrome. */
html { scrollbar-gutter:stable; scroll-behavior:smooth; }
body, button, input, select, textarea, dialog, .sidebar, .topbar, .quote-item,
.reader-surface, .studio-preview, .badge { transition:background-color .22s ease,color .22s ease,border-color .22s ease; }
.sidebar { background:var(--sidebar); }
.topbar { border-color:var(--line); }
.primary { color:var(--on-accent); }
.primary:hover { background:var(--primary); }
.book,.book:hover,.book.selected { background:var(--book); }
.book.book-1,.book.book-1:hover { background:var(--book-alt); }
.book.passport,.book.passport:hover { background:var(--book-passport); }
.shelf-stage { background:var(--surface); border-bottom-color:var(--line); }
.shelf-stage::after { background:var(--line); }
.stat,.quote-item,.quote-item .quote-meta,.ribbon,footer { border-color:var(--line); }
.dropzone { background:var(--surface); }
.badge.error { color:var(--error); background:var(--error-bg); }
.studio-preview { background:var(--preview); overflow:visible; }
.studio-preview iframe { background:var(--paper); }
.preview-viewport { width:100%; overflow:hidden; position:relative; }
.preview-viewport iframe { transform-origin:top left; }
[data-theme="dark"] .preview-viewport iframe { filter:brightness(.8); }
.reader-surface.paper { background:var(--page); background-image:var(--page-texture); border-color:var(--page-line); }
.reader-entry,.reader-surface.timeline .reader-entry { border-color:var(--line); }
.reader-entry mark { background:var(--highlight); color:var(--highlight-ink); }
.reader-entry .inline-note { background:var(--surface); }
dialog::backdrop { background:var(--backdrop); }
#toast { background:var(--toast); color:var(--toast-ink); }
.theme-switch { z-index:8; width:44px; height:44px; flex-shrink:0;
  border:1px solid var(--line); background:var(--paper); color:var(--accent); border-radius:50%; }
.theme-switch svg { width:20px; height:20px; }
.theme-sun { display:none; }
body.locked .theme-switch { position:fixed; right:24px; top:18px; }
[data-theme="dark"] .theme-sun { display:block; }
[data-theme="dark"] .theme-moon { display:none; }
body.locked [data-private] { display:none; }
.unlock[hidden], [hidden] { display:none!important; }
.unlock { min-height:100svh; display:grid; place-items:center; padding:64px 24px; background:var(--bg); }
.unlock-form { width:100%; max-width:360px; }
.unlock-mark { width:52px; height:52px; margin-bottom:32px; display:grid; place-items:center;
  color:var(--accent); border:1px solid var(--line); border-radius:50%; }
.unlock-mark svg { width:24px; height:24px; }
.unlock-form h1 { font-size:32px; margin-bottom:12px; }
.unlock-caption { color:var(--muted); font-family:var(--serif); font-size:18px; margin-bottom:36px; }
.unlock-form label { font-size:14px; }
.unlock-form input { height:50px; font-size:16px; }
.unlock-form .primary { width:100%; min-height:48px; justify-content:space-between; }
#unlock-error { min-height:24px; color:var(--error); font-size:13px; }
.page-heading,.section-title,.actions,.reader-header,.reader-layout>*,.archive-layout>*,.studio-layout>*,.shelf-layout>* { min-width:0; }
.passport-entry h2,.page-heading h1,.archive-result h3,.entry-meta,.quote-meta,.shelf-caption { overflow-wrap:anywhere; }
input:focus-visible,select:focus-visible,textarea:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
@media(max-width:760px) {
  html { scrollbar-gutter:auto; }
  body { font-size:15px; }
  .sidebar { position:relative; top:auto; padding:14px 12px 8px; }
  .brand { min-height:26px; font-size:12px; margin-bottom:12px; }
  .brand small { font-size:10px; }
  .sidebar nav { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:2px; }
  .sidebar nav button { font-size:11px; min-width:0; min-height:58px; padding:7px 0; gap:4px; }
  .sidebar nav svg { width:19px; height:19px; }
  .topbar { min-height:64px; height:auto; padding:9px 16px; gap:8px; }
  #breadcrumb { font-size:11px; min-width:0; line-height:1.6; }
  .topbar>div { gap:4px; flex-shrink:0; }
  .topbar #import-button { font-size:12px; padding:8px; }
  .topbar #lock-button { width:44px; height:44px; }
  body.locked .theme-switch { right:16px; }
  main { padding:26px 16px; }
  h1 { font-size:26px; }
  h2 { font-size:20px; }
  button,.icon { min-width:44px; min-height:44px; }
  input,textarea,select { font-size:16px!important; min-height:44px; }
  input[type=checkbox] { min-height:22px; min-width:22px; accent-color:var(--accent); }
  .page-heading { flex-wrap:wrap; }
  .page-heading p { font-size:13px; }
  .page-heading>.primary { font-size:13px; }
  .stats-strip { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:20px 12px; }
  .stat,.stat:first-child { padding-left:12px; border-left:1px solid var(--line); }
  .stat small { font-size:12px; }
  .stat strong { font-size:26px; }
  .section-title { flex-wrap:wrap; gap:8px; }
  .section-title h2 { font-size:18px; }
  .shelf-stage { max-width:100%; scroll-snap-type:x proximity; -webkit-overflow-scrolling:touch; }
  .book { scroll-snap-align:start; }
  .month-detail { grid-template-columns:1fr; }
  .month-detail dl { grid-template-columns:1fr auto; font-size:14px; }
  .month-detail .primary { margin-top:12px; }
  .quote-item { padding:20px 18px; }
  .quote-item .quote-meta { flex-wrap:wrap; font-size:12px; }
  .quote-item .quote-meta .actions { width:100%; justify-content:flex-end; }
  .quote-item .quote-meta button { padding:10px; }
  .quote-item .quote-text { font-size:18px; line-height:2; }
  .toolbar>input,.toolbar>select { width:100%; max-width:none; }
  .reader-header .segmented { width:100%; }
  .segmented button { flex:1; min-width:0; font-size:12px; padding:8px 4px; gap:5px; }
  .reader-header h1 { font-size:24px; }
  .reader-surface,.reader-surface.letter { padding:20px 16px; }
  .reader-surface.double .entry-text,.reader-entry .entry-text { font-size:18px; line-height:2.05; }
  .reader-entry .entry-meta { font-size:12px; align-items:flex-start; flex-wrap:wrap; }
  .reader-entry .entry-actions button { font-size:12px; padding:8px; }
  .reader-entry { scroll-margin-top:16px; }
  .reader-rail>div { padding:4px 0; scroll-snap-type:x proximity; }
  .ribbon { flex-basis:180px; font-size:14px; scroll-snap-align:start; }
  .reader-pager { position:sticky; bottom:0; padding:12px 0 max(12px,env(safe-area-inset-bottom));
    background:var(--bg); border-top:1px solid var(--line); z-index:2; }
  .reader-pager small { font-size:13px; }
  .studio-controls { grid-template-columns:minmax(0,1fr); }
  .studio-controls label { font-size:14px; }
  .studio-preview { padding:16px; }
  .file-row,.warning,.dropzone { font-size:13px; }
  .archive-layout .actions>button { flex-wrap:wrap; }
  .hash-block { padding:14px; gap:6px; }
  .passport-entry h2 { font-size:22px; }
  .passport-entry .passport-meta { font-size:13px; }
  .shelf-caption { gap:12px; line-height:1.8; }
  dialog { max-height:calc(100dvh - 32px); overflow:auto; padding:22px 18px; }
  dialog label { font-size:14px; }
  footer { font-size:9px; flex-wrap:wrap; }
  #toast { bottom:calc(20px + env(safe-area-inset-bottom)); width:max-content; max-width:calc(100% - 32px); }
}
@media(prefers-reduced-motion:reduce) {
  html { scroll-behavior:auto; }
  *,*::before,*::after { transition:none!important; animation:none!important; }
}
