@font-face {
  font-family: JianZiPu;
  src: url('/fonts/JianZiPu.woff2') format('woff2');
  font-display: swap;
}

main.content-main:has(> .portal) {
  max-width: 1372px;
  padding: 0 clamp(14px, 2.7vw, 36px) 52px;
  font: 17px/1.65 var(--font-sans);
}

.portal {
  background-image: repeating-linear-gradient(115deg, transparent 0 7px, var(--grain) 8px, transparent 9px 13px);
}

.portal [hidden] { display: none !important; }
.portal-sprite { position: absolute; pointer-events: none; }
.portal :is(h1, h2, h3) { margin: 0; padding: 0; border: 0; font-family: var(--font-serif); line-height: 1.3; }
.portal h2 { font-size: clamp(24px, 2.3vw, 32px); }
.portal h3 { font-size: clamp(20px, 1.8vw, 24px); line-height: 1.35; }
.portal p { margin: 0; }
.portal small, .portal-meta, .portal .readout { color: var(--fg-muted); font-size: 15px; line-height: 1.5; }
.portal a { border-bottom: 0; text-decoration: underline; text-underline-offset: .22em; }
.portal :is(a, button, input, select, summary):focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.portal :is(section, .chapter) { scroll-margin-top: 80px; }

.frontispiece {
  --wash: rgba(250, 247, 239, .78);
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-height: 148px;
  max-height: none;
  padding: 18px clamp(10px, 2.4vw, 36px);
}

.frontispiece::before,
.frontispiece::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.frontispiece::before {
  z-index: -2;
  inset-inline-start: 36%;
  background: url('/assets/hero-scholar-qin-banner.webp?v=748b05e5') right center / cover no-repeat;
}
.frontispiece::after {
  z-index: -1;
  background: linear-gradient(90deg, var(--bg) 0 36%, var(--wash) 62%, transparent 88%);
}
[data-theme='dark'] .frontispiece { --wash: rgba(25, 25, 21, .78); }
[data-theme='dark'] .frontispiece::before { opacity: .28; }
.portal .frontispiece h1 { font-size: clamp(1.75rem, 2.8vw, 2.625rem); letter-spacing: .045em; max-width: 76%; }
.portal .frontispiece h1:lang(en) { font-size: clamp(1.625rem, 2.65vw, 2.5rem); letter-spacing: 0; max-width: 67%; }
.frontispiece p { max-width: 60%; font-size: 17px; line-height: 1.6; color: var(--fg-muted); }
.frontispiece .eyebrow { max-width: none; color: var(--accent); font-size: 13.5px; font-weight: 650; letter-spacing: .08em; }
.frontispiece .beta-callout {
  max-width: 72%; margin-top: .9rem; font-size: 14.5px;
  border: 1px solid var(--line, #c9bfa8); border-radius: 999px; padding: .45rem 1.05rem;
}
.frontispiece .beta-callout a { white-space: nowrap; font-weight: 650; }

.tool-band, .categories, .roles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-block: 1px solid var(--border-strong);
}
/* 工具四项卡片化：沿用站内 kn-door-card 的「顶部金色双线 + 描边卡」语言，成为首页视觉锚点 */
.tool-band {
  gap: clamp(10px, 1.2vw, 16px);
  padding-block: 16px;
  border-block: 0;
}
.tool-band a {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.2vw, 16px);
  padding: 15px clamp(12px, 1.6vw, 22px);
  color: var(--fg);
  text-decoration: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-block-start: 3px double var(--accent);
  border-radius: 6px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.tool-band a:hover {
  transform: translateY(-2px);
  box-shadow: var(--content-shadow, 0 8px 22px rgba(0, 0, 0, .22));
  border-color: var(--accent);
}
.categories a {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.1vw, 14px);
  padding-inline: clamp(8px, 1.8vw, 28px);
  color: var(--fg);
  text-decoration: none;
}
:is(.categories, .roles) > :not(:last-child) { border-inline-end: 1px solid var(--border); }
.tool-band strong { font: 650 clamp(20px, 1.9vw, 25px)/1.4 var(--font-serif); letter-spacing: .02em; }
.categories strong { font: 650 clamp(18px, 1.5vw, 21px)/1.35 var(--font-serif); }
/* 图标底座：印章式圆角框（仅工具卡；categories 保持裸图标） */
.tool-band .portal-icon {
  width: 52px;
  height: 48px;
  padding: 7px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
}
.portal-icon {
  width: 38px;
  height: 34px;
  flex: none;
  color: var(--accent);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(18px, 2.6vw, 42px);
  margin: 20px 0 26px;
}
.classical-frame {
  position: relative;
  isolation: isolate;
  border: 2px solid var(--border-strong);
  outline: 1px solid var(--border);
  outline-offset: -6px;
  border-radius: 2px;
  background: var(--bg-elevated);
}
.classical-frame::before, .classical-frame::after {
  content: '';
  position: absolute;
  z-index: -1;
  pointer-events: none;
  width: 12px;
  height: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  clip-path: polygon(0 0, 100% 0, 100% 45%, 45% 45%, 45% 100%, 0 100%);
}
.classical-frame::before { left: -2px; top: -2px; }
.classical-frame::after { right: -2px; bottom: -2px; transform: rotate(180deg); }
.qin-desk { padding: clamp(14px, 1.65vw, 24px); container-type: inline-size; }

