/* LingoLens: quiet, neutral chrome; colour is reserved for glosses and progress. */

@font-face {
  font-family: "Literata";
  src: url("vendor/fonts/literata-latin.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("vendor/fonts/literata-latin-italic.woff2") format("woff2");
  font-weight: 300 800;
  font-style: italic;
  font-display: swap;
}

/* ------------------------------------------------------------ tokens */
:root {
  --canvas: #fafafa;
  --surface: #ffffff;
  --sunken: #f4f4f5;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --hover: #f4f4f5;
  --primary: #18181b;      /* buttons are ink, not a brand colour */
  --on-primary: #ffffff;
  --gloss: #d1343d;        /* word glosses and reading progress */
  --phrase: #2f6feb;       /* phrase glosses */
  --phrase-line: #a9c3f5;
  --focus: #2f6feb;
  --danger: #d1343d;
  --success: #15803d;
  --thread: var(--gloss);  /* reading progress under the header */
  --mark-tile: var(--ink); --mark-word: var(--canvas);
  --code-bg: var(--primary); --code-ink: var(--on-primary); /* level badge */
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, .06);
  --shadow: 0 1px 2px rgba(24, 24, 27, .04), 0 8px 24px rgba(24, 24, 27, .08);
  --shadow-lg: 0 2px 4px rgba(24, 24, 27, .04), 0 16px 48px rgba(24, 24, 27, .14);
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --serif: "Literata", Georgia, "Noto Serif CJK SC", "Songti SC", serif;
  --kai: "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  /* Night reading: warm charcoal, not black; soft off-white text (~12.7:1, not 17:1)
     and muted gloss colours, to cut glare and halo around letters. */
  :root:not([data-theme="light"]) {
    --canvas: #1c1b19; --surface: #242320; --sunken: #2a2825; --ink: #e3ddd2; --ink-2: #c8c1b5;
    --muted: #9b9488; --line: #33312d; --line-strong: #45423d; --hover: #2c2a27;
    --primary: #e3ddd2; --on-primary: #1c1b19; --gloss: #ec9a85; --phrase: #93b4dc; --phrase-line: #4a5d78;
    --focus: #93b4dc; --danger: #ec9a85; --success: #93c9a0;
    /* Header: a quiet neutral progress line, a navy logo tile, a tinted level badge. */
    --thread: #8f877a; --mark-tile: #2c3a50; --mark-word: #e3ddd2; --code-bg: #3a3731; --code-ink: #ece6db;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 16px 48px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #1c1b19; --surface: #242320; --sunken: #2a2825; --ink: #e3ddd2; --ink-2: #c8c1b5;
  --muted: #9b9488; --line: #33312d; --line-strong: #45423d; --hover: #2c2a27;
  --primary: #e3ddd2; --on-primary: #1c1b19; --gloss: #ec9a85; --phrase: #93b4dc; --phrase-line: #4a5d78;
  --focus: #93b4dc; --danger: #ec9a85; --success: #93c9a0;
    /* Header: a quiet neutral progress line, a navy logo tile, a tinted level badge. */
    --thread: #8f877a; --mark-tile: #2c3a50; --mark-word: #e3ddd2; --code-bg: #3a3731; --code-ink: #ece6db;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 16px 48px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ------------------------------------------------------------ base */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-tap-highlight-color: transparent; }
@media (pointer: fine) { html { overscroll-behavior: none; } }
body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, label, summary { touch-action: manipulation; }
a { color: inherit; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100; padding: 8px 14px; border-radius: var(--r-sm);
  background: var(--primary); color: var(--on-primary); text-decoration: none; font-weight: 600;
}
.skip-link:focus-visible { top: 12px; }

/* ------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font-weight: 500; font-size: 14px;
  cursor: pointer; white-space: nowrap; text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background-color .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); border-color: var(--line-strong); }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: .88; background: var(--primary); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; height: 42px; }
.btn.danger-link { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
/* A spinner while a request is in flight. */
.btn[aria-busy="true"] { color: transparent !important; position: relative; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--on-primary); border-right-color: transparent;
  animation: spin .7s linear infinite;
}
.btn:not(.primary)[aria-busy="true"]::after { border-color: var(--ink); border-right-color: transparent; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--hover); }

