:root {
  --bg: #0e0e10;
  --bg-side: #0a0a0b;
  --bg-bar: rgba(14, 14, 16, 0.94);
  --surface: #161618;
  --surface-2: #1e1e21;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --hover: rgba(255, 255, 255, 0.045);
  --active: rgba(255, 255, 255, 0.08);
  --txt: #d1d1d6;
  --txt-head: #f5f5f7;
  --txt-muted: #9e9ea4;
  --txt-dim: #6c6c72;
  /* yellow is reserved for the reader's own notes, so they stand out from the text */
  --accent: #f2c94c;
  --accent-soft: rgba(242, 201, 76, 0.16);
  --accent-line: rgba(242, 201, 76, 0.5);
  --good: #7fbf8e;
  --bad: #e07a6e;
  --info: #7fa8d9;
  --warn: #e0b04f;
  --serif: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --doc-size: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

::selection { background: rgba(110, 150, 255, 0.35); }

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

.view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: none;
  color: var(--txt);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--txt-head);
}

.btn-primary {
  background: var(--txt-head);
  border-color: var(--txt-head);
  color: #0e0e10;
  font-weight: 600;
}

.btn-quiet { border-color: transparent; color: var(--txt-muted); }

.btn:disabled { opacity: 0.4; }

@media (hover: hover) {
  .btn:hover { background-color: var(--hover); }
  .btn-primary:hover { background: #ffffff; }
}

.seg { display: inline-flex; }
.seg .btn:first-child { border-radius: 8px 0 0 8px; }
.seg .btn:last-child { border-radius: 0 8px 8px 0; border-left: 0; }

/* ---------- library ---------- */

#library {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(28px + env(safe-area-inset-top, 0px)) 24px 48px;
}

.lib-head {
  max-width: 760px;
  margin: 0 auto 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lib-head h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  color: var(--txt-head);
}

.lib-actions { display: flex; gap: 8px; }

.doc-list {
  list-style: none;
  max-width: 760px;
  margin: 0 auto;
  padding: 0;
  border-top: 1px solid var(--line);
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 4px;
  border-bottom: 1px solid var(--line);
}

.doc-item-main { flex: 1; min-width: 0; cursor: pointer; }

.doc-item-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--txt-head);
}

.doc-item-meta { margin-top: 5px; font-size: 13px; color: var(--txt-dim); }

.app-version { font-size: 11.5px; color: var(--txt-dim); }
.lib-version { max-width: 760px; margin: 40px auto 0; }
.side-version { flex-shrink: 0; padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }

.lib-empty {
  max-width: 760px;
  margin: 24px auto;
  color: var(--txt-muted);
  font-size: 15px;
  line-height: 1.6;
}

/* ---------- reader frame ---------- */

#reader { display: flex; flex-direction: column; }