.portal :is(.portal-button, input, select) {
  min-height: 36px;
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--fg);
  font: 16px/1.4 var(--font-sans);
}
.portal input::placeholder { color: var(--fg-muted); opacity: 1; }
.portal .portal-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer; }
.portal .portal-button:hover { background: var(--bg-soft); color: var(--cinnabar); }
.portal .portal-button[aria-pressed='true'] { color: var(--cinnabar); box-shadow: inset 0 -2px var(--cinnabar); }
.portal .portal-pine { border-color: var(--pine); background: var(--pine); color: var(--on-pine); }
.portal .portal-pine:hover { border-color: var(--pine-hover); background: var(--pine-hover); color: var(--on-pine); }
.desk-search { display: flex; gap: 6px; }
.desk-search input { flex: 1; min-width: 0; }
.quick-search { display: flex; flex-wrap: wrap; gap: 3px 12px; margin: 5px 0 13px; font-size: 16px; line-height: 1.4; }
.quick-search .desk-handbook { margin-inline-start: auto; font-weight: 700; color: var(--pine); }
.preview-switches { display: flex; float: right; gap: 4px; margin: 0 0 4px 8px; }
.preview-switches .portal-button { font-size: 16px; }
.score-preview h2 { font-size: clamp(19px, 1.85vw, 26px); margin-bottom: 5px; }
.score-preview .portal-meta { clear: both; }

