: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; }
.brand strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { font-size: 11px; opacity: .72; }
.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; }
.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; }
.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; }
}
