:root {
  --bg: #F3F4F1;
  --surface: #FFFFFF;
  --surface-2: #F7F8F5;
  --surface-3: #ECEFEA;
  --line: rgba(22, 38, 30, 0.10);
  --line-strong: rgba(22, 38, 30, 0.2);
  --text: #17201B;
  --text-2: #56625B;
  --text-3: #8A958E;
  --accent: #1E5B4A;
  --accent-2: #2A7560;
  --accent-soft: rgba(30, 91, 74, 0.11);
  --accent-ink: #FFFFFF;
  --brass: #B08A3E;
  --danger: #C2352B;
  --danger-soft: rgba(194, 53, 43, 0.1);
  --workspace: #E3E6E1;
  --page-shadow: rgba(20, 30, 25, 0.13);
  --bar: rgba(250, 251, 249, 0.88);
  --scrim: rgba(10, 16, 13, 0.34);
  --toast: #1E2622;
  --toast-ink: #F2F5F3;
  --shadow-1: 0 1px 2px rgba(16, 24, 20, 0.07), 0 2px 8px rgba(16, 24, 20, 0.06);
  --shadow-2: 0 6px 16px rgba(16, 24, 20, 0.10), 0 18px 48px rgba(16, 24, 20, 0.14);
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-num: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --bar-h: 54px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121513; --surface: #1C201E; --surface-2: #181C1A; --surface-3: #272D2A;
    --line: rgba(220, 235, 226, 0.10); --line-strong: rgba(220, 235, 226, 0.2);
    --text: #E7ECE9; --text-2: #A3AFA8; --text-3: #6F7B74;
    --accent: #63C2A0; --accent-2: #86D4B8; --accent-soft: rgba(99, 194, 160, 0.15); --accent-ink: #0D211A;
    --brass: #D4B06A; --danger: #FF6B5E; --danger-soft: rgba(255, 107, 94, 0.14);
    --workspace: #0E1110; --page-shadow: rgba(0, 0, 0, 0.55); --bar: rgba(28, 32, 30, 0.88);
    --scrim: rgba(0, 0, 0, 0.5); --toast: #E7ECE9; --toast-ink: #121513;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 8px 20px rgba(0, 0, 0, 0.45), 0 20px 50px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121513; --surface: #1C201E; --surface-2: #181C1A; --surface-3: #272D2A;
  --line: rgba(220, 235, 226, 0.10); --line-strong: rgba(220, 235, 226, 0.2);
  --text: #E7ECE9; --text-2: #A3AFA8; --text-3: #6F7B74;
  --accent: #63C2A0; --accent-2: #86D4B8; --accent-soft: rgba(99, 194, 160, 0.15); --accent-ink: #0D211A;
  --brass: #D4B06A; --danger: #FF6B5E; --danger-soft: rgba(255, 107, 94, 0.14);
  --workspace: #0E1110; --page-shadow: rgba(0, 0, 0, 0.55); --bar: rgba(28, 32, 30, 0.88);
  --scrim: rgba(0, 0, 0, 0.5); --toast: #E7ECE9; --toast-ink: #121513;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 8px 20px rgba(0, 0, 0, 0.45), 0 20px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { touch-action: manipulation; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
button:disabled { cursor: default; opacity: 0.35; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic-empty { width: 22px; }

#app { position: fixed; inset: 0; overflow: hidden; }
#splash { position: fixed; inset: 0; display: grid; place-items: center; color: var(--text-2); font: 600 15px var(--font-ui); background: var(--bg); transition: opacity 0.3s; z-index: 5; }
body.ready #splash { opacity: 0; pointer-events: none; }

/* Buttons & controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 11px;
  background: var(--surface-3); color: var(--text); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn .ic { width: 19px; height: 19px; }
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: var(--text-2); flex: none;
  font-size: 20px; font-weight: 500; line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn.sm .ic { width: 19px; height: 19px; }
.icon-btn.xs { width: 26px; height: 26px; border-radius: 7px; }
.icon-btn.xs .ic { width: 16px; height: 16px; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 11px; padding: 2px; gap: 2px; flex: none; }
.seg-btn { display: inline-flex; align-items: center; gap: 5px; height: 34px; padding: 0 13px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.seg-btn .ic { width: 18px; height: 18px; }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.seg.small .seg-btn { height: 30px; padding: 0 11px; font-size: 12.5px; }
.seg.wrap { flex-wrap: wrap; }

.switch { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 46px; height: 28px; border-radius: 14px; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); transition: background 0.18s; position: relative; }
.switch-knob { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.18s; }
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track .switch-knob { transform: translateX(18px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { width: 100%; height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-size: 15px; -webkit-user-select: text; user-select: text; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { height: auto; padding: 10px 12px; line-height: 1.45; resize: vertical; }
.field.num { width: 72px; text-align: center; font-variant-numeric: tabular-nums; }
.field-label, .pick-label { display: block; font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin: 2px 0 -2px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.slider-wrap { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.slider { flex: 1; accent-color: var(--accent); height: 28px; }
.slider-val { min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13px; }

/* Overlays */
#overlays { position: fixed; inset: 0; pointer-events: none; z-index: 900; }
#overlays > * { pointer-events: auto; }
.pop-back { position: fixed; inset: 0; z-index: 900; }
.pop {
  position: fixed; z-index: 901; min-width: 180px; max-width: min(380px, calc(100vw - 20px)); overflow: auto;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow-2); padding: 6px;
  opacity: 0; transform: translateY(-4px) scale(0.985); transform-origin: top center; transition: opacity 0.14s, transform 0.14s;
  -webkit-user-select: none; user-select: none;
}
.pop.in { opacity: 1; transform: none; }
.pop-title { font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); padding: 8px 10px 6px; }
.menu { display: flex; flex-direction: column; min-width: 230px; }
.menu-item { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; text-align: left; font-size: 15px; color: var(--text); }
.menu-item .ic { width: 20px; height: 20px; color: var(--text-2); }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.menu-item.danger, .menu-item.danger .ic { color: var(--danger); }
.menu-label { flex: 1; }
.menu-hint { font-size: 12.5px; color: var(--text-3); }
.menu-check { color: var(--accent) !important; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 8px; }
.menu-head { font-size: 12px; color: var(--text-3); font-weight: 600; padding: 8px 12px 4px; }

