/* The Magic of 四九五 — styling
   Playfair Display (headings) + Lora (body), both self-hosted under OFL.
   The two roman faces are variable fonts (wght axis), so one file each spans
   the 400–700 range; Lora italic is a static 400. The five kanji (四九五死苦)
   are served from Shippori Mincho, subset to just those glyphs (regular + bold),
   with a system serif CJK face left in the stack as a safety net. */

@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/playfairdisplay.woff2') format('woff2');
}

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora.woff2') format('woff2');
}

@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/lora-italic.woff2') format('woff2');
}

/* Shippori Mincho, subset to 四九五死苦 only. */
@font-face {
  font-family: 'Kanji';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/kanji-regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Kanji';
  font-weight: 700;
  font-display: swap;
  src: url('fonts/kanji-bold.woff2') format('woff2');
}

:root {
  --bg: #f6f3ec;          /* gentle off-white */
  --ink: #34322c;         /* dark warm grey, body text */
  --ink-strong: #29271f;  /* headings */
  --muted: #6c675d;       /* sources note, ToC */
  --hairline: #d9d3c6;
  --cjk: 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif JP',
         'Songti SC', 'MS Mincho', serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Lora', 'Kanji', Georgia, 'Times New Roman', var(--cjk), serif;
  font-size: 1.1875rem;      /* ~19px */
  line-height: 1.75;
  font-feature-settings: 'onum' 1, 'liga' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* The title sits above the single reading column. */
.masthead {
  max-width: 800px;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 0;
}

/* Single centred column (≤800px): the table of contents stacks on top. */
.layout {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
}

/* Table of contents — on top, between the title and the first section. */
.toc {
  margin-bottom: 2.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--hairline);
}

.toc-title {
  margin: 0 0 0.9rem;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink-strong);
  text-align: center;
}

/* Horizontal row of section links, centred, wrapping, with middle-dot separators. */
.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 0.4rem;
}

.toc li { margin: 0; }

.toc li:not(:first-child)::before {
  content: "\00B7";
  margin: 0 0.6rem;
  color: var(--muted);
}

.toc a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.toc a:hover,
.toc a:focus-visible {
  color: var(--ink-strong);
  border-bottom-color: var(--muted);
}

/* A contents copy beneath each section heading; current section bolded. */
.section-toc {
  margin: 0 0 2rem;      /* sits just under the h2, above the first paragraph */
  padding: 0;
  border-bottom: 0;      /* cancel the hairline the master ToC carries */
}

.section-toc .current {
  font-weight: 700;
  color: var(--ink-strong);
}

/* Section opener: a centred dot-ornament sets off the heading + contents strip
   on the plain page — no fill or border. The middle dot echoes the ToC dots. */
.section-head {
  margin: 4rem 0 2rem;             /* clear air above; gap below to the prose */
}

.section-head::before {
  content: "";
  display: block;
  height: 1.8rem;                  /* sets the glyph height; the main size dial */
  aspect-ratio: 5422 / 915;        /* the composite SVG's viewBox */
  max-width: 100%;                 /* the wide rule–四九五–rule shape stays edge-safe */
  margin: 0 auto 1.4rem;           /* centred; space to the heading */
  background-color: var(--muted);  /* colour lives in CSS, matches the old dots */
  -webkit-mask: url("four-nine-five.svg") center / contain no-repeat;
  mask: url("four-nine-five.svg") center / contain no-repeat;
}

.section-head h2 {
  margin: 0 0 0.9rem;              /* gap from heading to the ToC strip */
  scroll-margin-top: 3rem;         /* leave the ornament visible when jumped to */
}

.section-head .section-toc {
  margin: 0;                       /* .section-head's bottom margin owns the gap to prose */
}

/* Headings — Playfair Display, with its sculptural figures switched on. */
h1,
h2 {
  font-family: 'Playfair Display', 'Kanji', Georgia, var(--cjk), serif;
  color: var(--ink-strong);
  font-weight: 700;
  font-feature-settings: 'onum' 1, 'dlig' 1, 'liga' 1;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: break-word;
}

h1 {
  margin: 0 0 2.5rem;
  font-size: 2.75rem;
  letter-spacing: 0.005em;
}

h2 {
  margin: 3.25rem 0 1.1rem;
  font-size: 1.7rem;
  scroll-margin-top: 1.5rem;   /* breathing room when jumped to from the ToC */
}

p {
  margin: 0 0 1.4em;
  text-align: justify;
  hyphens: auto;
}

/* "Scroll to top" at the end of each section. */
.scroll-top {
  margin: 2.5rem 0 0;
  text-align: center;      /* overrides the justified p */
  font-style: italic;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
}

.scroll-top a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.scroll-top a:hover,
.scroll-top a:focus-visible {
  color: var(--ink-strong);
  border-bottom-color: var(--muted);
}

.sources {
  margin-top: 1.5em;
  font-style: italic;
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--muted);
}

hr {
  border: 0;
  width: 42%;
  height: 1px;
  margin: 3.5rem auto;
  background: var(--hairline);
}

::selection {
  background: #e4ddcb;
  color: var(--ink-strong);
}

/* Narrow screens: trim the frame and scale the title down. */
@media (max-width: 480px) {
  body { font-size: 1.0625rem; }
  .masthead { padding: 3rem 1.15rem 0; }
  .layout { padding: 0 1.15rem 4rem; }
  h1 { font-size: 2.1rem; margin-bottom: 2rem; }
  h2 { font-size: 1.45rem; margin-top: 2.75rem; }
}
