/* Shared page rhythm. Large workspaces use the screen; prose keeps a readable measure. */
@media screen {
  body {
    --frame-max: 1800px;
    --page-gutter: clamp(18px, 3.2vw, 96px);
    --page-inset: max(var(--page-gutter), calc((100% - var(--frame-max)) / 2));
  }
  body[data-page="world"] { --frame-max: 2800px; }
  body[data-page="wiki"] { --frame-max: 2240px; }
  body[data-page="wiki"]:has(.wk-reading-layout) { --frame-max: 1760px; }
  .section,
  body[data-page="wiki"] .page-content {
    width: 100%;
    max-width: calc(var(--frame-max) + 2 * var(--page-gutter));
    margin-inline: auto;
    padding-inline: var(--page-gutter);
  }
  .topline, header, footer,
  .page-heading, body[data-page="wiki"] .page-heading,
  body[data-page="admin"] .page-heading {
    padding-inline: var(--page-inset);
  }
  .page-heading h1 { max-width: 30ch; }
  .page-heading > p:last-child { max-width: 78ch; }
  .section-heading { flex-wrap: wrap; }
  .introduction > div > p, .alpha-note p { max-width: 68ch; }
  .path-grid p, .community-grid p { max-width: 52ch; }
  .book-layout { gap: clamp(28px, 4vw, 100px); }
  .book-layout > .form-sheet { width: 100%; max-width: 760px; }
  .book-layout > aside { max-width: 60ch; }
  .register-list article { max-width: 100ch; }
  .town-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
  .gazette-columns { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }

  /* Give the atlas a real workspace, including height on 1440p and 4K displays. */
  body[data-page="world"] .page-content { padding-top: clamp(28px, 3vh, 48px); }
  body[data-page="world"] .section-heading { margin-bottom: 22px; }
  .map-shell.atlas-shell {
    --atlas-height: clamp(520px, calc(100svh - 330px), 1120px);
    grid-template-columns: clamp(260px, 18vw, 330px) minmax(0, 1fr);
    margin-block: 20px 24px;
  }
  .atlas-shell .map-view, .atlas-shell .map-controls { height: var(--atlas-height); }
  .atlas-shell .map-controls {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    padding: clamp(16px, 1.2vw, 24px);
  }
  .atlas-controls-body {
    display: grid;
    grid-template-rows: minmax(120px, .8fr) minmax(140px, 1fr);
    gap: 12px;
    min-height: 0;
  }
  .atlas-controls-body > div { display: flex; flex-direction: column; min-height: 0; }
  .atlas-result-count { flex-shrink: 0; }
  .atlas-results { flex: 1; min-height: 0; max-height: none; margin-bottom: 0; }
  .atlas-filters, #map-filters { min-height: 0; }
  .atlas-filter-actions { flex-shrink: 0; margin-top: 0; }
  .atlas-help { margin: 16px 0 0; }
  .atlas-shell:fullscreen { --atlas-height: 100svh; margin: 0; }
  .atlas-shell:fullscreen .map-view, .atlas-shell:fullscreen .map-controls { height: 100svh; }

  /* The catalogue expands into columns. Reading chapters stay at book width. */
  .wk-toolbar {
    grid-template-columns: clamp(220px, 16vw, 280px) minmax(240px, 1fr) auto;
    gap: clamp(24px, 2.5vw, 56px);
  }
  .wk-toolbar form { max-width: 960px; }
  .wk-layout {
    grid-template-columns: clamp(220px, 16vw, 280px) minmax(0, 1fr);
    gap: clamp(24px, 2.5vw, 56px);
  }
  .wk-sidebar { padding-right: clamp(18px, 1.5vw, 30px); }
  .wk-navigation nav { max-height: calc(100svh - 140px); }
  .wk-reading-layout {
    grid-template-columns: minmax(0, 78ch) minmax(160px, 220px);
    gap: clamp(24px, 3vw, 64px);
  }
  .wk-article { min-width: 0; max-width: 78ch; font-size: 18px; }
  .wk-toc { min-width: 0; }
  .wk-opening { padding: clamp(26px, 3vw, 60px); }
  .wk-opening h2 { font-size: clamp(39px, 3vw, 58px); }
  .wk-opening > p:not(.eyebrow) { max-width: 62ch; }
  .wk-ornament { right: clamp(14px, 4vw, 100px); top: 35px; font-size: clamp(140px, 11vw, 240px); }
  .wk-opening > :not(.wk-ornament) { position: relative; }
  .wk-catalogue { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
  .wk-search-results { max-width: 90ch; }

  @media (min-width: 1101px) {
    header {
      display: grid;
      grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
      gap: clamp(18px, 2vw, 36px);
    }
    header .brand { justify-self: start; }
    header nav { margin: 0; width: auto; order: 0; justify-content: center; }
    header .account-link { margin: 0; justify-self: end; }
  }
  @media (min-width: 821px) {
    .hero-content { margin-left: var(--page-inset); }
    .hero-caption { right: var(--page-inset); }
  }
  @media (min-width: 1600px) {
    .hero { min-height: clamp(710px, 65svh, 900px); }
    .wk-paths { gap: 0 48px; }
    .wk-paths p { font-size: 16px; max-width: 48ch; }
    .wk-navigation nav { font-size: 15px; }
  }
  @media (max-width: 1150px) {
    .wk-toolbar { grid-template-columns: 210px minmax(0, 1fr); gap: 25px; }
    .wk-layout { grid-template-columns: 210px minmax(0, 1fr); gap: 25px; }
    .wk-reading-layout { display: block; }
  }
  @media (max-width: 820px) {
    header { padding-inline: var(--page-gutter); }
    .hero-content { margin-left: 0; padding-inline: var(--page-gutter); }
  }
  @media (max-width: 760px) {
    body[data-page="wiki"] .page-heading { padding-block: 29px; }
    .wk-toolbar { display: block; }
    .wk-layout { display: block; }
    .wk-sidebar { padding: 0; }
    .wk-navigation nav { max-height: min(230px, 50svh); }
    .wk-article { font-size: 16px; }
    .wk-opening { padding: 26px; }
    .wk-paths { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .map-shell.atlas-shell { display: grid; grid-template-columns: minmax(0, 1fr); }
    .atlas-shell .map-controls { height: auto; overflow: visible; }
    .atlas-controls-body { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto; gap: 16px; }
    .atlas-results { flex: auto; max-height: 170px; }
    .atlas-filters { max-height: 210px; }
    .atlas-help { margin-top: 12px; }
    .atlas-shell .map-view { height: clamp(360px, 65svh, 720px); min-height: 360px; }
    .atlas-shell:fullscreen .map-controls { height: auto; max-height: 35svh; overflow: auto; }
    .atlas-shell:fullscreen .map-view { height: auto; min-height: 0; }
  }
  @media (max-width: 600px) {
    .town-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .book-layout > .form-sheet { max-width: none; }
  }
  @media (max-width: 450px) {
    .atlas-controls-body { grid-template-columns: minmax(0, 1fr); }
    .atlas-results, .atlas-filters { max-height: 150px; }
    #map-filters { display: block; }
    .wk-paths, .wk-catalogue { grid-template-columns: minmax(0, 1fr); }
    .wk-opening { padding: 22px; }
    .wk-opening h2 { font-size: 34px; }
    .wk-counts strong { font-size: 23px; }
  }
}