.sheet-back { position: fixed; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 0.18s; z-index: 910; }
.sheet-back.in { opacity: 1; }
.sheet {
  position: fixed; z-index: 911; left: 50%; top: 50%; width: min(540px, calc(100vw - 32px)); max-height: calc(100% - 40px);
  display: flex; flex-direction: column; background: var(--surface); color: var(--text); border-radius: 20px; box-shadow: var(--shadow-2);
  transform: translate(-50%, -48%) scale(0.98); opacity: 0; transition: opacity 0.18s, transform 0.18s;
}
.sheet.in { opacity: 1; transform: translate(-50%, -50%); }
.sheet.wide { width: min(900px, calc(100vw - 32px)); }
.sheet-alert { width: min(420px, calc(100vw - 32px)); }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px 14px 8px 22px; }
.sheet-title { flex: 1; margin: 0; font: 600 21px/1.2 var(--font-display); text-wrap: balance; }
.sheet-body { padding: 8px 22px 18px; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 12px 18px max(16px, var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-msg { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.5; }
@media (max-width: 600px) {
  .sheet, .sheet.wide { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: calc(100% - 24px - var(--safe-t)); border-radius: 20px 20px 0 0; transform: translateY(30px); }
  .sheet.in { transform: none; }
}
.prog { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.prog-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; border-radius: 4px; }
.prog-text { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; min-height: 18px; }
.file-card { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.file-card > .ic { width: 34px; height: 34px; color: var(--accent); }
.file-name { font-weight: 600; word-break: break-word; }
.file-size { font-size: 13px; color: var(--text-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0;
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 14px;
  background: var(--toast); color: var(--toast-ink); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-2);
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 950;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.error { background: var(--danger); color: #fff; }
.toast-btn { font-weight: 700; color: inherit; opacity: 0.9; text-decoration: underline; text-underline-offset: 3px; }

/* Colour picker */
.pop-cp { width: 300px; }
.cp { display: flex; flex-direction: column; gap: 10px; padding: 6px; }
.cp-tabs { display: flex; justify-content: center; }
.cp-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px; padding: 2px; }
.cp-sw { width: 100%; aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.cp-sw.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.cp-svwrap { position: relative; border-radius: 12px; overflow: hidden; touch-action: none; aspect-ratio: 44 / 26; }
.cp-sv { width: 100%; height: 100%; display: block; }
.cp-dot { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); pointer-events: none; }
.cp-huewrap { position: relative; height: 26px; border-radius: 13px; overflow: hidden; touch-action: none; }
.cp-hue { width: 100%; height: 100%; display: block; }
.cp-hdot { position: absolute; top: 2px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4); pointer-events: none; }
.cp-hexrow { display: flex; gap: 10px; align-items: center; }
.cp-prev { width: 42px; height: 42px; border-radius: 11px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); flex: none; }
.cp-hex { font-family: var(--font-num); text-transform: uppercase; }
.cp-sub { font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); }
.cp-custom { display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px; }
.cp-add { width: 100%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.cp-add .ic { width: 18px; height: 18px; }

/* Library */
.library { position: absolute; inset: 0; display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.lib-side {
  display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); border-right: 1px solid var(--line);
  padding: calc(18px + var(--safe-t)) 12px calc(14px + var(--safe-b)) max(12px, var(--safe-l));
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark { display: inline-flex; }
.brand-name { font: 600 23px/1 var(--font-display); letter-spacing: -0.01em; }
.brand-pro { font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brass); border: 1px solid currentColor; border-radius: 6px; padding: 2px 5px 1px; }
.side-nav { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.side-link { display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 0 10px; border-radius: 11px; color: var(--text); text-align: left; font-size: 15px; width: 100%; }
.side-link .ic { width: 21px; height: 21px; color: var(--text-2); }
.side-link:hover { background: var(--surface-3); }
.side-link.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link.on .ic { color: var(--accent); }
.side-link.dim { color: var(--text-3); }
.side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.side-more { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; color: var(--text-3); margin-right: -4px; }
.side-more .ic { width: 18px; height: 18px; }
.side-more:hover { background: var(--surface); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 6px 4px 10px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }
.side-gap { height: 12px; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.side-storage { font-size: 12px; color: var(--text-3); padding: 2px 10px; font-variant-numeric: tabular-nums; }
.side-scrim { display: none; }
.side-toggle { display: none; }

.lib-main { overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 max(28px, var(--safe-r)) calc(40px + var(--safe-b)) 32px; min-width: 0; }
.lib-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: calc(18px + var(--safe-t)) 0 16px; background: linear-gradient(var(--bg) 78%, transparent);
}
.lib-heading { flex: 1; min-width: 180px; display: flex; align-items: baseline; gap: 12px; }
.lib-title { margin: 0; font: 600 30px/1.1 var(--font-display); letter-spacing: -0.015em; text-wrap: balance; }
.lib-count { color: var(--text-3); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lib-actions { display: flex; align-items: center; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); width: 280px; max-width: 100%; color: var(--text-3); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .ic { width: 18px; height: 18px; }
.search-input { flex: 1; min-width: 0; border: 0; background: none; height: 100%; font-size: 15px; color: var(--text); -webkit-appearance: none; appearance: none; }
.search-input::-webkit-search-decoration { -webkit-appearance: none; }
.new-btn { padding: 0 14px 0 11px; }
.lib-banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin: 0 0 18px; border-radius: 14px; background: var(--accent-soft); color: var(--text); font-size: 14px; line-height: 1.45; }
.lib-banner > .ic { color: var(--accent); }
.lib-banner > span { flex: 1; }
.lib-banner.warn { background: var(--danger-soft); }
.lib-banner.warn > .ic { color: var(--danger); }

.nb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 30px 24px; align-items: start; }
.trash-bar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-size: 14px; }
.card { position: relative; display: flex; flex-direction: column; gap: 11px; cursor: pointer; outline: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.card:focus-visible .cover { outline: 3px solid var(--accent); outline-offset: 3px; }
.card-cover { container-type: inline-size; transition: transform 0.18s; }
.card:hover .card-cover { transform: translateY(-2px); }
.card:active .card-cover { transform: scale(0.98); }
.card-info { display: flex; flex-direction: column; gap: 2px; padding-right: 30px; min-width: 0; }
.card-title { font: 600 15.5px/1.25 var(--font-display); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.card-meta { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-snip { font-size: 12.5px; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-top: 2px; }
.card-star { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgba(0, 0, 0, 0.22); opacity: 0; transition: opacity 0.15s; }
.card-star .ic { width: 18px; height: 18px; }
.card-star.on { opacity: 1; color: #FFD45E; background: rgba(0, 0, 0, 0.28); }
.card:hover .card-star, .card:focus-within .card-star { opacity: 1; }
@media (hover: none) { .card-star { opacity: 1; background: rgba(0, 0, 0, 0.16); } .card-star:not(.on) { opacity: 0.85; } }
.card-more { position: absolute; right: -6px; bottom: 2px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--text-3); }
.card-more:hover { background: var(--surface-3); color: var(--text); }

.empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 48px 4px; max-width: 520px; }
.empty-title { font: 600 24px/1.2 var(--font-display); }
.empty p { margin: 0; color: var(--text-2); font-size: 15px; line-height: 1.5; }
.empty-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* covers */
.cover {
  position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 4px 11px 11px 4px; overflow: hidden;
  background-color: var(--cc); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1), 0 1px 1px rgba(0, 0, 0, 0.1), 0 10px 22px -10px rgba(10, 20, 15, 0.55);
}
.cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0.1)); pointer-events: none; }
.cover-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 10%; background: linear-gradient(90deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1) 70%, rgba(255, 255, 255, 0.1)); }
.cover-linen { background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px); }
.cover-stripe { background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0 9px, transparent 9px 19px); }
.cover-dots { background-image: radial-gradient(rgba(255, 255, 255, 0.22) 1.2px, transparent 1.7px); background-size: 11px 11px; }
.cover-grid { background-image: linear-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px); background-size: 13px 13px; }
.cover-band::before { content: ""; position: absolute; top: 0; bottom: 0; right: 13%; width: 5%; background: rgba(0, 0, 0, 0.38); box-shadow: inset 1px 0 rgba(255, 255, 255, 0.12); z-index: 1; }
.cover-band .cover-label { right: 23%; }
.cover-label { position: absolute; left: 19%; right: 9%; top: 15%; padding: 7cqi 7cqi 6cqi; background: rgba(255, 255, 255, 0.94); color: #23282A; border-radius: 3px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); z-index: 2; }
.cover-label span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font: 600 clamp(10px, 9.5cqi, 19px)/1.2 var(--font-display); word-break: break-word; }
.cover-page { position: absolute; inset: 0; background: #fff; border-radius: inherit; overflow: hidden; }
.cover-page img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.cover-page::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6%; background: linear-gradient(90deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0)); z-index: 1; }

