:root {
  --bg: #f4f1ea;
  --paper: #ffffff;
  --ink: #161616;
  --muted: #696969;
  --line: #d8d4cb;
  --accent: #b21f2d;
  --accent-dark: #7e131d;
  --nav: #111111;
  --max-text: 860px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.72;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(17,17,17,.97);
  color: white;
  box-shadow: 0 1px 8px rgba(0,0,0,.18);
}
.brand { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.25; color: inherit; text-decoration: none; }
.brand strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { font-size: 11px; opacity: .72; }
.brand .brand-logos { display: flex; align-items: center; gap: 5px; margin-top: 3px; opacity: 1; }
.brand-logos img { display: block; width: auto; height: 19px; object-fit: contain; }
.brand-logos img:first-child { height: 21px; }
.topActions { display: flex; gap: 8px; }
.iconButton {
  min-height: 40px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,.08);
  color: inherit;
  text-decoration: none;
}
.iconButton:hover { background: rgba(255,255,255,.16); }
.linkButton { display: inline-flex; align-items: center; }
.appShell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  align-items: start;
}
.tocPanel {
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  overflow: auto;
  padding: 18px 14px 32px;
  background: #f8f6f1;
  border-right: 1px solid var(--line);
}
.tocPanel h2 { margin: 0 0 10px; font-size: 18px; }
.tocGroup { margin: 18px 0; }
.tocGroup h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.tocLink {
  display: block;
  padding: 7px 9px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.35;
}
.tocLink:hover, .tocLink:focus { background: #ebe6dc; outline: none; }
.tocUnitLink { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; overflow: hidden; }
.tocNumber { flex: 0 0 24px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.tocTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tocGroup h3 .inlineTermButton { font-size: inherit; font-weight: inherit; }
.content { min-width: 0; padding: 30px 34px 80px; }
.introCard,
.textBlock,
.figureCard {
  width: min(100%, var(--max-text));
  margin-left: auto;
  margin-right: auto;
}
.introCard {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}
.introCard h1 { margin: 0 0 8px; font-size: clamp(24px, 4vw, 34px); line-height: 1.3; }
.introCard p { margin: 8px 0 0; color: var(--muted); }
.textBlock {
  background: var(--paper);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0 30px;
}
.textBlock.first { border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; padding-top: 28px; }
.textBlock.last { border-bottom: 1px solid var(--line); border-radius: 0 0 14px 14px; padding-bottom: 28px; margin-bottom: 24px; }
.paragraph { margin: 0; padding: 0 0 14px; font-size: 16px; line-height: 1.82; }
.editorNote { padding: 12px 14px; background: #f7f2eb; border-radius: 10px; font-size: 14px; }
.heading1, .heading2, .heading3 {
  width: min(100%, var(--max-text));
  margin-left: auto;
  margin-right: auto;
  color: var(--ink);
}
.heading1 { margin-top: 36px; margin-bottom: 14px; font-size: 27px; line-height: 1.35; }
.heading2 { margin-top: 30px; margin-bottom: 12px; font-size: 21px; line-height: 1.45; }
.heading3 { margin-top: 28px; margin-bottom: 10px; font-size: 18px; line-height: 1.5; }
.unitAnchor { scroll-margin-top: 78px; }
.figureCard {
  margin-top: 18px;
  margin-bottom: 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.figureHead { display: flex; gap: 8px; align-items: baseline; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.figureHead strong { font-size: 15px; }
.figureHead span { color: var(--muted); font-size: 12px; }
.figureImageButton { display: block; width: 100%; border: 0; padding: 0; background: white; }
.figureImageButton img { display: block; width: 100%; height: auto; }
.figureActions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.figureActions a { text-decoration: none; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 13px; }
.scrim {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(0,0,0,.42);
}
.searchPanel {
  position: fixed;
  inset: 8vh max(16px, calc((100vw - 760px)/2));
  z-index: 50;
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  overflow: hidden;
}
.searchHeader { display: flex; gap: 10px; padding: 14px; background: var(--nav); color: white; }
.searchHeader input {
  flex: 1;
  min-width: 0;
  border: 1px solid #777;
  border-radius: 10px;
  padding: 10px 12px;
  background: white;
  color: #111;
}
.searchResults { max-height: 70vh; overflow: auto; padding: 8px; }
.searchResult { display: block; padding: 12px; border-radius: 10px; text-decoration: none; }
.searchResult:hover { background: #f2eee7; }
.searchResult strong { display: block; margin-bottom: 4px; }
.searchResult small { color: var(--muted); }
.imageViewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #111;
  color: white;
  display: flex;
  flex-direction: column;
}
.viewerBar {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid #333;
}
.viewerBar strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewerViewport {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  background: #222;
}
.viewerViewport img {
  display: inline-block;
  width: auto;
  min-width: min(100%, 780px);
  max-width: none;
  height: auto;
  background: white;
}
@media (max-width: 999px) {
  .appShell { display: block; }
  .tocPanel {
    position: fixed;
    left: 0;
    top: 62px;
    bottom: 0;
    z-index: 50;
    width: min(86vw, 340px);
    height: auto;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 10px 0 34px rgba(0,0,0,.2);
  }
  .tocPanel.open { transform: translateX(0); }
  .content { padding: 20px 14px 72px; }
  .textBlock { padding-left: 18px; padding-right: 18px; }
  .paragraph { font-size: 16px; line-height: 1.84; }
  .figureCard { border-radius: 12px; }
  .figureHead { align-items: flex-start; flex-direction: column; gap: 2px; }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .brand strong { font-size: 13px; }
  .iconButton { padding: 8px 10px; }
  .searchPanel { inset: 4vh 10px; }
  .viewerViewport img { min-width: 100%; }
}
[hidden] { display: none !important; }
@media print {
  body { background: white; }
  .topbar, .tocPanel, .searchPanel, .scrim, .imageViewer { display: none !important; }
  .appShell { display: block; }
  .content { padding: 0; }
  .textBlock, .figureCard, .introCard { width: 100%; box-shadow: none; }
  .figureCard { break-inside: avoid; }
  .paragraph { font-size: 10.5pt; line-height: 1.63; }
}
.reader {
  width: min(100%, var(--max-text));
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 30px 46px;
}
.reader .heading1, .reader .heading2, .reader .heading3,
.reader .figureCard { width: 100%; }
.reader .figureCard { margin-left: 0; margin-right: 0; }
.reader .paragraph[id] { scroll-margin-top: 78px; }
@supports (content-visibility: auto) {
  .contentChunk {
    content-visibility: auto;
    contain-intrinsic-size: auto 850px;
  }
  .glossaryGroup {
    content-visibility: auto;
    contain-intrinsic-size: auto 2400px;
  }
}
.backToToc {
  display: inline-block;
  margin: 4px 0 18px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
@media (max-width: 999px) {
  .reader { padding: 20px 17px 40px; border-radius: 12px; }
  @supports (content-visibility: auto) {
    .contentChunk { contain-intrinsic-size: auto 600px; }
  }
}

/* Glossary-only review layer. Keep this separate from the unchanged rule body. */
html { scroll-behavior: auto; }
.glossarySection { margin-top: 40px; border-top: 3px solid var(--ink); }
.glossarySection > h2 { font-size: 27px; line-height: 1.35; margin: 25px 0 8px; }
.glossaryLead { margin: 0 0 8px; color: #333; }
.glossaryReviewLink { margin: 0 0 26px; font-size: 14px; }
.glossaryReviewLink a { color: var(--accent-dark); }
.glossaryGroup { margin: 25px 0 32px; }
.glossaryGroup > h3 { margin: 0; padding: 0 0 8px; border-bottom: 2px solid var(--ink); font-size: 19px; }
.glossaryItem { padding: 15px 0 16px; border-bottom: 1px solid var(--line); }
.glossaryItemHead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 11px; }
.glossaryNumber { display: inline-block; min-width: 44px; padding: 3px 5px; border-radius: 4px; background: #f2ede5; color: #4b4137; text-align: center; text-decoration: none; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.glossaryItemHead h4 { flex: 1; min-width: 180px; margin: 0; font-size: 17px; line-height: 1.5; overflow-wrap: anywhere; }
.glossaryReviewBadge { color: #8a1a28; background: #fff0f1; border: 1px solid #e4b7bc; border-radius: 3px; padding: 1px 6px; font-size: 12px; font-weight: 700; }
.glossaryMeaning { margin: 8px 0 3px 55px; font-size: 15px; line-height: 1.75; }
.glossarySource { margin: 0 0 0 55px; font-size: 12px; color: var(--muted); }
.glossaryItem:target { background: #fff8e9; }
.inlineTermButton {
  display: inline;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  line-height: inherit;
  text-decoration-line: underline;
  text-decoration-color: #9ea6a8;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.inlineTermButton:hover, .inlineTermButton:focus-visible { color: var(--accent-dark); text-decoration-color: var(--accent-dark); }
.inlineTermButton:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 3px; }
.termPopover {
  position: fixed;
  z-index: 70;
  width: min(360px, calc(100vw - 24px));
  padding: 16px 18px;
  background: white;
  border: 1px solid #cabfb3;
  border-radius: 12px;
  box-shadow: 0 12px 36px rgba(0,0,0,.22);
  line-height: 1.6;
}
.termPopoverHead { display: flex; align-items: flex-start; gap: 9px; }
.termPopoverHead strong { flex: 1; line-height: 1.45; }
.termPopoverNumber { color: var(--accent-dark); font-size: 12px; font-weight: 700; }
.termPopoverHead button { border: 0; background: transparent; font-size: 22px; line-height: 1; color: #555; }
.termPopover p { margin: 10px 0; font-size: 14px; }
.termPopover > a { color: var(--accent-dark); font-size: 13px; }
@media (max-width: 600px) {
  .termPopover { inset: auto 12px max(12px, env(safe-area-inset-bottom)) !important; width: auto; }
}
@media (max-width: 600px) {
  .glossarySection > h2 { font-size: 23px; }
  .glossaryGroup > h3 { font-size: 17px; }
  .glossaryItemHead { gap: 6px 9px; }
  .glossaryItemHead h4 { min-width: calc(100% - 54px); font-size: 16px; }
  .glossaryReviewBadge { margin-left: 53px; }
  .glossaryMeaning, .glossarySource { margin-left: 53px; }
}

@media print {
  .contentChunk, .glossaryGroup { content-visibility: visible; contain-intrinsic-size: none; }
}
