/* After Tufte CSS (https://edwardtufte.github.io/tufte-css/): ET Book on ivory, italic headings,
   no boxes or icons, whitespace instead of rules, sparklines in the text. */
@font-face {
  font-family: "et-book";
  src: url("fonts/et-book-roman-old-style-figures.woff") format("woff");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "et-book";
  src: url("fonts/et-book-display-italic-old-style-figures.woff") format("woff");
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "et-book";
  src: url("fonts/et-book-semi-bold-old-style-figures.woff") format("woff");
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --paper: #fffff8;
  --ink: #111111;
  --ink-2: #6e6e66;
  --ink-3: #9b9b90;
  --rule: #dcdcd0;
  --field: #f4f4ea;
  --red: #a00000;
  --serif: "et-book", Palatino, "Palatino Linotype", "Book Antiqua", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", "Noto Serif CJK JP", "IPAMincho", Georgia, serif;
  --mono: Consolas, "SF Mono", Menlo, monospace;
  --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);
  --tab-h: 46px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151515;
    --ink: #dddddd;
    --ink-2: #a3a39b;
    --ink-3: #75756e;
    --rule: #34342f;
    --field: #1f1f1d;
    --red: #e07a6e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.5 var(--serif);
  font-variant-numeric: oldstyle-nums;
  /* Real italics come from ET Book; Japanese stays upright instead of getting a fake slant. */
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.viewer-open { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; text-decoration-skip-ink: auto; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }

.view {
  min-height: 100vh;
  padding: 0 calc(22px + var(--safe-r)) calc(var(--tab-h) + var(--safe-b) + 40px) calc(22px + var(--safe-l));
  max-width: 680px;
  margin: 0 auto;
}