select, input[type="url"], input[type="text"], input[type="email"], input[type="password"], input:not([type]), textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
select option { background: var(--surface); color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:not([type="checkbox"]):not([type="radio"]):focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
input[type="checkbox"]:not([role="switch"]) { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

/* Switch-styled checkbox */
input[role="switch"] {
  appearance: none; flex: none; width: 36px; height: 20px; border-radius: 10px; margin: 0;
  background: var(--line-strong); position: relative; cursor: pointer; transition: background-color .15s;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s;
}
input[role="switch"]:checked { background: var(--primary); }
input[role="switch"]:checked::after { transform: translateX(16px); background: var(--on-primary); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--sunken); border: 1px solid var(--line); }
.seg button {
  height: 28px; min-width: 34px; padding: 0 12px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.theme-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1; }
.theme-seg svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-seg button { padding: 0 9px; }
/* Switching themes recolours everything at once instead of animating each control. */
.theme-switching, .theme-switching * { transition: none !important; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field-error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.field-error:empty { display: none; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.key-row { display: flex; gap: 6px; align-items: center; }
.key-row input { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 14px; cursor: pointer; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.note:empty { display: none; }
.saved-status { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  /* Left: logo and where you are (shrinks and truncates). Right: actions (never shrink). */
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 56px; padding: 0 clamp(12px, 3vw, 28px);
  /* Nearly solid, so text scrolling underneath doesn't ghost through. */
  background: color-mix(in srgb, var(--canvas) 97%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  /* The bar sits flush with the page until content scrolls under it. */
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
body.scrolled .topbar, body[data-view="reader"] .topbar { border-bottom-color: var(--line); }
.bar-start { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 2px; }
.bar-end { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
/* The logo is the way home; padded so it is a comfortable target. */
.brand {
  display: inline-flex; align-items: center; gap: 9px; flex: none; padding: 6px; margin-left: -6px;
  color: var(--ink); text-decoration: none; border-radius: var(--r);
}
.brand .mark { transition: opacity .15s; }
body:not([data-view="library"]) .brand:hover .mark { opacity: .8; }
.wordmark { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }

/* Breadcrumb: Shelf / Title. Ancestors are muted links; the current page is ink. */
.crumbs { min-width: 0; }
.crumbs ol { display: flex; align-items: center; min-width: 0; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.crumbs li { display: flex; align-items: center; flex: none; }
.crumbs li.crumb-title { flex: 0 1 auto; min-width: 0; } /* only book titles shrink */
.crumbs li:not(.crumb-home)::before {
  content: "/"; flex: none; margin: 0 2px; color: var(--muted); opacity: .55; font-weight: 300;
}
.crumb {
  display: block; padding: 5px 6px; border-radius: var(--r-sm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-weight: 500; text-decoration: none; transition: background-color .15s, color .15s;
}
a.crumb:hover { color: var(--ink); background: var(--hover); }
.crumb[aria-current="page"] { color: var(--ink); font-weight: 600; }

/* Mark: one word in a line of text, with its gloss above it. */
.mark { width: 28px; height: 28px; flex: none; }
.mark .m-tile { fill: var(--mark-tile); }
.mark .m-gloss { fill: var(--gloss); }
.mark .m-word { fill: var(--mark-word); }
.mark .m-line { fill: var(--mark-word); opacity: .35; }


.bar-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 9px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s, color .15s;
}
/* Connection badge: offline, syncing, synced. */
.net-status {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px 0 8px; margin-right: 4px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--sunken); color: var(--ink-2);
  font: inherit; font-size: 12.5px; font-weight: 550; white-space: nowrap; cursor: pointer;
  animation: net-in .25s ease-out both;
}
.net-status[hidden] { display: none; }
.net-status svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; display: none; }
.net-status[data-mode="offline"] .i-offline,
.net-status[data-mode="waiting"] .i-offline,
.net-status[data-mode="syncing"] .i-sync,
.net-status[data-mode="synced"] .i-synced { display: block; }
.net-status[data-mode="syncing"] .i-sync { animation: net-spin 1.1s linear infinite; }
.net-status[data-mode="synced"] { color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, var(--line)); }
.net-status[data-mode="offline"], .net-status:hover { color: var(--ink); }
@keyframes net-in { from { opacity: 0; transform: translateY(-3px); } }
@keyframes net-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .net-status, .net-status[data-mode="syncing"] .i-sync { animation: none; } }

.bar-btn:hover, .bar-btn[aria-expanded="true"] { background: var(--hover); color: var(--ink); }
.bar-btn svg, .level-chip svg, .book-del svg {
  width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
#btn-menu svg { fill: currentColor; stroke: none; }
.count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center;
  background: var(--sunken); border: 1px solid var(--line); color: var(--muted);
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }

/* Reading controls (text options, level) share one pill, apart from the app buttons. */
.bar-group {
  display: inline-flex; align-items: center; gap: 2px; height: 36px; padding: 2px; margin: 0 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.bar-group .bar-btn { height: 30px; min-width: 30px; padding: 0 8px; border-radius: 999px; }
.bar-group .bar-btn:hover, .bar-group .bar-btn[aria-expanded="true"],
.level-chip:hover, .level-chip[aria-expanded="true"] { background: color-mix(in srgb, var(--ink) 8%, var(--surface)); color: var(--ink); }
.bar-sep { width: 1px; height: 16px; background: var(--line); flex: none; }
.level-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 8px 0 3px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink);
  cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 500;
}
.lv-code {
  display: inline-grid; place-items: center; height: 24px; min-width: 30px; padding: 0 6px; border-radius: 999px;
  background: var(--code-bg); color: var(--code-ink); font-weight: 650; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.level-chip .caret { width: 15px; height: 15px; color: var(--muted); }

.read-thread { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.read-thread > div { height: 100%; width: 0; background: var(--thread); border-radius: 0 2px 2px 0; transition: width .2s linear; }

body:not([data-view="reader"]) .reader-only,
body:not([data-view="library"]) .library-only,
body[data-view="library"] .not-library,
body[data-view="reader"] .not-reader { display: none !important; }
body[data-view="settings"] #btn-gear { background: var(--hover); color: var(--ink); }

.banner {
  display: flex; align-items: center; gap: 12px;
  margin: 16px auto 0; max-width: 1040px; width: calc(100% - 32px); padding: 10px 12px 10px 16px; border-radius: var(--r);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--danger) 28%, var(--line));
  font-size: 14px;
}
.banner.info { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-sm); }
#banner-text { flex: 1; min-width: 0; }

main { padding: 0 clamp(16px, 4vw, 32px) 96px; }

/* ------------------------------------------------------------ popovers & menus */
.pop {
  position: fixed; inset: auto; margin: 0; padding: 6px;
  width: max-content; min-width: 240px; max-width: calc(100vw - 16px); max-height: calc(100dvh - 80px); overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg);
}
.pop-head { margin: 8px 10px 0; font-weight: 600; font-size: 14px; }
.pop-note { margin: 2px 10px 8px; font-size: 13px; color: var(--muted); }
.pop-foot { margin: 6px 10px 6px; font-size: 12.5px; color: var(--muted); }
.pop-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 40px; padding: 4px 10px; border-radius: var(--r-sm); font-size: 14px;
}
label.pop-row { cursor: pointer; }
label.pop-row:hover { background: var(--hover); }
.menu-pop { min-width: 200px; }
.menu-item {
  display: flex; width: 100%; align-items: center; height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink); text-align: left; cursor: pointer; text-decoration: none; font-size: 14px;
}
.menu-item:hover { background: var(--hover); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

.level-list { display: flex; flex-direction: column; min-width: 280px; }
.level-opt {
  display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 10px;
  padding: 7px 10px 7px 6px; border: 0; background: transparent; border-radius: var(--r-sm);
  text-align: left; cursor: pointer; color: var(--ink);
}
.level-opt:hover { background: var(--hover); }
.lo-code {
  justify-self: center; display: inline-grid; place-items: center; min-width: 32px; height: 24px; border-radius: 999px;
  background: var(--sunken); border: 1px solid var(--line); font-weight: 650; font-size: 12.5px;
}
.lo-name { display: block; font-size: 14px; font-weight: 500; }
.lo-hint { display: block; font-size: 12.5px; color: var(--muted); }
.level-opt[aria-selected="true"] { background: var(--hover); }
.level-opt[aria-selected="true"] .lo-code { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* ------------------------------------------------------------ shelf */
.library { max-width: 1040px; margin: 48px auto 0; }
.shelf-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.shelf-head h1, .page-title { font-family: var(--serif); font-size: clamp(28px, 3.6vw, 34px); font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin: 0; }
.shelf-summary { margin: 6px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.shelf { display: grid; gap: 32px 24px; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
.book { position: relative; min-width: 0; }
.book-link { display: block; text-decoration: none; border-radius: var(--r); }
.book-link:focus-visible { outline-offset: 4px; }

/* A generated cover: a soft tint and the title in serif type. */
.cover {
  --tint-bg: #eef2fb; --tint-fg: #1e3a8a;
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
  aspect-ratio: 4 / 5; padding: 16px 16px 18px; overflow: hidden;
  background: var(--tint-bg); color: var(--tint-fg);
  border-radius: var(--r); border: 1px solid color-mix(in srgb, var(--tint-fg) 10%, transparent);
  transition: transform .2s ease, box-shadow .2s ease;
}
.cover[data-tint="1"] { --tint-bg: #e9f5ee; --tint-fg: #14532d; }
.cover[data-tint="2"] { --tint-bg: #fbf1df; --tint-fg: #713f12; }
.cover[data-tint="3"] { --tint-bg: #fbeaee; --tint-fg: #881337; }
.cover[data-tint="4"] { --tint-bg: #f0ecfb; --tint-fg: #4c1d95; }
.cover[data-tint="5"] { --tint-bg: #edeff2; --tint-fg: #1f2937; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cover { --tint-bg: #232a35; --tint-fg: #c3d0e4; }
  :root:not([data-theme="light"]) .cover[data-tint="1"] { --tint-bg: #212a23; --tint-fg: #bfd6c3; }
  :root:not([data-theme="light"]) .cover[data-tint="2"] { --tint-bg: #2e2920; --tint-fg: #e4d1ab; }
  :root:not([data-theme="light"]) .cover[data-tint="3"] { --tint-bg: #302427; --tint-fg: #e6c2c4; }
  :root:not([data-theme="light"]) .cover[data-tint="4"] { --tint-bg: #2a2633; --tint-fg: #d0c7e4; }
  :root:not([data-theme="light"]) .cover[data-tint="5"] { --tint-bg: #2b2a27; --tint-fg: #d5cfc4; }
}
:root[data-theme="dark"] .cover { --tint-bg: #232a35; --tint-fg: #c3d0e4; }
:root[data-theme="dark"] .cover[data-tint="1"] { --tint-bg: #212a23; --tint-fg: #bfd6c3; }
:root[data-theme="dark"] .cover[data-tint="2"] { --tint-bg: #2e2920; --tint-fg: #e4d1ab; }
:root[data-theme="dark"] .cover[data-tint="3"] { --tint-bg: #302427; --tint-fg: #e6c2c4; }
:root[data-theme="dark"] .cover[data-tint="4"] { --tint-bg: #2a2633; --tint-fg: #d0c7e4; }
:root[data-theme="dark"] .cover[data-tint="5"] { --tint-bg: #2b2a27; --tint-fg: #d5cfc4; }
.cover-words { font-size: 11.5px; font-weight: 600; opacity: .65; font-variant-numeric: tabular-nums; }
.cover-title {
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
  font-family: var(--serif); font-weight: 600; font-size: 19px; line-height: 1.2; letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.book-link:hover .cover { transform: translateY(-2px); box-shadow: var(--shadow); }
.book-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-top: 12px; font-weight: 600; font-size: 14.5px; line-height: 1.35; overflow-wrap: anywhere;
}
.book-meta { display: flex; align-items: center; gap: 8px; min-height: 28px; margin-top: 8px; }
.book-stat { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.book-stat.done { color: var(--success); }
.book-stat.done::before { content: "✓ "; }
.book-bar { margin-top: 4px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.book-bar > div { height: 100%; background: var(--gloss); border-radius: 2px; }
.book-del {
  display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: -6px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .15s, color .15s;
}
.book-del svg { width: 16px; height: 16px; }
.book-del:hover { color: var(--danger); background: var(--hover); }
.book:hover .book-del, .book:focus-within .book-del { opacity: 1; }

.shelf-empty { text-align: center; padding: 56px 0 24px; max-width: 440px; margin: 0 auto; }
.shelf-empty h2 { font-family: var(--serif); font-size: 22px; font-weight: 650; letter-spacing: -0.015em; margin: 28px 0 6px; }
.shelf-empty p { color: var(--muted); margin: 0; }
.shelf-empty .row { margin-top: 24px; }
.empty-art { position: relative; width: 140px; height: 130px; margin: 0 auto; }
.empty-art span {
  position: absolute; width: 84px; aspect-ratio: 4 / 5; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm);
}
.empty-art span:nth-child(1) { left: 2px; top: 16px; transform: rotate(-9deg); background: color-mix(in srgb, var(--phrase) 10%, var(--surface)); }
.empty-art span:nth-child(2) { right: 2px; top: 16px; transform: rotate(9deg); background: color-mix(in srgb, var(--gloss) 10%, var(--surface)); }
.empty-art span:nth-child(3) { left: 28px; top: 0; }

/* ------------------------------------------------------------ reader */
.reader { max-width: 700px; margin: 48px auto 0; }
.reader-head { margin-bottom: 28px; }
.book-heading {
  font-family: var(--serif); font-size: clamp(28px, 4.4vw, 40px); font-weight: 650; line-height: 1.15;
  letter-spacing: -0.02em; margin: 0;
}
.reader-head .book-stat { display: block; font-size: 14px; margin-top: 10px; }

.annotating { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: -12px 0 20px; }
.annotating .bar { flex: 1; max-width: 140px; height: 2px; background: var(--line); border-radius: 2px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--ink); transition: width .25s ease; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* The text: no card, just a well-set column. */
.article {
  font-family: var(--serif); font-size: var(--read-size, 20px); line-height: 2.3; font-optical-sizing: auto;
  color: var(--ink); overflow-wrap: break-word; cursor: text;
}
.article > :first-child { margin-top: 0; }
.article h1, .article h2, .article h3, .article h4 { font-weight: 650; line-height: 1.8; margin: 1.1em 0 .3em; letter-spacing: -0.01em; }
.article :is(h1, h2, h3) { scroll-margin-top: 76px; }
.article h1 { font-size: 1.5em; } .article h2 { font-size: 1.3em; } .article h3 { font-size: 1.12em; }
.article p, .article ul, .article ol, .article blockquote { margin: 0 0 1.1em; }
.article blockquote { border-left: 2px solid var(--line); padding-left: 18px; color: var(--muted); }
.article pre { background: var(--sunken); padding: 12px 14px; border-radius: var(--r-sm); overflow-x: auto; line-height: 1.5; font-size: 14px; }
.article code { font-size: .82em; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }
.article a { color: var(--phrase); }
.article table { border-collapse: collapse; display: block; overflow-x: auto; }
.article td, .article th { border: 1px solid var(--line); padding: 4px 10px; }
.article img { max-width: 100%; height: auto; }
.seg-failed { text-decoration: underline wavy color-mix(in srgb, var(--danger) 45%, transparent); text-decoration-skip-ink: none; text-underline-offset: 7px; }

/* Glosses above the line: red for words, blue with a dotted underline for phrases. */
ruby.ann {
  ruby-position: over; ruby-align: center; white-space: nowrap; overflow-wrap: normal;
  cursor: pointer; border-radius: 4px; transition: background-color .12s;
}
ruby.ann:hover, ruby.ann.active { background: var(--hover); }
ruby.ann rt {
  font-family: var(--kai); font-size: .55em; line-height: 1.15; letter-spacing: .02em;
  user-select: none; -webkit-user-select: none; white-space: nowrap;
}
ruby.ann-word rt { color: var(--gloss); }
ruby.ann-phrase rt { color: var(--phrase); }
ruby.ann-phrase { text-decoration: underline dotted var(--phrase-line); text-decoration-thickness: 2px; text-underline-offset: 6px; }
ruby.ann.known rt { display: none; }
.hide-words ruby.ann-word rt, .hide-phrases ruby.ann-phrase rt { display: none; }
.hide-phrases ruby.ann-phrase { text-decoration: none; }

/* ------------------------------------------------------------ word card */
.card {
  position: absolute; z-index: 40; width: min(340px, calc(100vw - 32px)); max-height: min(70vh, 560px); overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 16px;
}
.card .head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card .lemma { font-family: var(--serif); font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.card .ipa { color: var(--muted); font-size: 14px; }
.card .pos { color: var(--muted); font-style: italic; font-family: var(--serif); font-size: 14px; }
.card .zh { font-family: var(--kai); font-size: 18px; color: var(--gloss); margin: 4px 0 2px; }
.card .surface { color: var(--muted); font-size: 13px; }
.card .detail { margin-top: 12px; font-size: 14px; line-height: 1.6; color: var(--ink-2); }
.card .detail h4 { margin: 12px 0 3px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.card .detail ul { margin: 0; padding-left: 1.1em; }
.card .detail li { margin: 3px 0; }
.card .detail .expl { margin: 0; }
.card .detail.error { color: var(--danger); }
.card .actions { display: flex; gap: 6px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.card .speak { margin-left: auto; }

.ask-fab {
  position: absolute; z-index: 35; height: 34px; padding: 0 14px; border: 0; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 13.5px;
  box-shadow: var(--shadow-lg); cursor: pointer;
}

/* One-time reading hint, floating above the text. */
.hint {
  position: fixed; z-index: 25; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 18px; max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 16px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-lg);
  font-size: 13.5px; white-space: nowrap;
  transform: translateX(-50%); animation: hint-in .35s cubic-bezier(.2,.8,.2,1) both;
}
.hint[hidden] { display: none; }
.hint.leaving { animation: hint-out .2s ease-in both; }
.hint-item { display: inline-flex; align-items: center; gap: 7px; }
.hint-item svg { width: 15px; height: 15px; flex: none; }
.hint-text { display: contents; }
.hint-item .i-gloss { fill: var(--gloss); }
.hint-item .i-word { fill: currentColor; opacity: .85; }
.hint-item .i-sel { fill: var(--gloss); opacity: .7; }
.hint-item .i-caret { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.hint-ok {
  height: 28px; padding: 0 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: color-mix(in srgb, var(--on-primary) 16%, transparent); color: inherit; font: inherit; font-weight: 600;
}
.hint-ok:hover { background: color-mix(in srgb, var(--on-primary) 26%, transparent); }
.hint-ok:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
body.chat-open .hint { display: none; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes hint-out { to { opacity: 0; transform: translate(-50%, 8px); } }

/* ------------------------------------------------------------ chat drawer */
.drawer {
  position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; height: 100dvh; width: min(440px, 100vw);
  display: flex; flex-direction: column; overscroll-behavior: contain;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.quote {
  margin: 16px 16px 0; padding: 10px 14px; border-left: 2px solid var(--gloss);
  background: var(--sunken); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-family: var(--serif); font-size: 15.5px; line-height: 1.55; max-height: 9em; overflow-y: auto;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.chip {
  height: 30px; padding: 0 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  font-size: 13px; cursor: pointer; color: var(--ink-2);
}
.chip:hover { background: var(--hover); color: var(--ink); }
.chat-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 10px 13px; border-radius: 12px; max-width: 100%; overflow-wrap: break-word; line-height: 1.6; font-size: 14.5px; }
.msg.user { align-self: flex-end; background: var(--primary); color: var(--on-primary); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--sunken); border-bottom-left-radius: 4px; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p, .msg.assistant ul, .msg.assistant ol { margin: .45em 0; }
.msg.assistant ul, .msg.assistant ol { padding-left: 1.3em; }
.msg.error { background: color-mix(in srgb, var(--danger) 9%, var(--surface)); color: var(--danger); }
.msg.pending::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; }

/* ------------------------------------------------------------ dialogs */
.dialog {
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px 22px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overscroll-behavior: contain;
}
.dialog.wide { width: min(680px, calc(100vw - 32px)); }
.toc-dialog { width: min(460px, calc(100vw - 32px)); }
.toc-list { list-style: none; margin: 8px -8px 0; padding: 0; max-height: min(65vh, 560px); overflow-y: auto; overscroll-behavior: contain; }
.toc-list a {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); text-decoration: none; font-size: 14.5px; line-height: 1.4;
}
.toc-list a:hover { background: var(--hover); color: var(--ink); }
.toc-list a[aria-current="true"] { background: var(--sunken); color: var(--ink); font-weight: 600; }
.toc-list a[aria-current="true"]::before { content: ""; align-self: center; width: 6px; height: 6px; border-radius: 50%; background: var(--gloss); margin-left: -2px; flex: none; }
.toc-list .lv2 a { padding-left: 24px; }
.toc-list .lv3 a { padding-left: 38px; font-size: 13.5px; color: var(--muted); }
.dialog::backdrop { background: rgba(9, 9, 11, .4); backdrop-filter: blur(2px); }
.dialog h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.field textarea { resize: vertical; min-height: 220px; font-family: var(--serif); font-size: 16px; line-height: 1.6; }

.source-kinds { display: flex; gap: 2px; margin-top: 12px; padding: 3px; border-radius: 8px; background: var(--sunken); border: 1px solid var(--line); width: fit-content; max-width: 100%; flex-wrap: wrap; }
.kind {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 30px;
  padding: 0 12px; border-radius: 6px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--muted);
}
.kind input { position: absolute; opacity: 0; pointer-events: none; }
.kind:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.kind:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.kind:hover { color: var(--ink); }
.kind svg, .dropzone svg, .src-detected svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.src-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.src-offline { margin: 0 0 14px; padding: 9px 12px; border-radius: var(--r-sm); background: var(--sunken); color: var(--ink-2); }
.kind:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.src-detected { display: flex; align-items: center; gap: 6px; color: var(--success); }
.src-detected[hidden] { display: none; }
.link-btn { border: 0; padding: 0; background: none; color: var(--phrase); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  margin-top: 14px; min-height: 168px; padding: 24px 16px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--sunken); color: var(--muted);
  transition: border-color .15s, background-color .15s;
}
.dropzone svg { width: 26px; height: 26px; color: var(--ink-2); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:hover, .dropzone.dragging { border-color: var(--ink-2); background: var(--hover); }
.dropzone:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.dropzone.has-file { border-style: solid; border-color: var(--line-strong); background: var(--surface); }
.drop-title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.dropzone small { font-size: 12.5px; }

.wb-list { max-height: 60vh; overflow-y: auto; overscroll-behavior: contain; }
.wb-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.wb-item .w { font-family: var(--serif); font-weight: 650; font-size: 17px; }
.wb-item .w small { font-family: var(--sans); font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 13px; }
.wb-item .ctx { grid-column: 1 / 2; color: var(--muted); font-family: var(--serif); font-size: 14px; }
.wb-item .del { grid-row: 1 / 3; grid-column: 2; align-self: center; }
.wb-empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* ------------------------------------------------------------ settings page */
.settings-page { max-width: 720px; margin: 48px auto 0; }
.set-section { margin-top: 36px; }
.set-head h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.set-head p { margin: 4px 0 0; font-size: 13.5px; color: var(--muted); }
.set-body { min-width: 0; margin-top: 12px; }
.set-block {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.set-block + .set-block { margin-top: 12px; }
.set-block h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.set-help { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.set-inline { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.set-block > .field:first-child { margin-top: 0; }

.level-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.level-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  color: var(--ink); text-align: left; cursor: pointer; transition: border-color .15s, background-color .15s;
}
.level-card:hover { border-color: var(--line-strong); background: var(--hover); }
.level-card .lc-code { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; margin-bottom: 2px; }
.level-card .lc-name { font-size: 13.5px; font-weight: 500; }
.level-card .lc-hint { font-size: 12px; color: var(--muted); }
.level-card[aria-checked="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.level-card[aria-checked="true"]::after {
  content: "✓"; position: absolute; top: 9px; right: 10px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 700;
}

.role-tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; background: var(--sunken); border: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.member-list { list-style: none; margin: 0; padding: 0; }
.member { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 4px 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.member:first-child { padding-top: 0; }
.member:last-child { border-bottom: 0; padding-bottom: 0; }
.member-who { min-width: 0; display: flex; flex-direction: column; }
.member-name { font-weight: 500; overflow-wrap: anywhere; }
.member-email { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.member-role { font-size: 13px; color: var(--muted); }
.member-actions { display: flex; gap: 2px; }
.token-form { display: flex; align-items: flex-end; gap: 10px; }
.token-form .field { flex: 1; margin-top: 0; min-width: 0; }
.token-new { margin-top: 14px; padding: 14px; border-radius: var(--r-md); background: var(--sunken); border: 1px solid var(--line); }
.token-warn { margin: 0 0 10px; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.token-box { display: flex; align-items: flex-start; gap: 10px; }
.token-box code {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.6;
  white-space: pre; overflow-x: auto; overscroll-behavior-x: contain; user-select: all;
}
.token-new .set-help { margin-top: 10px; }
.token-head { margin-bottom: 12px; }
.token-list:empty { display: none; }
.token-list:not(:empty) + .token-empty { display: none; }
.token-hint { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* ------------------------------------------------------------ sign in */
body[data-view="login"] .topbar { display: none; }
body[data-view="login"] main { padding-bottom: 40px; }
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 32px 0; }
.login-card {
  width: min(380px, 100%); padding: 32px 28px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.mark-lg { width: 40px; height: 40px; display: block; margin-bottom: 20px; }
.login-card h1 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.25; }
.login-sub { margin: 6px 0 8px; color: var(--muted); font-size: 14px; }
.login-card .btn.wide { margin-top: 20px; }
.login-note { margin: 16px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

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

/* Wide screens: keep the text readable beside the open chat drawer. */
@media (min-width: 1180px) {
  body.chat-open main { padding-right: 480px; }
}

/* Touch: bigger targets; things revealed by hover on desktop are always shown. */
@media (pointer: coarse) {
  .btn { height: 40px; }
  .btn.small { height: 34px; }
  .bar-btn { height: 40px; min-width: 40px; }
  .bar-group { height: 40px; }
  .bar-group .bar-btn, .level-chip { height: 34px; min-width: 34px; }
  .chip { height: 34px; }
  .icon-btn { width: 40px; height: 40px; }
  .book-del { opacity: 1; }
  ruby.ann:hover { background: transparent; }
  ruby.ann.active { background: var(--hover); }
  .book-link:hover .cover { transform: none; box-shadow: none; }
}

@media (max-width: 900px) {
  body[data-view="reader"] .bar-label, body[data-view="reader"] .lv-name { display: none; }
}

@media (max-width: 640px) {
  .net-status { padding: 0; width: 28px; justify-content: center; margin-right: 2px; }
  .net-label { display: none; }
  .hint { width: calc(100vw - 32px); gap: 12px; padding: 10px 10px 10px 14px; border-radius: var(--r-lg); white-space: normal; }
  .hint-text { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
  .hint-ok { height: 32px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom on focus */
  .topbar { height: 52px; gap: 8px; padding: 0 8px 0 12px; }
  .bar-label, .lv-name { display: none; }
  .crumb-home { display: none !important; } /* the logo stands in for "Shelf" */
  .bar-group { margin: 0 2px; }
  .level-chip { padding: 0 4px; }
  .level-chip .caret { display: none; }
  .crumbs ol { font-size: 14.5px; }
  .library, .reader, .settings-page { margin-top: 28px; }
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 14px; }
  .cover { padding: 12px 12px 14px; }
  .cover-title { font-size: 16px; }
  .article { font-size: calc(var(--read-size, 20px) - 2px); line-height: 2.4; }
  .level-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
  .member { grid-template-columns: 1fr auto; }
  .token-form { flex-direction: column; align-items: stretch; }
  .member-actions { grid-column: 1 / -1; margin-left: -8px; }
  .login-card { padding: 26px 20px 20px; }
  .card {
    position: fixed; left: 0 !important; right: 0; top: auto !important; bottom: 0;
    width: 100%; max-height: 62vh; border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .drawer { width: 100vw; border-left: 0; }
  .chat-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .dialog { padding: 18px 16px; }
  .field textarea { min-height: 180px; }
  .banner { width: 100%; }
}

/* Too narrow for a useful book title in the bar; the heading is on the page. */
@media (max-width: 359px) {
  body[data-view="reader"] .crumbs { display: none; }
}
