/* One compact shell; illustrated chapter sections can opt into the wide canvas. */
:root {
  --site-shell-width: 56rem;
  --site-shell-padding: 1.5rem;
  --site-row-media: 9rem;
  --site-row-gap: 2.5rem;
}

html {
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

.site-shell {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--site-shell-width);
  margin-inline: auto;
  padding-inline: var(--site-shell-padding);
}

.page-shell { padding-top: 2rem; }
body > [data-section] { scroll-margin-top: 49px; }

.landing-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--site-row-media) minmax(0, 1fr);
  gap: var(--site-row-gap);
  align-items: start;
  min-height: 11rem;
}

.landing-list > article:first-child { padding-top: 0; }
.landing-list > article > .landing-row { margin-inline: 0; padding-inline: 0; }
.landing-list .landing-row > * { align-self: start; }
.landing-list .landing-row > :first-child {
  display: grid;
  place-items: center;
  width: var(--site-row-media);
  height: var(--site-row-media);
}
.landing-list .landing-row:hover { background: #fafafa; }
.row-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: baseline;
  margin-bottom: .25rem;
}
.row-title {
  min-width: 0;
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -.025em;
}
.row-meta {
  color: #737373;
  font: 400 .75rem/1.5 'JetBrains Mono', ui-monospace, monospace;
  white-space: nowrap;
}

