/* Goshuin reference: entry and index pages. Quiet, light, catalogue-like.
   Latin type is self-hosted Source Serif 4 (SIL OFL, see fonts/OFL.txt);
   Japanese uses the reader's own CJK fonts. */

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/goshuin/assets/fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/goshuin/assets/fonts/source-serif-4-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --wall: #fbfbf9;      /* page */
  --mat: #e8e9e5;       /* the mount the scan sits on */
  --ink: #23262a;       /* text */
  --quiet: #63676c;     /* secondary text, labels */
  --rule: #d6d8d3;      /* hairlines */
  --link: #2b4c7e;      /* indigo links */
  --latin: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --cjk: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif CJK JP",
    "Noto Serif JP", "Source Han Serif JP", "Noto Serif CJK", serif;
  --badge: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --gap: clamp(1.25rem, 3vw, 3rem);
}

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

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

body {
  margin: 0;
  background: var(--wall);
  color: var(--ink);
  font-family: var(--latin), var(--cjk);
  font-size: 1.0625rem;
  line-height: 1.6;
  font-optical-sizing: auto;
  font-variant-numeric: oldstyle-nums;
  overflow-wrap: break-word;
}

[lang="ja"] { font-family: var(--cjk); font-variant-numeric: normal; }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0; }
p { margin: 0; }

/* ---------- header: the catalogue label ---------- */

.entry-head, .entry, .pager, .site-foot {
  max-width: 96rem;
  margin-inline: auto;
  padding-inline: var(--gap);
}

.entry-head { padding-top: clamp(1.25rem, 3vw, 2.5rem); padding-bottom: 1.75rem; }

.crumb { font-size: 0.9375rem; margin-bottom: 1.25rem; }
.crumb a { color: var(--quiet); }

.entry-head h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.75rem); font-weight: 500; letter-spacing: -0.01em; }
.title-en { display: block; hyphens: auto; }
.title-jp {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.62em;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--quiet);
}

.facts {
  display: grid;
  gap: 0.75rem 2.5rem;
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
  line-height: 1.45;
}
.facts dt { color: var(--quiet); font-size: 0.875rem; }
.facts dd { margin: 0.1rem 0 0; }
@media (min-width: 900px) {
  .facts { grid-template-columns: minmax(0, 3fr) minmax(0, 1fr) minmax(0, 4fr); }
}

/* ---------- three parts ---------- */

.entry { display: grid; gap: 2.5rem var(--gap); padding-bottom: 3rem; }
.entry > * { min-width: 0; }

@media (min-width: 900px) {
  .entry { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr) minmax(0, 4fr); align-items: start; }
  .entry .scan { position: sticky; top: 1rem; }
  .entry.wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .entry.wide .scan { grid-column: 1 / -1; position: static; }
}

/* ---------- scan ---------- */

.scan { margin: 0; }

.sheet {
  position: relative;
  aspect-ratio: var(--ar);
  width: 100%;
  margin-inline: auto;
  outline: 1.5rem solid var(--mat);
  outline-offset: 0;
  margin-block: 1.5rem;
  background: var(--mat);
}
@media (min-width: 900px) {
  /* Fit the whole sheet in the window: cap the width by the height it implies. */
  .entry:not(.wide) .sheet { width: min(100% - 3rem, (100vh - 6rem) * var(--ar)); }
  .entry.wide .sheet { width: min(100% - 3rem, (100vh - 8rem) * var(--ar)); }
}
@media (max-width: 899.98px) {
  .sheet { width: calc(100% - 2rem); outline-width: 1rem; margin-block: 1rem; }
}

.sheet img { display: block; width: 100%; height: 100%; }

.overlay { position: absolute; inset: 0; }
.sheet:not(.on) .overlay { display: none; }

.box {
  position: absolute;
  border: 2px solid var(--c);
  border-radius: 2px;
}
.region-box { border-style: dashed; border-width: 1.5px; }
.box.hl { background: color-mix(in srgb, var(--c) 16%, transparent); }

.badge {
  position: absolute;
  z-index: 1;
  min-width: 1.25rem;
  height: 1.25rem;
  padding-inline: 0.2rem;
  border-radius: 0.625rem;
  background: var(--c);
  color: #fff;
  border: 1.5px solid #fff;
  font: 700 0.6875rem/1.0625rem var(--badge);
  font-style: normal;
  text-align: center;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
}
.s-l { right: 100%; top: 50%; transform: translate(-3px, -50%); }
.s-r { left: 100%; top: 50%; transform: translate(3px, -50%); }
.s-t { bottom: 100%; left: 50%; transform: translate(-50%, -3px); }
.s-b { top: 100%; left: 50%; transform: translate(-50%, 3px); }
.s-tl { right: 100%; bottom: 100%; transform: translate(7px, 7px); }
.s-tr { left: 100%; bottom: 100%; transform: translate(-7px, 7px); }
.s-bl { right: 100%; top: 100%; transform: translate(7px, -7px); }
.s-br { left: 100%; top: 100%; transform: translate(-7px, -7px); }
@media (max-width: 520px) {
  .entry.wide .badge { min-width: 0.875rem; height: 0.875rem; font-size: 0.5rem; line-height: 0.75rem; border-width: 1px; padding-inline: 0.05rem; }
  .badge { min-width: 1rem; height: 1rem; font-size: 0.5625rem; line-height: 0.8125rem; padding-inline: 0.1rem; }
}

