/* Books: shelf, reader and translation card.
   UI uses the site's fonts (Sicarius Remake, Helvetica Neue).
   The Japanese book text uses --book-font, set from settings.js. */

@font-face {
  font-family: 'Sicarius Remake';
  src: url('../uploads/SicariusRemake-Regular.otf') format('opentype');
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  /* Site palette (same as the home page) */
  --bg: oklch(0.14 0.006 260);
  --tile: oklch(0.18 0.008 260);
  --tile-2: oklch(0.22 0.01 260);
  --line: oklch(0.3 0.015 255);
  --fg: oklch(0.97 0.002 0);
  --muted: oklch(0.7 0.01 250);
  --dim: oklch(0.55 0.012 250);
  --accent: oklch(0.72 0.19 250);
  --accent-ink: oklch(0.13 0.01 260);

  /* Reading page ("paper" theme; sepia and night arrive in Phase 5) */
  --paper: oklch(0.965 0.012 85);
  --ink: oklch(0.24 0.012 60);
  --ink-soft: oklch(0.45 0.015 60);
  --rule: oklch(0.85 0.02 80);

  --ui-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --display-font: 'Sicarius Remake', var(--ui-font);
  --book-font: 'Noto Serif JP', serif;  /* overridden from settings.js */
  --text-size: 20px;
  --margin-x: 22px;
  --margin-y: 28px;
  --select: oklch(0.62 0.17 250);
  --saved: var(--saved-colour, oklch(0.9 0.11 95 / 0.65));
  --grain: 0.06;               /* paper texture strength */
  --grain-blend: multiply;
  --top-h: 56px;
}

