/* 阅读器公共外观 — 漫画 (htmltibiu416/chapter.html) and 小说 (htmltibiu416/book/read.html) readers.
 * html[data-cr-theme="light|dark"], html[data-cr-mode="scroll|page"]; body.cr-body; body.is-immersive hides both bars.
 * Bars, stage and the reader's own sheets take the dark tokens; the shared comment sheet stays light.
 * Page content lives in comic.css (pictures) and book.css (text). */

html {
  --cr-bg: #fff;
  --cr-bar-bg: rgb(255 255 255 / 97%);
  --cr-placeholder: #f4f4f4;
  --cr-top-h: 52px;
}
html[data-cr-theme="dark"] {
  --cr-bg: #111316;
  --cr-bar-bg: rgb(22 24 28 / 97%);
  --cr-placeholder: #1b1e22;
}
body.cr-body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--cr-bg) !important;
  -webkit-tap-highlight-color: transparent;
}
html[data-cr-theme="dark"] :is(.cr-bar, .cr-stage, .cr-layer) {
  --tb-surface: #16181c;
  --tb-ink: #e7e9ea;
  --tb-ink-2: #c4c9ce;
  --tb-muted: #8b98a5;
  --tb-line: #2f3336;
  --tb-line-strong: #3e4144;
  --tb-divider: #2f3336;
  --tb-fill: #202327;
  --tb-press: rgb(255 255 255 / 8%);
  --tb-btn-primary: #eff3f4;
  --tb-mask: rgb(0 0 0 / 55%);
  color-scheme: dark;
}
html[data-cr-theme="dark"] :is(.cr-bar, .cr-stage, .cr-layer) .tb-btn--primary { color: #0f1419; }
.cr-body [hidden] { display: none !important; }

/* ---------- Bars ---------- */
.cr-bar {
  position: fixed;
  right: 0;
  left: 0;
  z-index: 100;
  background: var(--cr-bar-bg);
  color: var(--tb-ink);
  transition: transform .22s ease, visibility 0s linear 0s;
}
.cr-bar__inner { box-sizing: border-box; display: flex; align-items: center; max-width: 760px; margin: 0 auto; }
.cr-top { top: 0; padding-top: env(safe-area-inset-top, 0px); box-shadow: inset 0 -1px 0 var(--tb-divider); }
.cr-top .cr-bar__inner { gap: 4px; height: var(--cr-top-h); padding: 0 4px; }
.cr-top .tb-icon-btn { color: inherit; }
.cr-top__title {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  color: inherit;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
}
.cr-top__title > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-top__title strong { font-size: 16px; font-weight: 600; }
.cr-top__title span { color: var(--tb-muted); font-size: 12px; }
.cr-bottom { bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px); box-shadow: inset 0 1px 0 var(--tb-divider); }
/* Toasts ride above the tool bar while it is shown. */
body.cr-body:not(.is-immersive) [data-ti-toast] { bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important; }
body.is-immersive .cr-bar { visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; }
body.is-immersive .cr-top { transform: translateY(-100%); }
body.is-immersive .cr-bottom { transform: translateY(100%); }

/* Page slider row */
.cr-progress { gap: 6px; height: 48px; padding: 0 6px; }
.cr-progress__step {
  flex: none;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--tb-ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.cr-progress__step:disabled, .cr-progress__step[aria-disabled="true"] { color: var(--tb-muted); opacity: .5; cursor: default; }
a.cr-progress__step { display: inline-flex; align-items: center; box-sizing: border-box; text-decoration: none; }
.cr-progress__num { flex: none; min-width: 48px; color: var(--tb-muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: center; }
.cr-progress__range {
  --cr-fill: 0%;
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.cr-progress__range:disabled { opacity: .4; cursor: default; }
/* Thumb: the site-wide range style (refresh.css); the track shows how far into the chapter you are. */
body.cr-body .cr-progress__range[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--tb-primary) var(--cr-fill), var(--tb-line) 0);
}
body.cr-body .cr-progress__range[type="range"][dir="rtl"]::-webkit-slider-runnable-track {
  background: linear-gradient(to left, var(--tb-primary) var(--cr-fill), var(--tb-line) 0);
}
body.cr-body .cr-progress__range[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--tb-primary); }

/* Tool tabs */
.cr-tabs { height: 56px; }
.cr-tab {
  position: relative;
  display: grid;
  flex: 1 1 0;
  justify-items: center;
  align-content: center;
  gap: 2px;
  height: 56px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tb-ink);
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  cursor: pointer;
}
.cr-tab ti-icon { --ti-icon-size: 24px !important; width: 24px; height: 24px; }
.cr-tab[aria-pressed="true"] ti-icon { color: var(--tb-danger); }
.cr-tab.is-loading { opacity: .6; pointer-events: none; }
.cr-tab__badge {
  position: absolute;
  top: 5px;
  left: calc(50% + 8px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 8px;
  background: var(--tb-ink);
  color: var(--tb-surface);
  font-size: 10px;
  font-style: normal;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}
@media (hover: hover) {
  .cr-progress__step:not(:disabled):not([aria-disabled="true"]):hover, .cr-tab:hover { background: var(--tb-press); }
}

/* ---------- Stage ---------- */
.cr-stage { box-sizing: border-box; min-height: 100vh; min-height: 100dvh; padding-top: calc(var(--cr-top-h) + env(safe-area-inset-top, 0px)); color: var(--tb-ink); }

/* Loading / locked / error */
.cr-state {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 60vh;
  min-height: 60dvh;
  padding: 48px 24px;
  text-align: center;
}
.cr-state__icon { --ti-icon-size: 48px !important; width: 48px; height: 48px; color: var(--tb-muted); }
.cr-state__title { margin: 8px 0 0; color: var(--tb-ink); font-size: 18px; font-weight: 700; line-height: 1.4; }
.cr-state__text { max-width: 320px; margin: 0; color: var(--tb-muted); font-size: 14px; line-height: 1.6; }
.cr-state__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 16px; }
.cr-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  border: 2.5px solid var(--tb-line);
  border-top-color: var(--tb-ink);
  border-radius: 50%;
  animation: cr-spin .8s linear infinite;
}
@keyframes cr-spin { to { transform: rotate(360deg); } }