/* new notebook / pickers */
.new-nb { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 26px; }
.new-nb-left { display: flex; flex-direction: column; gap: 10px; }
.title-field { font: 600 17px var(--font-display); }
.cover-picker { display: flex; flex-direction: column; gap: 10px; }
.cover-preview { width: 150px; container-type: inline-size; margin: 6px 0 4px; }
.cover-opts { display: flex; flex-direction: column; gap: 10px; }
.paper-picker { display: flex; flex-direction: column; gap: 10px; }
.paper-row { display: flex; flex-wrap: wrap; gap: 9px; }
.paper-sw { width: 34px; height: 34px; border-radius: 10px; box-shadow: inset 0 0 0 1px var(--line-strong); }
.paper-sw.round { border-radius: 50%; width: 30px; height: 30px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.paper-sw.on { box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.pick-row { display: flex; align-items: center; gap: 10px; }
.pick-row.wrap { flex-wrap: wrap; }
.pick-row .seg { max-width: 100%; overflow-x: auto; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
.tpl-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px; border-radius: 12px; }
.tpl-cell:hover { background: var(--surface-2); }
.tpl-canvas { width: 100%; aspect-ratio: 1; display: grid; place-items: center; }
.tpl-canvas canvas { width: 100%; height: 100%; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.16)); }
.tpl-name { font-size: 12px; color: var(--text-2); text-align: center; line-height: 1.2; }
.tpl-cell.on { background: var(--accent-soft); }
.tpl-cell.on .tpl-name { color: var(--accent); font-weight: 600; }
@media (max-width: 720px) { .new-nb { grid-template-columns: 1fr; } }