.bar {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.ver-sel {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--txt-muted) 50%), linear-gradient(135deg, var(--txt-muted) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.bar-title {
  flex: 1;
  min-width: 0;
  padding: 0 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--txt-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
.bar-progress span { display: block; width: 0; height: 100%; background: rgba(255, 255, 255, 0.4); }

.reader-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

/* ---------- side: contents + notes ---------- */

.side {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.reader-body.no-side .side { display: none; }

.side-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.side-tab {
  flex: 1;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--txt-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.side-tab[aria-selected="true"] { background: var(--active); color: var(--txt-head); }

.side-pane {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 48px;
}

.toc-group {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt-dim);
  padding: 22px 10px 8px;
}

.toc-ch {
  position: relative;
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 11px 32px 11px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
  margin-bottom: 2px;
}

.toc-ch::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 18px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--txt-dim);
  border-bottom: 1.5px solid var(--txt-dim);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.toc-ch.open::after { transform: rotate(45deg); }
.toc-ch.current { background: var(--active); }
.toc-ch.current .toc-code { color: var(--txt-head); }
.toc-ch.current .toc-title { color: var(--txt-head); }

.toc-code {
  flex-shrink: 0;
  min-width: 30px;
  padding-top: 2px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--txt-dim);
}

.toc-title { font-size: 13.5px; font-weight: 500; line-height: 1.42; color: var(--txt); }
.toc-notes { display: block; margin-top: 3px; font-size: 11.5px; color: var(--accent); }

.toc-subs {
  margin: 2px 0 14px 23px;
  padding-left: 10px;
  border-left: 1px solid var(--line-strong);
}

.toc-sub {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.45;
  color: var(--txt-muted);
  cursor: pointer;
}

.toc-sub.l3 { padding-left: 20px; font-size: 12.5px; color: var(--txt-dim); }
.toc-sub.caps { font-size: 11.5px; letter-spacing: 0.02em; }
.toc-sub.here { color: var(--txt-head); background: var(--active); }

@media (hover: hover) {
  .toc-ch:hover, .toc-sub:hover, .note-row:hover { background-color: var(--hover); }
}

.note-row {
  display: block;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.note-row-where { font-size: 11.5px; font-weight: 600; color: var(--txt-dim); margin-bottom: 4px; }
.note-row-n { color: var(--accent); margin-right: 6px; }
.note-row-quote { font-family: var(--serif); font-size: 14px; line-height: 1.5; color: var(--txt); }
.note-row-text { margin-top: 4px; font-size: 13px; line-height: 1.45; color: var(--txt-muted); }
.note-row-ink { margin-top: 4px; font-size: 12px; color: var(--txt-dim); }
.notes-file { margin: 14px 4px; }
.side-empty { padding: 18px 10px; font-size: 13.5px; line-height: 1.55; color: var(--txt-muted); }

/* ---------- page ---------- */

.page {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 44px 32px 24px;
  font-family: var(--serif);
  font-size: var(--doc-size);
  line-height: 1.8;
  color: var(--txt);
}

.marks {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.marks .area { fill: rgba(242, 201, 76, 0.07); stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.9; pointer-events: stroke; cursor: pointer; }
.marks .area-hit { fill: transparent; stroke: transparent; stroke-width: 22; pointer-events: stroke; cursor: pointer; }
.marks .badge { fill: var(--accent); pointer-events: all; cursor: pointer; }
.marks .badge-n { fill: #0e0e10; font: 600 11px var(--sans); text-anchor: middle; pointer-events: none; }
.marks .live { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.mark-capture {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
  background: rgba(242, 201, 76, 0.03);
}

.mark-capture.finger { touch-action: none; }

.pager {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 32px calc(96px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.pager-card {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.pager-card.next { grid-column: 2; text-align: right; }
.pager-dir { font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--txt-dim); margin-bottom: 6px; }
.pager-title { font-family: var(--serif); font-size: 16px; font-weight: 600; line-height: 1.38; color: var(--txt-head); }

/* ---------- document typography (ipf v1) ---------- */

.doc .ipf-chapter-head,
.doc > header {
  padding-bottom: 28px;
  margin-bottom: 36px;
  border-bottom: 1px solid var(--line);
}

.doc .ipf-meta {
  margin: 0 0 14px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--txt-muted);
}

.doc .ipf-chapter-head h1,
.doc > header h1 {
  margin: 0 0 12px;
  font-size: 1.9em;
  line-height: 1.2;
  font-weight: 600;
  color: var(--txt-head);
}

.doc .ipf-lede {
  margin: 0;
  font-style: italic;
  font-size: 1.02em;
  line-height: 1.6;
  color: var(--txt-muted);
}

.doc h2, .doc h3, .doc h4 { color: var(--txt-head); font-weight: 600; scroll-margin-top: 24px; }
.doc h2 { font-size: 1.4em; line-height: 1.34; margin: 64px 0 20px; }
.doc h3 { font-size: 1.17em; line-height: 1.4; margin: 46px 0 16px; }
.doc h4 { font-family: var(--sans); font-size: 0.86em; line-height: 1.5; color: var(--txt-head); margin: 34px 0 10px; }
.doc h2.caps { font-size: 1.06em; line-height: 1.5; letter-spacing: 0.035em; }
.doc h3.caps { font-size: 0.98em; letter-spacing: 0.03em; }

.doc p { margin: 0 0 1.2em; }
.doc strong { color: var(--txt-head); font-weight: 600; }
.doc strong.lead {
  display: block;
  margin-bottom: 0.2em;
  font-family: var(--sans);
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.5;
}
.doc strong.emph { font-weight: inherit; color: #ffffff; }
.doc ul, .doc ol { margin: 0 0 1.6em; padding-left: 1.4em; }
.doc li { margin-bottom: 0.85em; padding-left: 0.25em; }
.doc li::marker { color: var(--txt-dim); }
.doc li > ul, .doc li > ol { margin: 0.7em 0 0.4em; }
.doc li > p:last-child { margin-bottom: 0; }

.doc .ipf-task { list-style: none; position: relative; }
.doc .ipf-task::before {
  content: "";
  position: absolute;
  left: -1.4em;
  top: 0.42em;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--txt-dim);
  border-radius: 4px;
}
.doc .ipf-task[data-done]::before { background: var(--good); border-color: var(--good); }

.doc code { font-family: inherit; color: var(--txt-head); font-variant-numeric: tabular-nums; word-break: break-word; }
.doc a { color: var(--txt-head); text-decoration: underline; text-decoration-color: rgba(255, 255, 255, 0.35); text-underline-offset: 3px; }

.doc hr { border: 0; border-top: 1px solid var(--line-strong); width: 72px; margin: 60px auto; }

.doc blockquote {
  margin: 30px 0 34px;
  padding: 18px 22px;
  background: var(--surface);
  border-left: 2px solid var(--line-strong);
  border-radius: 0 8px 8px 0;
}
.doc blockquote p:last-child { margin-bottom: 0; }
.doc [data-tone="good"] { border-left-color: var(--good); }
.doc [data-tone="bad"] { border-left-color: var(--bad); }
.doc [data-tone="info"] { border-left-color: var(--info); }

.doc pre {
  margin: 26px 0 34px;
  padding: 16px 18px;
  background: #0a0a0b;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.doc pre code { font-family: inherit; color: #d4d4d8; }

.doc .tbl {
  margin: 30px 0 38px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.doc table { width: 100%; min-width: 520px; border-collapse: collapse; font-family: var(--sans); font-size: 0.8em; line-height: 1.55; }
.doc th { background: var(--surface-2); color: var(--txt-head); font-weight: 600; text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line-strong); }
.doc td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc tr:last-child td { border-bottom: 0; }

.doc figure { margin: 28px 0 34px; }
.doc figure img { display: block; max-width: 100%; height: auto; border-radius: 6px; }
.doc figure svg { display: block; width: 100%; min-width: 620px; height: auto; font-family: var(--sans); }
.doc figure:has(> svg) { overflow-x: auto; }
.doc figcaption { margin-top: 10px; font-family: var(--sans); font-size: 13px; line-height: 1.55; color: var(--txt-muted); }

.doc .ipf-panel {
  margin: 0 0 44px;
  padding: 26px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}
.doc .ipf-panel > h3 { margin: 0 0 22px; font-family: var(--serif); font-size: 21px; line-height: 1.35; }
.doc .ipf-panel figure { margin: 0; overflow-x: auto; }

.doc .ipf-kicker {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.5;
  color: var(--txt-dim);
}
.doc .ipf-panel > .ipf-kicker:not(:first-child) { margin: 30px 0 16px; padding-top: 22px; border-top: 1px solid var(--line); }

.doc .ipf-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.doc .ipf-stat { padding: 16px 16px 18px; background: var(--surface-2); border-radius: 10px; }
.doc .ipf-stat p { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--txt-muted); }
.doc .ipf-stat .ipf-stat-label { margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--txt); }
.doc .ipf-stat-value { display: block; margin-bottom: 6px; font-family: var(--serif); font-size: 26px; font-weight: 600; color: var(--txt-head); }
.doc .ipf-stat[data-tone="bad"] .ipf-stat-value { color: var(--bad); }
.doc .ipf-stat[data-tone="warn"] .ipf-stat-value { color: var(--warn); }
.doc .ipf-stat[data-tone="info"] .ipf-stat-value { color: var(--info); }
.doc .ipf-stat[data-tone="good"] .ipf-stat-value { color: var(--good); }

.doc .ipf-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.doc .ipf-gallery figure { margin: 0; overflow: hidden; background: var(--surface-2); border-radius: 10px; border-top: 2px solid transparent; }
.doc .ipf-gallery figure[data-tone="good"] { border-top-color: rgba(127, 191, 142, 0.6); }
.doc .ipf-gallery figure[data-tone="bad"] { border-top-color: rgba(224, 122, 110, 0.6); }
.doc .ipf-media { position: relative; height: 168px; background: #0a0a0b; }
.doc .ipf-media img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; }
.doc .ipf-tag { position: absolute; top: 10px; left: 10px; padding: 4px 8px; border-radius: 4px; background: rgba(10, 10, 11, 0.86); font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; color: var(--txt); }
.doc .ipf-gallery figure[data-tone="good"] .ipf-tag { color: #a3d4ae; }
.doc .ipf-gallery figure[data-tone="bad"] .ipf-tag { color: #eea79e; }
.doc .ipf-gallery figcaption { margin: 0; padding: 14px 16px 18px; }
.doc .ipf-gallery figcaption p { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--txt-muted); }
.doc .ipf-fig-title { margin-bottom: 8px !important; font-size: 13.5px !important; font-weight: 600; color: var(--txt-head) !important; }
.doc .ipf-fig-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; margin-bottom: 9px !important; padding-bottom: 9px; border-bottom: 1px solid var(--line); font-size: 12px !important; }

.doc .ipf-flow { margin: 30px 0 38px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-family: var(--sans); }
.doc .ipf-flow-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.doc .ipf-flow-row:last-child { margin-bottom: 0; }
.doc .ipf-node { padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 6px; font-size: 13px; line-height: 1.45; color: var(--txt); }
.doc .ipf-edge { font-size: 12px; font-weight: 500; color: var(--txt-muted); }
.doc .ipf-arrow { color: var(--txt-dim); }

.doc .ipf-math { font-style: italic; color: var(--txt-head); }
.doc span.ipf-math { white-space: nowrap; }
.doc div.ipf-math { margin: 26px 0; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; text-align: center; overflow-x: auto; }
.doc .ipf-upright { font-style: normal; }
.doc .ipf-frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: 0.85em; padding: 0 4px; }
.doc .ipf-frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 3px; }

/* ---------- highlights ---------- */

.doc mark.hl {
  background: rgba(242, 201, 76, 0.2);
  color: inherit;
  border-bottom: 1.5px solid rgba(242, 201, 76, 0.8);
  border-radius: 2px;
  cursor: pointer;
}

.doc mark.hl.active { background: rgba(242, 201, 76, 0.38); }

.doc mark.hl[data-n]::after {
  content: attr(data-n);
  margin-left: 3px;
  font: 600 10px var(--sans);
  vertical-align: super;
  color: var(--accent);
}

.doc .flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 40% { background-color: rgba(242, 201, 76, 0.22); } 100% { background-color: transparent; } }

/* ---------- note panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px 8px;
}

.panel-where { flex: 1; min-width: 0; padding-top: 8px; font-size: 12px; font-weight: 600; line-height: 1.45; color: var(--txt-dim); }
.panel-where b { color: var(--accent); margin-right: 6px; }
.panel-head-actions { display: flex; gap: 6px; flex-shrink: 0; }

.panel-quote {
  margin: 0 14px 10px;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--accent-line);
  font-family: var(--serif);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--txt-muted);
  max-height: 6.4em;
  overflow-y: auto;
}

#noteText {
  margin: 0 14px 10px;
  padding: 10px 12px;
  min-height: 64px;
  max-height: 30vh;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--txt-head);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  outline: none;
}

#noteText:focus { border-color: var(--accent-line); }

.ink-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 0 14px 10px;
}

.btn-tool { height: 32px; padding: 0 10px; font-size: 12.5px; }

.swatches { display: flex; gap: 6px; margin-right: 4px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--txt-head); }

.ink-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--line);
  background: #111113;
}

#ink {
  display: block;
  width: 100%;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* millimetre paper: fine, half-centimetre and centimetre lines; sizes follow the ink scale (Ink.layout) */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.11) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.11) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 60px 60px, 60px 60px, 30px 30px, 30px 30px, 6px 6px, 6px 6px;
}

