:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --line: #2a3542;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3d9a7a;
  --book-w: min(920px, 92vw);
  --book-h: min(78vh, 680px);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  /* System fonts so Android offline works after leaving the app (no Google Fonts) */
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 0% 0%, #1e3a32 0%, transparent 50%),
    radial-gradient(800px 400px at 100% 100%, #243044 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; padding: 28px; }
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.6rem;
  margin: 0;
  letter-spacing: -0.02em;
}
.brand-logo {
  display: block;
  width: min(280px, 78vw);
  height: auto;
  background: #fff;
  border-radius: 16px;
  margin: 0 0 8px;
}
.brand-logo-bar {
  width: 150px;
  border-radius: 10px;
  margin: 0;
}
.hero { max-width: 520px; margin: 8vh auto 24px; }
.hero h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.15;
  margin: 8px 0 12px;
}
.lead, .muted { color: var(--muted); }
.card-form {
  max-width: 420px;
  margin: 0 auto;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  display: grid;
  gap: 12px;
}
label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
input {
  font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #121820; color: var(--text);
}
button {
  font: inherit; font-weight: 700; border: none; border-radius: 8px;
  padding: 10px 14px; background: var(--accent); color: #04140f; cursor: pointer;
}
button.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 600;
}
button.open-btn {
  background: #e8eef4; color: #0f1419; border: none; font-weight: 700;
}
button:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error { color: #f0a0a0; min-height: 1.2em; }
.bar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.hint-sm { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.4; }
.password-rules {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #121820;
}
.password-rules-title {
  margin: 0 0 8px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
}
.password-rules ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.password-rules li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .8rem;
  color: #d48a8a;
  line-height: 1.35;
}
.password-rules li .rule-icon {
  flex: 0 0 1em;
  width: 1em;
  text-align: center;
  font-weight: 700;
}
.password-rules li .rule-icon::before { content: "✗"; color: #e07070; }
.password-rules li.ok { color: #9eb0c0; }
.password-rules li.ok .rule-icon::before {
  content: "✓";
  color: var(--accent);
}
.break-all { word-break: break-all; }
.oauth-row { display: grid; gap: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
a.oauth-btn {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; font-weight: 600; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  background: transparent;
}
.library-toolbar { max-width: 800px; margin: 0 0 14px; }
.ebook-select-label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
select {
  font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: #121820; color: var(--text);
  width: 100%; max-width: 800px;
}
.security-panel { max-width: 520px; margin: 18px 0; }
.security-panel h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
.totp-secret {
  display: block; padding: 10px 12px; border-radius: 8px;
  background: #121820; border: 1px solid var(--line);
  letter-spacing: .06em; word-break: break-all; font-size: .9rem;
}
.book-list { display: grid; gap: 12px; max-width: 800px; }
.book {
  border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  background: var(--panel); display: flex; justify-content: space-between; gap: 12px; align-items: center;
  flex-wrap: wrap;
}
.book h3 { margin: 0 0 4px; font-size: 1.05rem; }
.book.dimmed { opacity: .45; }
.offline-badge {
  display: inline-block;
  margin-top: 6px;
  font-size: .75rem;
  color: var(--accent);
}
.secure-warning {
  max-width: 800px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #c97b3a;
  background: #3a2a14;
  color: #f0c090;
  font-size: .88rem;
  line-height: 1.45;
}
.install-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.install-banner p { margin: 0; font-size: .9rem; }

.stage {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 110px);
  padding-bottom: 12px;
}
.flip-scene {
  position: relative;
  width: var(--book-w);
  perspective: 2200px;
}
.book-shadow {
  position: absolute;
  left: 8%; right: 8%; bottom: -18px; height: 40px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), transparent 70%);
  filter: blur(6px);
  pointer-events: none;
  z-index: 0;
}
.flipbook {
  position: relative;
  width: 100%;
  height: var(--book-h);
  transform-style: preserve-3d;
  background: #1a1510;
  border-radius: 4px 10px 10px 4px;
  box-shadow:
    0 24px 60px rgba(0,0,0,.5),
    inset 0 0 0 1px rgba(255,255,255,.06);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  cursor: grab;
}
.flipbook:active { cursor: grabbing; }
.sheet {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}
.sheet-under {
  z-index: 1;
  background: #f4f0e8;
}
.sheet-under img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f4f0e8;
  display: block;
}
.sheet-flip {
  z-index: 4;
  transform-origin: left center;
  transition: transform 0s linear;
  transform: rotateY(0deg);
}
.sheet-flip.flipping {
  transition: transform 0.6s cubic-bezier(0.22, 0.72, 0.25, 1);
}
.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #f4f0e8;
  overflow: hidden;
}
.face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f4f0e8;
  display: block;
  pointer-events: none;
}
.face-front {
  z-index: 2;
  box-shadow: inset -12px 0 24px rgba(0,0,0,.06);
}
.face-back {
  transform: rotateY(180deg);
  z-index: 1;
  box-shadow: inset 12px 0 24px rgba(0,0,0,.08);
}
.face-back img {
  transform: scaleX(-1);
}
.page-shine {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 42%, rgba(255,255,255,.2) 50%, transparent 58%);
  opacity: .4;
  mix-blend-mode: soft-light;
}
.page-shine.back { opacity: .25; }