/* Chapter end: name, comments + next chapter, the ad slot, auto-load status */
.cr-end {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px var(--tb-gutter) 40px;
  color: var(--tb-ink);
  text-align: center;
}
.cr-end__name { max-width: 100%; margin: 0; overflow: hidden; color: var(--tb-muted); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.cr-end__name span::before { content: " · "; }
.cr-end__actions { display: flex; justify-content: center; gap: 12px; width: 100%; max-width: 420px; }
.cr-end__actions > .tb-btn { flex: 1 1 0; min-width: 0; }
.cr-end__status { display: flex; align-items: center; gap: 4px; margin: 0; color: var(--tb-muted); font-size: 13px; }

/* ---------- Paged mode: the stage is fixed; comic.css / book.css lay out the pages ---------- */
html[data-cr-mode="page"] body.cr-body { overflow: hidden; overscroll-behavior: none; }
html[data-cr-mode="page"] .cr-stage { position: fixed; inset: 0; min-height: 0; padding: 0; }

/* ---------- Sheets: 目录 / 阅读设置 ---------- */
.cr-layer { position: fixed; inset: 0; z-index: 1200; }
.cr-layer:not(.is-open) { display: none; }
.cr-layer.is-open > .tb-mask { animation: cr-fade .2s ease; }
.cr-layer.is-open > .cr-sheet { animation: cr-rise .26s cubic-bezier(.2, .8, .2, 1); }
@keyframes cr-fade { from { opacity: 0; } }
@keyframes cr-rise { from { transform: translateY(100%); } }
@keyframes cr-slide { from { transform: translateX(-100%); } }
.cr-sheet { color: var(--tb-ink); }

.cr-set { display: grid; padding: 4px var(--tb-gutter) 16px; }
.cr-set__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.cr-set__row + .cr-set__row { border-top: 1px solid var(--tb-divider); }
.cr-set__label { flex: none; font-size: 15px; }
.cr-set .tb-chips { flex-wrap: nowrap; justify-content: flex-end; }
.cr-set__range { flex: 1 1 auto; max-width: 240px; accent-color: var(--tb-ink); }

.cr-catalog { display: flex; flex-direction: column; height: min(80vh, 720px); height: min(80dvh, 720px); max-height: none; overflow: hidden; }
.cr-work { display: flex; align-items: center; gap: 12px; padding: 4px var(--tb-gutter) 12px; color: inherit; text-decoration: none; }
.cr-work__cover { flex: none; width: 48px; height: 64px; overflow: hidden; border-radius: 6px; background: var(--tb-fill); }
.cr-work__cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cr-work__body { display: grid; flex: 1 1 auto; gap: 2px; min-width: 0; line-height: 1.35; }
.cr-work__body > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-work__body strong { font-size: 16px; font-weight: 700; }
.cr-work__body small { color: var(--tb-muted); font-size: 13px; }
.cr-work > ti-icon { flex: none; color: var(--tb-muted); }
.cr-catalog__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 8px 0 var(--tb-gutter);
  border-top: 1px solid var(--tb-divider);
  color: var(--tb-muted);
  font-size: 13px;
}
.cr-catalog__list { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0 0 env(safe-area-inset-bottom, 0px); overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.cr-ch { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 var(--tb-gutter); color: var(--tb-ink); font-size: 15px; text-decoration: none; }
.cr-ch.is-current { color: var(--tb-primary); font-weight: 600; }
.cr-ch__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cr-ch__tag { display: inline-flex; flex: none; align-items: center; gap: 2px; color: var(--tb-muted); font-size: 12px; font-weight: 400; }
.cr-ch__tag ti-icon { --ti-icon-size: 14px !important; width: 14px; height: 14px; }
.cr-catalog__note { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 40px var(--tb-gutter); color: var(--tb-muted); font-size: 14px; }
@media (hover: hover) { .cr-ch:hover, .cr-work:hover { background: var(--tb-press); } }

@media (max-width: 760px) {
  .cr-set__row--wide { display: none !important; }
}
@media (min-width: 761px) {
  .cr-sheet > .tb-sheet__handle { display: none; }
  .cr-layer:not(.cr-layer--catalog) > .cr-sheet { right: 0; bottom: 24px; left: 0; width: 460px; margin: 0 auto; padding-top: 8px; border-radius: 20px; }
  .cr-layer--catalog > .cr-catalog { top: 0; right: auto; bottom: 0; left: 0; width: 380px; height: auto; border-radius: 0; }
  .cr-layer--catalog.is-open > .cr-catalog { animation: cr-slide .24s cubic-bezier(.2, .8, .2, 1); }
  .cr-catalog .cr-work { padding-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .cr-bar, .cr-layer.is-open > * { transition: none; animation: none !important; }
}
