:root {
  --bg: #eef6f3;
  --card: #fff;
  --text: #13403c;
  --muted: #5d7a74;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --accent: #e11d48;
  --border: #cfe8e2;
  --ok: #047857;
  --paper: #fbf7ef;
  --shadow: 0 10px 28px rgba(15, 55, 50, .08);
  --radius: 16px;
}
html[data-theme="night"] {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --brand: #2dd4bf;
  --brand-2: #5eead4;
  --accent: #fb7185;
  --border: #334155;
  --ok: #34d399;
  --paper: #111827;
  --shadow: none;
}
html[data-theme="read"] {
  --bg: #f3ead2;
  --card: #fffaf0;
  --text: #3f2f1c;
  --muted: #7a684c;
  --brand: #9a3412;
  --brand-2: #c2410c;
  --border: #e8d7b0;
  --paper: #fbf3dd;
}
html[data-ui="chibi"] {
  --bg: #fff3f7;
  --card: #fff;
  --text: #5a3144;
  --muted: #b06b84;
  --brand: #ec4899;
  --brand-2: #fb923c;
  --accent: #8b5cf6;
  --border: #fbcfe8;
  --ok: #db2777;
  --paper: #fff7ed;
  --shadow: 0 12px 28px rgba(236, 72, 153, .12);
  --radius: 22px;
}
html[data-ui="chibi"][data-theme="night"] {
  --bg: #2a1530;
  --card: #3b2044;
  --text: #fce7f3;
  --muted: #e8b4c8;
  --brand: #f9a8d4;
  --brand-2: #fdba74;
  --border: #6b3a58;
  --paper: #1f1224;
}
html[data-ui="chibi"][data-theme="read"] {
  --bg: #fff1e6;
  --card: #fffaf3;
  --text: #6b3f2a;
  --muted: #c08563;
  --brand: #ea580c;
  --brand-2: #f472b6;
  --border: #fdba74;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  font-family: "Segoe UI", "Be Vietnam Pro", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  padding-bottom: env(safe-area-inset-bottom);
}
html[data-ui="chibi"] body {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
}
a { color: var(--brand); }
img { max-width: 100%; height: auto; }
.wrap { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.site-header {
  background: var(--brand);
  color: #fff;
  padding: 14px 0 16px;
  position: relative;
  overflow: hidden;
}
html[data-ui="chibi"] .site-header {
  background:
    radial-gradient(circle at 88% 120%, rgba(255, 255, 255, .28), transparent 36%),
    radial-gradient(circle at 12% -10%, rgba(255, 255, 255, .35), transparent 32%),
    linear-gradient(135deg, #fb7185, #f472b6 42%, #c4b5fd 78%, #93c5fd);
  border-radius: 0 0 32px 32px;
  overflow: visible;
  box-shadow: 0 12px 28px rgba(190, 80, 130, .18);
}
.site-header a { color: #fff; text-decoration: none; }
.site-header h1 { font-size: 1.45rem; letter-spacing: -.02em; }
.site-header p { opacity: .92; margin-top: 6px; }
.header-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}
html[data-ui="chibi"] .header-row { padding-right: 8px; }
html[data-ui="chibi"] body.library .header-row { padding-right: 150px; }
.header-copy { min-width: 0; flex: 1 1 220px; }
.site-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
}
.site-brand img {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff8f0;
  box-shadow: 0 6px 16px rgba(15, 55, 50, .18), 0 0 0 3px rgba(255, 255, 255, .88);
}
html[data-ui="chibi"] .site-brand img {
  box-shadow: 0 8px 20px rgba(236, 72, 153, .28), 0 0 0 3px #fff;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.brand-text strong {
  font-size: 1.2rem;
  letter-spacing: .06em;
  font-weight: 800;
}
.brand-text em {
  font-style: normal;
  font-size: .72rem;
  font-weight: 700;
  opacity: .9;
  letter-spacing: .04em;
}
.header-mascot {
  display: none;
  position: absolute;
  right: 4px;
  bottom: -18px;
  width: 150px;
  max-height: 128px;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  z-index: 2;
  filter: drop-shadow(0 10px 16px rgba(80, 20, 50, .2));
}
html[data-ui="chibi"] .header-mascot {
  display: block;
  animation: librarian-idle 3.6s ease-in-out infinite;
}
.book-page .header-mascot { display: none !important; }
.ui-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ui-bar .chibi-face {
  width: 48px; height: 48px;
  display: none;
  object-fit: cover;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.site-header:has(.site-brand) .ui-bar .chibi-face { display: none !important; }
.ui-switch { display: flex; flex-wrap: wrap; gap: 4px; }
.ui-switch button {
  border: 1px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.18);
  color: #fff;
  border-radius: 999px;
  padding: 6px 11px;
  cursor: pointer;
  font-weight: 800;
  font-size: .78rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1.2;
}
.ui-switch button::before {
  font-size: .95rem;
  line-height: 1;
}
.ui-switch [data-ui="chibi"]::before { content: "✦"; }
html[data-ui="chibi"] .ui-switch [data-ui="chibi"]::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff url("/assets/chibi.png?v=vy2") center/cover no-repeat;
}
.ui-switch [data-ui="classic"]::before { content: "Aa"; font-size: .68rem; font-weight: 900; }
.ui-switch [data-theme-set=""]::before { content: "☀"; }
.ui-switch [data-theme-set="night"]::before { content: "☾"; }
.ui-switch [data-theme-set="read"]::before { content: "✎"; }
.ui-switch button.on { background: #fff; color: var(--brand); }
html[data-ui="chibi"] .ui-switch {
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 999px;
  padding: 4px;
  backdrop-filter: blur(10px);
  gap: 3px;
}
html[data-ui="chibi"] .ui-switch button {
  border: 0;
  background: transparent;
  min-height: 34px;
}
html[data-ui="chibi"] .ui-switch button.on {
  background: #fff;
  color: #ea580c;
  box-shadow: 0 3px 0 #fdba74, 0 6px 12px rgba(234, 88, 12, .16);
}
.chibi-float {
  display: none;
  position: fixed;
  right: 10px;
  bottom: 10px;
  width: 96px;
  height: 96px;
  object-fit: contain;
  z-index: 20;
  pointer-events: none;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.15));
  border-radius: 22px;
}
html[data-ui="chibi"] .chibi-float { display: block; }
.book-page .chibi-float { display: none !important; }
.librarian {
  display: none;
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 40;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .28));
}
body.library .librarian,
body.has-librarian .librarian { display: flex; pointer-events: none; }
.librarian-talk,
.librarian-mascot,
.librarian-mascot-stack,
.librarian button,
.librarian a,
.librarian input { pointer-events: auto; }
.librarian-mascot {
  width: 168px;
  height: auto;
  display: block;
  background: transparent;
  transform-origin: 70% 100%;
  animation: librarian-idle 3.4s ease-in-out infinite;
}
.librarian-mascot-stack {
  position: relative;
  display: block;
  width: 168px;
  flex: 0 0 auto;
  transform-origin: 70% 100%;
  animation: librarian-idle 3.4s ease-in-out infinite;
  cursor: pointer;
}
.librarian-mascot-stack .librarian-mascot {
  width: 100%;
  animation: none;
}
.librarian-mascot-lid {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
  opacity: 0;
  animation: vy-blink 5.2s ease-in-out infinite !important;
}
.librarian-mascot-stack .librarian-mascot:first-child {
  animation: vy-unblink 5.2s ease-in-out infinite;
}
.librarian.is-searching .librarian-mascot,
.librarian.is-searching .librarian-mascot-stack {
  animation: librarian-look 0.7s ease-in-out infinite;
}
.librarian.is-found .librarian-mascot,
.librarian.is-found .librarian-mascot-stack {
  animation: librarian-yay 0.55s ease;
}
@keyframes vy-blink {
  0%, 82%, 86%, 91%, 100% { opacity: 0; }
  83.6%, 84.8% { opacity: 1; }
  87.8%, 89.4% { opacity: 1; }
}
@keyframes vy-unblink {
  0%, 82%, 86%, 91%, 100% { opacity: 1; }
  83.6%, 84.8% { opacity: 0; }
  87.8%, 89.4% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .librarian-mascot-lid,
  .librarian-mascot-stack .librarian-mascot:first-child {
    animation: none !important;
  }
  .librarian-mascot-lid { opacity: 0; }
}
@keyframes librarian-idle {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-7px) rotate(1.5deg); }
}
@keyframes librarian-look {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-4px) rotate(5deg); }
}
@keyframes librarian-yay {
  0% { transform: scale(1); }
  40% { transform: scale(1.08) translateY(-10px) rotate(-6deg); }
  100% { transform: scale(1); }
}
.librarian.is-water .librarian-mascot,
.librarian.is-water .librarian-mascot-stack {
  animation: librarian-yay 0.7s ease;
}
.librarian.is-water .librarian-talk {
  border-color: #7dd3fc;
  box-shadow: 0 10px 24px rgba(14, 165, 233, .22);
}
.librarian.is-water .librarian-say::before {
  content: "💧 ";
}
.librarian.is-eyes .librarian-mascot,
.librarian.is-eyes .librarian-mascot-stack,
.librarian.is-night-offer .librarian-mascot,
.librarian.is-night-offer .librarian-mascot-stack {
  animation: librarian-yay 0.7s ease;
}
.librarian.is-eyes .librarian-talk {
  border-color: #c4b5fd;
  box-shadow: 0 10px 24px rgba(139, 92, 246, .2);
}
.librarian.is-eyes .librarian-say::before {
  content: "👀 ";
}
.librarian.is-night-offer .librarian-talk {
  border-color: #818cf8;
  box-shadow: 0 10px 24px rgba(79, 70, 229, .22);
}
.librarian.is-night-offer .librarian-say::before {
  content: "🌙 ";
}
.librarian-talk {
  width: min(280px, calc(100vw - 200px));
  background: #fff;
  color: #5a3144;
  border: 2px solid #f9a8d4;
  border-radius: 18px 18px 6px 18px;
  padding: 10px 12px 12px;
  box-shadow: 0 12px 28px rgba(236, 72, 153, .18);
}
html[data-theme="night"] .librarian-talk {
  background: #3b2044;
  color: #fce7f3;
  border-color: #f9a8d4;
}
.librarian-say {
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 0 0 8px;
}
.librarian-talk form {
  display: flex;
  gap: 6px;
}
.librarian-talk input[type="search"] {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 16px;
}
.librarian-talk button {
  border: 0;
  background: #ec4899;
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.librarian-hits {
  list-style: none;
  margin: 8px 0 0;
  max-height: 168px;
  overflow: auto;
  padding: 0;
}
.librarian-hits a {
  display: block;
  padding: 6px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  font-size: .8rem;
  line-height: 1.3;
}
.librarian-hits a:hover,
.librarian-hits a:focus {
  background: #fce7f3;
}
html[data-theme="night"] .librarian-hits a:hover {
  background: #5a3144;
}
.librarian-hits small {
  display: block;
  opacity: .7;
  font-size: .72rem;
}
.librarian-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.librarian-actions button,
.librarian-actions a {
  border: 0;
  background: #ec4899;
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  min-height: 40px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.librarian-actions button.ghost {
  background: #fce7f3;
  color: #9d174d;
}
html[data-theme="night"] .librarian-actions button.ghost {
  background: #5a3144;
  color: #fce7f3;
}
.resume-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 14px 0 8px;
  padding: 12px 14px;
  background: #fff;
  border: 2px solid #f9a8d4;
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(236, 72, 153, .14);
  color: #5a3144;
}
html[data-theme="night"] .resume-banner {
  background: #3b2044;
  color: #fce7f3;
  border-color: #f9a8d4;
}
.resume-banner[hidden] { display: none !important; }
.resume-banner-face {
  width: 64px;
  height: auto;
  flex: 0 0 auto;
}
.resume-banner p { margin: 0 0 8px; font-weight: 700; line-height: 1.35; }
.resume-banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.resume-banner .btn.ghost {
  background: #fce7f3;
  color: #9d174d;
}
html[data-theme="night"] .resume-banner .btn.ghost {
  background: #5a3144;
  color: #fce7f3;
}
.librarian.is-collapsed .librarian-talk { display: none; }
.librarian.is-hidden { display: none !important; }
.vy-tools { margin-top: 8px; }
.vy-tools button {
  border: 0;
  background: #fce7f3;
  color: #9d174d;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 36px;
}
html[data-theme="night"] .vy-tools button {
  background: #5a3144;
  color: #fce7f3;
}
.vy-restore {
  display: none;
  position: fixed;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 45;
  align-items: center;
  gap: 6px;
  border: 2px solid #f9a8d4;
  background: #fff;
  color: #9d174d;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(236, 72, 153, .22);
}
.vy-restore img { width: 32px; height: auto; display: block; }
body.vy-hidden .vy-restore { display: inline-flex; }
body.book-page .librarian { display: flex; z-index: 50; }
body.book-page .librarian.is-hidden { display: none !important; }
body.book-page.has-librarian { padding-bottom: 0; }
body.library { padding-bottom: 200px; }
body.has-librarian { padding-bottom: 200px; }
.crumbs { font-size: .86rem; margin-bottom: 8px; opacity: .95; }
.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.crumbs li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.crumbs li:not(:last-child)::after {
  content: "›";
  margin: 0 2px;
  opacity: .7;
  font-weight: 800;
}
.crumbs a,
.crumbs [aria-current="page"] {
  font-weight: 700;
}
html[data-ui="chibi"] .crumbs a,
html[data-ui="chibi"] .crumbs [aria-current="page"] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, .94);
  color: #c2410c;
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
  box-shadow: 0 3px 0 rgba(253, 186, 116, .9), 0 8px 16px rgba(124, 45, 18, .1);
  font-weight: 800;
  font-size: .8rem;
}
html[data-ui="chibi"] .crumbs li:first-child a::before,
html[data-ui="chibi"] .crumbs li:first-child [aria-current="page"]::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff url("/assets/logo-sgk.png?v=vy2") center/cover no-repeat;
  box-shadow: 0 0 0 2px #ffe4e6;
  flex: 0 0 auto;
}
html[data-ui="chibi"] .crumbs li:not(:last-child)::after {
  content: "❀";
  color: #fff;
  opacity: .95;
  font-size: .72rem;
  text-shadow: 0 1px 0 rgba(190, 80, 120, .25);
}
html[data-ui="chibi"] .crumbs [aria-current="page"] {
  background: linear-gradient(180deg, #fff7ed, #ffedd5);
  color: #9a3412;
}
.bar { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 0; align-items: center; }
input[type="search"], select {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: .95rem;
}
html[data-ui="chibi"] input, html[data-ui="chibi"] select { border-radius: 999px; }
input[type="search"] { flex: 1; min-width: 0; width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 14px; }
.chips button,
.chips a {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.chips button.on,
.chips a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
html[data-ui="chibi"] .chips button,
html[data-ui="chibi"] .chips a {
  border: 2px solid #fdba74;
  background: #fff;
  color: #c2410c;
  box-shadow: 0 3px 0 #fed7aa;
}
html[data-ui="chibi"] .chips button.on,
html[data-ui="chibi"] .chips a.on {
  background: linear-gradient(180deg, #fb923c, #f97316);
  color: #fff;
  border-color: #ea580c;
  box-shadow: 0 3px 0 #c2410c;
}
.meta-line { color: var(--muted); font-size: .9rem; margin-bottom: 14px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
  padding-bottom: 48px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  text-decoration: none;
  color: inherit;
  min-height: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card:hover { border-color: var(--brand-2); transform: translateY(-2px); }
.cover-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  height: auto;
  background: linear-gradient(180deg, #fff7fb, #eef6ff);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cover-wrap img.cover {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #fff;
}
.cover-wrap img.cover.off { display: none; }
.chibi-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #fff;
  box-shadow: 0 6px 14px rgba(0,0,0,.12);
}
.card .card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
html[data-ui="chibi"] .card { border-width: 2px; }
.subj { font-size: .72rem; color: var(--brand); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }

/* Kệ sách trang chủ */
body.library {
  --wood: #4a2c18;
  --wood-2: #6b3e22;
  --plank-top: #e3c59a;
  --plank: #b8874e;
  --plank-edge: #6b3e1a;
  --shelf-back: #2a1810;
  --shelf-ink: #f8ead3;
  background-color: var(--wood);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(255, 210, 140, .18), transparent 55%),
    repeating-linear-gradient(
      90deg,
      #3d2414 0px,
      #5a341c 7px,
      #4a2c18 14px,
      #2e1a0e 15px
    );
}
html[data-theme="night"] body.library {
  --wood: #1a1210;
  --wood-2: #2a1c16;
  --plank-top: #8a6a48;
  --plank: #5c4030;
  --plank-edge: #2a1810;
  --shelf-back: #120c0a;
  --shelf-ink: #e2e8f0;
}
html[data-theme="read"] body.library {
  --wood: #5c4328;
  --shelf-back: #3d2a18;
  --plank-top: #f3ead2;
  --plank: #c4a06a;
  --shelf-ink: #fffaf0;
}
html[data-ui="chibi"] body.library {
  --wood: #6b2d44;
  --wood-2: #8b3d5c;
  --plank-top: #f9c5d5;
  --plank: #e8a0b8;
  --plank-edge: #9d3d5c;
  --shelf-back: #3b1828;
  --shelf-ink: #fff1f5;
  background-image:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(255, 180, 210, .22), transparent 55%),
    repeating-linear-gradient(90deg, #5a2438 0px, #7a3550 7px, #6b2d44 14px, #3b1828 15px);
}
body.library section[aria-labelledby="gioi-thieu"],
body.library section[aria-labelledby="theo-lop"],
body.library section[aria-labelledby="bo-theo-lop"],
body.library section[aria-labelledby="theo-bo"],
body.library section[aria-labelledby="theo-mon"],
body.library section[aria-labelledby="danh-muc"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
body.library .chibi-float { display: none !important; }
body.library .wrap { width: min(1240px, calc(100% - 24px)); }
body.library .meta-line { color: var(--shelf-ink); opacity: .9; }
body.library .chips button,
body.library .chips a {
  background: rgba(255, 255, 255, .12);
  color: var(--shelf-ink);
  border-color: rgba(255, 220, 160, .28);
}
body.library .chips button.on,
body.library .chips a.on {
  background: var(--plank-top);
  color: #3b2416;
  border-color: var(--plank-top);
}
html[data-ui="chibi"] body.library .chips button,
html[data-ui="chibi"] body.library .chips a {
  background: #fff8f0;
  color: #9a3412;
  border: 2px solid #fdba74;
  box-shadow: 0 3px 0 #e8a0b8;
}
html[data-ui="chibi"] body.library .chips button.on,
html[data-ui="chibi"] body.library .chips a.on {
  background: linear-gradient(180deg, #fb923c, #ea580c);
  color: #fff;
  border-color: #c2410c;
  box-shadow: 0 3px 0 #9a3412;
}
body.library .bar input,
body.library .bar select {
  background: rgba(255, 248, 235, .94);
  border-color: rgba(0, 0, 0, .12);
}
html[data-theme="night"] body.library .bar input,
html[data-theme="night"] body.library .bar select {
  background: var(--card);
}
body.library section[aria-labelledby="bo-loc"] {
  background: transparent;
  padding-top: 8px;
}
.shelves { display: flex; flex-direction: column; gap: 28px; padding-bottom: 56px; }
.shelf { color: var(--shelf-ink); }
.shelf-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 14px;
  margin: 0 4px 8px;
}
.shelf-head h2 {
  font-size: 1.15rem;
  letter-spacing: .02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}
.shelf-head span { opacity: .8; font-size: .9rem; }
.shelf-head a {
  margin-left: auto;
  color: var(--plank-top);
  font-weight: 700;
  font-size: .88rem;
  text-decoration: none;
}
.shelf-head a:hover { text-decoration: underline; }
.shelf-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 6px 8px;
  padding: 22px 14px 8px;
  background:
    linear-gradient(180deg, rgba(255, 220, 160, .08), transparent 28%),
    linear-gradient(180deg, #1a0e08, var(--shelf-back) 45%, #3a2418);
  border: 1px solid rgba(255, 220, 160, .14);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  box-shadow: inset 0 18px 36px rgba(0, 0, 0, .35);
  min-height: 168px;
}
.shelf-plank {
  height: 16px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, var(--plank-top), var(--plank) 42%, var(--plank-edge));
  box-shadow:
    0 10px 18px rgba(0, 0, 0, .4),
    inset 0 1px 0 rgba(255, 255, 255, .35);
}
.shelf-book {
  position: relative;
  width: 86px;
  flex: 0 0 86px;
  text-decoration: none;
  color: inherit;
  transform-origin: 50% 100%;
  transition: transform .18s ease, filter .18s ease;
  z-index: 1;
}
.shelf-book:hover,
.shelf-book:focus-visible {
  transform: translateY(-12px) rotate(-2.5deg) scale(1.06);
  z-index: 3;
  filter: brightness(1.06);
  outline: none;
}
.shelf-book .shelf-spine {
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 28px;
  width: 7px;
  border-radius: 2px 0 0 2px;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, .2);
  z-index: 2;
}
.shelf-book .cover-wrap {
  width: 86px;
  height: 118px;
  aspect-ratio: auto;
  border-radius: 2px 5px 4px 1px;
  box-shadow:
    4px 0 0 rgba(0, 0, 0, .18),
    8px 10px 16px rgba(0, 0, 0, .32);
  background: #1a120c;
}
.shelf-book .cover-wrap img.cover {
  object-fit: cover;
  background: #2a1c14;
}
.shelf-caption {
  display: block;
  margin-top: 6px;
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  color: var(--shelf-ink);
  opacity: .92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.shelf-empty {
  color: var(--shelf-ink);
  padding: 28px 12px 48px;
  text-align: center;
}
html[data-ui="chibi"] .shelf-book .cover-wrap {
  border-radius: 8px 12px 10px 6px;
}

.card h2, .card h3 {
  font-size: .92rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.blurb,
.catalog-ol,
.pad-line,
.catalog-list,
section.block:has(.pad-line) { display: none !important; }
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  background: #ecfdf5;
  color: var(--ok);
}
html[data-theme="night"] .badge { background: #134e4a; color: #99f6e4; }
html[data-ui="chibi"] .badge { background: #fce7f3; color: #be185d; }
.book-hero { display: grid; grid-template-columns: 1fr; gap: 18px; padding: 22px 0 8px; }
@media (min-width: 880px) {
  .book-hero { grid-template-columns: 1.2fr .8fr; align-items: start; }
}
.kicker { color: var(--brand); font-weight: 700; font-size: .86rem; }
.book-page .site-header { padding: 6px 0 8px; }
.book-page .reader-top,
.book-page .reader-wrap {
  min-height: calc(100dvh - 72px);
}
.book-page .reader-stage,
.book-page .fallback-pdf,
.book-page .pdf-scroller {
  height: calc(100dvh - 108px);
}
.book-page .book-title { font-size: 1.05rem; margin: 0; }
.book-page .crumbs li:last-child { display: none; }
.book-page .kicker { font-size: .78rem; color: #fff; }
h1.book-title { font-size: clamp(1.4rem, 2.4vw, 2rem); line-height: 1.25; margin: 6px 0 10px; }
.lead { font-size: 1.02rem; max-width: 62ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn, button.btn {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 11px;
  padding: 9px 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-size: .9rem;
}
html[data-ui="chibi"] .btn {
  border-radius: 999px;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--brand) 70%, #7c2d12);
}
html[data-ui="chibi"] .btn:hover { transform: translateY(-1px); }
.btn.ghost { background: var(--card); color: var(--brand); border: 1px solid var(--border); }
html[data-ui="chibi"] .btn.ghost { box-shadow: 0 3px 0 var(--border); }
.stars { display: flex; gap: 4px; align-items: center; margin-top: 12px; }
.stars button {
  background: none; border: 0; cursor: pointer; font-size: 1.35rem; color: #d1d5db; line-height: 1;
}
.stars button.on { color: #f59e0b; }
.stars span { color: var(--muted); font-size: .88rem; }
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.pad-line { color: var(--muted); font-size: .9rem; margin: 8px 0; }
.toc-item h4 { margin: 10px 0 6px; font-size: .92rem; }
.toc-item ul, .toc-item ol { margin: 0 0 10px 1.2em; }
.toc-item { padding: 14px 0; border-top: 1px solid var(--border); }
.toc-item:first-child { border-top: 0; }
.toc-item h3 { font-size: .98rem; }
.toc-item.l1 h3 { color: var(--brand); }
.toc-item h3 a { color: inherit; text-decoration: none; }
.toc-item h3 a:hover { text-decoration: underline; }
.toc-item p { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.toc-item button.linkish, .toc-item a.linkish {
  background: none; border: 0; color: var(--brand); cursor: pointer; font-weight: 700; padding: 0; margin-top: 4px;
  font: inherit; text-decoration: none;
}
.faq details {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}
.faq details:first-child { border-top: 0; }
.faq summary { cursor: pointer; font-weight: 700; }
.faq p { margin-top: 6px; color: var(--muted); }
.reader-top { width: 100%; margin: 0; }
.reader-wrap {
  margin: 0;
  background: #0f172a;
  border-radius: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr;
}
html[data-ui="chibi"] .reader-wrap {
  margin: 0 10px 0;
  border-radius: 18px;
  border: 3px solid #f9a8d4;
}
html[data-ui="chibi"] .book-page .reader-wrap {
  margin: 0;
  border-radius: 0;
  border: 0;
}
html[data-theme="read"] .reader-wrap { background: #3f2f1c; }
.reader-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 12px; background: #111827; color: #e5e7eb;
}
.reader-bar a { color: #fff; }
.reader-bar button, .reader-bar a.btn {
  background: #334155; color: #fff; border: 0; border-radius: 9px; padding: 7px 10px; cursor: pointer; font-weight: 600;
  font-size: .82rem;
}
.reader-bar button.on { background: var(--brand-2); color: #042f2e; }
.lbl-short { display: none; }
.reader-dl {
  margin-left: auto;
  white-space: nowrap;
}
.reader-dl::before { content: "↓"; margin-right: 6px; font-weight: 900; }
.reader-stage {
  height: calc(100dvh - 104px);
  min-height: 0;
  display: block;
  position: relative;
  padding: 0;
  overflow: hidden;
}
html[data-theme="night"] .fallback-pdf,
html[data-theme="night"] #pdf-canvas,
html[data-theme="night"] .pdf-page-slot canvas { filter: invert(1) hue-rotate(180deg); }
html[data-theme="read"] .fallback-pdf,
html[data-theme="read"] #pdf-canvas,
html[data-theme="read"] .pdf-page-slot canvas { filter: sepia(.35) contrast(1.05); }
.fallback-pdf { width: 100%; height: 100%; min-height: 0; border: 0; background: #525659; }
.pdf-scroller {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: #525659;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: pan-x pan-y pinch-zoom;
}
#pdf-canvas {
  display: block;
  margin: 0 auto;
  background: #fff;
  max-width: 100%;
  max-height: 100%;
  height: auto;
}
#pdf-canvas:not(.ready) { visibility: hidden; }
#pdf-canvas.zoomed { max-width: none; max-height: none; }
.pdf-scroller.stack {
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  padding: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  touch-action: pan-y pinch-zoom;
  scroll-snap-type: y mandatory;
  scroll-snap-stop: always;
}
.pdf-scroller.stack.zoomed {
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
  scroll-snap-type: none;
}
.pdf-page-slot {
  width: 100%;
  flex: 0 0 100%;
  height: 100%;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  background: #404040;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  box-sizing: border-box;
}
.pdf-scroller.stack.zoomed .pdf-page-slot {
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
  scroll-snap-align: none;
}
.pdf-page-slot canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #fff;
}
.pdf-scroller.stack.zoomed .pdf-page-slot canvas {
  max-height: none;
}
.pdf-scroller.stack.scroll-read {
  scroll-snap-type: y proximity;
  padding: 12px 0 32px;
}
.pdf-scroller.stack.scroll-read .pdf-page-slot {
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
  margin: 0 auto 16px;
  scroll-snap-stop: normal;
  background: transparent;
}
.pdf-scroller.stack.scroll-read .pdf-page-slot canvas {
  max-height: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .35);
}
.fs-btn { display: none; }
@media (min-width: 880px) {
  .fs-btn { display: inline-flex; align-items: center; }
}
.reader-wrap:fullscreen,
.reader-wrap:-webkit-full-screen,
.reader-wrap.is-fs {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #0f172a;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
}
.reader-wrap:fullscreen .toc-jump,
.reader-wrap:-webkit-full-screen .toc-jump,
.reader-wrap.is-fs .toc-jump {
  display: none;
}
.reader-wrap:fullscreen .toc-jump.open,
.reader-wrap:-webkit-full-screen .toc-jump.open,
.reader-wrap.is-fs .toc-jump.open {
  display: block;
}
.reader-wrap:fullscreen .reader-stage,
.reader-wrap:-webkit-full-screen .reader-stage,
.reader-wrap.is-fs .reader-stage,
.reader-wrap:fullscreen .pdf-scroller,
.reader-wrap:-webkit-full-screen .pdf-scroller,
.reader-wrap.is-fs .pdf-scroller,
.reader-wrap:fullscreen .fallback-pdf,
.reader-wrap:-webkit-full-screen .fallback-pdf,
.reader-wrap.is-fs .fallback-pdf {
  height: 100%;
  min-height: 0;
}
.reader-wrap.is-fs {
  position: fixed;
  inset: 0;
  z-index: 80;
}
html[data-ui="chibi"] .reader-wrap:fullscreen,
html[data-ui="chibi"] .reader-wrap:-webkit-full-screen,
html[data-ui="chibi"] .reader-wrap.is-fs,
html[data-ui="chibi"] .book-page .reader-wrap.is-fs {
  margin: 0;
  border: 0;
  border-radius: 0;
}
.pdf-status {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #e2e8f0;
  background: rgba(15, 23, 42, .78);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: .9rem;
  z-index: 3;
  text-align: center;
  max-width: 90%;
}
.pdf-status.on { display: block; }
.reader-stage { position: relative; }
.reader-stage.has-pdfjs .fallback-pdf { display: none !important; }
.hub-pick {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 18px 0 36px;
}
.hub-pick a {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  min-height: 96px;
}
.hub-pick a strong { color: var(--brand); font-size: 1.15rem; }
.hub-pick a span {
  font-size: .86rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.reader-modes {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.reader-bar .ui-switch,
html[data-ui="chibi"] .reader-bar .ui-switch {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  backdrop-filter: none;
}
.reader-bar .ui-switch button,
html[data-ui="chibi"] .reader-bar .ui-switch button {
  color: #e5e7eb;
  min-height: 36px;
  padding: 6px 8px;
  font-size: .72rem;
  border: 0;
  background: transparent;
}
.reader-bar .ui-switch button.on,
html[data-ui="chibi"] .reader-bar .ui-switch button.on {
  background: var(--brand-2);
  color: #042f2e;
}
.toc-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 30;
}
.toc-backdrop.open { display: block; }
.reader-bar #goto-page {
  width: 4.4rem;
  border: 1px solid #475569;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 700;
}
.toc-jump {
  background: #111827;
  color: #e5e7eb;
  padding: 10px 12px 16px;
  max-height: 42vh;
  overflow: auto;
  border-top: 1px solid #334155;
}
.toc-jump h2 { font-size: .92rem; margin: 0 0 4px; color: #fff; }
.toc-jump p { font-size: .78rem; color: #94a3b8; margin: 0 0 8px; }
.toc-jump ol, .toc-index ol { list-style: none; margin: 0; padding: 0; }
.toc-jump a, .toc-index a {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #e2e8f0;
  text-decoration: none;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: .86rem;
  line-height: 1.35;
}
.toc-jump a span, .toc-index a span { color: #94a3b8; white-space: nowrap; font-size: .78rem; }
.toc-jump a:hover, .toc-index a:hover { background: #334155; }
.toc-jump a.on, .toc-index a.on { background: var(--brand); color: #fff; }
.toc-jump a.on span, .toc-index a.on span { color: inherit; }
.toc-index { margin: 10px 0 16px; }
.toc-index ol { display: grid; gap: 2px; }
@media (min-width: 880px) {
  .reader-wrap:has(.reader-bar-theme) {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto 1fr;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-bar-theme {
    grid-column: 1;
    grid-row: 1;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-bar-pages {
    grid-column: 2;
    grid-row: 1;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-stage {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .reader-bar-theme .reader-modes { margin-left: 0; }
  .book-page .reader-wrap:has(.reader-bar-theme) .reader-stage,
  .book-page .reader-wrap:has(.reader-bar-theme) .fallback-pdf,
  .book-page .reader-wrap:has(.reader-bar-theme) .pdf-scroller {
    height: 100%;
    min-height: 0;
  }
}
@media (min-width: 1100px) {
  .reader-wrap {
    grid-template-columns: 1fr min(280px, 28vw);
    grid-template-rows: auto 1fr;
  }
  .reader-bar { grid-column: 1 / -1; }
  .reader-stage { grid-column: 1; grid-row: 2; }
  .toc-jump {
    grid-column: 2;
    grid-row: 2;
    max-height: none;
    height: calc(100dvh - 104px);
    border-top: 0;
    border-left: 1px solid #334155;
  }
  .reader-wrap:has(.reader-bar-theme) {
    grid-template-columns: auto 1fr min(280px, 28vw);
    grid-template-rows: auto 1fr;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-bar-theme {
    grid-column: 1;
    grid-row: 1;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-bar-pages {
    grid-column: 2 / -1;
    grid-row: 1;
  }
  .reader-wrap:has(.reader-bar-theme) .reader-stage {
    grid-column: 1 / 3;
    grid-row: 2;
  }
  .reader-wrap:has(.reader-bar-theme) .toc-jump {
    grid-column: 3;
    grid-row: 2;
  }
}
.sr { position: absolute; left: -9999px; }
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
}
.skip-link:focus { top: 8px; }
.hub-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.hub-list a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 700;
}
.hub-list a:hover { border-color: var(--brand); }
html[data-ui="chibi"] .hub-list a {
  background: #fff;
  border: 2px solid #fdba74;
  color: #c2410c;
  border-radius: 18px;
  box-shadow: 0 3px 0 #fed7aa;
  font-weight: 800;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
html[data-ui="chibi"] .hub-list a:hover {
  transform: translateY(-2px);
  border-color: #f97316;
  box-shadow: 0 5px 0 #fb923c;
}
html[data-ui="chibi"] .hub-list a.on {
  background: linear-gradient(180deg, #fb923c, #f97316);
  color: #fff;
  border-color: #ea580c;
  box-shadow: 0 3px 0 #c2410c;
}
.series-jump {
  margin: 0;
  padding: 14px 0 12px;
  background: linear-gradient(180deg, #fff8f0, #ffe4e6 90%, transparent);
  position: relative;
  z-index: 1;
}
html[data-ui="chibi"] .series-jump {
  background:
    radial-gradient(circle at 8% 0%, rgba(253, 186, 116, .35), transparent 28%),
    linear-gradient(180deg, #fff7ed 0%, #ffe4e6 70%, rgba(255, 228, 230, 0));
}
body.library .series-jump {
  background: linear-gradient(180deg, #fff8f0, #fce7f3);
  box-shadow: 0 8px 18px rgba(80, 20, 40, .08);
}
.series-jump .wrap { width: min(1240px, calc(100% - 24px)); margin: 0 auto; }
.series-jump .hub-list a {
  padding: 8px 14px;
  font-size: .84rem;
  font-weight: 800;
}
.series-jump .hub-list a::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff url("/assets/chibi.png?v=vy2") center/cover no-repeat;
  box-shadow: 0 0 0 2px #ffedd5;
  flex: 0 0 auto;
}
.site-header p { font-size: .9rem; max-width: 52ch; }
.item-list { list-style: none; margin: 0; padding: 0; }
ol.grid.item-list,
ol.grid.item-list > li {
  list-style: none;
  padding: 0;
  margin: 0;
}
.catalog-ol { list-style: none; margin: 0; padding: 0; }
.catalog-list h4 { font-size: .98rem; margin: 14px 0 8px; color: var(--brand); }
.catalog-list h5 { font-size: 1.02rem; }
.catalog-list h5 a { color: inherit; }
.catalog-list h5 a:hover { color: var(--brand); }
.card h3 { margin: 0; }
.catalog-list article {
  margin: 0 0 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.catalog-list article:last-child { border-bottom: 0; }
.catalog-list h3 { font-size: 1.05rem; }
.catalog-list h3 a { color: inherit; }
.catalog-list h3 a:hover { color: var(--brand); }
footer.site { padding: 28px 0 40px; color: var(--muted); font-size: .85rem; }
footer.site a { color: var(--brand); }
body.library footer.site { color: var(--shelf-ink); }
body.library footer.site a { color: var(--plank-top); }
body.library .faq h2 { color: var(--shelf-ink); }
body.library .faq .panel {
  background: rgba(255, 248, 235, .94);
  color: #3b2416;
  border-radius: 18px;
  padding: 4px 16px 12px;
}
body.library .faq summary { color: #3b2416; }
body.library .faq p { color: #5c4633; }
html[data-theme="night"] body.library .faq .panel {
  background: var(--card);
  color: var(--text);
}
html[data-theme="night"] body.library .faq summary,
html[data-theme="night"] body.library .faq p { color: var(--text); }
section.block { margin: 22px 0; }
section.block h2 { font-size: 1.15rem; margin-bottom: 10px; }
.hidden { display: none !important; }
html[data-theme="read"] .site-header { background: #9a3412; }
html[data-theme="night"] .site-header { background: #0f766e; }
html[data-ui="chibi"][data-theme="read"] .site-header,
html[data-ui="chibi"][data-theme="night"] .site-header {
  background:
    radial-gradient(circle at 88% 120%, rgba(255, 255, 255, .2), transparent 36%),
    linear-gradient(135deg, #fb7185, #a78bfa);
}

@media (max-width: 1099px) {
  .toc-jump {
    display: none;
    max-height: 28vh;
  }
  .toc-jump.open {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100%, 340px);
    max-height: none;
    height: 100%;
    z-index: 40;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    border-top: 0;
    box-shadow: -12px 0 28px rgba(0, 0, 0, .28);
  }
  .toc-jump a { padding: 10px 8px; min-height: 44px; align-items: center; }
}

@media (max-width: 879px) {
  .wrap { width: calc(100% - 20px); }
  body.book-page {
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .book-page .site-header {
    flex: 0 0 auto;
    padding: 6px 0;
    padding-top: max(6px, env(safe-area-inset-top));
    overflow: hidden;
    transition: transform .28s ease, max-height .28s ease, padding .28s ease, opacity .2s ease;
  }
  body.book-page.chrome-hide .site-header {
    max-height: 0;
    padding: 0 !important;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-100%);
  }
  .book-page .reader-top {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    max-height: none;
  }
  .book-page .reader-wrap {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto 1fr;
    position: relative;
  }
  .book-page .reader-wrap:has(.reader-bar-theme) {
    grid-template-rows: 1fr;
  }
  .book-page .reader-bar-theme,
  .book-page .reader-bar-pages {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 18;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform .28s ease, opacity .2s ease;
  }
  .book-page .reader-bar-theme {
    top: 0;
    justify-content: center;
    background: rgba(17, 24, 39, .92);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  }
  .book-page .brand-text { display: none; }
  .book-page .crumbs li:last-child { display: none; }
  .book-page .reader-bar-theme {
    justify-content: stretch;
    gap: 8px;
    padding: 8px 10px;
  }
  .book-page .reader-modes {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    margin-left: 0;
  }
  .book-page .reader-bar-theme .ui-switch {
    flex: 1 1 0;
    min-width: 0;
    justify-content: space-evenly;
  }
  .book-page .reader-bar-theme .ui-switch button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    font-size: 0;
    gap: 0;
    padding: 8px 4px;
  }
  .book-page .reader-bar-theme .reader-modes { margin-left: 0; }
  .reader-dl { display: none !important; }
  .book-page .reader-bar-pages {
    bottom: 0;
    top: auto;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: rgba(17, 24, 39, .94);
    backdrop-filter: blur(10px);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .25);
  }
  body.chrome-theme-hide .reader-bar-theme,
  body.chrome-hide .reader-bar-theme {
    transform: translateY(calc(-100% - 16px));
    pointer-events: none;
  }
  body.chrome-pages-hide .reader-bar-pages,
  body.chrome-hide .reader-bar-pages {
    transform: translateY(calc(100% + 16px));
    pointer-events: none;
  }
  .book-page > main,
  .book-page > footer.site {
    display: none;
  }
  .site-header {
    padding: 10px 0 10px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .site-header h1 { font-size: 1.18rem; }
  .header-row { gap: 8px; }
  .ui-bar .chibi-face,
  .chibi-float { display: none !important; }
  .header-mascot {
    width: 108px;
    bottom: -10px;
    right: -6px;
    opacity: .95;
  }
  .site-brand img { width: 52px; height: 52px; }
  .brand-text strong { font-size: 1rem; }
  html[data-ui="chibi"] .header-row { padding-right: 96px; }
  html[data-ui="chibi"] .crumbs a,
  html[data-ui="chibi"] .crumbs [aria-current="page"] {
    padding: 4px 10px 4px 6px;
    font-size: .74rem;
  }
  .librarian {
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: column-reverse;
    align-items: flex-end;
  }
  .book-page .librarian {
    bottom: calc(58px + env(safe-area-inset-bottom));
    transition: bottom .28s ease;
  }
  body.book-page.chrome-pages-hide .librarian,
  body.book-page.chrome-hide .librarian {
    bottom: max(8px, env(safe-area-inset-bottom));
  }
  .librarian-mascot,
  .librarian-mascot-stack { width: 118px; }
  .librarian-talk {
    width: min(270px, calc(100vw - 20px));
    border-radius: 16px 16px 16px 6px;
  }
  .ui-switch button {
    padding: 8px 10px;
    min-height: 40px;
    font-size: .75rem;
  }
  .book-page .kicker { display: none; }
  .book-page .ui-bar { display: none; }
  .book-page:not(:has(.reader-bar)) .ui-bar { display: flex; }
  .book-page .book-title {
    font-size: 1.02rem;
    margin: 2px 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .bar {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 0 8px;
  }
  input[type="search"], select {
    width: 100%;
    min-width: 0;
    font-size: 16px;
    min-height: 44px;
  }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
  }
  .chips button,
  .chips a {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 8px 12px;
  }
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding-bottom: 32px;
  }
  .card { min-height: 0; }
  .cover-wrap { aspect-ratio: 3 / 4; }
  .card .card-body { padding: 8px 8px 10px; gap: 4px; }
  .card h2, .card h3 { font-size: .82rem; }
  .chibi-badge { width: 34px; height: 34px; }
  .actions .btn, .btn, button.btn {
    min-height: 44px;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  html[data-ui="chibi"] .reader-wrap {
    margin: 0;
    border-radius: 0;
    border: 0;
  }
  .reader-bar {
    gap: 6px;
    padding: 8px 8px;
    position: sticky;
    top: 0;
    z-index: 12;
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .reader-bar button, .reader-bar a.btn {
    min-height: 44px;
    padding: 8px 10px;
    font-size: .82rem;
  }
  .reader-bar .ui-switch button {
    font-size: 0;
    gap: 0;
    width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: 8px 0;
  }
  .reader-bar .ui-switch button::before { font-size: 1.05rem; }
  .book-page .librarian-mascot,
  .book-page .librarian-mascot-stack { width: 72px; }
  .reader-bar #pg { display: none; }
  .lbl-full { display: none; }
  .lbl-short { display: inline; font-size: 1.35rem; line-height: 1; }
  .reader-bar #goto-page {
    width: 3.6rem;
    min-height: 44px;
    font-size: 16px;
  }
  .reader-stage,
  .fallback-pdf,
  .pdf-scroller {
    height: calc(100dvh - 92px);
    min-height: 0;
  }
  .book-page .reader-stage,
  .book-page .fallback-pdf,
  .book-page .pdf-scroller {
    height: 100%;
    min-height: 0;
  }
  .stars button { min-width: 40px; min-height: 40px; }
  .toc-index a { padding: 10px 8px; min-height: 44px; align-items: center; }
  .faq summary { padding: 8px 0; min-height: 44px; }
  .hub-nav {
    flex-wrap: wrap;
    gap: 8px;
  }
  .hub-nav h1 { flex-basis: 100%; }
}

@media (max-width: 879px) and (prefers-reduced-motion: reduce) {
  .book-page .reader-bar-theme,
  .book-page .reader-bar-pages,
  .book-page .librarian { transition: none; }
}

@media (max-width: 640px) {
  .shelf-book { width: 72px; flex-basis: 72px; }
  .shelf-book .cover-wrap { width: 72px; height: 100px; }
  .shelf-book .shelf-spine { width: 5px; bottom: 26px; }
  .shelf-row { padding: 16px 8px 6px; min-height: 140px; gap: 4px 6px; }
  .shelf-head a { margin-left: 0; }
}

#history-pill {
  font-weight: 800;
}
html[data-ui="chibi"] #history-pill {
  background: #fce7f3;
  color: #9d174d;
  border-color: #f9a8d4;
}
body.history-page main.wrap { width: min(860px, calc(100% - 24px)); }
.history-lead { margin: 8px 0 16px; max-width: 62ch; }
.history-quota {
  margin: 0 0 18px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
body.library .history-quota {
  background: rgba(255, 248, 235, .94);
  color: #3b2416;
  border-color: rgba(0, 0, 0, .08);
}
html[data-theme="night"] body.library .history-quota {
  background: rgba(30, 20, 18, .88);
  color: var(--shelf-ink);
}
.history-quota p { margin: 8px 0 0; font-size: .88rem; color: var(--muted); }
body.library .history-quota p { color: inherit; opacity: .88; }
.history-quota-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(15, 118, 110, .16);
  overflow: hidden;
}
html[data-ui="chibi"] .history-quota-bar { background: rgba(236, 72, 153, .18); }
.history-quota-bar span {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  min-width: 0;
}
.history-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.history-empty {
  text-align: center;
  padding: 36px 16px 48px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
body.library .history-empty {
  background: rgba(255, 248, 235, .94);
  color: #3b2416;
}
.history-empty img { width: 96px; height: auto; margin-bottom: 8px; }
.history-empty p { margin-top: 8px; color: var(--muted); }
.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 48px;
  list-style: none;
}
.history-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 14px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
}
body.library .history-card {
  background: rgba(255, 248, 235, .96);
  color: #3b2416;
}
html[data-theme="night"] body.library .history-card {
  background: rgba(30, 20, 18, .92);
  color: var(--shelf-ink);
  border-color: rgba(255, 220, 160, .18);
}
html[data-ui="chibi"] .history-card { border-width: 2px; border-color: #f9a8d4; }
.history-cover {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, #fff7fb, #eef6ff);
  aspect-ratio: 3 / 4;
}
.history-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.history-cover img.off { display: none; }
.history-body h2 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.3;
}
.history-body h2 a { color: inherit; text-decoration: none; }
.history-body h2 a:hover { text-decoration: underline; }
.history-meta, .history-page { margin: 4px 0 0; font-size: .86rem; color: var(--muted); }
html[data-theme="night"] body.library .history-meta,
html[data-theme="night"] body.library .history-page { color: #e8d5c4; }
.history-section { margin: 6px 0 0; font-size: .88rem; }
.history-progress {
  height: 6px;
  margin: 8px 0 4px;
  border-radius: 999px;
  background: rgba(15, 118, 110, .14);
  overflow: hidden;
}
html[data-ui="chibi"] .history-progress { background: rgba(236, 72, 153, .16); }
.history-progress span {
  display: block;
  height: 100%;
  background: var(--brand);
}
.history-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}
.history-sections a {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  font-size: .78rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
}
.history-sections a span { color: var(--muted); font-weight: 600; }
.history-sections a:hover { border-color: var(--brand); }
.history-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

@media (max-width: 640px) {
  .history-card { grid-template-columns: 72px 1fr; gap: 10px; padding: 10px; }
  .history-body h2 { font-size: .92rem; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .chibi-badge { width: 30px; height: 30px; }
  .brand-text { display: none; }
  .header-mascot { width: 88px; }
  html[data-ui="chibi"] .header-row { padding-right: 72px; }
  .ui-switch [data-ui="classic"] span,
  .ui-switch button { font-size: .72rem; }
  .reader-bar .ui-switch button { font-size: 0; }
}