.watermark {
  pointer-events: none;
  position: absolute; inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.watermark.diagonal .wm-text,
.watermark.diagonal .wm-logo {
  transform: rotate(-24deg);
}
.wm-logo {
  max-width: 18%;
  max-height: 18%;
  object-fit: contain;
  margin-bottom: 12px;
}
.wm-text {
  font-size: clamp(14px, 2vw, 22px);
  letter-spacing: .04em;
  text-align: center;
  padding: 0 24px;
  max-width: 90%;
  white-space: pre-wrap;
}
.watermark.tile .wm-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  gap: 48px;
  transform: rotate(-24deg) scale(1.2);
  opacity: 0.85;
}
.page-msg {
  position: absolute; inset: 0; z-index: 9;
  display: grid; place-items: center;
  background: rgba(15,20,25,.9); padding: 24px; text-align: center;
}
.reader-shield {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 12;
  place-items: center;
  align-content: center;
  gap: 8px;
  background: rgba(15, 20, 25, 0.72);
  backdrop-filter: blur(48px) saturate(0.2);
  -webkit-backdrop-filter: blur(48px) saturate(0.2);
  color: var(--text);
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
.reader-shield p {
  margin: 0;
  font-family: "Source Serif 4", serif;
  font-size: 1.25rem;
}
.reader-shield span {
  color: var(--muted);
  font-size: .9rem;
}
body.reader-shielded #flipbook {
  filter: blur(80px) brightness(0.15) contrast(0.6) saturate(0);
}
body.reader-shielded #flipbook .sheet img {
  opacity: 0;
}
body.reader-shielded #reader-shield {
  display: grid;
}
body.reader-shielded #watermark {
  opacity: 0;
}
.hint { text-align: center; margin: 14px 0 0; font-size: .85rem; }
.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;
}