.scan figcaption { margin-top: 0.25rem; font-size: 0.9375rem; line-height: 1.55; color: var(--quiet); }
.entry.wide .scan figcaption { max-width: 46rem; }
.full-size { margin-top: 0.5rem; }
.caption-label { color: var(--ink); font-weight: 600; }
.toggle {
  display: inline-block;
  margin-bottom: 0.75rem;
  padding: 0.35rem 0.8rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--wall);
  border: 1px solid #b9bcb6;
  border-radius: 3px;
  cursor: pointer;
}
.toggle:hover { border-color: var(--ink); }
/* A switch-like box before the fixed label shows the state at a glance. */
.toggle::before {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 0.5em;
  vertical-align: -0.05em;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  background: transparent;
}
.toggle[aria-pressed="true"]::before {
  background: var(--ink);
  box-shadow: inset 0 0 0 2px var(--wall);
}
.toggle[aria-pressed="false"] { color: var(--quiet); }
.toggle[hidden] { display: none; }

/* ---------- readings ---------- */

.readings h2, .about > h2 {
  font-size: 1.3125rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 0.25rem;
}

.groups, .regions, .parts { list-style: none; margin: 0; padding: 0; }

.group, .region { padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }

.group-head, .region-head { display: flex; align-items: baseline; gap: 0.75rem; }

.range, .rid {
  flex: none;
  align-self: center;
  min-width: 1.6rem;
  padding: 0.05rem 0.45rem;
  border-radius: 1rem;
  font: 700 0.75rem/1.25rem var(--badge);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.range { background: var(--c); color: #fff; }
.rid { border: 1.5px dashed #6f6a64; color: #4b4743; }

.group .kanji { font-size: 1.75rem; line-height: 1.25; letter-spacing: 0.06em; }
.reading { margin-top: 0.3rem; }
.reading .hira { margin-right: 0.5rem; }
.romaji { color: var(--quiet); }
.region .reading .kanji { font-size: 1.25rem; margin-right: 0.5rem; letter-spacing: 0.04em; }

.parts {
  display: grid;
  grid-template-columns: minmax(2rem, auto) auto minmax(0, 1fr);
  margin-top: 0.7rem;
  font-size: 0.9375rem;
  line-height: 1.45;
}
.parts li {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  grid-template-areas: "n k e" "n h e";
  column-gap: 0.75rem;
  padding: 0.3rem 0.25rem;
  border-radius: 2px;
}
.parts .n { grid-area: n; white-space: nowrap; color: var(--quiet); font-size: 0.8125rem; font-variant-numeric: lining-nums tabular-nums; padding-top: 0.15rem; }
.parts .k { grid-area: k; font-size: 1.125rem; line-height: 1.35; }
.parts .h { grid-area: h; font-size: 0.8125rem; color: var(--quiet); }
.parts .e { grid-area: e; align-self: center; }
.parts li.hl { background: color-mix(in srgb, var(--c) 12%, transparent); }

.gloss { margin-top: 0.6rem; font-size: 0.9375rem; color: #3b3f44; }

.seals h3 { font-size: 1.0625rem; margin-top: 2rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--ink); }
.region-head .label { font-weight: 600; }
.rkind { margin-left: auto; font-size: 0.8125rem; color: var(--quiet); }
.region.hl { background: color-mix(in srgb, #6f6a64 8%, transparent); }

/* ---------- about ---------- */

.about > h2 [lang="ja"] { display: block; margin-top: 0.3rem; font-size: 0.85em; font-weight: 400; color: var(--quiet); }
.issued { margin: 0.9rem 0 1.1rem; font-size: 0.9375rem; color: var(--quiet); }
.about > p + p { margin-top: 0.9rem; }
.about { max-width: 40rem; }

.tidbits { margin-top: 2rem; }
.tidbits h3 { font-size: 1.0625rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--ink); }
.tidbits ul { margin: 0; padding: 0; list-style: none; font-size: 0.9375rem; }
.tidbits li { padding: 0.75rem 0; border-bottom: 1px solid var(--rule); }

/* ---------- pager and footer ---------- */

.pager {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "prev up next";
  gap: 1.5rem;
  padding-block: 1.5rem;
  /* a hairline the width of the content, not of the padded box */
  background: linear-gradient(var(--ink), var(--ink)) top center / calc(100% - 2 * var(--gap)) 1px no-repeat;
}
.pager a { display: flex; flex-direction: column; text-decoration: none; min-width: 0; }
.pager a:hover .name { text-decoration: underline; }
.pager .prev { grid-area: prev; }
.pager .up { grid-area: up; text-align: center; }
.pager .next { grid-area: next; text-align: right; }
.pager .dir { font-size: 0.8125rem; color: var(--quiet); }
.pager .name { font-size: 0.9375rem; color: var(--ink); }
@media (max-width: 899.98px) {
  .pager { grid-template-columns: 1fr; grid-template-areas: "prev" "next" "up"; }
  .pager .up, .pager .next { text-align: left; }
}

.site-foot { padding-block: 1.25rem 2.5rem; font-size: 0.875rem; color: var(--quiet); }
.site-foot a { color: inherit; }

/* ---------- index: title, primer, catalogue ---------- */

.index-head, .index main, .index .site-foot {
  max-width: 76rem;
  margin-inline: auto;
  padding-inline: var(--gap);
}
.index-head { padding-top: clamp(1.5rem, 4vw, 3rem); padding-bottom: 1.25rem; }
.index-head .crumb { margin-bottom: 0; }
.index-head h1 { font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem); font-weight: 500; letter-spacing: -0.015em; }
.lede {
  max-width: 40rem;
  margin-top: 1rem;
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.3125rem);
  line-height: 1.5;
  color: #3b3f44;
}

.primer { max-width: 40rem; }
.primer h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem); font-weight: 500; letter-spacing: -0.015em; }
.primer-pointer {
  max-width: 40rem;
  margin: 0 0 2rem;
  padding: 0.65rem 0 0.65rem 1rem;
  border-left: 3px solid var(--ink);
}
.primer-pointer .q { font-weight: 600; }
.primer-pointer.back { margin-top: 3rem; }
.primer section { margin-top: 1.75rem; }
.primer h2 { font-size: 1.0625rem; margin-bottom: 0.4rem; }
.primer p { hyphens: auto; }
/* line-height 1 keeps the CJK fallback font from opening up the line it sits on */
.primer [lang="ja"], .lede [lang="ja"] { letter-spacing: 0.03em; line-height: 1; }