.qin-board { display: block; width: 100%; height: auto; margin-top: 5px; }
.qin-board .qin-body-use {
  filter: drop-shadow(0 5px 8px rgba(34, 20, 14, 0.28));
}
[data-theme='dark'] .qin-board .qin-body-use {
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.65)) brightness(0.95);
}
.qin-board text {
  font: 600 16px var(--font-sans);
  fill: var(--fg-muted);
  text-anchor: middle;
}
.qin-board .string-label { text-anchor: start; }
.qin-board .string-leader { fill: none; stroke: var(--border-strong); stroke-width: .8; }
.qin-board .string {
  fill: none;
  stroke: #e7cfa6;
  filter: drop-shadow(0 1px 0.6px rgba(14, 7, 4, 0.58));
}
.qin-board .hui-compact { font-size: 10.5px; }
.qin-board .active-string { fill: none; stroke: #f4d396; stroke-width: 2.25px; stroke-linecap: round; }
.qin-board .active-string:is([data-mode='pressed'], [data-mode='slide']) { stroke: #f1ad7c; }
.qin-board .active-string[data-mode='harmonic'] { stroke: #d6f0e8; }
.qin-board .pluck-gesture { color: #f29b80; }
.qin-board .pluck-gesture[data-direction='out'] { color: #8ae0c6; }
.qin-board .pluck-ripple { fill: none; stroke: #f3d08b; stroke-width: 1.3px; }
.qin-board .slide-origin { fill: #e8a778; fill-opacity: .24; stroke: #ecad7f; stroke-opacity: .55; }
.qin-board .press-point circle { fill: #a83f30; stroke: #f5cb93; stroke-width: 1.4px; }
.qin-board .press-point text { text-anchor: middle; dominant-baseline: central; fill: #fff7ea; font-size: 12px; font-weight: 700; }
.qin-board .is-lit text { fill: var(--cinnabar); font-weight: 700; }
.portal .readout { min-height: 2.3em; margin-bottom: 5px; color: var(--fg-muted); font-size: 15px; line-height: 1.5; }

.beat-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  border-block: 3px double var(--border-strong);
}
.beat-cell {
  display: grid;
  align-content: start;
  justify-items: center;
  row-gap: 2px;
  min-width: 0;
  min-height: 73px;
  padding: 3px;
  border: 0;
  border-inline-end: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.beat-cell:last-child { border-inline-end: 0; }
.beat-cell:disabled { cursor: default; opacity: 1; }
.beat-cell:hover:not(:disabled), .beat-cell[aria-pressed='true'] { background: var(--tint); }
.beat-cell[aria-pressed='true'] { box-shadow: inset 0 -3px var(--cinnabar); }
.beat-jianpu { font: 600 17px/1.35 Consolas, monospace; }
.beat-lyric { font-family: var(--font-serif); }
.beat-jianzi, .glyph-out { overflow-wrap: anywhere; font-size: .84rem; }
.beat-jianzi { --jzp-size: 28px; }
.beat-chord .beat-jianzi { --jzp-size: 32px; }
.portal .jzp-box {
  position: relative;
  display: block;
  width: var(--jzp-size);
  height: var(--jzp-size);
  user-select: none;
}
.portal .jzp-ink {
  position: absolute;
  inset: 50% auto auto 50%;
  display: block;
  white-space: nowrap;
  font-family: JianZiPu, serif;
  font-weight: 400;
  font-style: normal;
  font-feature-settings: 'liga' 1, 'calt' 1;
  font-variant-ligatures: common-ligatures contextual;
  text-rendering: optimizeLegibility;
  pointer-events: none;
}
.portal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 13px; margin-top: 12px; }

@container (width < 455px) {
  .beat-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .beat-cell:nth-child(-n+4) { border-bottom: 1px solid var(--border); }
  .beat-cell:nth-child(4n) { border-inline-end: 0; }
  .preview-switches { float: none; margin: 0 0 8px; }
}

.portal-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 16px; flex-wrap: wrap; }
.timeline-panel { padding: 10px 0 12px 14px; border-block: 3px double var(--border-strong); }
.timeline-panel .portal-meta { margin-top: 5px; }
.timeline {
  list-style: none;
  margin: 13px 0 11px 5px;
  padding-left: 18px;
  border-left: 1px solid var(--border-strong);
}
.timeline li { position: relative; margin-bottom: 9px; }
.timeline li::before {
  content: '';
  position: absolute;
  left: -22px;
  top: .46em;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}
.timeline small { display: block; }
.timeline a, .watch-links a { color: var(--fg); text-decoration: none; }
.timeline a:hover, .watch-links a:hover { text-decoration: underline; }
.timeline-panel .minor { border-top: 1px solid var(--border); padding-top: 9px; margin-top: 8px; }
.watch-links { list-style: none; margin: 4px 0 7px; padding: 0; }
.watch-links li + li { margin-top: 3px; }

.chapter { border-top: 1px solid var(--border-strong); padding-block: 22px 26px; }
.chapter > h2, .chapter > .portal-heading, .study-grid h2 { margin-bottom: 10px; }
.bookshelf {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 28px);
  padding: 12px clamp(4px, 2vw, 32px) 10px;
  border-bottom: 4px double var(--border-strong);
}
.portal .book {
  display: block;
  min-width: 0;
  text-decoration: none;
}
.book-cover {
  position: relative;
  display: block;
  aspect-ratio: 1.28;
  width: 100%;
  min-height: 106px;
  background: #21383c;
  color: #fcf5de;
  box-shadow: 2px 3px 0 #a89c82, inset 12px 0 0 #0002;
  border: 1px solid #766b54;
  border-radius: 2px;
}
.book:nth-child(3n + 2) .book-cover { background: #efe8d8; color: #302e26; }
.book:nth-child(3n) .book-cover { background: #342c26; }
.portal .book:hover .book-name { color: #943d2e; }
.binding {
  position: absolute;
  inset: 3% auto 3% 8%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 3px;
  border-inline: 1px solid #bcae91;
}
.binding-stitch {
  width: clamp(8px, 1.2vw, 15px);
  margin-left: calc(2px - clamp(8px, 1.2vw, 15px));
  border-top: 2px solid #c8b99b;
  box-shadow: 0 1px #3c3328;
}
.book-name {
  position: absolute;
  inset: 9% auto auto 21%;
  writing-mode: vertical-rl;
  padding: .38em .22em;
  font: clamp(14px, 1.4vw, 21px)/1.1 var(--font-serif);
  color: #2e2922;
  background: #f8f1de;
  border: 3px double #8e8067;
}
.book-seal {
  position: absolute;
  inset: auto 8% 9% auto;
  padding: 1px;
  color: #fff9e7;
  background: #903f30;
  border: 2px double #f9d9bc;
  font: 12px/1.2 var(--font-serif);
}
.book-seal-complete { background: #26584d; }
.book-seal-guide { background: #725729; }
.book-motif {
  position: absolute;
  inset: auto 0 8% auto;
  width: 65%;
  height: 65%;
  opacity: .13;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
}
.book-translation {
  display: block;
  padding-top: 7px;
  text-align: center;
  font: 600 15px/1.45 var(--font-serif);
  overflow-wrap: anywhere;
}
.portal .catalog-count { margin-top: 10px; }

.study-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
.study-grid > section + section { border-inline-start: 1px solid var(--border); padding-inline-start: 24px; }
.slot-pickers, .topic-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.slot-pickers { margin-block: 7px; }
.slot-pickers label { display: grid; gap: 2px; font-size: 15px; line-height: 1.5; }
.slot-pickers select { min-width: 58px; }
.slot-pickers select:disabled { background: var(--bg-soft); color: var(--fg-muted); }
.glyph-result { display: flex; align-items: center; gap: 10px; }
.glyph-out { --jzp-size: 40px; display: inline-grid; place-items: center; min-width: 56px; min-height: 56px; padding: 2px 7px; border: 1px solid var(--border-strong); background: var(--bg-elevated); }
.token-out { font-family: var(--font-serif); }
.quote { margin-block: 12px 8px; padding: 8px 12px; border-inline-start: 2px solid var(--border-strong); background: var(--bg-elevated); }
.quote .quote-text { margin: 0 0 5px; padding: 0; border: 0; background: transparent; color: var(--fg); font: 18px/1.75 var(--font-serif); }
.quote .gloss { margin-bottom: 4px; }
.topic-links { padding-bottom: 8px; }
.library-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.library-row a::before { content: '❖'; color: var(--accent); font-size: 11px; margin-inline-end: 8px; }
.categories, .roles { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 12px; }
.categories a { padding-block: 12px; }
.roles article { padding: 14px clamp(10px, 1.65vw, 20px); }
.roles h3 { margin-bottom: 4px; }
.faq-item { border-bottom: 1px solid var(--border); padding: 8px 0; }
.faq-item summary { color: var(--link); cursor: pointer; }
.faq-item p { padding: 4px 0 3px 18px; }

@media (width < 860px) {
  .hero-grid { grid-template-columns: minmax(0, 1fr); }
  .timeline-panel { padding-inline-start: 0; }
}

@media (width < 720px) {
  .frontispiece::before, .frontispiece::after { content: none; }
  .frontispiece p, .portal .frontispiece h1, .portal .frontispiece h1:lang(en) { max-width: none; }
  .portal .frontispiece h1 { font-size: clamp(20px, 5.6vw, 26px); text-wrap: balance; }
  .portal .frontispiece h1:lang(en) { font-size: clamp(19px, 5.6vw, 23px); }
  .frontispiece p { font-size: 16px; line-height: 1.55; }
  .tool-band { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-block: 12px; }
  .tool-band a { padding: 12px 14px; }
  .tool-band strong { font-size: 21px; }
  .tool-band .portal-icon { width: 46px; height: 42px; padding: 6px; }
  .portal-icon { width: 32px; height: 29px; }
  .bookshelf { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; }
  .study-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .study-grid > section + section { border-inline-start: 0; border-top: 1px solid var(--border); padding: 16px 0 0; }
  .roles, .categories { grid-template-columns: minmax(0, 1fr); }
  :is(.roles, .categories) > :not(:last-child) { border-inline-end: 0; border-bottom: 1px solid var(--border); }
}

@media (width < 360px) {
  .frontispiece { padding: 6px 0; gap: 3px; }
  .frontispiece .eyebrow { font-size: .68rem; letter-spacing: .04em; }
}

@media (max-width: 560px) {
  .qin-board :is(text, .hui-compact) { font-size: 24px; font-weight: 700; }
  .qin-board [data-hui]:not([data-hui="1"], [data-hui="4"], [data-hui="5"], [data-hui="7"], [data-hui="9"], [data-hui="10"], [data-hui="13"]) > text {
    display: none;
  }
  .qin-board .string-label { font-size: 17px; }
  .qin-board .hui-compact {
    transform: scaleX(2.5);
    transform-box: fill-box;
    transform-origin: center;
  }
}