#reader.screen {
  padding: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  background: #0b0f14;
  overflow: hidden;
}
.reader-shell {
  display: grid;
  grid-template-columns: 272px 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns .28s ease;
}
body.toc-collapsed .reader-shell,
body.zen .reader-shell {
  grid-template-columns: 1fr;
}
.reader-toc {
  background: linear-gradient(180deg, rgba(18, 24, 32, .92), rgba(11, 15, 20, .96));
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  color: #c5d0da;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,.06);
  z-index: 5;
}
body.toc-collapsed .reader-toc,
body.zen .reader-toc {
  display: none;
}
.toc-book {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 18px 16px 14px;
  flex-shrink: 0;
}
.toc-cover {
  width: 44px;
  height: 58px;
  border-radius: 6px;
  flex-shrink: 0;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--accent) 55%, #1a2a28), #1a222c);
  box-shadow: 0 8px 18px rgba(0,0,0,.35);
}
.toc-book-meta { min-width: 0; }
.toc-title {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  color: #f2f6f9;
  line-height: 1.3;
}
.toc-sub {
  margin: 4px 0 0;
  font-size: .7rem;
  color: var(--muted);
}
.toc-progress {
  margin: 8px 0 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--accent);
}
.toc-heading {
  margin: 0;
  padding: 8px 16px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #6f8194;
  flex-shrink: 0;
}
.toc-nav {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.32) transparent;
}
.toc-nav::-webkit-scrollbar {
  width: 8px;
}
.toc-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.28);
  border-radius: 8px;
}
.toc-nav::-webkit-scrollbar-track {
  background: transparent;
}
.toc-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #c5d0da;
  font-weight: 500;
  font-size: .82rem;
  padding: 8px 10px;
  cursor: pointer;
}
.toc-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc-marks {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.toc-mark {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.toc-mark.note { background: #74c0fc; }
.toc-mark.bookmark { background: var(--accent); }
.toc-mark.highlight { background: #ffe066; }
.toc-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.toc-item.active {
  color: #fff;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  box-shadow: inset 2px 0 0 var(--accent);
}

.reader-main {
  position: relative;
  display: grid;
  /* progress, top chrome, stage, bottom chrome — 1fr must be the page, not the header */
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: #0b0f14;
}
.reader-progress {
  height: 2px;
  background: rgba(255,255,255,.06);
  z-index: 8;
}
#reader-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .25s ease;
}
.filmstrip {
  position: relative;
  z-index: 7;
  transition: opacity .35s ease, transform .35s ease;
}
body.chrome-idle:not(.zen) .filmstrip {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}
body.chrome-idle:not(.zen) .reader-bottom.filmstrip {
  transform: translateY(4px);
}
body.zen .filmstrip,
body.zen .reader-zoom {
  opacity: 0;
  pointer-events: none;
}
body.chrome-hold:not(.zen) .filmstrip {
  opacity: 1 !important;
  pointer-events: auto !important;
  transform: none !important;
}
.reader-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  background: linear-gradient(180deg, rgba(11,15,20,.92), rgba(11,15,20,.35) 70%, transparent);
  color: #e8eef4;
  min-width: 0;
}
.reader-top-left, .reader-top-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.reader-home {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: #e8eef4;
  font-weight: 600;
  font-size: .82rem;
  padding: 6px 10px;
  border-radius: 999px;
}
.reader-home:hover { background: rgba(255,255,255,.08); }
.reader-crumb {
  font-size: .82rem;
  color: #9eb0c0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.reader-icon-btn {
  background: rgba(255,255,255,.04);
  color: #e8eef4;
  border: 1px solid rgba(255,255,255,.06);
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
}
.reader-icon-btn:hover { background: rgba(255,255,255,.1); }
.reader-icon-btn.active {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.reader-icon-btn.active svg { fill: currentColor; }

#reader .stage {
  position: relative;
  display: block;
  min-height: 0;
  height: 100%;
  padding: 0 0 8px;
  background: #0b0f14;
  overflow: hidden;
}
#reader .flip-scene {
  width: 100%;
  height: 100%;
  min-height: 0;
  perspective: 2600px;
}
#reader .book-shadow { display: none; }
#reader .flipbook {
  width: 100%;
  max-width: none;
  height: 100%;
  min-height: 0;
  border-radius: 0;
  box-shadow: none;
  background: #f4f0e8;
}
#reader .sheet-under img,
#reader .face img {
  background: #f4f0e8;
}
.page-hl {
  pointer-events: none;
  position: absolute;
  z-index: 6;
  mix-blend-mode: multiply;
  opacity: .4;
  inset: 0;
}
.page-hl.region {
  inset: auto;
  border-radius: 2px;
}
.page-stickies {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#sheet-flip.flipping ~ .page-stickies {
  opacity: 0;
  pointer-events: none;
}
body.hl-armed .page-stickies {
  opacity: .22;
  pointer-events: none;
}
.sticky-note {
  pointer-events: auto;
  position: absolute;
  width: min(158px, 42%);
  min-height: 108px;
  padding: 10px 10px 12px;
  border: 0;
  border-radius: 2px 10px 10px 3px;
  box-shadow: 2px 5px 12px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.45);
  color: #2c2618;
  font: 600 12px/1.4 inherit;
  text-align: left;
  cursor: grab;
  overflow: hidden;
  transform-origin: top left;
  touch-action: none;
}
.sticky-note:hover { filter: brightness(1.03); }
.sticky-note.active {
  box-shadow: 2px 8px 18px rgba(0,0,0,.38), 0 0 0 2px rgba(255,255,255,.55);
  z-index: 11;
}
.sticky-note.dragging {
  cursor: grabbing;
  z-index: 11;
  transform: scale(1.03) rotate(-1.2deg);
}
.sticky-preview {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  color: inherit;
  font-weight: 600;
}
.sticky-preview b { font-weight: 800; }
.sticky-preview s { text-decoration: line-through; }
.reader-toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 16;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12,16,22,.92);
  color: #e8eef4;
  font-size: .8rem;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0,0,0,.4);
  pointer-events: none;
}
.note-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.hl-draw {
  position: absolute;
  inset: 0;
  z-index: 7;
  cursor: crosshair;
  touch-action: none;
}
.hl-draw[hidden] { display: none !important; }
.hl-draw-rect {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  pointer-events: none;
}
.reader-zoom {
  position: absolute;
  right: 14px;
  bottom: 18px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity .3s ease;
}
body.chrome-idle:not(.zen) .reader-zoom,
body.zen .reader-zoom { opacity: 0; pointer-events: none; }
body.chrome-hold:not(.zen) .reader-zoom { opacity: 1; pointer-events: auto; }
.reader-zoom button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  background: rgba(12,16,22,.78);
  color: #e8eef4;
  font-size: 1.05rem;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.08);
}
.reader-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 12px;
  background: linear-gradient(0deg, rgba(11,15,20,.94), rgba(11,15,20,.28) 75%, transparent);
  color: #d5dee6;
}
.reader-nav {
  background: rgba(255,255,255,.05);
  color: #e8eef4;
  font-weight: 600;
  font-size: .82rem;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.06);
}
.reader-nav:hover { background: rgba(255,255,255,.1); }
.reader-nav:disabled { opacity: .3; }
.reader-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}
.reader-tool {
  background: rgba(255,255,255,.05);
  color: #d5dee6;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.06);
}
.reader-tool:hover,
.reader-tool.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: #fff;
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.page-ind {
  font-size: .78rem;
  color: #8b9aab;
  min-width: 4.6em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.goto-label input {
  width: 3.6rem;
  padding: 6px 8px;
  font-size: .8rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(20, 28, 36, .9);
  color: #e8eef4;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.goto-label input::-webkit-outer-spin-button,
.goto-label input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.hl-wrap { position: relative; }
.hl-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  padding: 12px;
  border-radius: 14px;
  background: #1c242e;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 16px 40px rgba(0,0,0,.55);
  z-index: 12;
}
.hl-hint {
  margin: 0 0 10px;
  font-size: .72rem;
  color: #8b9aab;
  line-height: 1.4;
}
.hl-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.hl-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.2);
}
.hl-swatch.selected { border-color: #fff; }

.note-card {
  position: absolute;
  right: 18px;
  bottom: 22px;
  z-index: 14;
  width: min(360px, calc(100% - 32px));
  padding: 14px;
  border-radius: 16px;
  background: #1c242e;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 20px 50px rgba(0,0,0,.55);
  display: grid;
  gap: 10px;
  color: #e8eef4;
}
.note-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.note-card h2 {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  font-family: inherit;
}
.note-format {
  display: flex;
  align-items: center;
  gap: 2px;
  width: max-content;
  padding: 3px;
  border-radius: 12px;
  background: #8d6a84;
}
.note-format button {
  width: 34px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #f7f1ea;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.note-format button:hover,
.note-format button.active {
  background: rgba(255,255,255,.18);
}
.note-format .fmt-i { font-style: italic; font-weight: 600; }
.note-format .fmt-u { text-decoration: underline; text-underline-offset: 2px; }
.note-format .fmt-s { text-decoration: line-through; }
.note-editor {
  width: 100%;
  min-height: 110px;
  max-height: 220px;
  overflow: auto;
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: #0c1116;
  color: #e8eef4;
  white-space: pre-wrap;
  word-break: break-word;
}
.note-editor:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
.note-editor[data-empty="1"]::before {
  content: attr(data-placeholder);
  color: #8b9aab;
}
.note-editor ul,
.note-editor ol {
  margin: 4px 0;
  padding-left: 1.25em;
}
.nb-form-meta { margin: 4px 0 0; color: #8b9aab; font-size: .75rem; }
.nb-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.nb-btn-primary {
  background: var(--accent);
  color: #04140f;
  font-weight: 700;
  padding: 8px 14px;
}
.nb-btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,.12);
  color: #c5d0da;
  font-weight: 600;
  padding: 8px 12px;
}
.nb-close {
  background: transparent;
  color: #8b9aab;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1;
  border-radius: 50%;
}
.nb-close:hover { background: rgba(255,255,255,.08); color: #fff; }

.toc-backdrop,
.nb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 20;
}
.nb-backdrop { z-index: 24; }

.nb-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  z-index: 26;
  background: linear-gradient(180deg, rgba(16,22,30,.98), rgba(11,15,20,.98));
  border-left: 1px solid rgba(255,255,255,.07);
  box-shadow: -18px 0 50px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  color: #e8eef4;
  transform: translateX(0);
}
.nb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}
.nb-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
}
.nb-search {
  display: block;
  padding: 0 16px 10px;
}
.nb-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: #0c1116;
  color: #e8eef4;
}
.nb-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 0 16px 12px;
  padding: 4px;
  background: rgba(255,255,255,.05);
  border-radius: 10px;
}
.nb-tab {
  background: transparent;
  color: #9eb0c0;
  font-weight: 600;
  font-size: .78rem;
  padding: 8px 4px;
  border-radius: 8px;
}
.nb-tab.active {
  background: var(--accent);
  color: #04140f;
}
.nb-body {
  overflow: auto;
  padding: 0 16px 20px;
  flex: 1;
}
.nb-empty {
  text-align: center;
  padding: 28px 12px;
  color: #8b9aab;
}
.nb-empty strong {
  display: block;
  color: #e8eef4;
  font-size: 1rem;
  margin-bottom: 6px;
}
.nb-empty p { margin: 0; font-size: .85rem; line-height: 1.45; }
.nb-list { display: grid; gap: 8px; }
.nb-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font-weight: 500;
}
.nb-item:hover { border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: rgba(255,255,255,.06); }
.nb-item-title { margin: 0; font-size: .88rem; color: #f2f6f9; }
.nb-item-meta { margin: 4px 0 0; font-size: .72rem; color: #8b9aab; }
.nb-item-del {
  background: transparent;
  color: #6f8194;
  padding: 0 6px;
  font-weight: 600;
  font-size: 1.1rem;
}
.nb-item-del:hover { color: #f0a0a0; }
.nb-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
}

@media (max-width: 860px) {
  .reader-shell { grid-template-columns: 1fr; }
  .reader-toc {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    height: 100%;
    max-height: 100dvh;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 10px 0 32px rgba(0,0,0,.45);
    z-index: 30;
    display: flex;
  }
  body.toc-collapsed .reader-toc { display: flex; }
  body.toc-open .reader-toc { transform: none; }
  body.zen .reader-toc { display: none; }
}

@media (max-width: 720px) {
  :root { --book-h: min(70vh, 520px); }
  .screen { padding: 16px; }
  #reader.screen { padding: 0; }
  .reader-crumb { max-width: 26vw; }
  .reader-nav { font-size: .75rem; padding: 8px 10px; }
  .note-card { right: 10px; left: 10px; width: auto; }
}

/* CSP-safe replacements for former inline styles */
.book-hint { font-size: .75rem; display: block; margin-top: 6px; }
.privacy-card { max-width: 640px; }
