@font-face {
  font-family: "Instrument Serif";
  src: url("../assets/fonts/instrument-serif.woff2") format("woff2");
  font-display: swap;
}

.kb-page {
  --ink: #38291e;
  --paper: #f8ecd4;
  --muted: #6e5943;
  --cream: #fff4e4;
  --accent: #8d472c;
  --serif: "Songti SC", "Noto Serif SC", SimSun, serif;
  --nav-bg: linear-gradient(100deg, #914d35, #6f3526 65%, #5c2c20);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  margin: 0;
  isolation: isolate;
  color: var(--ink);
  background: #a86a42;
  font: 16px/1.6 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

.kb-page *, .kb-page *::before, .kb-page *::after { box-sizing: border-box; }
.kb-page [hidden] { display: none; }
.kb-page a { color: inherit; text-decoration: none; }
.kb-page a:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }

.kb-page::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  content: "";
  background: url("workbench.webp") center / cover no-repeat;
}

.site-header {
  position: relative;
  z-index: 2;
  color: var(--cream);
  background: linear-gradient(180deg, #2c1c14be, #2c1c1410);
}

.reader-bar {
  width: min(100% - clamp(32px, 8.2vw, 152px), 1760px);
  margin-inline: auto;
}

.book-control:hover {
  text-decoration: underline;
  text-underline-offset: 5px;
}

.workbench {
  --book-height: min(81svh, 100svh - 112px);
  display: grid;
  height: 100%;
  place-items: end center;
  padding: 12px 24px clamp(12px, 2.3svh, 26px);
}

.book-cover {
  position: relative;
  display: grid;
  width: min(37vw, var(--book-height) * .94);
  height: var(--book-height);
  place-items: center;
  border: 1px solid #dbae8170;
  border-radius: 12px 8px 11px 12px;
  background: radial-gradient(ellipse at 63% 12%, #b4784b38, transparent 62%),
    linear-gradient(108deg, #32160f6e, #5a211b08 58%, #2a0f0c66), #66352d url("book-leather.webp") center / cover no-repeat;
  box-shadow: inset 0 2px 3px #f7c88c66, inset -3px -4px 6px #260c09a0,
    0 4px 0 #edcda0, 0 7px 0 #c7a67c, 0 10px 0 #50261e,
    1px 24px 41px #3e1e12ae, 0 6px 15px #2c130ca5;
  transform-origin: 0 50%;
}

.kb-page .book-cover { color: #f2d8a2; }
.book-cover:hover .cover-action { color: #fff6e2; }

.book-cover::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 10.5%;
  border-radius: 11px 0 0 11px;
  background: linear-gradient(90deg, #220b09a3, #5d2a1866 11%, #d19b662c 42%, #31110e88 87%, #b8784c46);
  box-shadow: 1px 0 #e7b07b3d, 5px 0 7px #210c0945;
  content: "";
}

.cover-border {
  position: absolute;
  inset: 4.5% 4.5% 4.5% 14%;
  border: 1px solid #daa76f79;
  border-radius: 3px 4px 4px 3px;
  pointer-events: none;
}
.cover-border::after { position: absolute; inset: 6px; border: 1px dashed #d7a56b4d; border-radius: inherit; content: ""; }

.cover-emblem {
  position: absolute;
  top: 18%;
  left: 54.5%;
  display: grid;
  width: clamp(54px, 6.5vw, 110px);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid #e7b97e8f;
  border-radius: 50%;
  box-shadow: inset 0 1px 1px #e8b9825c, 0 2px 4px #2e110d78;
  color: #ecca8f;
  font-size: clamp(26px, 3.7vw, 62px);
  text-shadow: 0 2px 1px #391a13;
  transform: translateX(-50%);
}
.cover-emblem::before { position: absolute; inset: 6px; border: 1px solid #e0ac714f; border-radius: 50%; content: ""; }

.book-cover h1 {
  z-index: 1;
  position: absolute;
  top: 50%;
  left: 54.5%;
  transform: translate(-50%, -50%);
  margin: 0;
  font: 600 clamp(32px, 4.6vw, 86px)/1 var(--serif);
  white-space: nowrap;
  letter-spacing: .045em;
  text-shadow: 0 -1px #ffe9b779, 0 2px 1px #54281c, 0 4px 6px #240e0ca6;
}
.book-cover h1 span { font: 1.4em/.8 "Instrument Serif", Georgia, serif; }

.cover-action {
  position: absolute;
  bottom: 13%;
  left: 54.5%;
  transform: translateX(-50%);
  padding-top: 10px;
  border-top: 1px solid #dbbd7f75;
  color: #fff0cf;
  font-size: clamp(13px, 1vw, 18px);
  white-space: nowrap;
  letter-spacing: .13em;
}
.cover-action span { margin-left: 2px; color: #f6d394; }

.cover-corner {
  position: absolute;
  right: -2px;
  bottom: -4px;
  width: clamp(45px, 5vw, 90px);
  aspect-ratio: 1;
  border-radius: 54% 0 8px 0;
  background: linear-gradient(138deg, #fff6db 8%, #efd9ac 42%, #be9366 57%, #744a30 88%);
  clip-path: polygon(0 100%, 100% 0, 100% 100%);
  transform-origin: bottom right;
  animation: corner-lift 3.1s ease-in-out infinite;
}

@keyframes corner-lift {
  0%, 44%, 100% { transform: scale(.54) rotate(0); }
  60%, 80% { transform: scale(1) rotate(4deg); }
}

.book {
  position: relative;
  width: min(100%, max(740px, 62vw), 1240px);
  height: var(--book-height);
  padding: 7px 9px 10px;
  border-radius: 10px 13px 15px 12px;
  background: #623229 url("book-leather.webp") center / 400px;
  box-shadow: 0 1px 3px #2f130e inset, 0 4px 0 #b59873, 0 7px 0 #50261e,
    1px 23px 41px #3e1e12ae;
}

.book-pages {
  position: relative;
  height: 100%;
  overflow: clip;
  border-radius: 6px 8px 11px 7px;
  box-shadow: 0 2px #c8ae85, 0 4px #f9e4bd, 0 6px #b79a73;
  perspective: 1300px;
}

.book-spread { display: grid; height: 100%; grid-template: minmax(0, 1fr) / 1fr 1fr; }
.book-spread:focus, .reader:focus { outline: none; }

.book-page {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 30px clamp(28px, 3.4vw, 52px);
  background-color: var(--paper);
}

.book-left {
  display: grid;
  grid-template-rows: auto 1fr;
  background-image: linear-gradient(90deg, #fff4df 0%, #f8e9ce 88%, #cdb28d 100%);
}

.book-right {
  background-image: linear-gradient(90deg, #d1b695, #f7e8cc 6%, #fff3dc 46%, #f8e8cb);
}

.contents-paper { padding: clamp(16px, 2.2vw, 38px); }
.contents-list {
  display: grid;
  height: 100%;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(9px, 1.4svh, 19px);
}

.kb-page .contents-list .page-entry {
  --tab-ink: #763d28;
  --tab-wash: #e5c49c80;
  position: relative;
  min-height: 0;
  padding: 10px clamp(14px, 1.9vw, 36px);
  border: 1px solid #ac77574d;
  border-radius: 5px 11px 11px 5px;
  background: linear-gradient(105deg, var(--tab-wash), transparent 84%), #fff6e3;
  box-shadow: inset 0 1px 1px #fffaf1b0, 0 3px 0 #a477470f;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.kb-page .contents-list .page-entry:nth-child(2) { --tab-ink: #4c563b; --tab-wash: #b9c29b60; }
.kb-page .contents-list .page-entry:nth-child(3) { --tab-ink: #814832; --tab-wash: #e0a99165; }
.contents-list .page-entry::before {
  position: absolute;
  inset: 12% auto 12% 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  opacity: .6;
  background: var(--tab-ink);
  content: "";
}
.kb-page .contents-list .page-entry:hover { border-color: var(--tab-ink); box-shadow: 0 5px 14px #67412726; }
.contents-list .page-entry strong { color: var(--tab-ink); font: 700 clamp(23px, 2.05vw, 37px)/1.15 var(--serif); }
.contents-list .page-entry small { margin-top: 8px; }
.contents-arrow {
  display: grid;
  width: clamp(33px, 3.3vw, 55px);
  aspect-ratio: 1;
  flex-shrink: 0;
  place-items: center;
  border: 1px solid #9f785973;
  border-radius: 50%;
  color: var(--tab-ink);
  font-size: clamp(16px, 1.4vw, 24px);
  transition: transform 160ms ease;
}
.contents-list .page-entry:hover .contents-arrow { transform: translateX(3px); }

.chapter-paper { display: grid; grid-template-rows: minmax(0, 1fr); gap: 8px; }
.chapter-list { min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-gutter: stable; }
.chapter-list a:focus-visible { outline-offset: -2px; }
.chapter-pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  border-top: 1px solid #ad8b6259;
  color: var(--muted);
  font-size: 13px;
}
.chapter-pagination button {
  justify-self: start;
  min-height: 40px;
  padding: 0 5px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.chapter-pagination button:last-child { justify-self: end; }
.chapter-pagination button[aria-disabled="true"] { opacity: .44; cursor: default; }
.chapter-pagination button:not([aria-disabled="true"]):hover { background: #c98a4b25; }
.chapter-page-count { white-space: nowrap; }

.page-heading {
  align-self: center;
  padding: 14px 0 23px;
}
.page-emblem { display: block; margin-bottom: 9px; color: var(--accent); font-size: 23px; }
.page-heading h2 { margin: 0; font: 700 clamp(43px, 4.2vw, 66px)/1.05 var(--serif); }
.page-heading h2::after { display: block; width: 48px; height: 1px; margin-top: 19px; background: #a86b4f; content: ""; }
.page-heading p { max-width: 21em; margin: 15px 0 0; color: var(--muted); font-size: 15px; }
.book-control { color: var(--muted); font-size: 13px; }
.book-control { justify-self: start; }

.page-list { display: grid; align-content: start; }
.page-entry {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #ad8b6259;
  transition: background-color 150ms ease;
}
.page-entry { min-height: 66px; padding: 10px 3px; }
.page-entry:hover { background: #9d633015; }
.page-entry strong { display: block; font-size: 17px; line-height: 1.4; }
.page-entry small { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.entry-arrow { color: var(--accent); font-size: 20px; }

.kb-page .featured-row {
  margin: 0 0 7px;
  padding-inline: 12px;
  border: 1px solid #b4865b65;
  border-left: 3px solid #a46246;
  border-radius: 2px 6px 6px 2px;
  background: #c98a4b16;
}
.kb-page .featured-row:hover { background: #c98a4b32; }
.featured-row strong { color: #78402c; }
.guide-entry strong { font-size: 16px; }

.tip-entry { padding-inline: 4px 9px; }
.tip-entry strong { font-size: 16px; }
.tip-entry:hover strong { color: var(--accent); }

.tip-detail .page-heading h2 { font-size: clamp(29px, 2.8vw, 49px); line-height: 1.18; text-wrap: balance; }
.tip-title-line { display: block; }
.tip-paper {
  display: grid;
  align-content: start;
  gap: clamp(15px, 2.5svh, 26px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #b8916a transparent;
}
.tip-paper:focus-visible { outline: 2px solid var(--accent); outline-offset: -5px; }
.tip-paper section + section { padding-top: clamp(14px, 2.3svh, 24px); border-top: 1px solid #ad8b6259; }
.tip-paper h3 { margin: 0 0 8px; color: var(--accent); font: 700 clamp(18px, 1.4vw, 24px)/1.3 var(--serif); }
.tip-paper p { margin: 0; color: #594633; font-size: 15px; line-height: 1.85; }
.ai-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.07fr);
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 6px 2px;
  border-bottom: 1px solid #ad8b6259;
  font-size: clamp(13px, 1.1vw, 16px);
  line-height: 1.4;
}
.ai-pick strong { color: var(--accent); font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.ai-picks-date { margin-top: 12px; color: var(--muted); font-size: 13px; text-align: right; }
.resource-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title link" "summary summary";
  align-items: center;
  gap: 2px 10px;
  margin-bottom: 8px;
  padding: 6px 11px 9px;
  border: 1px solid #b4865b6b;
  border-radius: 6px;
  background: #c98a4b10;
}
.resource-card h3 { grid-area: title; margin: 0; font-size: 16px; line-height: 1.35; }
.resource-card p { grid-area: summary; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.kb-page .resource-card a {
  grid-area: link;
  padding: 6px 3px;
  color: var(--accent);
  font-size: 12px;
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.kb-page .resource-card a:hover { color: var(--ink); }
.exploring {
  min-height: 44px;
  margin-top: 8px;
  padding: 7px 11px;
  border: 1px dashed #ad8b6288;
  border-radius: 6px;
  background: #ecdcc14d;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
  cursor: default;
}

.turn-sheet {
  position: absolute;
  z-index: 3;
  inset: 0 0 0 50%;
  border-radius: 0 8px 10px 0;
  outline: 1px solid #b98d62;
  background: repeating-linear-gradient(180deg, #63462b00 0px 21px, #63462b14 21px 22px, #63462b00 22px 26px),
    linear-gradient(90deg, #c7a881, #f8e6c8 15%, #fff2d6 80%, #e8c697);
  box-shadow: 10px 10px 19px #4223125e;
  pointer-events: none;
  transform-origin: 0 50%;
  will-change: transform, opacity;
}

.kb-reading {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: #fffaf1;
}
.kb-reading::before { display: none; }
.kb-reading .site-header { color: #654a39; background: linear-gradient(100deg, #fff9ef, #fff2df); border-bottom: 1px solid #e5d2bb; }
.reader-bar {
  display: grid;
  min-height: 54px;
  grid-template-columns: minmax(max-content, 1fr) minmax(100px, 32rem) minmax(max-content, 1fr);
  grid-template-areas: "back progress controls";
  align-items: center;
  gap: 0 18px;
  border-top: 1px solid #e5d2bb;
  font-size: 14px;
}
.reader-back { grid-area: back; justify-self: start; }
.reader-action {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding-inline: 9px;
  border-radius: 5px;
  white-space: nowrap;
  transition: color 170ms ease, background-color 170ms ease;
}
.kb-page .reader-bar a:is(:hover, :focus-visible) { color: #8d472c; background: #b97b4320; }
.reader-controls { grid-area: controls; display: flex; justify-self: end; gap: 7px; }
.reader-controls button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 11px;
  border: 1px solid #d9bfa3;
  border-radius: 7px;
  color: #70513b;
  background: #fffaf3;
  box-shadow: inset 0 1px #fff, 0 1px 2px #7955390c;
  font: 600 12px/1.4 "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.reader-controls button:hover { background: #f9e9d1; border-color: #b78b65; }
.reader-controls button[aria-pressed="true"] { background: #efd9ba; border-color: #a57650; color: #623e26; }
.reader-controls button:focus-visible { outline: 2px solid #a7744e; outline-offset: 3px; }
.reader-controls button:disabled { opacity: .5; cursor: default; }
.reader-progress { display: grid; grid-area: progress; gap: 5px; min-width: 0; }
.reader-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #806044;
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}
.reader-progress-value { color: #805131; font-variant-numeric: tabular-nums; }
.reader-progress-track { height: 4px; overflow: hidden; border-radius: 4px; background: #e8d7c1; }
.reader-progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #bd8c5c, #91603b);
  transform: scaleX(var(--read, 0));
  transform-origin: left;
}
.reader { position: relative; height: 100%; }
.reader iframe { display: block; width: 100%; height: 100%; border: 0; }
.reader iframe[data-loading] { visibility: hidden; }
.reader-status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }

@media (max-width: 900px) {
  .reader-bar { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "back progress" "controls controls"; gap: 0 18px; }
  .reader-controls { padding: 0 0 9px; }
}

@media (max-width: 660px) {
  .kb-page::before { background-image: url("workbench-mobile.webp"); }
  .workbench {
    --book-height: min(69svh, (100vw - 40px) * 1.43, 100svh - 105px);
    padding: 12px 14px clamp(18px, 3.4svh, 34px);
  }
  .book-cover { width: min(85vw, 420px); }
  .cover-emblem { width: 55px; font-size: 28px; }
  .book-cover h1 { font-size: clamp(29px, 8.5vw, 40px); }
  .book { width: min(100%, 480px); padding: 5px 6px 8px; }
  .book-spread { grid-template: auto minmax(0, 1fr) / 1fr; }
  .book-page { min-height: 0; padding: 16px 20px; }
  .book-left { gap: 5px; background: linear-gradient(135deg, #fff4df, #f2dfbd); }
  .book-right { padding-top: 0; background: linear-gradient(135deg, #fff4df, #f5e4c6); }
  .contents-paper { padding: 8px 14px 13px; }
  .contents-list { gap: 7px; }
  .kb-page .contents-list .page-entry { padding: 5px 12px; }
  .contents-list .page-entry strong { font-size: 19px; }
  .contents-list .page-entry small { margin-top: 3px; }
  .contents-arrow { width: 30px; }
  .chapter-paper { padding-top: 8px; }
  .tip-detail .page-heading h2 { font-size: 26px; }
  .tip-paper { padding-top: 12px; }
  .tip-paper p { font-size: 14px; line-height: 1.75; }
  .page-heading { padding: 6px 0 4px; }
  .page-emblem { display: none; }
  .page-heading h2 { font-size: 36px; }
  .page-heading h2::after { margin-top: 11px; }
  .page-heading p { margin-top: 7px; font-size: 13px; }
  .page-entry { min-height: 60px; }
  .page-entry strong { font-size: 15px; }
  .page-entry small { font-size: 12px; }
  .resource-card h3 { font-size: 14px; }
  .turn-sheet { inset: 0; }
  .reader-bar { width: calc(100% - 24px); gap: 0 10px; border-top: 0; }
  .reader-controls { gap: 6px; }
  .reader-controls button { min-height: 40px; padding: 5px 10px; }
  .reader-action { padding-inline: 5px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .page-entry, .contents-arrow, .kb-page .contents-list .page-entry, .reader-bar a, .reader-controls button { transition: none; }
  .cover-corner { transform: scale(.73); animation: none; }
}
