:root {
  color-scheme: light;
  --paper: #f6f2eb;
  --surface: #fffdf8;
  --ink: #272324;
  --muted: #665c57;
  --line: #ded4c9;
  --wine: #861f35;
  --wine-dark: #641328;
  --wash: #f6e8e8;
  --radius: .8rem;
  font: 100%/1.65 system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-inline-size: 0; }
a { color: var(--wine-dark); text-underline-offset: .18em; }
a:hover { color: var(--wine); }
:focus-visible { outline: 3px solid var(--wine); outline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button, input, select, textarea { border-radius: .45rem; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
input, textarea, select { background: #fff; border: 1px solid #9f9087; padding: .55rem .7rem; }
input, textarea { inline-size: 100%; min-inline-size: 0; }
textarea { resize: vertical; }
label { display: block; font-weight: 650; }
h1, h2, h3 { line-height: 1.25; overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.75rem, 4.5vw, 2.75rem); }
h2 { margin: 0; font-size: clamp(1.35rem, 3vw, 1.85rem); }
h3 { margin: 0; font-size: 1.05rem; }
p { overflow-wrap: anywhere; }

.shell { inline-size: min(100% - 2rem, 82rem); margin-inline: auto; }
.skip-link { position: fixed; z-index: 5; inset-block-start: .5rem; inset-inline-start: .5rem; background: var(--surface); padding: .6rem 1rem; }
.skip-link:not(:focus) { clip-path: inset(50%); }
.masthead { border-block-start: 4px solid var(--wine); border-block-end: 1px solid var(--line); background: var(--surface); }
.masthead-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .45rem 1.4rem; padding-block: .65rem; }
.brand { display: flex; inline-size: fit-content; gap: .65rem; align-items: center; color: var(--ink); text-decoration: none; font-weight: 820; font-size: 1.2rem; letter-spacing: .06em; }
.seal { display: inline-grid; place-items: center; inline-size: 2rem; block-size: 2rem; border: 1px solid var(--wine); border-radius: .22rem; color: var(--wine); line-height: 1; }
.tools { display: flex; flex-wrap: wrap; gap: 0 1rem; }
.tools a { display: inline-flex; align-items: center; min-block-size: 44px; font-weight: 650; }
.eyebrow { margin: 0 0 .5rem; color: var(--wine-dark); font-size: .85rem; font-weight: 750; letter-spacing: .09em; }
.primary, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 44px;
  border: 1px solid var(--line);
  border-radius: .45rem;
  padding: .45rem .8rem;
  background: var(--surface);
  color: var(--wine-dark);
  font-weight: 700;
  text-decoration: none;
}
.button:hover { background: var(--wash); }
.primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.primary:hover { background: var(--wine-dark); }
.notice { border-inline-start: .2rem solid var(--wine); padding: .55rem .85rem; background: var(--wash); }
.error { color: var(--wine-dark); }

.gate-body { min-block-size: 100vh; min-block-size: 100dvh; display: grid; place-items: center; padding: 1.25rem 1rem; border-block-start: 5px solid var(--wine); }
.gate { inline-size: min(100%, 38rem); }
.gate > .brand { margin-block-end: 1.25rem; }
.gate-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 6vw, 2.5rem); box-shadow: 0 12px 28px rgb(50 24 15 / 7%); }
.gate h1 { color: var(--wine); }
.gate-panel > p:not(.eyebrow) { color: var(--muted); }
.gate label { margin-block-end: .3rem; }
.gate button { margin-block-start: .8rem; inline-size: 100%; }

