:root {
  color-scheme: light;
  --paper: #fff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e8e8ed;
  --soft: #f5f5f7;
  --accent: #0066cc;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 24px; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px var(--sans); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button, a, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { border: 0; background: none; color: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
a { color: inherit; text-decoration: none; }
.site-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; padding: 24px; color: var(--muted); font-size: 12px; line-height: 1.8; text-align: center; }
.site-footer a { display: inline-flex; align-items: center; gap: 6px; }
.site-footer img { flex-shrink: 0; }
.site-footer a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }
.mono { font-family: "Consolas", "Courier New", monospace; font-size: 11px; letter-spacing: 1px; }
.library { max-width: 1120px; margin: auto; padding: 32px 40px 20px; }
.library-loading #library-loading { display: block !important; color: var(--muted); padding: 40px 0; text-align: center; }
.library-loading .book-header, .library-loading #main-content, .library-loading #back-library { display: none !important; }
.login-panel { width: min(360px, calc(100% - 48px)); margin: 18vh auto 40px; }
.login-panel h1 { font-size: 28px; font-weight: 600; }
.login-panel > p { color: var(--muted); margin-bottom: 36px; }
.login-panel label { display: block; margin-bottom: 10px; }
.login-panel input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
.login-panel .save-button { width: 100%; margin-top: 20px; }
.book-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }
.book-header h1 { font-size: 30px; font-weight: 600; letter-spacing: -.8px; line-height: 1.4; margin: 0; }
.book-header p { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.book-heading { display: flex; align-items: center; gap: 28px; min-width: 0; }
.book-title-block { min-width: 0; }
.reading-cover { flex-shrink: 0; width: 112px; height: 168px; padding: 0; border-radius: 4px; background: var(--soft); cursor: zoom-in; }
.reading-cover img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
#cover-dialog { width: min(920px, calc(100% - 48px)); height: 88dvh; }
#cover-preview-title { font-size: 13px; font-weight: 500; margin: 0; line-height: 1.7; }
.cover-preview-body { display: flex; flex: 1; min-height: 0; padding: 18px; }
#cover-preview-image { width: 100%; height: 100%; object-fit: contain; }
.book-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.organize-button { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.organize-button svg { width: 18px; height: 18px; }
.book-actions .favorite-filter, .book-actions .organize-button { padding: 8px; }
.icon-button { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 24px; display: grid; place-items: center; color: var(--muted); }
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover, .icon-button[aria-expanded="true"] { background: var(--soft); color: var(--ink); }
.topics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; align-items: start; outline: none; }
.theme { border-bottom: 1px solid var(--line); min-width: 0; }
.theme:last-child { grid-column: 1 / -1; }
.theme:last-child:nth-child(even) { grid-column: auto; }
.theme summary { min-height: 64px; padding: 16px 0; cursor: pointer; display: flex; align-items: center; gap: 15px; list-style: none; }
.theme summary::-webkit-details-marker { display: none; }
.theme-number { font-size: 11px; color: #a1a1a6; font-variant-numeric: tabular-nums; }
.theme-title { font-size: 20px; font-weight: 500; letter-spacing: -.3px; }
.expand-icon { position: relative; width: 16px; height: 16px; margin-left: auto; flex-shrink: 0; color: #86868b; }
.expand-icon::before, .expand-icon::after { content: ""; position: absolute; background: currentColor; border-radius: 1px; }
.expand-icon::before { width: 12px; height: 1.5px; top: 7px; left: 2px; }
.expand-icon::after { height: 12px; width: 1.5px; top: 2px; left: 7px; transition: transform .18s; }
.theme[open] .expand-icon::after { transform: rotate(90deg); }
.theme summary:hover .theme-title { color: #55555a; }
.theme-notes { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; }
.theme > .theme-notes { padding: 0 0 12px 29px; }
.reading-basis { color: var(--muted); font-size: 11px; line-height: 1.8; margin: 0 0 14px; overflow-wrap: anywhere; }
.chapter-group { min-width: 0; border-bottom: 1px solid var(--line); }
.chapter-group > summary { min-height: 52px; display: flex; align-items: center; gap: 15px; padding: 12px 0; cursor: pointer; list-style: none; }
.chapter-group:last-child:nth-child(odd) { grid-column: 1 / -1; }
.chapter-group > summary::-webkit-details-marker { display: none; }
.chapter-group[open] > summary .expand-icon::after { transform: rotate(90deg); }
.chapter-list { padding: 0 0 12px 12px; }
.chapter-list .theme { grid-column: auto; }
.chapter-list .theme:last-child { border-bottom: 0; }
.chapter-list .theme summary { min-height: 48px; padding: 12px 0; gap: 10px; }
.chapter-list .theme-title { font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; }
.chapter-list .theme > .theme-notes { padding-left: 0; }
.note-link { min-height: 32px; border-radius: 8px; background: var(--soft); padding: 6px 11px; text-align: left; font-size: 13px; line-height: 1.5; color: #424245; transition: background .15s, color .15s; overflow-wrap: anywhere; max-width: 100%; }
.note-link:hover { background: #e8e8ed; color: var(--ink); }
.note-link.visited { color: var(--muted); }
.favorite-mark { margin-left: 6px; color: var(--muted); font-size: 11px; }
.favorite-filter { white-space: nowrap; font-size: 12px; padding: 6px 8px; }
.favorite-filter[aria-pressed="true"], #favorite-note[aria-pressed="true"] { color: var(--ink); background: var(--soft); border-radius: 8px; }
.dialog-top > span { min-width: 0; overflow-wrap: anywhere; }
.dialog-top > div { flex-shrink: 0; }
#organizer-dialog { width: min(940px, calc(100% - 48px)); height: min(680px, 88dvh); }
.dialog-top > .organizer-heading { display: block; min-width: 0; flex: 1; }
#organizer-title { font-size: 18px; font-weight: 500; color: var(--ink); margin: 0; }
#organizer-book { font-size: 12px; margin: 6px 0 0; overflow-wrap: anywhere; }
.organizer-basis { padding: 10px 22px 0; margin: 0; }
.organizer-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); flex: 1; min-height: 0; }
.organizer-sidebar { padding: 16px 12px; border-right: 1px solid var(--line); overflow-y: auto; min-width: 0; }
.organizer-sidebar > .text-button { margin: 12px 10px 0; }
.organizer-theme { display: flex; align-items: baseline; gap: 12px; width: 100%; padding: 12px; border-radius: 8px; text-align: left; line-height: 1.7; }
.organizer-theme span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.organizer-theme small { color: var(--muted); font-size: 11px; }
.organizer-theme:hover, .organizer-theme[aria-current="true"] { background: var(--soft); }
.organizer-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; padding: 22px 26px; }
.organizer-theme-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; flex-shrink: 0; }
.organizer-theme-heading h3 { font-size: 20px; font-weight: 500; line-height: 1.6; margin: 0; overflow-wrap: anywhere; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.organizer-theme-heading > div { display: flex; align-items: center; gap: 8px; }
.organizer-add-note { white-space: nowrap; }
#organizer-hint { flex-shrink: 0; margin: 12px 0 0; }
#organizer-keywords { gap: 8px; margin: 12px 0 0; overflow-y: auto; flex: 1; min-height: 0; padding: 2px 6px 12px; }
#organizer-keywords .note-link { border: 1px solid transparent; }
#organizer-keywords .note-link[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); background: #f0f7ff; }
#organizer-menu { position: fixed; inset: auto; margin: 0; width: 160px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: var(--paper); color: var(--ink); box-shadow: 0 8px 32px #00000020; }
#organizer-menu button { display: block; width: 100%; padding: 10px 12px; min-height: 40px; border-radius: 6px; text-align: left; font-size: 13px; line-height: 1.7; }
#organizer-menu button:hover, #organizer-menu button:focus-visible { background: var(--soft); }
#organizer-menu .organizer-menu-delete { color: #a52c25; border-top: 1px solid var(--line); margin-top: 4px; border-radius: 0 0 6px 6px; }
#organizer-menu-cancel { display: none !important; }
.organizer-empty { min-width: 0; align-self: center; padding: 24px; }
#organizer-back { display: none; margin-bottom: 14px; flex-shrink: 0; align-self: flex-start; }
#map-edit-dialog { width: min(520px, calc(100% - 32px)); height: auto; max-height: 90dvh; margin: auto; }
#map-edit-form { overflow-y: auto; }
#map-edit-title { font-size: 18px; margin: 0; }
.map-form-body { padding: 22px; }
.map-form-body label { display: block; font-size: 13px; margin: 12px 0 8px; }
.map-form-body input, .map-form-body textarea, .map-form-body select { width: 100%; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; padding: 11px; font: inherit; background: white; color: var(--ink); }
#create-manual-book { margin-bottom: 20px; }
.search-panel { display: flex; gap: 12px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.search-panel input { flex: 1; min-width: 0; padding: 12px 0; background: none; border: 0; font-size: 16px; color: var(--ink); }
.search-panel input::placeholder { color: var(--muted); }
.search-count { font-size: 12px; color: var(--muted); margin: 24px 0; }
.empty-state { text-align: center; padding: 35px 0; }
.empty-state h2 { font-size: 19px; font-weight: 500; }
.empty-state p { color: var(--muted); font-size: 13px; line-height: 1.8; }
.text-button { color: var(--accent); min-height: 40px; padding: 8px 0; font-size: 13px; }
dialog { border: 1px solid var(--line); padding: 0; border-radius: 18px; width: min(760px, calc(100% - 48px)); max-height: 88dvh; background: var(--paper); color: var(--ink); box-shadow: 0 24px 100px #00000020; overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #00000030; backdrop-filter: blur(8px); }
.modal-open { overflow: hidden; }
.dialog-top { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 22px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.dialog-top > div { display: flex; gap: 4px; }
.dialog-scroll { overflow: auto; overscroll-behavior: contain; }
#note-article { padding: 32px 48px; }
.note-eyebrow { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: 10px; }
.note-eyebrow > span { font-size: 9px; }
#note-title { font-size: 34px; font-weight: 600; line-height: 1.4; letter-spacing: -.5px; margin: 22px 0 14px; outline: none; }
.note-title-row { display: flex; align-items: center; gap: 12px; margin: 22px 0 14px; }
.note-title-row #note-title { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
#open-note-images { flex-shrink: 0; white-space: nowrap; color: var(--muted); }
#open-note-images span { font-size: 10px; }
#note-title-field { margin: 22px 0 14px; }
#note-title-field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
#note-title-input { width: 100%; min-width: 0; border: 1px solid #d2d2d7; border-radius: 10px; padding: 10px 12px; background: var(--paper); color: var(--ink); font: 600 26px/1.5 var(--sans); }
.note-lead { font-size: 18px; line-height: 1.8; color: var(--muted); }
.note-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 30px; }
.note-tags span { font-size: 11px; border-radius: 6px; background: var(--soft); padding: 5px 9px; color: var(--muted); }
.prose { border-top: 1px solid var(--line); padding-top: 6px; }
.prose h3 { font-size: 14px; font-weight: 600; margin: 28px 0 15px; }
.prose h3 span { color: var(--muted); font: 11px monospace; margin-right: 8px; }
.prose p, .prose blockquote { font-size: 16px; line-height: 2; letter-spacing: .2px; }
.prose blockquote { margin: 0; padding: 18px 22px; border-radius: 10px; background: var(--soft); }
.prose .annotation-placeholder { color: var(--muted); font-size: 13px; line-height: 1.9; }
.related { border-top: 1px solid var(--line); margin-top: 30px; padding-top: 20px; color: var(--muted); font-size: 11px; }
.related > div { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.related button { background: var(--soft); border-radius: 8px; padding: 8px 11px; font-size: 12px; color: var(--accent); min-height: 36px; }
.dialog-bottom { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 12px 22px; border-top: 1px solid var(--line); }
.dialog-bottom button { font-size: 12px; min-height: 40px; }
.dialog-bottom > span { font-size: 10px; color: var(--muted); }
.status-toast { position: fixed; bottom: 25px; left: 50%; transform: translate(-50%, 15px); background: var(--ink); color: var(--paper); padding: 13px 22px; border-radius: 10px; max-width: 90vw; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
.status-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.skip-link { position: fixed; top: -100px; left: 20px; background: var(--ink); color: white; padding: 15px; z-index: 50; }
.skip-link:focus { top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.noscript { position: fixed; inset: 0; background: var(--paper); display: grid; place-items: center; padding: 30px; z-index: 100; }
.backup-menu { position: relative; }
.back-library { margin: -12px 0 10px; }
.bookshelf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; padding-top: 20px; }
.book-card { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 16px; transition: background .2s, border-color .2s; }
.book-card:hover { background: #fafafa; border-color: #d2d2d7; }
.book-open { width: 100%; min-height: 190px; padding: 26px 48px 26px 24px; display: flex; align-items: center; gap: 24px; text-align: left; border-radius: 16px; }
.book-cover { width: 88px; height: 126px; flex-shrink: 0; background: var(--soft); border-radius: 3px 6px 6px 3px; overflow: hidden; box-shadow: 0 2px 6px #0000000a; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: space-between; padding: 14px 11px 16px; border-left: 4px solid #e8e8ed; color: #707075; }
.cover-placeholder > span { font-size: 7px; letter-spacing: 1.7px; }
.cover-placeholder strong { font-size: 12px; line-height: 1.7; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-card-body { display: grid; gap: 15px; min-width: 0; }
.book-card-title { font-size: 21px; font-weight: 500; line-height: 1.6; overflow-wrap: anywhere; }
.book-card-author { font-size: 13px; color: var(--muted); line-height: 1.6; }
.book-menu { position: absolute; top: 10px; right: 8px; }
.book-menu > summary { cursor: pointer; list-style: none; }
.book-menu > summary::-webkit-details-marker { display: none; }
.book-menu-options { position: absolute; top: 40px; right: 0; z-index: 12; width: 150px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px #00000010; padding: 5px; }
.book-menu-options button { width: 100%; min-height: 40px; text-align: left; padding: 10px 12px; border-radius: 6px; font-size: 12px; }
.book-menu-options button:not(:disabled):hover { background: var(--soft); }
.book-menu-options .delete-book { color: #b33a30; }
.library-empty { grid-column: 1 / -1; padding: 70px 0; text-align: center; }
.library-empty h2 { font-size: 20px; font-weight: 500; }
.library-empty p { font-size: 13px; color: var(--muted); }
.job-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.generation-job .book-menu { position: relative; top: auto; right: auto; }
.generation-job { display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px; margin-top: 20px; }
.generation-job h2 { font-size: 17px; font-weight: 500; margin: 0 0 10px; }
.generation-job p { font-size: 12px; color: var(--muted); line-height: 1.8; margin: 4px 0; }
.generation-job .job-error { color: #a33a25; max-width: 680px; }
.job-spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--muted); border-radius: 50%; animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .job-spinner { animation: none; } }
#add-book-dialog { width: min(680px, calc(100% - 32px)); }
#add-book-title { font-size: 15px; font-weight: 500; margin: 0; color: var(--ink); }
.add-book-content { overflow: auto; overscroll-behavior: contain; padding: 24px 32px; }
.generation-step { color: var(--muted); font-size: 12px; margin: 0 0 24px; }
.add-book-content label { display: block; font-size: 13px; margin: 20px 0 10px; }
.title-input-row { display: flex; align-items: center; gap: 12px; }
.add-book-content input, .add-book-content textarea, .add-book-content select { border: 1px solid #d2d2d7; background: white; border-radius: 9px; color: var(--ink); padding: 12px; min-width: 0; font: inherit; }
.title-input-row input { flex: 1; width: 100%; }
#book-author-input { width: 100%; }
.title-input-row button, .outline-actions button { flex-shrink: 0; }
.add-book-content textarea { width: 100%; resize: vertical; }
.book-candidate { display: block; width: 100%; text-align: left; padding: 18px; margin: 18px 0; border: 1px solid var(--line); border-radius: 10px; }
.book-candidate[aria-pressed="true"] { border-color: var(--ink); background: var(--soft); }
.book-candidate strong { display: block; margin-bottom: 10px; font-size: 17px; font-weight: 500; }
.book-candidate span, .book-candidate p { font-size: 12px; color: var(--muted); line-height: 1.8; }
.book-candidate p { margin: 8px 0 0; }
#outline-book-title { margin: 0 0 8px; font-size: 24px; font-weight: 500; }
.outline-author { color: var(--muted); font-size: 12px; margin: 0 0 24px; }
.outline-theme { padding: 12px 0; border-bottom: 1px solid var(--line); }
.outline-group { border-bottom: 1px solid var(--line); padding: 14px 0; }
.outline-group > summary { cursor: pointer; font-size: 15px; line-height: 1.8; }
.outline-group > div { padding-left: 12px; }
.outline-group .outline-theme:last-child { border-bottom: 0; }
.outline-theme h4 { font-size: 14px; font-weight: 500; margin: 0 0 10px; }
.outline-theme summary { cursor: pointer; font-size: 14px; line-height: 1.8; overflow-wrap: anywhere; }
.outline-theme .theme-title { font-size: 16px; }
.outline-theme[open] summary { margin-bottom: 12px; }
.outline-theme ul { padding-left: 20px; font-size: 12px; line-height: 1.9; color: var(--muted); }
.outline-theme li { margin: 8px 0; }
.outline-theme strong { color: var(--ink); font-weight: 500; }
.outline-theme .coverage-warning { color: #885600; margin-top: 12px; }
.outline-theme p { font-size: 12px; line-height: 1.9; margin: 0; color: var(--muted); }
.outline-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.outline-actions > .text-button { margin-right: auto; }
.optional { font-size: 11px; color: var(--muted); margin-left: 5px; }
.generation-busy { color: var(--muted); font-size: 13px; line-height: 1.8; }
.generation-notice { color: var(--muted); font-size: 11px; line-height: 1.9; margin: 26px 0 0; }
@media (max-width: 640px) {
  .bookshelf { grid-template-columns: 1fr; gap: 14px; padding-top: 10px; }
  .book-open { min-height: 166px; padding: 22px 40px 22px 18px; gap: 16px; }
  .book-cover { width: 76px; height: 110px; }
  .book-card-title { font-size: 19px; }
  .add-book-content { padding: 20px; }
  .generation-job { align-items: flex-start; padding: 18px; gap: 12px; }
  .generation-job > button { flex-shrink: 0; padding: 9px; }
  .title-input-row { flex-wrap: wrap; }
}
.backup-menu > summary { cursor: pointer; list-style: none; }
.backup-menu > summary::-webkit-details-marker { display: none; }
.backup-options { position: absolute; right: 0; top: 46px; z-index: 10; width: 250px; padding: 9px; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 35px #00000012; }
.backup-options button { width: 100%; text-align: left; min-height: 42px; padding: 10px 12px; font-size: 13px; border-radius: 7px; }
.backup-options button:not(:disabled):hover { background: var(--soft); }
.backup-options p { margin: 8px 12px 10px; font-size: 11px; line-height: 1.8; color: var(--muted); }
.storage-warning { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; background: #fff7ed; border-radius: 10px; font-size: 13px; line-height: 1.8; margin-bottom: 20px; }
.error-message { color: #a52c25; background: #fff2f0; border-radius: 8px; padding: 12px 16px; font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
#note-message { flex-shrink: 0; max-height: 100px; overflow: auto; margin: 8px 20px; }
.dialog-top .text-button { padding: 8px; font-size: 12px; }
.editor-tools { flex-shrink: 0; background: white; border-bottom: 1px solid var(--line); padding: 8px 18px; }
.format-tools { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.format-tools button { min-width: 33px; min-height: 36px; border-radius: 6px; padding: 7px 9px; font-size: 12px; }
.format-tools button:not(:disabled):hover { background: var(--soft); }
.format-tools strong, .format-tools em { font-family: Georgia, serif; font-size: 17px; }
.link-form { display: flex; gap: 12px; align-items: center; padding: 8px 0 0; }
.link-form input { min-width: 0; flex: 1; background: var(--soft); color: var(--ink); font-size: 14px; padding: 9px 11px; border: 0; border-radius: 6px; }
.link-form button { flex-shrink: 0; }
.note-body { font-size: 16px; line-height: 2; overflow-wrap: anywhere; }
.note-body:empty::before { content: attr(data-placeholder); font-size: 13px; color: #86868b; }
.note-body p:first-child { margin-top: 0; }
.note-body p:last-child { margin-bottom: 0; }
.note-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.note-body figure { margin: 18px 0; }
.note-body img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
#note-gallery { border-top: 1px solid var(--line); margin: 28px 0 24px; padding-top: 16px; }
.gallery-heading { display: flex; align-items: center; gap: 12px; }
.gallery-heading h3 { font-size: 14px; font-weight: 500; margin: 0; }
.gallery-heading span { color: var(--muted); font-size: 12px; }
.gallery-heading button { margin-left: auto; }
.gallery-navigation { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-shrink: 0; padding: 12px 20px; border-top: 1px solid var(--line); }
.gallery-navigation span { margin: 0 auto; color: var(--muted); font-size: 12px; }
.gallery-thumbnails { display: flex; gap: 10px; overflow-x: auto; padding: 12px 2px 6px; }
.gallery-thumbnails button { flex-shrink: 0; width: 88px; height: 88px; border: 1px solid transparent; border-radius: 8px; padding: 5px; background: var(--soft); cursor: zoom-in; }
.editing .gallery-thumbnails button { cursor: pointer; }
.gallery-thumbnails button[aria-pressed="true"] { border-color: var(--accent); }
.gallery-thumbnails img { width: 100%; height: 100%; object-fit: contain; }
.gallery-caption, .gallery-empty { color: var(--muted); font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
.gallery-caption-label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 8px; }
#gallery-caption { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--ink); background: var(--paper); }
.gallery-edit-actions { display: flex; flex-wrap: wrap; gap: 8px 20px; }
#gallery-preview-dialog { height: 90dvh; }
.gallery-full { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.gallery-full button { display: block; width: 100%; height: 100%; padding: 0; cursor: zoom-in; }
.gallery-full img { display: block; width: 100%; height: 100%; object-fit: contain; }
.gallery-zoomed .gallery-full button { width: max-content; min-width: 100%; height: auto; cursor: zoom-out; }
.gallery-zoomed .gallery-full img { width: auto; min-width: 100%; height: auto; max-width: none; }
#gallery-preview-caption { flex-shrink: 0; max-height: 18dvh; overflow-y: auto; margin: 0; padding: 8px 20px; }
.note-body figcaption { font-size: 12px; line-height: 1.8; color: var(--muted); margin-top: 8px; text-align: center; }
.note-body figcaption:empty { display: none; }
.editing .note-body { min-height: 100px; border: 1px solid #d2d2d7; border-radius: 10px; padding: 15px 17px; background: white; }
.editing .note-body:focus { outline: 2px solid #0066cc40; border-color: var(--accent); outline-offset: 1px; }
.editing .note-body[contenteditable="false"] { opacity: .7; }
.editing .note-body figcaption:empty { display: block; min-height: 22px; }
.editing .note-body figcaption:empty::before { content: "添加图片说明…"; color: #86868b; }
.editing .note-body img { cursor: pointer; }
.editing .note-body .selected-image { outline: 3px solid var(--accent); outline-offset: 3px; }
.editing .related { display: none; }
.save-state { flex-shrink: 0; margin: 8px 24px; color: var(--muted); font-size: 11px; line-height: 1.8; }
.edit-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-shrink: 0; border-top: 1px solid var(--line); padding: 15px 22px; }
.edit-actions > span { font-size: 11px; line-height: 1.7; color: var(--muted); }
.edit-actions > div, .confirm-actions { display: flex; gap: 10px; flex-shrink: 0; }
.save-button, .secondary-button { border-radius: 8px; padding: 10px 18px; min-height: 40px; font-size: 13px; }
.save-button { background: var(--ink); color: white; }
.save-button:not(:disabled):hover { background: #454549; }
.danger-button { background: #b33a30; }
.danger-button:not(:disabled):hover { background: #912d25; }
.secondary-button { background: var(--soft); }
#confirm-dialog { width: min(420px, calc(100% - 40px)); max-height: 85dvh; height: auto; padding: 27px; border-radius: 16px; margin: auto; }
#confirm-dialog h2 { font-size: 20px; margin: 0 0 14px; line-height: 1.5; }
#confirm-dialog p { color: var(--muted); font-size: 14px; line-height: 1.9; margin: 0 0 24px; }
.confirm-actions { justify-content: flex-end; }

@media (max-width: 650px) {
  .library { padding: 34px 25px 28px; }
  .book-header { gap: 10px; margin-bottom: 22px; align-items: flex-start; }
  .book-header h1 { font-size: clamp(24px, 5.2vw, 30px); letter-spacing: -.6px; }
  .book-header p { font-size: 11px; margin-top: 10px; }
  .book-header.has-cover { display: grid; grid-template-columns: 64px minmax(0, 1fr); column-gap: 16px; row-gap: 8px; align-items: center; }
  .has-cover .book-heading { display: contents; }
  .has-cover .reading-cover { grid-column: 1; grid-row: 1 / 3; width: 64px; height: 96px; }
  .has-cover .book-title-block { grid-column: 2; grid-row: 1; }
  .has-cover h1 { font-size: 21px; }
  .has-cover p { margin-top: 8px; }
  .has-cover .book-actions { grid-column: 2; grid-row: 2; margin-left: 0; }
  .book-actions { gap: 6px; flex-wrap: wrap; max-width: 100%; min-width: 0; }
  .book-actions .icon-button { width: 34px; height: 34px; }
  .book-actions svg { width: 18px; height: 18px; }
  .topics { grid-template-columns: 1fr; }
  .theme summary { min-height: 63px; padding: 18px 0; gap: 14px; }
  .theme-title { font-size: 18px; }
  .theme-number { font-size: 10px; }
  .theme > .theme-notes { padding-bottom: 20px; padding-left: 27px; }
  .note-link { min-height: 40px; font-size: 13px; padding: 9px 11px; }
  dialog { width: 100%; max-width: none; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  #add-book-dialog { width: 100%; }
  #organizer-dialog { width: 100%; height: 100dvh; }
  .organizer-layout { display: flex; flex-direction: column; }
  .organizer-sidebar { flex: 1; border-right: 0; }
  .organizer-panel { flex: 1; padding: 12px 20px 24px; }
  .organizer-empty { display: none; }
  #organizer-dialog:not(.show-theme) .organizer-panel { display: none; }
  #organizer-dialog.show-theme .organizer-sidebar { display: none; }
  #organizer-back { display: inline-block; }
  .organizer-theme-heading h3 { font-size: 18px; }
  #organizer-menu { inset: auto 0 0; width: 100%; max-width: none; max-height: 75dvh; border: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 12px 18px max(16px, env(safe-area-inset-bottom)); }
  #organizer-menu::backdrop { background: #00000025; }
  #organizer-menu button { min-height: 46px; }
  #organizer-menu-cancel { display: block !important; text-align: center !important; color: var(--muted); }
  #cover-dialog { width: 100%; height: 100dvh; }
  .cover-preview-body { padding: 12px; }
  .dialog-top { padding: 12px 18px; font-size: 10px; }
  .dialog-scroll { flex: 1; }
  #note-article { padding: 28px 23px; }
  #note-title { font-size: 29px; }
  #note-title-input { font-size: 22px; }
  .note-eyebrow { font-size: 9px; letter-spacing: .4px; }
  .note-eyebrow > span { font-size: 8px; }
  .note-lead { font-size: 17px; }
  .prose blockquote { padding: 15px 17px; }
  .dialog-bottom { padding: 13px 18px; padding-bottom: max(13px, env(safe-area-inset-bottom)); }
  .dialog-bottom > span { font-size: 9px; }
  .editor-tools { padding: 7px 13px; }
  .format-tools { gap: 1px; }
  .format-tools button { padding: 7px 8px; }
  .edit-actions { padding: 12px 18px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .edit-actions > span { max-width: 145px; }
  .save-button, .secondary-button { padding: 10px 14px; }
}

@media (max-width: 360px) {
  .library { padding-right: 20px; padding-left: 20px; }
  .book-header { flex-wrap: wrap; }
  .book-actions { margin-left: auto; }
  .theme summary { min-height: 56px; padding: 14px 0; }
}

@media (min-width: 651px) and (max-height: 820px) {
  .library { padding-top: 24px; padding-bottom: 16px; }
  .back-library { min-height: 32px; margin: -8px 0 6px; }
  .book-header { margin-bottom: 16px; }
  .theme summary { min-height: 58px; padding: 13px 0; }
  .theme > .theme-notes { padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
