/* Constellation — notebook styles */
:root {
  --bg: #ece8df;
  --bg-2: #e2ddd1;
  --panel: #faf8f3;
  --ink: #23272b;
  --muted: #6b6f73;
  --line: #d6d0c3;
  --accent: #2f6f73;
  --accent-ink: #fff;
  --danger: #b3412f;
  --shadow: 0 1px 2px rgba(40, 30, 10, .08), 0 8px 24px rgba(40, 30, 10, .10);
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hand: "Bradley Hand", Noteworthy, "Segoe Print", "Comic Sans MS", cursive;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* #app's black borders cover the status bar and home-indicator areas, so content needs no extra inset. */
  --inset-top: env(safe-area-inset-top, 0px);
  --inset-bot: env(safe-area-inset-bottom, 0px);
  --safe-top: 0px;
  --safe-bot: 0px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
/* Home Screen app: the status bar (time, battery) sits on a solid black band, with nothing drawn under it. */
#app { height: 100%; display: flex; flex-direction: column; box-sizing: border-box; background: var(--bg); border-top: var(--inset-top) solid #000; border-bottom: var(--inset-bot) solid #000; }

/* ---------- generic controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; min-height: 40px; }
.btn:hover { background: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 8px; display: inline-grid; place-items: center; color: var(--ink); flex: none; position: relative; }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); }
.icon-btn.on { background: var(--accent); color: #fff; }
.icon-btn[disabled] { opacity: .35; pointer-events: none; }
.icon-btn .badge { position: absolute; right: 4px; bottom: 4px; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid #fff; }
input[type=text], input[type=url], input[type=password], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
}
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 6px 4px; flex: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; z-index: 20; }
.topbar h1 { font-family: var(--serif); font-size: 20px; margin: 0 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title-input { border: 0; background: transparent; font-family: var(--serif); font-size: 18px; font-weight: 600; min-width: 60px; padding: 4px 6px; flex: 1; min-height: 36px; }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 52px; text-align: right; }

/* ---------- library ---------- */
.library { flex: 1; overflow: auto; padding: 24px clamp(14px, 4vw, 48px) calc(40px + var(--safe-bot)); }
.lib-head { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.lib-head .search { flex: 1; min-width: 180px; position: relative; }
.lib-head .search svg { position: absolute; left: 10px; top: 10px; width: 20px; height: 20px; color: var(--muted); }
.lib-head .search input { padding-left: 36px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 34px 26px; }
.book { display: grid; gap: 8px; text-align: left; background: none; border: 0; padding: 0; color: inherit; }
.book-cover { position: relative; aspect-ratio: 560 / 794; border-radius: 3px 8px 8px 3px; overflow: hidden; box-shadow: var(--shadow), inset 4px 0 0 rgba(0,0,0,.18); transition: transform .2s ease, box-shadow .2s ease; }
.book:hover .book-cover { transform: translateY(-3px) rotate(-.6deg); box-shadow: 0 16px 30px rgba(40, 30, 10, .22); }
.book-cover .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.book-cover::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 10px; background: linear-gradient(90deg, rgba(0,0,0,.25), rgba(255,255,255,.12) 50%, rgba(0,0,0,0)); }
.book-meta { display: flex; align-items: flex-start; gap: 4px; }
.book-meta .t { font-weight: 600; font-size: 14px; line-height: 1.25; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-meta .d { font-size: 12px; color: var(--muted); }
.book-meta .icon-btn { width: 32px; height: 32px; margin-top: -6px; }
.new-book { aspect-ratio: 560 / 794; border: 2px dashed var(--line); border-radius: 8px; display: grid; place-items: center; color: var(--muted); background: rgba(255,255,255,.35); }
.new-book svg { width: 34px; height: 34px; margin: 0 auto 6px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
.search-results { display: grid; gap: 8px; max-width: 760px; }
.search-hit { display: block; padding: 12px 14px; background: var(--panel); border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: inherit; }
.search-hit b { display: block; font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.search-hit mark { background: #ffe58a; }

/* ---------- menus & popovers ---------- */
.menu { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; display: grid; }
.menu button { display: flex; gap: 10px; align-items: center; border: 0; background: none; padding: 9px 10px; border-radius: 6px; text-align: left; min-height: 40px; }
.menu button:hover { background: rgba(0,0,0,.06); }
.menu button.danger { color: var(--danger); }
.menu button svg { width: 18px; height: 18px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.popover { position: fixed; z-index: 55; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; display: grid; gap: 8px; max-width: min(340px, 94vw); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.swatch input[type=color] { opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.swatch.custom { background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); position: relative; overflow: hidden; }
.sizes { display: flex; gap: 6px; }
.sizes button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; }
.sizes button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.sizes i { display: block; border-radius: 50%; background: var(--ink); }
.toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; min-height: 36px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 18, 12, .35); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.3); width: min(440px, 100%); max-height: min(90vh, 900px); display: flex; flex-direction: column; }
.modal.wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; padding: 10px 10px 4px 18px; }
.modal-head h2 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 8px 18px 18px; overflow: auto; display: grid; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 9px; }
.tabs button { flex: 1; border: 0; background: none; border-radius: 6px; padding: 7px; min-height: 36px; }
.tabs button.on { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.pick-list { display: grid; gap: 2px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px; }
.pick-list button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; display: flex; gap: 8px; }
.pick-list button:hover, .pick-list button.on { background: rgba(47, 111, 115, .12); }
.pick-list .lvl2 { padding-left: 26px; } .pick-list .lvl3 { padding-left: 42px; }
.pick-list small { color: var(--muted); margin-left: auto; }
.cover-preview { width: 150px; aspect-ratio: 560/794; position: relative; border-radius: 3px 6px 6px 3px; overflow: hidden; box-shadow: var(--shadow); flex: none; }
.cover-preview .page { transform-origin: 0 0; position: absolute; }
.cover-form { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.cover-form .fields { flex: 1; min-width: 220px; display: grid; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(24px + var(--inset-bot)); transform: translate(-50%, 30px); background: #23272b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- pages (shared by editor / reader / print) ---------- */
.page { width: 560px; height: 794px; position: relative; overflow: hidden; flex: none; background: var(--paper, #fbf8f1); color: #222; }
.page.paper[data-template=lined] { background-image: linear-gradient(to bottom, transparent 27px, #c9d6e3 27px, #c9d6e3 28px); background-size: 100% 28px; background-position: 0 56px; background-repeat: repeat-y; }
.page.paper[data-template=lined]::before { content: ""; position: absolute; left: 40px; top: 0; bottom: 0; width: 1px; background: #e7a9a3; }
.page.paper[data-template=grid] { background-image: linear-gradient(#dde3ea 1px, transparent 1px), linear-gradient(90deg, #dde3ea 1px, transparent 1px); background-size: 20px 20px; background-position: 0 0; }
.page.paper[data-template=dots] { background-image: radial-gradient(circle, #b9c0c8 1.1px, transparent 1.3px); background-size: 20px 20px; background-position: 10px 10px; }
.page.paper[data-template=cornell]::before { content: ""; position: absolute; left: 150px; top: 56px; bottom: 120px; width: 1px; background: #c9b8a6; }
.page.paper[data-template=cornell]::after { content: ""; position: absolute; left: 0; right: 0; bottom: 120px; height: 1px; background: #c9b8a6; }
.page-num { position: absolute; bottom: 26px; left: 0; right: 0; text-align: center; font: 12px var(--serif); color: #8a8378; pointer-events: none; }

.pg-text { position: absolute; inset: 56px 52px 64px; overflow: hidden; outline: none; }
.pg-items { position: absolute; inset: 0; pointer-events: none; }
.pg-lines, .pg-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.pg-ink .hl { opacity: .35; mix-blend-mode: multiply; }

/* rich text typography — 28px rhythm matches the ruled template */
.rt { font-family: var(--serif); font-size: 17px; line-height: 28px; word-wrap: break-word; overflow-wrap: anywhere; }
.rt > :first-child { margin-top: 0; }
.rt p, .rt div { margin: 0; }
.rt h1 { font-size: 28px; line-height: 42px; margin: 0 0 14px; font-weight: 600; letter-spacing: -.01em; }
.rt h2 { font-size: 21px; line-height: 28px; margin: 14px 0 0; font-weight: 600; }
.rt h3 { font-size: 17px; line-height: 28px; margin: 0; font-weight: 700; font-style: italic; }
.rt ul, .rt ol { margin: 0; padding-left: 26px; }
.rt ul.checklist { list-style: none; padding-left: 4px; }
.rt ul.checklist li { position: relative; padding-left: 28px; }
.rt ul.checklist li::before { content: ""; position: absolute; left: 0; top: 6px; width: 15px; height: 15px; border: 1.6px solid #555; border-radius: 3px; background: #fff; cursor: pointer; }
.rt ul.checklist li.done::before { background: var(--accent) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M3.5 8.5l3 3 6-7" fill="none" stroke="white" stroke-width="2"/></svg>') center/12px no-repeat; border-color: var(--accent); }
.rt ul.checklist li.done { color: #888; text-decoration: line-through; }
.rt blockquote { margin: 0; padding-left: 16px; border-left: 3px solid #c9b8a6; color: #555; font-style: italic; }
.rt pre, .rt code { font-family: var(--mono); font-size: 14px; background: rgba(0,0,0,.05); border-radius: 4px; }
.rt pre { padding: 0 10px; white-space: pre-wrap; margin: 0; }
.rt code { padding: 1px 4px; }
.rt hr { border: 0; border-top: 1px solid #bbb; margin: 13px 0 14px; }
.rt a { color: #1f5f8b; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.rt a[href^="#/"] { color: #7a4a14; text-decoration-style: dotted; }
.rt img { max-width: 100%; }
.rt font[size="1"] { font-size: 11px; } .rt font[size="2"] { font-size: 14px; } .rt font[size="3"] { font-size: 17px; }
.rt font[size="4"] { font-size: 21px; } .rt font[size="5"] { font-size: 26px; } .rt font[size="6"] { font-size: 34px; line-height: 42px; } .rt font[size="7"] { font-size: 44px; line-height: 56px; }
.font-hand, .rt .f-hand { font-family: var(--hand); }
.font-sans, .rt .f-sans { font-family: var(--sans); }
.font-serif { font-family: var(--serif); }
.font-mono, .rt .f-mono { font-family: var(--mono); }

/* items */
.item { position: absolute; pointer-events: auto; }
.item img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-select: none; }
.item video { width: 100%; height: 100%; background: #000; border-radius: 6px; display: block; object-fit: contain; }
.it-audio { background: #f2eee6; border: 1px solid #d9d1c2; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.it-audio audio { width: 100%; height: 36px; }
.audio-name { font-size: 13px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-ph { width: 100%; height: 100%; display: grid; place-items: center; text-align: center; background: #eee; color: #666; border: 1px dashed #aaa; border-radius: 6px; }
.it-shape .shape-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.shape-text { position: absolute; inset: 8%; display: flex; flex-direction: column; justify-content: center; text-align: center; font-size: 15px; line-height: 1.3; outline: none; overflow: hidden; }
.it-textbox { border-radius: 4px; }
.tb-content { width: 100%; height: 100%; padding: 4px 6px; overflow: hidden; outline: none; }
.tb-content.font-hand { font-size: 22px; line-height: 28px; }

/* ---------- contents page ---------- */
.toc-body { position: absolute; inset: 56px 52px 64px; font-family: var(--serif); }
.toc-title { font-size: 30px; font-weight: 600; margin: 0 0 18px; letter-spacing: .02em; }
.toc-cont { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: #8a8378; margin-bottom: 16px; }
.toc-entry { display: flex; align-items: baseline; gap: 6px; text-decoration: none; color: inherit; min-height: 28px; line-height: 28px; font-size: 16px; }
.toc-entry[data-level="1"] { font-weight: 600; margin-top: 6px; }
.toc-entry[data-level="2"] { padding-left: 20px; }
.toc-entry[data-level="3"] { padding-left: 40px; font-size: 15px; color: #555; }
.toc-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 78%; }
.toc-dots { flex: 1; border-bottom: 1.5px dotted #aaa; transform: translateY(-5px); min-width: 12px; }
.toc-num { font-variant-numeric: tabular-nums; }
.toc-entry:hover .toc-text { text-decoration: underline; }
.toc-empty { color: #8a8378; font-style: italic; line-height: 1.5; }

/* ---------- cover ---------- */
.page.cover { background: var(--cover); color: var(--cover-ink); display: flex; flex-direction: column; }
.page.cover[data-pattern=linen] { background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 1px, transparent 1px 3px); }
.page.cover[data-pattern=dots] { background-image: radial-gradient(rgba(255,255,255,.14) 1.4px, transparent 1.6px); background-size: 18px 18px; }
.page.cover[data-pattern=stripes] { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.07) 0 14px, transparent 14px 28px); }
.page.cover[data-pattern=leather] { background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.12), transparent 60%), radial-gradient(ellipse at 80% 90%, rgba(0,0,0,.25), transparent 60%); }
.page.cover[data-pattern=frame]::before { content: ""; position: absolute; inset: 26px; border: 2px solid currentColor; opacity: .55; border-radius: 4px; pointer-events: none; }
.cover-img { position: absolute; inset: 0; background-size: cover; background-position: center; }
.page.cover[data-layout=framed] .cover-img { inset: 230px 70px 150px; border-radius: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.25); background-size: cover; }
.page.cover[data-layout=cover] .cover-text { background: linear-gradient(to bottom, rgba(0,0,0,.45), transparent); }
.cover-text { position: relative; padding: 90px 60px 40px; display: grid; gap: 14px; text-align: center; }
.cover-title { font-size: 46px; line-height: 1.1; font-weight: 600; letter-spacing: .01em; text-wrap: balance; }
.cover-sub { font-size: 20px; opacity: .85; font-style: italic; }
.cover-author { position: absolute; left: 0; right: 0; top: 650px; font-size: 17px; letter-spacing: .18em; text-transform: uppercase; opacity: .85; }
.page.cover[data-layout=framed] .cover-text { padding-top: 70px; }

/* ---------- editor ---------- */
.toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; z-index: 15; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar select { width: auto; min-height: 36px; padding: 4px 6px; }
.toolbar.fmt { background: #f4f1ea; }
.toolbar .color-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.editor-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 18px 0 calc(80px + var(--safe-bot)); }
.page-stack { display: grid; justify-content: center; gap: 22px; }
.page-frame { position: relative; box-shadow: var(--shadow); border-radius: 2px; }
.page-frame > .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.page-frame.active { box-shadow: 0 0 0 2px rgba(47,111,115,.45), var(--shadow); }
.page-tools { position: absolute; right: -2px; top: 100%; display: flex; gap: 2px; padding-top: 2px; opacity: .85; }
.page-tools .icon-btn { width: 34px; height: 34px; }
.page-tools .icon-btn svg { width: 18px; height: 18px; }
.page-label { position: absolute; left: 0; top: 100%; padding-top: 9px; font-size: 12px; color: var(--muted); }
.overflow-flag { position: absolute; right: 8px; bottom: 8px; background: #b3412f; color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 10px; pointer-events: none; z-index: 5; }
.cover-frame, .toc-frame { cursor: pointer; }
.cover-frame::after, .toc-frame::after { content: attr(data-hint); position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); background: rgba(0,0,0,.65); color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 13px; opacity: 0; transition: .2s; pointer-events: none; white-space: nowrap; }
.cover-frame:hover::after, .toc-frame:hover::after { opacity: 1; }
.add-page-btn { justify-self: center; }

/* modes: which layer receives pointer input */
.page-frame .pg-text { pointer-events: none; }
.mode-text .page-frame .pg-text { pointer-events: auto; cursor: text; }
.mode-text .page-frame .pg-items .item { pointer-events: none; }
.mode-text .page-frame .pg-items .it-video, .mode-text .page-frame .pg-items .it-audio { pointer-events: auto; }
.mode-select .page-frame .pg-items .item { cursor: move; }
.mode-select .page-frame .pg-lines .line-hit { pointer-events: stroke; cursor: move; }
.mode-select .page-frame .pg-lines .line-item * { pointer-events: none; }
.mode-select .page-frame .pg-lines .line-item .line-hit { pointer-events: stroke; }
.ink-capture { position: absolute; inset: 0; z-index: 4; display: none; touch-action: pan-x pan-y pinch-zoom; }
.mode-ink .ink-capture, .mode-shape .ink-capture { display: block; cursor: crosshair; }
.pencil-strict .ink-capture { touch-action: pan-x pan-y pinch-zoom; }
.no-pencil-only.mode-ink .ink-capture, .no-pencil-only.mode-shape .ink-capture { touch-action: none; }
.mode-ink .page-frame .pg-items .item, .mode-shape .page-frame .pg-items .item { pointer-events: none; }
.sel-box { position: absolute; border: 1.5px dashed var(--accent); pointer-events: none; z-index: 6; }
.sel-box.items { border-style: solid; }
.handle { position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); pointer-events: auto; z-index: 7; touch-action: none; }
.handle.br { right: -10px; bottom: -10px; cursor: nwse-resize; }
.handle.pt { margin: -9px 0 0 -9px; cursor: move; }
.item.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.item.editing { cursor: text !important; }
.item.drop-target { outline: 2px dashed #e08a1e; outline-offset: 3px; }
.lasso-path { fill: rgba(47,111,115,.08); stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; }
.float-bar { position: absolute; z-index: 9; display: flex; gap: 2px; background: #23272b; color: #fff; border-radius: 10px; padding: 3px; box-shadow: var(--shadow); transform: translate(-50%, -100%); white-space: nowrap; }
.float-bar button { border: 0; background: none; color: #fff; padding: 7px 10px; border-radius: 7px; font-size: 13px; display: flex; gap: 6px; align-items: center; min-height: 36px; }
.float-bar button:hover { background: rgba(255,255,255,.14); }
.float-bar svg { width: 16px; height: 16px; }
.uploading { position: fixed; left: 50%; top: calc(70px + var(--inset-top)); transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; z-index: 70; box-shadow: var(--shadow); font-size: 14px; }
.uploading progress { width: 160px; vertical-align: middle; margin-left: 8px; }
.page-list { display: grid; gap: 4px; max-height: 60vh; overflow: auto; }
.page-list .pl-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.page-list .pl-row .n { width: 28px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.page-list .pl-row .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-list .icon-btn { width: 34px; height: 34px; }

/* ---------- reader ---------- */
.reader { flex: 1; position: relative; overflow: hidden; background: radial-gradient(ellipse at center, #4a4f52, #2a2d30); user-select: none; -webkit-user-select: none; touch-action: pan-y pinch-zoom; }
.reader.light { background: radial-gradient(ellipse at center, #e9e4d9, #cfc8b9); }
.reader-bar { position: absolute; left: 0; right: 0; top: 0; z-index: 30; display: flex; gap: 6px; align-items: center; padding: 6px 10px; background: #000; color: #fff; transition: opacity .25s, transform .25s; }
.reader-bar .icon-btn { color: #fff; }
.reader-bar .icon-btn:hover { background: rgba(255,255,255,.14); }
.reader-bar h1 { flex: 1; font: 600 16px var(--serif); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-foot { position: absolute; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 16px calc(12px + var(--safe-bot)); display: flex; align-items: center; gap: 12px; color: #fff; background: #000; transition: opacity .25s, transform .25s; }
.reader-foot input[type=range] { flex: 1; accent-color: #fff; }
.reader-foot span { font-size: 13px; min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }
.reader.chrome-hidden .reader-bar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.reader.chrome-hidden .reader-foot { opacity: 0; transform: translateY(100%); pointer-events: none; }
.stage { position: absolute; left: 50%; top: 50%; perspective: 2600px; }
.stage .slot, .stage .leaf { position: absolute; top: 0; width: 560px; height: 794px; }
.stage .slot > .page, .leaf-face > .page { box-shadow: none; }
.stage .slot { box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.stage .slot.empty { box-shadow: none; }
.stage.spread .slot.left::after { content: ""; position: absolute; inset: 0 0 0 auto; width: 40px; background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.16)); pointer-events: none; }
.stage.spread .slot.right::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 40px; background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(0,0,0,0)); pointer-events: none; }
.curl { position: absolute; top: 0; width: 560px; height: 794px; z-index: 10; --curl-shadow: .3; }
.curl > div { position: absolute; inset: 0; }
.curl-front, .curl-flap { overflow: visible; }
.curl-front > .page, .curl-flap > .page, .curl-flap > .blank-back { position: absolute; left: 0; top: 0; }
.curl-flap { transform-origin: 0 0; width: 560px; height: 794px; will-change: transform, clip-path; }
.curl-flap > .page { box-shadow: none; }
.curl-flapwrap { filter: drop-shadow(-4px 2px 10px rgba(0,0,0,var(--curl-shadow))); pointer-events: none; }
.curl-flapshade, .curl-under { pointer-events: none; }
.curl-strip { position: absolute; left: 0; top: 0; height: 3000px; transform-origin: 0 0; pointer-events: none; }
.curl-strip.s-under { background: linear-gradient(90deg, rgba(0,0,0,.38), rgba(0,0,0,.12) 35%, rgba(0,0,0,0)); }
.curl-strip.s-flap { background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(255,255,255,.18) 18%, rgba(255,255,255,0) 45%, rgba(0,0,0,.08)); }
.curl-strip.s-front { background: linear-gradient(90deg, rgba(0,0,0,.16), rgba(0,0,0,0)); }
.board { position: absolute; top: 0; width: 560px; height: 794px; z-index: 10; transform-style: preserve-3d; transform-origin: 0 50%; will-change: transform; --board-lift: 0; }
.board-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; border-radius: 0 6px 6px 0; box-shadow: 0 calc(8px + 30px * var(--board-lift)) calc(18px + 50px * var(--board-lift)) rgba(0,0,0,.45); }
.board-face > .page { box-shadow: none; }
.board-face.back { transform: rotateY(180deg); border-radius: 6px 0 0 6px; }
.board-shade { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.board-face.front .board-shade { background: linear-gradient(90deg, rgba(0,0,0,.15), rgba(0,0,0,.7)); }
.board-face.back .board-shade { background: linear-gradient(270deg, rgba(0,0,0,.15), rgba(0,0,0,.7)); }
.board-edge { position: absolute; top: 0; right: -1px; width: 6px; height: 100%; transform-origin: 0 50%; transform: rotateY(90deg); background: linear-gradient(#e9e2d0, #cfc5ad); }
.blank-back { width: 560px; height: 794px; background: #f6f2e8; box-shadow: inset 0 0 40px rgba(0,0,0,.06); }
.reader .page a, .reader .page video, .reader .page audio { pointer-events: auto; }
.reader .pg-items .item { pointer-events: none; }
.reader .pg-items .it-video, .reader .pg-items .it-audio { pointer-events: auto; }
.reader .rt ul.checklist li::before { cursor: default; }
.jump-flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: rgba(255, 214, 102, .7); } 100% { background: transparent; } }

/* ---------- login ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 20px; }
.login form { background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); display: grid; gap: 14px; width: min(360px, 100%); }
.login h1 { font-family: var(--serif); margin: 0; }

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  @page { size: A5 portrait; margin: 0; }
  html, body { background: #fff !important; height: auto; }
  #app, #toast, .modal-back { display: none !important; }
  #print-root { display: block; }
  .print-sheet { width: 148mm; height: 210mm; overflow: hidden; position: relative; break-after: page; page-break-after: always; }
  .print-sheet:last-child { break-after: auto; page-break-after: auto; }
  .print-sheet > .page { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* accounts */
.topbar .brand { width: 30px; height: 30px; border-radius: 8px; margin-left: 4px; }
.topbar .grow { flex: 1; }
.account-btn { max-width: 40vw; }
.account-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) { .account-btn span { display: none; } }
.login-logo { width: 72px; height: 72px; border-radius: 18px; justify-self: center; box-shadow: 0 6px 20px rgba(7, 25, 38, .35); }
.login h1 { text-align: center; }
.user-list { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.user-row .who { flex: 1; min-width: 0; }
.user-row .who b { display: block; }
.user-row .who small { color: var(--muted); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--accent); color: #fff; vertical-align: 2px; margin-left: 6px; }