/* ---------- head of page ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  margin: 0 -22px; padding: calc(var(--safe-t) + 12px) 22px 4px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.tb-row { display: flex; align-items: baseline; min-height: 40px; gap: 12px; }
.tb-spacer { flex: 1; }
.tb-title { margin: 0; font-size: 2rem; font-weight: 400; line-height: 1.1; letter-spacing: -0.005em; }
.topbar.has-back .tb-title { margin-top: 6px; font-size: 1.45rem; font-style: italic; }
.tb-back, .sync-btn {
  padding: 8px 0; border: 0; background: none; color: var(--ink-2); font-size: 1rem; font-style: italic; cursor: pointer;
}
.tb-back { margin-left: 0; }
.tb-back .ic { display: none; }
.sync-btn.spinning { color: var(--ink-3); }
.sync-status { font-size: 0.85rem; font-style: italic; color: var(--ink-2); }
.sync-status:empty { display: none; }

/* A sentence with a word-sized graphic in it. */
.lede { margin: 4px 0 2px; font-size: 0.95rem; color: var(--ink-2); }
.lede .now { color: var(--red); }
.spark { display: inline-block; width: auto; height: 0.85em; vertical-align: -0.05em; margin: 0 0.25em; overflow: visible; }
.spark polyline { fill: none; stroke: var(--ink-2); stroke-width: 1; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.spark circle { fill: var(--red); }

/* ---------- tabs: words, not icons ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: space-between; gap: 8px;
  padding: 0 calc(22px + var(--safe-r)) var(--safe-b) calc(22px + var(--safe-l));
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 0.5px solid var(--rule);
}
.tab {
  display: flex; align-items: center; height: var(--tab-h);
  color: var(--ink-3); font-size: 0.95rem; text-decoration: none;
}
.tab .ic { display: none; }
.tab.active { color: var(--ink); font-style: italic; }

/* ---------- search & counts ---------- */
.search-wrap { margin: 2px 0 8px; }
.search {
  width: 100%; height: 38px; padding: 0; border: 0; border-bottom: 0.5px solid var(--rule); border-radius: 0;
  background: none; font-size: 1rem;
  -webkit-appearance: none; appearance: none;
}
.search::placeholder { color: var(--ink-3); font-style: italic; }
.search:focus { outline: none; border-bottom-color: var(--ink-2); }
.count { margin: 10px 0 0; font-size: 0.9rem; color: var(--ink-2); }
.count.bar { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sort {
  border: 0; background: none; color: var(--ink-2); font-size: 0.9rem; font-style: italic; text-align: right;
  -webkit-appearance: none; appearance: none; padding: 6px 0; cursor: pointer;
}

/* ---------- entries ---------- */
.list { margin-top: 6px; }
.row {
  display: flex; align-items: flex-start; gap: 16px; width: 100%;
  padding: 9px 0 10px; border: 0;
  background: none; color: inherit; text-align: left; text-decoration: none; cursor: pointer;
  -webkit-touch-callout: none;
}
.row-main { flex: 1; min-width: 0; }
.row-btn { display: block; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.row-title {
  font-size: 1.08rem; line-height: 1.3; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.cite, .meta {
  margin-top: 2px; font-size: 0.9rem; line-height: 1.4; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta { display: flex; align-items: baseline; gap: 0.7em; }
.meta > span:not(.offline-dot) { overflow: hidden; text-overflow: ellipsis; }
.meta > span:nth-child(2) { font-style: italic; }
.cite-ay { margin-right: 0.45em; }
.cite-venue { font-style: italic; }
.row-marks { padding-top: 3px; flex: none; }
.row-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; padding-top: 2px; }
.text-btn {
  padding: 2px 0; border: 0; background: none; color: var(--ink);
  font-size: 0.92rem; font-style: italic; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em;
  cursor: pointer;
}
.text-btn.quiet { color: var(--ink-3); text-decoration: none; }

.kind { font-size: 0.88rem; font-style: italic; color: var(--ink-3); white-space: nowrap; }
.kind-slides { color: var(--ink-2); }

.chip {
  padding: 4px 0; border: 0; background: none; color: var(--ink-2);
  font-size: 0.92rem; font-style: italic; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer;
}
.offline-dot { display: none; width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); flex: none; align-self: center; }
.is-offline .offline-dot { display: inline-block; }

.folder-row { align-items: baseline; }
.folder-name { font-size: 1.08rem; }
.folder-n { color: var(--ink-3); font-size: 0.95rem; }
.chev { display: none; }

.sentinel { height: 1px; }
.empty { padding: 56px 0; }
.empty-title { margin: 0 0 6px; font-size: 1.25rem; font-style: italic; }
.empty-body { margin: 0 0 18px; max-width: 30em; color: var(--ink-2); font-size: 1rem; }

/* ---------- an item, set like the head of a paper ---------- */
.item-head { padding: 2px 0 6px; }
.item-title { margin: 0; font-size: 1.85rem; font-weight: 400; line-height: 1.15; }
.item-authors { margin: 12px 0 0; font-size: 1.12rem; font-style: italic; line-height: 1.35; }
.item-pub { margin: 4px 0 0; font-size: 1rem; color: var(--ink-2); }
.item-year { margin-left: 0.5em; }
.citekey {
  margin-top: 8px; padding: 0; border: 0; background: none;
  font: 0.8rem/1.5 var(--mono); color: var(--ink-3); cursor: pointer;
}
.sec { margin-top: 32px; }
.sec-title { margin: 0 0 4px; font-size: 1.3rem; font-weight: 400; font-style: italic; line-height: 1.2; }
.group { margin-top: 2px; }
.file-row { align-items: baseline; padding: 7px 0; }
.file-mark { width: 4.6em; flex: none; }
.file-title { font-size: 1.02rem; line-height: 1.35; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; text-decoration-color: var(--ink-3); }
.file-name { margin-top: 1px; font-size: 0.8rem; color: var(--ink-3); overflow-wrap: anywhere; }
.file-row.unavailable .file-title { text-decoration: none; color: var(--ink-3); }
.abstract { margin: 6px 0 0; font-size: 1.05rem; line-height: 1.6; hyphens: auto; -webkit-hyphens: auto; }
.abstract.clamp { display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden; }
.newthought { font-variant: small-caps; letter-spacing: 0.03em; font-size: 1.12em; }
.link-btn { margin-top: 4px; padding: 4px 0; border: 0; background: none; color: var(--ink-2); font-style: italic; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.note { padding: 6px 0; }
.note summary { font-size: 1.02rem; cursor: pointer; list-style: none; }
.note summary::-webkit-details-marker { display: none; }
.note summary::before { content: "+ "; color: var(--ink-3); }
.note[open] summary::before { content: "− "; }
.note-body { margin: 6px 0 0 1.2em; font-size: 0.98rem; line-height: 1.55; overflow-wrap: anywhere; }
.note-body h3, .note-body h4 { font-size: 1rem; font-style: italic; font-weight: 400; margin: 0.9em 0 0.2em; }
.links { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.ext { word-break: break-all; font-size: 1rem; }
.tags { display: flex; flex-wrap: wrap; gap: 2px 0; margin-top: 4px; }
.tag {
  padding: 0; border: 0; background: none; color: var(--ink-2); font-size: 1rem; font-style: italic; text-decoration: none; cursor: pointer;
}
.tags > .tag:not(:last-child)::after { content: ","; margin-right: 0.45em; font-style: normal; }

/* ---------- forms, setup, settings ---------- */
.lead { margin: 6px 0 24px; color: var(--ink-2); font-size: 1rem; }
.step { margin: 0 0 30px; padding: 0; }
.step-title { display: flex; align-items: baseline; gap: 0.5em; margin: 0 0 8px; font-size: 1.3rem; font-weight: 400; font-style: italic; }
.step-n { font-style: normal; color: var(--ink-3); }
.step.done .step-n { color: var(--ink); }
.ok { margin: 0 0 10px; font-style: italic; }
.howto { margin: 0 0 12px; padding-left: 1.3em; font-size: 0.98rem; color: var(--ink-2); }
.howto li { margin: 3px 0; }
.field { display: block; margin: 12px 0; }
.field-label { display: block; margin-bottom: 2px; font-size: 0.9rem; font-style: italic; color: var(--ink-2); }
.field-hint { display: block; margin: 6px 0; font-size: 0.88rem; color: var(--ink-3); }
.field-msg { margin: 8px 0 0; font-size: 0.95rem; color: var(--red); font-style: italic; }
.field-msg:empty { display: none; }
.input {
  width: 100%; height: 40px; padding: 0; border: 0; border-bottom: 0.5px solid var(--rule); border-radius: 0;
  background: none; font-size: 1rem;
}
.input:focus { outline: none; border-bottom-color: var(--ink-2); }
.redirect { display: flex; align-items: baseline; gap: 12px; }
.redirect code { flex: 1; min-width: 0; font: 0.82rem/1.45 var(--mono); overflow-wrap: anywhere; }
.alt { margin: 10px 0 4px; }
.alt summary { color: var(--ink-2); font-size: 0.95rem; font-style: italic; cursor: pointer; padding: 6px 0; list-style: none; }
.alt summary::-webkit-details-marker { display: none; }
.btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0; margin: 2px 22px 2px 0;
  border: 0; background: none; color: var(--ink-2);
  font-size: 1.02rem; font-style: italic; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.2em;
  cursor: pointer;
}
.btn-primary { color: var(--ink); font-style: normal; font-size: 1.08rem; }
.btn-danger { color: var(--red); }
.btn-quiet { color: var(--ink-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; }
.hidden { display: none !important; }
.kv-group { margin-bottom: 6px; }
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 5px 0; font-size: 1rem; }
.kv-k { color: var(--ink-2); font-style: italic; flex: none; }
.kv-v { text-align: right; overflow-wrap: anywhere; }
.kv-v .sort { padding: 0; }
.version { margin-top: 40px; font-size: 0.82rem; font-style: italic; color: var(--ink-3); }

/* ---------- toast & progress ---------- */
#toast {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 300;
  display: flex; align-items: baseline; gap: 14px;
  padding: 11px calc(22px + var(--safe-r)) 11px calc(22px + var(--safe-l));
  border-top: 0.5px solid var(--rule); background: var(--paper); color: var(--ink);
  font-size: 0.95rem; font-style: italic; line-height: 1.45; opacity: 0; pointer-events: none;
  transition: opacity 0.18s;
}
#toast.show { opacity: 1; pointer-events: auto; }
.toast-act { flex: none; margin-left: auto; border: 0; background: none; color: var(--ink); font-style: normal; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.prog { position: fixed; inset: 0; z-index: 250; display: grid; place-items: center; background: color-mix(in srgb, var(--paper) 82%, transparent); }
.prog-card { width: min(84vw, 340px); text-align: left; }
.prog-title { font-size: 1.15rem; font-style: italic; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.prog-track { height: 1px; margin: 14px 0 8px; background: var(--rule); overflow: hidden; }
.prog-fill { width: 4%; height: 100%; background: var(--ink); transition: width 0.15s; }
.prog-label { font-size: 0.88rem; color: var(--ink-2); margin-bottom: 2px; }
.prog .btn { min-height: 36px; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 200; background: #151515; color: #dddddd; font-family: var(--serif); }
.viewer[data-mode="doc"] { background: #f1f1e6; color: #111; }
.v-stage { position: absolute; inset: 0; overflow: hidden; }
.v-stage.slides { display: flex; align-items: center; justify-content: center; touch-action: none; }
.v-stage.slides.zoomed { display: block; overflow: auto; touch-action: pan-x pan-y; }
.v-slide-wrap { flex: none; line-height: 0; will-change: transform; transition: transform 0.12s ease-out; }
.v-stage.slides.zoomed .v-slide-wrap { display: inline-block; transition: none; }
.v-slide-wrap canvas { display: block; background: #fff; }
.v-stage.doc { overflow: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.v-doc {
  position: relative; transform-origin: 0 0;
  padding: calc(var(--safe-t) + 56px) 8px calc(var(--safe-b) + 60px);
}
.v-page { position: relative; margin: 0 auto 10px; background: #fff; box-shadow: 0 0 0 0.5px #d6d6ca; }
.v-page canvas { display: block; width: 100%; height: 100%; }

.v-bar {
  position: absolute; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 10px;
  padding-left: calc(10px + var(--safe-l)); padding-right: calc(16px + var(--safe-r));
  background: rgb(21 21 21 / 0.82);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: opacity 0.2s;
}
.viewer[data-mode="doc"] .v-bar { background: rgb(255 255 248 / 0.9); }
.v-top { top: 0; padding-top: calc(var(--safe-t) + 2px); padding-bottom: 4px; }
.v-bottom { bottom: 0; padding-top: 4px; padding-bottom: calc(var(--safe-b) + 6px); }
.viewer.chrome-hidden .v-bar { opacity: 0; pointer-events: none; }
.v-icon {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border: 0;
  background: none; color: inherit; cursor: pointer;
}
.v-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
.v-icon:disabled { opacity: 0.25; }
.v-head { flex: 1; min-width: 0; }
.v-title { font-size: 1rem; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-sub { font-size: 0.8rem; opacity: 0.65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-mode { flex: none; padding: 8px 0; border: 0; background: none; color: inherit; opacity: 0.75; font-size: 0.92rem; font-style: italic; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.v-count { flex: none; min-width: 52px; text-align: right; font-size: 1rem; }

/* Page scrubber as a rug: one tick per page (or per few pages), a dot for where you are. */
.v-scrub { position: relative; flex: 1; min-width: 0; height: 32px; }
.v-rug { position: absolute; left: 5px; right: 5px; top: 50%; height: 7px; transform: translateY(-50%); opacity: 0.45; pointer-events: none; }
.v-tick { position: absolute; top: 0; bottom: 0; width: 1px; margin-left: -0.5px; background: currentColor; }
.v-range {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  background: none; -webkit-appearance: none; appearance: none; cursor: pointer;
}
.v-range::-webkit-slider-runnable-track { height: 32px; background: none; }
.v-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 10px; height: 10px; margin-top: 11px;
  border-radius: 50%; background: currentColor; border: 0;
}
.v-range::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: currentColor; border: 0; }

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