/* Reading themes (the reader only; the top bar and card keep the site look). */
:root[data-reading='sepia'] {
  --paper: oklch(0.91 0.035 75);
  --ink: oklch(0.3 0.035 55);
  --ink-soft: oklch(0.48 0.04 60);
  --rule: oklch(0.8 0.04 70);
  --grain: 0.08;
}
:root[data-reading='night'] {
  --paper: oklch(0.2 0.012 260);
  --ink: oklch(0.86 0.012 85);
  --ink-soft: oklch(0.64 0.012 85);
  --rule: oklch(0.33 0.015 260);
  --saved: oklch(0.62 0.11 90 / 0.38);
  --select: oklch(0.72 0.14 250);
  --grain: 0.05;
  --grain-blend: screen;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom: a second tap expands the chunk */
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---------- Top bar (shared) ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in oklch, var(--bg) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  color: var(--fg);
}
.top-in {
  height: var(--top-h); max-width: 1120px; margin: 0 auto;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 4px;
}
.back {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: 999px;
  text-decoration: none; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.back:hover { color: var(--fg); background: var(--tile); }
.back svg { flex: none; }
.top-title {
  flex: 1; min-width: 0; text-align: center;
  font-family: var(--display-font); font-size: 22px; letter-spacing: 0.04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-title .jp { font-family: var(--book-font); font-size: 17px; letter-spacing: 0; }
.top-end { position: relative; width: 92px; gap: 2px; flex: none; margin-left: auto; display: flex; justify-content: flex-end; }

/* ---------- Font button and menu ---------- */
.hl-btn {
  width: 44px; height: 44px; border-radius: 999px; cursor: pointer; flex: none;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--dim);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.hl-btn .ink { stroke: currentColor; opacity: 0.35; }
.hl-btn[aria-pressed='true'] { color: var(--fg); }
.hl-btn[aria-pressed='true'] .ink { stroke: oklch(0.88 0.14 95); opacity: 1; }
.hl-btn:hover { background: var(--tile); border-color: var(--line); }
.font-btn {
  width: 44px; height: 44px; border-radius: 999px; cursor: pointer;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  font-family: var(--book-font); font-size: 19px; line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.font-btn:hover, .font-btn[aria-expanded='true'] { background: var(--tile); border-color: var(--line); color: var(--fg); }
.font-menu {
  position: absolute; z-index: 50; top: calc(100% + 6px); right: 0;
  width: min(300px, calc(100vw - 16px)); max-height: calc(100vh - var(--top-h) - 24px); overflow: auto;
  padding: 6px; border-radius: 14px;
  background: var(--tile); border: 1px solid var(--line); color: var(--fg);
  box-shadow: 0 18px 50px oklch(0.1 0.02 260 / 0.45);
}
.font-menu-title { font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); padding: 10px 12px 6px; }
.font-item {
  display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: baseline;
  width: 100%; min-height: 44px; padding: 10px 12px; border: 0; border-radius: 10px;
  background: transparent; text-align: left; cursor: pointer;
}
.font-item:hover, .font-item:focus-visible { background: var(--tile-2); outline: none; }
.font-item[aria-checked='true'] { background: color-mix(in oklch, var(--accent) 16%, transparent); }
.font-item[aria-checked='true'] .font-name::after { content: ' ✓'; color: var(--accent); }
.font-sample { grid-column: 1 / -1; font-size: 21px; line-height: 1.45; }
.font-name { font-size: 13px; color: var(--fg); margin-top: 2px; }
.font-style { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* Display menu sections (reader) */
.menu-section { padding: 4px 12px 10px; }
.menu-label { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); padding: 8px 12px 6px; }
.menu-section .menu-label { padding: 4px 0 6px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 3px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  color: var(--muted); font: 600 13px/1 var(--ui-font); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.seg:hover { color: var(--fg); background: var(--tile-2); }
.seg[aria-checked='true'] { background: var(--accent); color: var(--accent-ink); }
.sizes .seg span { font-family: var(--book-font); line-height: 1; }
.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid oklch(0.5 0.01 260 / 0.5); flex: none; }
.swatch.paper { background: oklch(0.965 0.012 85); }
.swatch.sepia { background: oklch(0.91 0.035 75); }
.swatch.night { background: oklch(0.2 0.012 260); }
.menu-hint { margin: 6px 2px 0; font-size: 12px; line-height: 1.4; color: var(--dim); }

/* ---------- Shelf ---------- */
body.shelf {
  min-height: 100vh; color: var(--fg);
  background:
    radial-gradient(1200px 600px at 50% -10%, oklch(0.22 0.04 255 / 0.55), transparent 70%),
    linear-gradient(oklch(1 0 0 / 0.025) 1px, transparent 1px) 0 0 / 100% 48px,
    linear-gradient(90deg, oklch(1 0 0 / 0.025) 1px, transparent 1px) 0 0 / 48px 100%,
    var(--bg);
}
.shelf main { max-width: 880px; margin: 0 auto; padding: clamp(28px, 6vh, 64px) 16px 48px; }
.kicker { font-size: 12px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--accent); }
.shelf h1 {
  font-family: var(--display-font); font-weight: 400; letter-spacing: 0.02em;
  font-size: clamp(48px, 12vw, 96px); line-height: 0.95; margin: 12px 0 10px;
}
.shelf .sub { color: var(--muted); font-size: 16px; line-height: 1.5; margin: 0 0 32px; max-width: 520px; }
.books { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.book {
  display: flex; flex-direction: column; gap: 6px; min-height: 150px;
  padding: 20px; border-radius: 14px; text-decoration: none;
  background: var(--tile); border: 1px solid var(--line);
  transition: border-color 0.2s, transform 0.2s;
}
.book:hover, .book:focus-visible { border-color: color-mix(in oklch, var(--accent) 60%, var(--line)); transform: translateY(-2px); }
.book .jp { font-family: var(--book-font); font-size: 26px; font-weight: 600; line-height: 1.35; }
.book .en { font-family: var(--display-font); font-size: 20px; letter-spacing: 0.04em; color: var(--muted); }
.book .by { font-size: 13px; color: var(--muted); line-height: 1.5; margin-top: auto; padding-top: 10px; }
.book .len { font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); }
.credits { margin-top: 40px; font-size: 12px; line-height: 1.6; color: var(--dim); max-width: 600px; }
.credits a { color: var(--muted); }
.status { color: var(--muted); font-size: 15px; }

/* ---------- Reader ---------- */
/* The reader is a fixed screen of pages: nothing scrolls. */
body.reader {
  background: var(--paper); color: var(--ink);
  height: 100vh; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  overscroll-behavior: none;
}
.stage {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  /* Sideways drags turn pages, so the browser mustn't pan; pinch-zoom still works. */
  touch-action: pinch-zoom;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.viewport { position: absolute; left: 0; right: 0; overflow: hidden; z-index: 1; }
/* Paper texture: a tiny generated noise tile (no image file), very faint. */
.stage::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  opacity: var(--grain); mix-blend-mode: var(--grain-blend);
  background:
    radial-gradient(120% 90% at 50% 40%, transparent 55%, oklch(0.4 0.04 60 / 0.35) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.22 0 0 0 1.1 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}
.run-head, .run-foot, .progress { position: relative; z-index: 1; }
.flow {
  position: absolute; top: 0;
  column-fill: auto;           /* fill each page in turn, don't balance */
  will-change: transform;
}
.flow > .status { color: var(--ink-soft); font-size: 15px; }
.edge {
  position: absolute; top: 0; bottom: 0; left: 0; width: 28px; opacity: 0; pointer-events: none;
  background: linear-gradient(to right, oklch(0.3 0.03 60 / 0.16), oklch(0.3 0.03 60 / 0.05) 40%, transparent);
}
.run-head span, .run-foot span {
  position: absolute; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12px; letter-spacing: 0.06em; color: var(--ink-soft);
}
.run-head span { top: calc(var(--margin-y) / 2 - 8px); font-family: var(--book-font); }
.run-foot span { bottom: calc(var(--margin-y) / 2 - 8px + env(safe-area-inset-bottom, 0px)); font-variant-numeric: tabular-nums; }
.progress { position: absolute; left: 0; right: 0; bottom: env(safe-area-inset-bottom, 0px); height: 3px; background: color-mix(in oklch, var(--rule) 70%, transparent); }
.progress-bar { height: 100%; background: color-mix(in oklch, var(--select) 70%, var(--ink-soft)); transform-origin: 0 50%; transform: scaleX(0); transition: transform 0.25s ease; }

/* Title page: a page of its own, centred. */
.title-block {
  text-align: center; min-height: var(--page-h, auto);
  display: flex; flex-direction: column; justify-content: center;
  -webkit-column-break-after: always; break-after: column;
}
.title-block h1 + .en { margin-bottom: 4px; }
.contents { margin: 26px auto 0; width: min(100%, 22em); text-align: left; }
.contents-head { font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--ink-soft); text-align: center; padding-bottom: 8px; border-bottom: 1px solid var(--rule); }
.contents ol { list-style: none; margin: 0; padding: 0; }
.contents li { border-bottom: 1px solid var(--rule); }
.contents-item {
  display: flex; align-items: baseline; gap: 12px; width: 100%; min-height: 44px; padding: 10px 4px;
  background: transparent; border: 0; color: var(--ink); cursor: pointer; text-align: left;
}
.contents-item:hover { color: var(--select); }
.contents-item .n { font: 12px/1 var(--ui-font); color: var(--ink-soft); min-width: 1.5em; font-variant-numeric: tabular-nums; }
.contents-item .t { font-family: var(--book-font); font-size: calc(var(--text-size) * 0.9); }
.contents-item .te { margin-left: auto; font-size: 12px; color: var(--ink-soft); text-align: right; }
.title-credits { margin-top: 22px; font-size: 11.5px; line-height: 1.6; color: var(--ink-soft); }
.title-credits a { color: inherit; }
.title-block h1 { font-family: var(--book-font); font-weight: 600; font-size: calc(var(--text-size) * 1.6); margin: 0 0 6px; letter-spacing: 0.08em; }
.title-block .en { font-family: var(--display-font); font-size: 20px; letter-spacing: 0.05em; color: var(--ink-soft); }
.title-block .meta { font-size: 13px; line-height: 1.6; color: var(--ink-soft); margin-top: 14px; }
.title-block .meta a { color: inherit; }
.chapter-title { font-family: var(--book-font); font-weight: 600; font-size: calc(var(--text-size) * 1.2); text-align: center; margin: 8px 0 24px; }

.text {
  font-family: var(--book-font); font-size: var(--text-size); line-height: 2.05;
  font-feature-settings: 'palt' 0;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  line-break: strict; word-break: normal; overflow-wrap: anywhere;
}
.text p { margin: 0 0 0.6em; text-indent: 1em; orphans: 2; widows: 2; }
.text p.quote { text-indent: 0; }

/* Furigana (native ruby). The line height leaves room above each line for
   it, so lines stay evenly spaced whichever mode is on. */
.text ruby { ruby-position: over; ruby-align: center; }
.text rt { font-size: 0.48em; line-height: 1; letter-spacing: 0; color: color-mix(in oklch, var(--ink) 72%, var(--paper)); font-weight: 400; user-select: none; }
:root[data-furigana='never'] .text rt { display: none; }
/* Words in your library: the reading is hidden but keeps its space, so
   saving a word never moves the text around it. */
:root[data-furigana='unsaved'] .text .w.saved rt { visibility: hidden; }

/* A word's hit area covers the whole line height, so small kana are easy to tap.
   Inline padding doesn't move the text. */
.w { padding-block: 0.5em; cursor: pointer; border-radius: 3px; }
.sel, .sel .w {
  text-decoration: underline; text-decoration-thickness: 2px;
  text-underline-offset: 0.3em; text-decoration-color: color-mix(in oklch, var(--select) 70%, transparent);
}
.w.sel, .ph.sel, .s.sel { background: color-mix(in oklch, var(--select) 9%, transparent); }

/* Saved chunks (when the highlighter is on): a marker stroke over the text
   itself. content-box keeps it off the word's enlarged tap area. */
.hl-on .w.saved, .hl-on .ph.saved {
  background-color: var(--saved); background-clip: content-box;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.hl-on .ph.saved .w.saved { background-color: transparent; }
/* A saved sentence is marked more quietly, with a dotted underline. */
.hl-on .s.saved {
  text-decoration: underline dotted; text-decoration-thickness: 2px; text-underline-offset: 0.32em;
  text-decoration-color: color-mix(in oklch, var(--saved) 100%, var(--ink) 25%);
}

.end-credits { margin-top: 32px; padding-top: 16px; break-inside: avoid; border-top: 1px solid var(--rule); font-size: 12px; line-height: 1.6; color: var(--ink-soft); }
.end-credits a { color: inherit; }

/* ---------- Translation card ---------- */
.card {
  position: fixed; z-index: 40; left: 0; top: 0;
  width: min(var(--card-w, 360px), calc(100vw - 24px));
  max-height: calc(100vh - 24px); overflow: auto; overscroll-behavior: contain;
  background: var(--tile); color: var(--fg);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 50px oklch(0.1 0.02 260 / 0.35), 0 2px 8px oklch(0.1 0.02 260 / 0.25);
  padding: 14px 16px 14px;
  opacity: 0; transform: translateY(4px) scale(0.98); transform-origin: var(--origin, 50% 100%);
  transition: opacity 0.14s ease, transform 0.16s ease;
  pointer-events: none;
}
.card.open { opacity: 1; transform: none; pointer-events: auto; }
/* For a sentence the translation comes first: the Japanese is underlined on the page. */
.card { display: flex; flex-direction: column; }
.card.is-sentence .card-gloss { order: 1; margin-top: 6px; }
.card.is-sentence .card-jp { order: 2; margin-top: 10px; color: var(--muted); }
.card.is-sentence .card-actions { order: 3; }
.card.sheet {
  left: 0; right: 0; width: auto; border-radius: 16px 16px 0 0; border-bottom: 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateY(12px);
}
.card.sheet.at-top {
  border-radius: 0 0 16px 16px; border-top: 0; border-bottom: 1px solid var(--line);
  padding-top: calc(14px + env(safe-area-inset-top, 0px)); padding-bottom: 14px;
  transform: translateY(-12px);
}
.card.sheet.open { transform: none; }

.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-level { font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); padding-top: 4px; }
.card-close {
  margin: -10px -10px 0 auto; flex: none; width: 44px; height: 44px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer;
}
.card-close:hover { background: var(--tile-2); color: var(--fg); }
.card-jp { font-family: var(--book-font); font-size: 24px; line-height: 1.5; margin: 2px 0 0; overflow-wrap: anywhere; }
.card.is-sentence .card-jp { font-size: 18px; line-height: 1.7; }
.card-reading { font-family: var(--book-font); font-size: 15px; color: var(--muted); margin-top: 2px; }
.card-gloss { font-size: 18px; line-height: 1.4; margin: 10px 0 0; }
.card.is-sentence .card-gloss { font-size: 16px; line-height: 1.5; }
.card-meta { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.5; color: var(--muted); }
.card-meta li + li { margin-top: 2px; }
.card-meta .jp { font-family: var(--book-font); color: var(--fg); }
.card-meta .archaic::before { content: '古'; font-family: var(--book-font); display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; margin-right: 6px; border-radius: 4px; background: oklch(0.5 0.08 60 / 0.35); color: oklch(0.88 0.06 75); font-size: 12px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-actions button {
  min-height: 44px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  font-size: 14px; letter-spacing: 0.04em;
  border: 1px solid var(--line); background: var(--tile-2);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.card-actions button:hover { border-color: color-mix(in oklch, var(--accent) 60%, var(--line)); }
.card-actions .save { margin-left: auto; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.card-actions .save[aria-pressed='true'] { background: transparent; color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .card, .card.sheet, .card.sheet.at-top { transform: none; }
}

/* ---------- Library ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.lib-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.lib-search {
  flex: 1 1 240px; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  background: var(--tile); border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
}
.lib-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 25%, transparent); }
.lib-search input {
  flex: 1; min-width: 0; height: 42px; border: 0; background: transparent; color: var(--fg);
  font: 15px/1 var(--ui-font); outline: none;
}
.lib-search input::placeholder { color: var(--dim); }
.lib-filter select {
  min-height: 44px; padding: 0 36px 0 14px; border-radius: 999px; max-width: 100%;
  background: var(--tile) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23a3a8b4' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1px solid var(--line); color: var(--fg); font: 14px/1 var(--ui-font); appearance: none; -webkit-appearance: none;
}
.lib-count { font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); margin: 6px 0 12px; min-height: 1em; }
.lib-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lib-item { background: var(--tile); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; transition: border-color 0.2s; }
.lib-item.open, .lib-item:hover { border-color: color-mix(in oklch, var(--accent) 50%, var(--line)); }
.lib-head {
  display: grid; gap: 3px; width: 100%; padding: 14px 16px; text-align: left; cursor: pointer;
  background: transparent; border: 0; min-height: 44px;
}
.lib-jp { font-family: var(--book-font); font-size: 24px; line-height: 1.4; overflow-wrap: anywhere; }
.lib-jp.sentence { font-size: 17px; line-height: 1.7; }
.lib-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.lib-reading { font-family: var(--book-font); font-size: 14px; }
.lib-dict span { font-family: var(--book-font); color: var(--fg); }
.lib-gloss { font-size: 16px; line-height: 1.4; margin-top: 2px; }
.lib-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12px; color: var(--dim); margin-top: 6px; }
.lib-foot [lang='ja'] { font-family: var(--book-font); }
.lib-type { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent); }
.lib-panel { padding: 0 16px 14px; border-top: 1px solid var(--line); }
.lib-sentence { font-family: var(--book-font); font-size: 18px; line-height: 1.8; margin: 12px 0 4px; }
.lib-sentence mark { background: color-mix(in oklch, oklch(0.88 0.14 95) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.lib-sentence-gloss { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 4px; }
.lib-actions { display: flex; gap: 8px; margin-top: 12px; }
.lib-go, .lib-del, .lib-link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 999px;
  font: 600 14px/1 var(--ui-font); letter-spacing: 0.03em; text-decoration: none; cursor: pointer;
}
.lib-go, .lib-link { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
.lib-del { margin-left: auto; background: transparent; color: var(--muted); border: 1px solid var(--line); }
.lib-del:hover { color: oklch(0.75 0.15 25); border-color: oklch(0.6 0.15 25); }
.lib-empty { display: grid; gap: 6px; justify-items: start; padding: 22px 20px; border-radius: 14px; border: 1px dashed var(--line); color: var(--muted); line-height: 1.5; }
.lib-empty strong { color: var(--fg); font-size: 17px; }
.lib-empty .lib-link { margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 24px);
  padding: 6px 6px 6px 18px; border-radius: 999px; background: var(--fg); color: var(--bg);
  box-shadow: 0 10px 30px oklch(0.1 0.02 260 / 0.4); font-size: 14px;
}
.toast span { font-family: var(--book-font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast button { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }

/* Shelf: the way into the library */
.lib-entry {
  display: flex; align-items: center; gap: 14px; margin: 0 0 18px; padding: 14px 18px; min-height: 64px;
  background: var(--tile); border: 1px solid var(--line); border-radius: 14px; text-decoration: none;
  transition: border-color 0.2s, transform 0.2s;
}
.lib-entry:hover, .lib-entry:focus-visible { border-color: color-mix(in oklch, var(--accent) 60%, var(--line)); transform: translateY(-2px); }
.lib-entry .jp { font-family: var(--book-font); font-size: 26px; line-height: 1; color: var(--accent); }
.lib-entry strong { display: block; font-family: var(--display-font); font-weight: 400; font-size: 20px; letter-spacing: 0.04em; }
.lib-entry small { display: block; color: var(--muted); font-size: 13px; }
.lib-entry .arrow { margin-left: auto; color: var(--accent); font-size: 20px; }