#ink.finger { touch-action: none; }
#ink.erasing { cursor: cell; }

.ink-more { display: block; margin: 6px auto 18px; }

/* ---------- sync sheet ---------- */

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 70;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(72px + env(safe-area-inset-top, 0px)) 16px 24px;
  background: rgba(0, 0, 0, 0.6);
}

.sheet-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  padding: 22px 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
}

.sheet-card h2 { margin: 0 0 6px; font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--txt-head); }
.sheet-status { margin: 0 0 14px; font-size: 13px; color: var(--txt-muted); }
.sheet-text { margin: 0 0 12px; font-size: 14px; line-height: 1.55; color: var(--txt); }
.sheet-input {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--txt-head);
  font-family: var(--mono);
  font-size: 14px;
  outline: none;
}
.sheet-input:focus { border-color: rgba(255, 255, 255, 0.35); }
.sheet-row { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-close { position: absolute; top: 14px; right: 12px; }

/* ---------- popovers ---------- */

.sel-pop {
  position: fixed;
  z-index: 50;
  padding: 5px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}
.sel-pop .btn { height: 42px; padding: 0 22px; font-size: 15px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  font-size: 13.5px;
  color: var(--txt-head);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* ---------- layouts ---------- */

/* Wide landscape: contents column · page · note panel (right half) */
@media (min-width: 900px) and (orientation: landscape) {
  .reader-body.with-panel .side { display: none; }
  .reader-body.with-panel .panel { width: 50%; flex-shrink: 0; }
}

/* Portrait / narrow: contents is a drawer, note panel is the bottom half */
@media not all and (min-width: 900px) and (orientation: landscape) {
  .side {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 15;
    width: min(330px, 86vw);
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.4);
  }
  .reader-body.with-panel { flex-direction: column; }
  .reader-body.with-panel .page { flex: 1 1 50%; }
  .reader-body.with-panel .panel { flex: 0 0 52%; border-left: 0; border-top: 1px solid var(--line-strong); }
  .reader-body.with-panel .side { display: none; }
}

@media (max-width: 700px) {
  .bar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .bar .seg, .bar-title { display: none; }
  .doc { padding: 28px 18px 24px; }
  .pager { padding-left: 18px; padding-right: 18px; }
  .doc .ipf-panel { padding: 20px 16px; }
}