.catalogue { margin-top: 2.5rem; }
.catalogue > h2 {
  font-size: 1.625rem;
  font-weight: 500;
  padding-top: 1.5rem;
  border-top: 1px solid var(--ink);
}
.regions-nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin-top: 0.75rem; font-size: 0.9375rem; }
.regions-nav .jump { color: var(--quiet); }
.regions-nav .count { color: var(--quiet); font-size: 0.875em; }

.area { margin-top: 2.75rem; scroll-margin-top: 1rem; }
.area > h3 {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-size: 1.3125rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--ink);
}
.area .count { margin-left: auto; font-size: 0.875rem; font-weight: 400; color: var(--quiet); }

/* Places sit side by side and wrap, so a one-sheet place does not take a whole row.
   Every card has the same picture height; a landscape sheet takes two card widths,
   so it is neither cropped, nor shrunk to a sliver, nor taller than its neighbours. */
.places { display: flex; flex-wrap: wrap; gap: 2rem 2.75rem; margin-top: 1.5rem; }
.place { flex: 0 1 auto; min-width: 0; }
.place h4 { font-size: 1rem; font-weight: 600; margin: 0 0 0.75rem; max-width: 20rem; }
.cards {
  --th: 13rem;
  --cw: 10rem;
  --cg: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem var(--cg);
}
.card { width: var(--cw); }
.card.wide { width: calc(2 * var(--cw) + var(--cg)); }
.card a { display: flex; flex-direction: column; height: 100%; color: var(--ink); text-decoration: none; }
.thumb {
  display: grid;
  place-items: center;
  height: var(--th);
  padding: 0.75rem;
  background: var(--mat);
  margin-bottom: 0.6rem;
}
.thumb img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(var(--th) - 1.5rem);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.18);
}
.card a:hover .title-en, .card a:focus-visible .title-en { text-decoration: underline; text-underline-offset: 0.18em; }
.card a:hover .thumb { background: #dfe0dc; }
.card .title-en { font-size: 0.9375rem; line-height: 1.35; hyphens: auto; }
.card .title-jp { margin-top: 0.2rem; font-size: 0.875rem; color: var(--quiet); letter-spacing: 0.04em; word-break: keep-all; overflow-wrap: anywhere; }
.card .kind {
  align-self: flex-start;
  margin-top: 0.4rem;
  font: 600 0.6875rem/1.4 var(--badge);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--quiet);
}
@media (max-width: 520px) {
  .place { flex-basis: 100%; }
  .cards { --th: 10.5rem; --cg: 1rem; }
  .card { width: calc(50% - var(--cg) / 2); }
  .card.wide { width: 100%; }
  .thumb { padding: 0.5rem; }
  .thumb img { max-height: calc(var(--th) - 1rem); }
}

.provenance {
  max-width: 40rem;
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
  color: var(--quiet);
}
.index .site-foot { padding-top: 0.5rem; }