.search-panel { display: grid; grid-template-columns: 1fr minmax(18rem, .85fr); align-items: end; gap: 1rem 2rem; padding-block: clamp(1.2rem, 4vw, 2.5rem); border-block-end: 1px solid var(--line); }
.search-panel label { color: var(--muted); font-size: .9rem; margin-block-end: .25rem; }
.search-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
.layout { display: grid; grid-template-columns: minmax(13rem, 19rem) minmax(0, 1fr); align-items: start; gap: 1rem; padding-block: 1rem 3rem; }
.sidebar, .surface { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.sidebar { align-self: start; position: sticky; inset-block-start: 1rem; max-block-size: calc(100vh - 2rem); overflow: auto; }
.sidebar summary { min-block-size: 44px; padding: .65rem .8rem; cursor: pointer; font-weight: 750; overflow-wrap: anywhere; }
.sidebar details > summary:focus-visible { outline-offset: -3px; }
#catalog { padding: 0 .5rem .5rem; }
#catalog > details { border-block-start: 1px solid var(--line); }
#catalog details details { margin-inline-start: .5rem; }
#catalog ul { list-style: none; padding: 0; margin: 0 .25rem .35rem 1rem; }
#catalog a { display: block; border-radius: .25rem; padding: .55rem .45rem; min-block-size: 44px; line-height: 1.45; overflow-wrap: anywhere; }
#catalog a[aria-current="page"] { background: var(--wash); font-weight: 750; }
.content { min-inline-size: 0; display: grid; gap: 1rem; }
.surface { min-inline-size: 0; padding: clamp(.85rem, 2.5vw, 1.55rem); }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .5rem 1rem; }
.matches { margin: 0; padding-inline-start: 1.65rem; }
.matches li { padding-block: .7rem; }
.matches li + li { border-block-start: 1px solid var(--line); }
.matches p { margin: .15rem 0 0; color: var(--muted); }
.matches a { font-weight: 720; overflow-wrap: anywhere; }
.reader-header { border-block-end: 1px solid var(--line); padding-block-end: .75rem; margin-block-end: .75rem; }
.reader-toolbar, .page-nav, .reader-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.reader-toolbar { justify-content: space-between; margin-block-start: .8rem; }
.zoom-control { display: flex; align-items: center; gap: .45rem; color: var(--muted); }
.zoom-control select { min-block-size: 44px; }
.selection-action { position: sticky; inset-block-start: .5rem; z-index: 2; inline-size: max-content; max-inline-size: 100%; margin-block-end: .5rem; }
.selection-action .primary { box-shadow: 0 2px 10px rgb(50 24 15 / 25%); }
.read-frame { display: block; inline-size: 100%; min-block-size: 14rem; border: 0; background: #fff; }
.embedded-chapter { background: #fff; line-height: 1.75; overflow-wrap: anywhere; }
.embedded-chapter article { display: flow-root; padding: .25rem .65rem; }
.embedded-chapter :is(img, figure) { max-inline-size: 100%; }
.embedded-chapter img { block-size: auto; }
.embedded-chapter figure { margin-inline: 0; }
.embedded-chapter table { border-collapse: collapse; max-inline-size: 100%; }
.embedded-chapter :is(th, td) { border: 1px solid var(--line); padding: .25rem .45rem; }
.embedded-chapter pre { overflow: auto; }
.read-text { white-space: pre-wrap; word-break: break-word; margin: .65rem 0; font: inherit; }
.pdf-scroll { overflow: auto; min-inline-size: 0; background: #eae2d9; }
.textLayer[data-main-rotation="90"] { transform: rotate(90deg) translateY(-100%); }
.textLayer[data-main-rotation="180"] { transform: rotate(180deg) translate(-100%, -100%); }
.textLayer[data-main-rotation="270"] { transform: rotate(270deg) translateX(-100%); }
.pdf-page { position: relative; margin-inline: auto; background: #fff; }
.pdf-page canvas { display: block; inline-size: 100%; block-size: 100%; }

/* PDF.js TextLayer geometry: --font-height, --rotate and --scale-x are set by PDF.js. */
.textLayer { position: absolute; inset: 0; overflow: clip; text-align: initial; line-height: 1; -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 1; --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); }
.textLayer :is(span, br) { position: absolute; white-space: pre; color: transparent; cursor: text; transform-origin: 0 0; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) {
  --font-height: 0;
  --scale-x: 1;
  --rotate: 0deg;
  z-index: 1;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(calc(1 / var(--min-font-size)));
}
.textLayer .markedContent { display: contents; }
.textLayer span[role="img"] { user-select: none; cursor: default; }
.textLayer ::selection { color: transparent; background: rgb(134 31 53 / 27%); }
.textLayer br::selection { background: transparent; }

#report-dialog { inline-size: min(100% - 1.5rem, 35rem); max-block-size: 92dvh; margin: auto; padding: clamp(.85rem, 4vw, 1.5rem); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); }
#report-dialog::backdrop { background: rgb(34 27 25 / 58%); }
#report-location { margin-block: .5rem; }
#quote-field { margin-block: .8rem; }
#report-quote { max-block-size: 9rem; overflow: auto; margin: .3rem 0 0; padding: .5rem .7rem; border-inline-start: .2rem solid var(--wine); background: var(--wash); white-space: pre-wrap; overflow-wrap: anywhere; }
.report-fields { display: grid; gap: .35rem; }
.report-fields textarea + label { margin-block-start: .4rem; }
#report-status:empty, #report-hint:empty { display: none; }

@media (max-width: 50rem) {
  .search-panel, .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-block-size: 48vh; }
}
@media (max-width: 25rem) {
  .shell { inline-size: calc(100% - 1.25rem); }
  .tools { gap: 0 .8rem; font-size: .92rem; }
  .reader-toolbar { align-items: start; }
}
