:root {
  color-scheme: light;
  --brand: #a90000;
  --brand-dark: #720000;
  --gold: #c9a45c;
  --ink: #251d19;
  --paper: #f8f4ec;
  --toolbar-height: 54px;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--ink);
  background-color: #e9e1d3;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

a { color: inherit; text-decoration: none; }

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.loading-screen {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  background: #f6f1e8;
  transition: opacity .55s ease, visibility .55s ease;
}

.loading-screen::before {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, rgba(169, 0, 0, .08) 1px, transparent 0);
  background-size: 24px 24px;
  content: "";
  opacity: .45;
}

.loading-screen.is-ready {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loader-book {
  position: relative;
  width: 82px;
  height: 62px;
  margin-bottom: 28px;
  perspective: 700px;
}

.loader-book::before,
.loader-book::after,
.loader-book i {
  position: absolute;
  top: 0;
  width: 40px;
  height: 58px;
  border: 1px solid rgba(169, 0, 0, .3);
  background: #fffdf8;
  box-shadow: 0 8px 18px rgba(63, 32, 12, .12);
  content: "";
}

.loader-book::before { left: 1px; border-radius: 4px 0 0 4px; }
.loader-book::after { right: 1px; border-radius: 0 4px 4px 0; }

.loader-book i {
  left: 41px;
  z-index: 2;
  border-radius: 0 4px 4px 0;
  transform-origin: left center;
  animation: loader-page 1.5s ease-in-out infinite;
}

.loader-book i:nth-child(2) { animation-delay: .24s; }
.loader-book i:nth-child(3) { animation-delay: .48s; }

@keyframes loader-page {
  0%, 20% { transform: rotateY(0); opacity: 1; }
  75%, 100% { transform: rotateY(-178deg); opacity: .28; }
}

.loading-screen strong {
  position: relative;
  color: var(--brand-dark);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .08em;
}

.loading-screen p {
  position: relative;
  margin: 9px 0 20px;
  color: #8d8175;
  font-size: 13px;
}

.loader-track {
  position: relative;
  width: min(260px, 68vw);
  height: 3px;
  overflow: hidden;
  background: rgba(169, 0, 0, .12);
}

.loader-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand);
  transition: width .25s ease;
}

.loading-screen > small {
  position: relative;
  margin-top: 10px;
  color: var(--brand);
  font: 600 12px/1.2 Arial, sans-serif;
}

.reader-header {
  position: relative;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 68px;
  padding: 0 clamp(18px, 3.4vw, 58px);
  border-bottom: 1px solid rgba(92, 59, 39, .12);
  background: rgba(250, 247, 240, .9);
  box-shadow: 0 8px 30px rgba(67, 43, 28, .06);
  backdrop-filter: blur(14px);
}

.reader-brand {
  display: inline-flex;
  align-items: center;
  width: max-content;
  gap: 10px;
}

.brand-seal {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 3px;
  color: white;
  background: var(--brand);
  box-shadow: 0 6px 14px rgba(169, 0, 0, .18);
}

.brand-seal svg { width: 26px; height: 26px; stroke-width: 1.6; }