/* settings */
.settings { display: flex; flex-direction: column; gap: 22px; }
.set-title { margin: 0 0 8px 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }
.set-card { border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); padding: 2px 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 13px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.set-row:first-child { border-top: 0; }
.set-text { flex: 1; min-width: 200px; }
.set-label { font-size: 15px; font-weight: 600; }
.set-hint { display: block; font-size: 13px; color: var(--text-2); margin-top: 2px; line-height: 1.45; max-width: 60ch; }
.set-val { color: var(--text-2); font-variant-numeric: tabular-nums; }
.about p { margin: 12px 0; line-height: 1.5; }

/* Editor */
.editor { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--workspace); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ed-bar {
  position: relative; z-index: 4; flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px;
  min-height: calc(var(--bar-h) + var(--safe-t)); padding: var(--safe-t) max(10px, var(--safe-r)) 0 max(8px, var(--safe-l));
  background: var(--bar); -webkit-backdrop-filter: saturate(1.5) blur(18px); backdrop-filter: saturate(1.5) blur(18px); border-bottom: 1px solid var(--line);
}
.ed-left { display: flex; align-items: center; gap: 2px; min-width: 0; }
.ed-back { display: inline-flex; align-items: center; gap: 2px; height: 40px; padding: 0 10px 0 4px; border-radius: 11px; color: var(--accent); font-size: 15px; font-weight: 600; flex: none; }
.ed-back:hover { background: var(--accent-soft); }
.ed-back .ic { width: 24px; height: 24px; }
.ed-title-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ed-title { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 600 16.5px var(--font-display); padding: 6px 8px; border-radius: 9px; }
.ed-title:hover { background: var(--surface-3); }
.save-state { font-size: 12px; color: var(--text-3); opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
.save-state.saved { opacity: 1; }
.save-state.error { opacity: 1; color: var(--danger); font-weight: 600; }
.ed-tools { display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: 14px; background: var(--surface-3); }
.tool { position: relative; display: grid; place-items: center; width: 44px; height: 40px; border-radius: 11px; color: var(--text-2); }
.tool .ic { width: 23px; height: 23px; }
.tool:hover { color: var(--text); }
.tool.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-1); }
.tool-dot { position: absolute; left: 50%; bottom: 3px; width: 14px; height: 3px; margin-left: -7px; border-radius: 2px; box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.15); }
.tool-sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; flex: none; }
.ed-right { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }

.ed-sub {
  position: absolute; z-index: 3; left: 50%; top: calc(var(--bar-h) + var(--safe-t) + 8px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px); padding: 6px 10px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); overflow-x: auto; scrollbar-width: none;
}
.ed-sub::-webkit-scrollbar { display: none; }
.ed-sub:empty { display: none; }
.sub-sep { width: 1px; height: 24px; background: var(--line); flex: none; }
.sub-hint { font-size: 13px; color: var(--text-2); white-space: nowrap; padding: 0 4px; }
.sw-row, .size-row { display: flex; align-items: center; gap: 4px; flex: none; }
.sw { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; position: relative; }
.sw::before { content: ""; width: 24px; height: 24px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14); }
.sw.on::after { content: ""; position: absolute; inset: 1px; border-radius: 50%; box-shadow: 0 0 0 2px var(--c), inset 0 0 0 1px rgba(0, 0, 0, 0.1); }
.sw-more::before { display: none; }
.sw-more { color: var(--text-2); }
.sw-more .ic { width: 22px; height: 22px; }
.size { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; color: var(--text); }
.size.on { background: var(--surface-3); box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.size-dot { display: block; border-radius: 50%; }
.size-dot.ring { box-shadow: inset 0 0 0 1.6px var(--text-2); }
.size-dot.bar { border-radius: 2px; opacity: 0.85; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 13px; font-weight: 600; white-space: nowrap; flex: none; }
.chip .ic { width: 18px; height: 18px; }
.chip.on { background: var(--accent-soft); color: var(--accent); }
.chip.primary { background: var(--accent); color: var(--accent-ink); }
.kind-btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 8px 0 6px; border-radius: 11px; flex: none; }
.kind-btn:hover { background: var(--surface-3); }
.kind-btn .ic { width: 16px; height: 16px; color: var(--text-3); }
.kind-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.kind-prev { width: 44px; height: 18px; display: block; }
.kind-prev.wide { width: 75px; height: 20px; }
.pop-kinds { min-width: 240px; }
.kind-list { display: flex; flex-direction: column; }
.kind-item { display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 0 12px; border-radius: 10px; font-size: 15px; text-align: left; }
.kind-item span { flex: 1; }
.kind-item .ic { color: var(--accent); width: 20px; height: 20px; }
.kind-item:hover, .kind-item.on { background: var(--surface-3); }
.stepper { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.stepper-val { min-width: 48px; text-align: center; font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.size-pop { padding: 4px 8px 10px; width: 280px; }

.ed-main { position: relative; flex: 1; display: flex; min-height: 0; }
.ed-view { position: relative; flex: 1; min-width: 0; overflow: hidden; outline: none; }
.ed-canvas { position: absolute; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
.cv { position: absolute; left: 0; top: 0; pointer-events: none; }

.selbar {
  position: absolute; left: 0; top: 0; z-index: 3; display: flex; gap: 2px; padding: 4px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); will-change: transform;
}
.sb-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 52px; height: 50px; padding: 0 6px; border-radius: 10px; color: var(--text); font-size: 11px; font-weight: 600; }
.sb-btn .ic { width: 20px; height: 20px; color: var(--text-2); }
.sb-btn:hover { background: var(--surface-3); }
.sb-btn.danger, .sb-btn.danger .ic { color: var(--danger); }
.sb-btn.accent, .sb-btn.accent .ic { color: var(--accent); }

.zoom-badge {
  position: absolute; z-index: 3; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%) translateY(6px); opacity: 0; pointer-events: none;
  padding: 7px 14px; border-radius: 999px; background: var(--toast); color: var(--toast-ink); font: 600 13px var(--font-ui); font-variant-numeric: tabular-nums; transition: opacity 0.2s, transform 0.2s;
}
.zoom-badge.show { opacity: 0.94; transform: translateX(-50%); pointer-events: auto; }
.page-badge {
  position: absolute; z-index: 3; right: max(14px, var(--safe-r)); bottom: calc(14px + var(--safe-b)); height: 34px; padding: 0 13px; border-radius: 999px;
  background: var(--bar); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid var(--line); color: var(--text-2);
  font: 600 13px var(--font-ui); font-variant-numeric: tabular-nums; box-shadow: var(--shadow-1);
}
.ed-flash { position: absolute; z-index: 3; left: 50%; top: 42%; transform: translate(-50%, -50%); padding: 9px 18px; border-radius: 999px; background: var(--toast); color: var(--toast-ink); font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; }
.ed-flash.show { animation: flash 0.75s ease-out; }
@keyframes flash { 0% { opacity: 0; transform: translate(-50%, -40%); } 18% { opacity: 0.95; transform: translate(-50%, -50%); } 70% { opacity: 0.95; } 100% { opacity: 0; } }