.story-copy.site-shell {
  width: 100%;
  max-width: var(--site-shell-width);
  padding-inline: var(--site-shell-padding);
}
.story-copy.site-shell.is-section-open {
  width: calc(100% - 2 * clamp(1.5rem, 4vw, 4rem));
  max-width: 1720px;
  padding-inline: 0;
}
.story-copy > .chapter-intro {
  max-width: calc(var(--site-shell-width) - 2 * var(--site-shell-padding));
  margin-inline: auto;
}
@media screen {
  .story-copy.is-section-open > .chapter-intro { display: none; }
  .story-copy.is-section-open > [data-reader-section] > .section-heading-shell {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

@media (max-width: 767px) {
  :root { --site-row-media: 5rem; --site-row-gap: 1rem; }
  .landing-row { min-height: 0; }
  .home-intro { grid-template-columns: 1fr; gap: 2rem; }
}

.site-nav,
.reader-navigation {
  view-transition-name: site-navigation;
}

.reader-navigation {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 49px;
  background: rgba(255, 255, 255, .96);
}

.reader-navigation-inner {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  max-width: var(--site-shell-width);
  height: 48px;
  margin-inline: auto;
  padding-inline: var(--site-shell-padding);
}

.reader-navigation[data-reader-layout="wide"]:has(~ main .story-copy.is-section-open) .reader-navigation-inner {
  width: calc(100% - 2 * clamp(1.5rem, 4vw, 4rem));
  max-width: 1720px;
  padding-inline: 0;
}

.reader-navigation a:focus-visible {
  outline: 2px solid #525252;
  outline-offset: 4px;
  border-radius: .2rem;
}

.reader-navigation ~ main [id],
.reader-navigation ~ article [id] {
  scroll-margin-top: 4.5rem;
}
.story-copy .section-heading-shell { scroll-margin-top: 4.5rem; }

@view-transition {
  navigation: auto;
}

/* Fade between finished layouts; never stretch or slide the reading column. */
::view-transition-group(root),
::view-transition-group(site-navigation) {
  animation: none;
}

::view-transition-old(root),
::view-transition-old(site-navigation) {
  animation: page-fade-out 140ms ease-out both;
  mix-blend-mode: normal;
}

::view-transition-new(root),
::view-transition-new(site-navigation) {
  animation: page-fade-in 140ms ease-out both;
  mix-blend-mode: normal;
}

@keyframes page-fade-out { to { opacity: 0; } }
@keyframes page-fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  html { scroll-behavior: auto !important; }
}

@media print {
  .reader-navigation { display: none; }
}

/* Keep the original contents and navigation; page only the selected section. */
@media screen {
  html.is-reading-pages, .is-reading-pages body { height: 100%; overflow: hidden; }
  .is-reading-pages main { height: calc(100dvh - 49px); }
  .story-copy.is-section-open { height: 100%; padding-block: 0; margin-block: 0; }
  .story-copy.is-section-open > .has-reader-pages:not([hidden]) { height: 100%; min-height: 0; display: flex; flex-direction: column; }
  .is-section-open .has-reader-pages > .section-heading-shell { display: contents; }
  .is-section-open .has-reader-pages .section-heading { display: none; }
  .is-section-open .has-reader-pages .section-back-row { flex: 0 0 auto; margin: 0; padding: 12px 0; }
  .is-section-open .has-reader-pages .section-panel { flex: 1 1 0; min-height: 0; margin: 0; overflow: hidden; background: #f7f5ef; border: 1px solid #dedfd7; }
  .is-section-open .has-reader-pages .section-panel[hidden], .reader-page[hidden] { display: none !important; }
  .reader-page { height: 100%; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
  .reader-page:focus { outline: none; }
  .reader-page-content { --reader-media-height: max(130px, calc(100dvh - 240px)); display: flex; flex-direction: column; align-items: stretch; gap: 14px; min-height: 100%; padding: 22px 28px; color: #29362e; }
  .reader-page.has-illustration .reader-page-content { height: 100%; }
  .reader-page-content > * { margin-block: 0 !important; }
  .reader-page-content > p, .reader-page-content > blockquote, .reader-page-content > div:not(.kuru-opening-family):not(:has(.character-row)), .reader-page-content > ol { flex: 0 0 auto; }
  .reader-page-content > p, .reader-page-content > blockquote, .reader-page-content figcaption { font-size: clamp(16px, 1.25vw, 20px); line-height: 1.65; }
  .reader-page:not(.has-illustration) .reader-page-content { justify-content: center; max-width: 1060px; margin-inline: auto; }
  .reader-page:not(.has-illustration) .reader-page-content > p { font-size: clamp(18px, 1.6vw, 24px); }
  .reader-page-content > figure { flex: 1 1 0; min-height: 160px; max-width: 100% !important; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
  .reader-page-content > figure > img, .reader-page-content > figure > video { display: block; flex: 1 1 0; min-height: 0; width: 100% !important; height: 100% !important; max-height: var(--reader-media-height); object-fit: contain !important; aspect-ratio: auto; border-radius: 0; border: 0; }
  .reader-page-content > figure > [hidden] { display: none !important; }
  .reader-page-content > figure > figcaption { flex: 0 0 auto; width: 100%; padding: 0; margin: 0; font-size: clamp(16px, 1.25vw, 20px) !important; line-height: 1.65 !important; }
  .reader-page-content > figure > .family-map-frame { flex: 0 1 auto; width: min(100%, calc(var(--reader-media-height) * var(--map-ratio, 2.27))); max-width: 100%; aspect-ratio: var(--map-ratio, 2.27); margin: auto; }
  .reader-page .family-map-image { width: 100%; height: 100%; }
  .reader-page .family-map-hotspots { width: 100%; height: 100%; }
  .reader-page .battlefield-location-map { width: 100%; max-width: none; }
  .reader-page .kuru-opening-family { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
  .reader-page .kuru-opening-family .ancestry { margin-block: 0; }
  .reader-page .sources { padding-left: 1.25rem; color: #525252; font-size: 16px; line-height: 1.7; }
  .reader-page .sources > li + li { margin-top: 1.2rem; }
  .reader-page.has-characters .reader-page-content { height: 100%; }
  .reader-page.has-characters dl { display: flex; flex: 1 1 0; min-height: 200px; margin: 0; }
  .reader-page .character-row { display: flex; flex: 1; flex-direction: column; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; text-align: center; }
  .reader-page .character-row .character-action { flex: 1 1 0; min-height: 100px; width: 100%; max-width: 900px; height: 100%; max-height: var(--reader-media-height); object-fit: contain; border-radius: 0; }
  .reader-page .character-row dt { font-size: clamp(18px, 1.6vw, 23px); }
  .reader-page .character-row dd { max-width: 760px; font-size: clamp(16px, 1.25vw, 20px); line-height: 1.5; }
  .reader-page .reader-fluid-frame { flex: 1 1 0; width: 100%; min-height: 130px; height: 100%; max-height: var(--reader-media-height); border: 0; background: #050918; }
  .reader-page .gita-source { display: block; margin-top: 8px; font-size: 12px; line-height: 1.4; color: #64715f; }
  .reader-page-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; flex: 0 0 64px; gap: 16px; }
  .reader-page-controls button, .reader-page-select { min-height: 44px; border: 1px solid #d9dcd4; border-radius: 4px; padding: 8px 14px; background: #fff; color: #344638; font: 500 14px/1.4 Inter, system-ui, sans-serif; }
  .reader-page-controls button:first-child { justify-self: start; }
  .reader-page-controls button:last-child { justify-self: end; }
  .reader-page-controls button:disabled { opacity: .35; cursor: default; }
  .reader-page-controls :focus-visible { outline: 2px solid #526c50; outline-offset: 3px; }
  .reader-page-select { cursor: pointer; }
  @media (max-width: 700px) {
    .story-copy.site-shell.is-section-open { width: calc(100% - 24px); }
    .reader-page-content { padding: 16px; gap: 12px; --reader-media-height: max(130px, calc(100dvh - 320px)); }
    .reader-page-controls { gap: 8px; flex-basis: 62px; }
    .reader-page-controls button, .reader-page-select { padding-inline: 10px; }
    .reader-page-content > figure { min-height: 130px; }
    .reader-page.has-characters dl { min-height: 200px; }
  }
}
@media print {
  .reader-page-controls { display: none; }
  .reader-page[hidden] { display: block !important; }
  .reader-page { break-after: page; }
  .reader-fluid-frame { display: none; }
  [data-fluid-src] > img[hidden] { display: block !important; }
}

/* Compact place context for the background map. */
.kingdom-map-image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: auto 1100 / 1030;
  border: 0;
}

.is-reading-pages .reader-page .kingdom-map-figure > .kingdom-map-image {
  flex: 0 1 auto;
  width: min(100%, calc(var(--reader-media-height) * 1100 / 1030));
  max-width: 100%;
  min-height: 0;
  height: auto;
  max-height: var(--reader-media-height);
  aspect-ratio: 1100 / 1030;
  margin: auto;
}

.kingdom-place-popup {
  position: fixed;
  z-index: 115;
  box-sizing: border-box;
  width: min(33rem, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 18px;
  border: 1px solid #dfddd7;
  border-radius: 12px;
  background: #fffefa;
  box-shadow: 0 10px 32px #17171724;
  color: #494843;
  font: 400 16px/1.55 Inter, sans-serif;
  text-align: left;
}

.kingdom-place-popup[hidden] { display: none; }
.kingdom-place-alignment { margin: 0 30px 5px 0; color: #6c6755; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.kingdom-place-title { margin: 0 30px 10px 0; color: #292721; font: 600 25px/1.25 Georgia, serif; }
.kingdom-place-copy { margin: 0; }
.kingdom-place-close { position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #6e6b62; font: 400 25px/1 sans-serif; cursor: pointer; }
.kingdom-place-close:hover { background: #efede5; }
.kingdom-place-popup :is(a, button):focus-visible { outline: 2px solid #595a45; outline-offset: 3px; }
.kingdom-place-people { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-top: 20px; }
.kingdom-place-person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.kingdom-place-portrait { flex: 0 0 88px; width: 88px; height: 112px; border-radius: 8px; object-fit: cover; object-position: center 22%; }
.kingdom-place-person-caption { display: grid; gap: 4px; }
.kingdom-place-person-name { color: #36342e; font-size: 16px; font-weight: 600; }
.kingdom-place-person-role { color: #757166; font-size: 13px; line-height: 1.45; }
.kingdom-place-sources { display: grid; gap: 4px; margin-top: 18px; padding-top: 12px; border-top: 1px solid #e9e5da; }
.kingdom-place-source { color: #726747; font-size: 11px; line-height: 1.45; text-decoration: underline; text-underline-offset: 2px; }
.kingdom-place-source:hover { color: #292721; }

@media print { .kingdom-place-popup { display: none !important; } }