.reader-brand > span:last-child { display: grid; gap: 1px; }
.reader-brand b { color: #241b17; font-size: 17px; line-height: 1; }
.reader-brand small { color: var(--brand); font: 600 8px/1.2 Arial, sans-serif; letter-spacing: .22em; }

.reader-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.reader-title b { font-size: 16px; }
.reader-title span { color: #8c7c6e; font-size: 12px; }

.reader-links {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 20px;
  font-size: 13px;
}

.reader-links > a:first-child { color: #74675e; }
.reader-links > a:first-child:hover { color: var(--brand); }

.reader-consult {
  padding: 9px 17px;
  border: 1px solid var(--brand);
  border-radius: 3px;
  color: white;
  background: var(--brand);
  transition: background .2s ease, transform .2s ease;
}

.reader-consult:hover { background: var(--brand-dark); transform: translateY(-1px); }

.reader-workspace {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: calc(100dvh - 68px);
  min-height: 430px;
  padding: 12px 20px 8px;
}

.reader-workspace::before {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(100deg, rgba(255,255,255,.34), transparent 38%, rgba(104,67,39,.05)),
    repeating-linear-gradient(14deg, rgba(86,52,27,.018) 0, rgba(86,52,27,.018) 1px, transparent 1px, transparent 7px);
  content: "";
  pointer-events: none;
}

.book-stage {
  position: relative;
  display: grid;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  place-items: center;
}

.book-backdrop {
  position: absolute;
  left: 50%;
  bottom: 3.5%;
  width: min(86vw, 1100px);
  height: 18%;
  border-radius: 50%;
  background: rgba(45, 25, 13, .16);
  filter: blur(34px);
  transform: translateX(-50%);
}

.book-shell {
  position: relative;
  z-index: 2;
  display: grid;
  width: min(1120px, calc((100dvh - 188px) * 1.4841), calc(100vw - 46px));
  max-height: 100%;
  aspect-ratio: 5102 / 3437;
  place-items: center;
  filter: drop-shadow(0 20px 20px rgba(48, 27, 16, .22));
}

.book {
  width: 100%;
  margin: 0 auto;
  transition: transform .55s cubic-bezier(.22, .72, .22, 1);
}

.book.is-front-cover { transform: translateX(-25%); }
.book.is-back-cover { transform: translateX(25%); }

.book-page {
  overflow: hidden;
  border: 1px solid rgba(73, 48, 31, .14);
  background: #fffdf7;
  box-shadow: inset 0 0 18px rgba(80, 50, 28, .045);
  cursor: grab;
}

.book-page:active { cursor: grabbing; }

.book-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.book-cover { border-color: rgba(79, 0, 0, .32); }

.book .stf__wrapper { overflow: visible; }

.turn-hint {
  position: absolute;
  z-index: 20;
  right: 25%;
  bottom: 7%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, .6);
  border-radius: 3px;
  color: white;
  background: rgba(77, 0, 0, .72);
  box-shadow: 0 10px 24px rgba(40, 0, 0, .18);
  font-size: 12px;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
  backdrop-filter: blur(7px);
}

.turn-hint i {
  width: 18px;
  height: 18px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  animation: hint-drag 1.6s ease-in-out infinite;
}

.turn-hint.is-hidden { opacity: 0; transform: translateY(8px); }

@keyframes hint-drag {
  0%, 100% { transform: translate(0, 0); }
  55% { transform: translate(-8px, -5px); }
}

.reader-toolbar {
  position: relative;
  z-index: 25;
  display: flex;
  flex: 0 0 var(--toolbar-height);
  align-items: center;
  min-height: var(--toolbar-height);
  margin-top: 4px;
  padding: 5px 8px;
  border: 1px solid rgba(90, 60, 42, .14);
  border-radius: 4px;
  background: rgba(251, 248, 242, .93);
  box-shadow: 0 8px 24px rgba(62, 38, 22, .1);
  backdrop-filter: blur(12px);
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 3px;
  color: #4f443c;
  background: transparent;
  gap: 7px;
  cursor: pointer;
  transition: color .2s ease, background .2s ease;
}

.tool-button:hover:not(:disabled) { color: var(--brand); background: rgba(169, 0, 0, .06); }
.tool-button:disabled { color: #c5bbb2; cursor: default; }
.tool-button svg { width: 20px; height: 20px; }

.page-status {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  color: #817268;
  font: 500 13px/1 Arial, sans-serif;
  gap: 10px;
}

.page-status b { color: var(--brand); font-size: 16px; }
.page-status i { width: 24px; height: 1px; background: #d2c6ba; }

.toolbar-divider { width: 1px; height: 24px; margin: 0 5px; background: #ded5cc; }

.tool-button.icon-only { min-width: 42px; width: 42px; padding: 0; }
.tool-button .shrink-icon { display: none; }
.tool-button[aria-pressed="true"] .expand-icon { display: none; }
.tool-button[aria-pressed="true"] .shrink-icon { display: block; }

.reader-help {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  margin: 7px 0 0;
  color: #93867b;
  font-size: 11px;
}

.consult-overlay {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  visibility: hidden;
  place-items: center;
  padding: 22px;
  background: rgba(29, 18, 13, .52);
  opacity: 0;
  transition: opacity .3s ease, visibility .3s ease;
  backdrop-filter: blur(5px);
}

.consult-overlay.is-visible { visibility: visible; opacity: 1; }

.consult-dialog {
  position: relative;
  width: min(460px, 100%);
  padding: 38px 40px 34px;
  border: 1px solid rgba(201, 164, 92, .75);
  border-radius: 6px;
  background: #fbf7ee;
  box-shadow: 0 28px 90px rgba(31, 12, 5, .32);
  text-align: center;
  transform: translateY(18px) scale(.98);
  transition: transform .35s cubic-bezier(.22, .76, .26, 1);
}

.consult-overlay.is-visible .consult-dialog { transform: translateY(0) scale(1); }

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #7d6e63;
  background: transparent;
  place-items: center;
  cursor: pointer;
}

.dialog-close:hover { color: var(--brand); background: rgba(169, 0, 0, .06); }
.dialog-close svg { width: 20px; height: 20px; }

.dialog-mark {
  display: grid;
  width: 48px;
  height: 48px;
  margin: 0 auto 15px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--brand);
  place-items: center;
}

.dialog-mark svg { width: 24px; height: 24px; stroke-width: 2; }

.consult-dialog > small { color: var(--brand); font-size: 12px; letter-spacing: .16em; }

.consult-dialog h2 {
  margin: 11px 0 13px;
  color: #2b211c;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 25px;
  line-height: 1.45;
}

.consult-dialog p { margin: 0; color: #77695f; font-size: 14px; line-height: 1.8; }

.dialog-actions { display: grid; margin-top: 25px; gap: 9px; }

.dialog-actions a,
.dialog-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  border-radius: 3px;
  cursor: pointer;
}

.dialog-actions a {
  color: white;
  background: var(--brand);
  box-shadow: 0 10px 22px rgba(169, 0, 0, .2);
  gap: 8px;
}

.dialog-actions a:hover { background: var(--brand-dark); }
.dialog-actions a svg { width: 18px; height: 18px; }

.dialog-actions button { border: 0; color: #756960; background: transparent; }
.dialog-actions button:hover { color: var(--brand); }

.noscript-note {
  position: fixed;
  z-index: 1200;
  inset: auto 20px 20px;
  padding: 14px;
  color: white;
  background: var(--brand);
  text-align: center;
}

@media (max-width: 720px) {
  .reader-header {
    grid-template-columns: 1fr auto;
    height: 58px;
    padding: 0 13px;
  }

  .brand-seal { width: 32px; height: 32px; }
  .brand-seal svg { width: 23px; height: 23px; }
  .reader-brand b { font-size: 15px; }
  .reader-title { display: none; }
  .reader-links { gap: 8px; }
  .reader-links > a:first-child { display: none; }
  .reader-consult { padding: 8px 12px; font-size: 12px; }

  .reader-workspace {
    height: calc(100dvh - 58px);
    min-height: 500px;
    padding: 8px 8px 7px;
  }

  .book-shell {
    width: min(560px, calc(100vw - 18px), calc((100dvh - 178px) * .7422));
    aspect-ratio: 2551 / 3437;
    filter: drop-shadow(0 15px 15px rgba(48, 27, 16, .22));
  }

  .book.is-front-cover,
  .book.is-back-cover { transform: none; }

  .book-backdrop { bottom: 6%; width: 88vw; height: 12%; filter: blur(25px); }

  .turn-hint {
    right: 13px;
    bottom: 8%;
    padding: 7px 9px;
  }

  .reader-toolbar { width: calc(100vw - 22px); justify-content: center; }
  .tool-button { min-width: 76px; padding: 0 8px; font-size: 12px; }
  .page-status { min-width: 84px; gap: 7px; }
  .page-status i { width: 14px; }
  .toolbar-divider { margin: 0 1px; }
  .reader-help { margin-top: 5px; font-size: 10px; }

  .consult-overlay { align-items: end; padding: 10px; }
  .consult-dialog { width: 100%; padding: 30px 23px 20px; border-radius: 7px 7px 3px 3px; }
  .consult-dialog h2 { font-size: 21px; }
  .consult-dialog p { font-size: 13px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .reader-header { height: 52px; }
  .reader-title span, .reader-brand small { display: none; }
  .reader-workspace { height: calc(100dvh - 52px); padding-top: 5px; }
  .book-shell { width: min(980px, calc((100dvh - 124px) * 1.4841), calc(100vw - 30px)); }
  .reader-toolbar { min-height: 46px; height: 46px; flex-basis: 46px; }
  .tool-button { height: 36px; }
  .reader-help { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