.ed-text {
  position: absolute; left: 0; top: 0; z-index: 2; transform-origin: 0 0; margin: 0; padding: 0; border: 0; background: transparent; resize: none; overflow: hidden;
  line-height: 1.32; white-space: pre-wrap; overflow-wrap: break-word; outline: 1.5px dashed var(--accent); outline-offset: 5px; border-radius: 1px;
  -webkit-user-select: text; user-select: text; touch-action: auto; caret-color: var(--accent);
}

/* navigator */
.ed-nav { flex: none; width: 212px; display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); border-right: 1px solid var(--line); padding-left: var(--safe-l); }
.nav-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 6px 16px; }
.nav-title { font: 600 17px var(--font-display); display: flex; align-items: baseline; gap: 8px; }
.nav-count { font: 500 12.5px var(--font-ui); color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-filter { padding: 2px 12px 10px; }
.nav-filter .seg { width: 100%; }
.nav-filter .seg-btn { flex: 1; justify-content: center; }
.nav-list { flex: 1; overflow: auto; overscroll-behavior: contain; padding: 4px 18px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; touch-action: pan-y; }
.nav-item { display: flex; flex-direction: column; gap: 5px; cursor: pointer; border-radius: 6px; outline: none; }
.nav-thumb { position: relative; width: 100%; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--line), 0 2px 6px rgba(0, 0, 0, 0.08); }
.nav-thumb canvas { width: 100%; height: 100%; display: block; }
.nav-item.cur .nav-thumb { box-shadow: 0 0 0 2.5px var(--accent), 0 2px 8px rgba(0, 0, 0, 0.12); }
.nav-item:focus-visible .nav-thumb { box-shadow: 0 0 0 3px var(--accent); }
.nav-item.dragging { opacity: 0.6; }
.nav-bm { position: absolute; top: -2px; right: 8px; color: #E5484D; }
.nav-bm .ic { width: 18px; height: 18px; }
.nav-meta { display: flex; align-items: center; gap: 4px; }
.nav-num { flex: 1; text-align: center; font-size: 12px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.nav-item.cur .nav-num { color: var(--accent); }
.nav-handle { display: grid; place-items: center; width: 32px; height: 32px; color: var(--text-3); touch-action: none; cursor: grab; }
.nav-handle .ic { width: 18px; height: 18px; }
.nav-add { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 64px; border-radius: 6px; border: 1.5px dashed var(--line-strong); color: var(--text-2); font-weight: 600; font-size: 13px; }
.nav-add:hover { border-color: var(--accent); color: var(--accent); }
.nav-empty { color: var(--text-2); font-size: 13px; line-height: 1.5; padding: 8px 0; }

/* stickers */
.pop-stk { width: min(372px, calc(100vw - 20px)); }
.stk-pop { display: flex; flex-direction: column; gap: 10px; padding: 6px; }
.stk-pop > .seg { align-self: center; max-width: 100%; overflow-x: auto; }
.stk-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 340px; overflow: auto; }
.stk { display: grid; place-items: center; aspect-ratio: 1; border-radius: 12px; }
.stk.wide { grid-column: span 2; aspect-ratio: 5 / 2; }
.stk canvas { width: 82%; height: 82%; object-fit: contain; }
.stk:hover { background: var(--surface-3); }
.sp-row { display: flex; flex-direction: column; gap: 6px; }

/* Responsive */
@media (max-width: 980px) {
  .ed-back-label { display: none; }
}
@media (max-width: 900px) {
  .tool { width: 38px; }
  .ed-right .icon-btn { width: 36px; }
  .save-state { display: none; }
  .ed-tools .tool-sep, .ed-right .tool-sep { margin: 0 2px; }
}
@media (max-width: 860px) {
  .library { grid-template-columns: minmax(0, 1fr); }
  .lib-side { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: 280px; transform: translateX(-102%); transition: transform 0.22s; }
  .library.side-open .lib-side { transform: none; box-shadow: var(--shadow-2); }
  .side-scrim { display: block; position: fixed; inset: 0; z-index: 19; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity 0.22s; }
  .library.side-open .side-scrim { opacity: 1; pointer-events: auto; }
  .side-toggle { display: inline-grid; margin-left: -8px; }
  .lib-main { padding-left: max(18px, var(--safe-l)); padding-right: max(18px, var(--safe-r)); }
  .search { width: 220px; }
  .tool { width: 40px; }
}
@media (max-width: 760px) {
  .ed-bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "left right" "tools tools"; row-gap: 4px; padding-bottom: 6px; }
  .ed-left { grid-area: left; }
  .ed-right { grid-area: right; }
  .ed-tools { grid-area: tools; justify-self: center; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .ed-sub { top: calc(var(--bar-h) * 2 + var(--safe-t) + 4px); }
  .ed-nav { position: absolute; z-index: 3; top: 0; bottom: 0; left: 0; box-shadow: var(--shadow-2); }
}
@media (max-width: 560px) {
  .lib-title { font-size: 25px; }
  .lib-actions { width: 100%; }
  .search { flex: 1; width: auto; min-width: 0; }
  .nb-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 24px 16px; }
  .tool { width: 38px; }
  .ed-right .tool-sep { display: none; }
}
.ai-study { display: flex; flex-direction: column; gap: 14px; min-height: 320px; }
.ai-panel, .ai-area, .ai-settings { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ai-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ai-row.end { justify-content: flex-end; }
.ai-lead, .ai-empty { margin: 0; color: var(--text-2); font-size: 14.5px; flex: 1; min-width: 180px; }
.ai-notice { padding: 10px 12px; border-radius: 11px; background: var(--accent-soft); font-size: 13.5px; }
.ai-error { margin: 0; color: var(--danger, #B3261E); font-size: 14px; }
.ai-working { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--text-2); font-size: 14px; }
.ai-answer, .ai-msg { font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.ai-line.ai-head { font-weight: 600; margin-top: 4px; }
.ai-line.ai-bullet { padding-left: 1.2em; text-indent: -1.2em; }
.ai-gap { height: 8px; }
.ai-chat { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; }
.ai-msg { padding: 10px 12px; border-radius: 13px; background: var(--surface-3); align-self: flex-start; max-width: 92%; }
.ai-msg.user { background: var(--accent); color: var(--accent-ink); align-self: flex-end; }
.ai-compose { display: flex; align-items: flex-end; gap: 8px; }
.field.ai-input { height: auto; padding: 10px 12px; resize: vertical; font: inherit; }
.ai-card { width: 100%; min-height: 170px; padding: 22px; border-radius: 15px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 17px; line-height: 1.4; text-align: center; overflow-wrap: anywhere; }
.ai-card.back { background: var(--accent-soft); }
.ai-count { color: var(--text-3); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.ai-question { display: flex; flex-direction: column; gap: 7px; }
.ai-q { margin: 0 0 2px; font-weight: 600; font-size: 15px; }
.ai-option { padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 14.5px; text-align: left; overflow-wrap: anywhere; }
.ai-option.right { background: rgba(30, 140, 80, 0.16); border-color: #1E8C50; }
.ai-option.wrong { background: rgba(179, 38, 30, 0.13); border-color: #B3261E; }
.ai-map, .ai-map ul { margin: 0; padding-left: 18px; list-style: none; border-left: 1px solid var(--line-strong); }
.ai-map { border-left: 0; padding-left: 0; }
.ai-map li { margin: 7px 0; }
.ai-node { display: inline-block; padding: 5px 10px; border-radius: 9px; background: var(--surface-3); font-size: 14.5px; }
.ai-map > li > .ai-node { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ai-setting { display: flex; flex-direction: column; gap: 9px; }
.ai-setting h3 { margin: 0; font-size: 15.5px; }
.ai-setting .set-hint { margin: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
