/* Dake Publishing — The Plan of the Ages viewer. Loaded only on /the-plan-of-the-ages/.
   Uses the site palette (navy / gold / ivory). Mobile first; every control is at least 44 px. */

.chart-hero { background: var(--navy); color: #e9e4d8; padding: clamp(3rem, 7vw, 5rem) 0 clamp(2.25rem, 5vw, 3.5rem); border-bottom: 1px solid rgba(201,173,124,.35); }
.chart-hero .eyebrow { color: var(--gold-soft); }
.chart-hero h1 { color: #fff; margin-bottom: .6rem; }
.chart-hero .lead { color: #d3d6dc; margin: 0; }

.chart-app { padding: clamp(1.75rem, 4vw, 3rem) 0 clamp(3rem, 6vw, 5rem); }
.chart-mobile-intro, .chart-mobile-picker, .chart-mobile-notes, .chart-mobile-back { display: none; }

/* ---------- Dispensation navigation ---------- */
.period-nav { margin-bottom: 1.5rem; }
.period-nav__head h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: .3rem; }
.period-nav__head p { color: var(--muted); font-size: 1rem; margin: 0 0 1rem; }
.period-track {
  list-style: none; margin: 0; padding: .25rem .1rem .9rem; display: flex; gap: .6rem;
  overflow-x: auto; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.period-track li { flex: 0 0 auto; scroll-snap-align: start; }
.period-chip {
  display: flex; flex-direction: column; justify-content: center; gap: .1rem;
  min-height: 56px; min-width: 7.5rem; max-width: 12rem; padding: .55rem .9rem;
  background: var(--paper); border: 1px solid var(--rule); border-top: 3px solid var(--gold-soft); border-radius: var(--radius);
  color: var(--navy); text-decoration: none; font-family: var(--sans); line-height: 1.2;
}
.period-chip__k { font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.period-chip__n { font-size: .95rem; font-weight: 600; }
.period-chip--frame { border-top-color: var(--navy); background: var(--parchment); }
.period-chip:hover { border-color: var(--gold-soft); color: var(--navy); }
.period-chip[aria-current="true"] { background: var(--navy); border-color: var(--navy); border-top-color: var(--gold); color: #fff; }
.period-chip[aria-current="true"] .period-chip__k { color: var(--gold-soft); }

/* ---------- Layout ---------- */
.chart-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.chart-entry, .chart-mobile-bar, .chart-options-toggle, .chart-mobile-fit, .chart-done { display: none; }
@media (min-width: 1100px) { .chart-layout { grid-template-columns: minmax(0, 1fr) 360px; } }

.chart-viewer { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; scroll-margin-top: 96px; }

.chart-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem;
  border-bottom: 1px solid var(--rule); background: #f9f6ef;
}
.chart-toolbar__group { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chart-toolbar__group--layers { margin-left: auto; }
.chart-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-width: 44px; min-height: 44px; padding: 0 .8rem;
  font-family: var(--sans); font-size: .88rem; font-weight: 600; color: var(--navy);
  background: #fff; border: 1px solid #c9b993; border-radius: var(--radius); cursor: pointer;
}
.chart-btn svg { width: 18px; height: 18px; flex: none; }
.chart-toolbar .chart-options-toggle, .chart-toolbar .chart-done { display: none; }
/* Quick repeated taps on the controls (zoom, arrows, Next) must not double-tap-zoom the page on phones. */
.chart-btn, .chart-toolbar, .chart-footer, .chart-panel, .chart-mobile-picker { touch-action: manipulation; }
.chart-btn:hover:not(:disabled) { background: var(--navy); border-color: var(--navy); color: #fff; }
.chart-btn:disabled { opacity: .45; cursor: default; }
.chart-btn[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chart-btn[aria-pressed="true"]::before { content: "\2713"; font-size: .8rem; }
.chart-btn--icon { padding: 0; width: 44px; }
.chart-status { font-family: var(--sans); font-size: .8rem; color: var(--muted); min-width: 6.5rem; }
@media (max-width: 640px) {
  .chart-btn__text--wide { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chart-toolbar__group--layers { margin-left: 0; width: 100%; }
  .chart-toolbar__group--layers .chart-btn { flex: 1 1 0; }
}

/* ---------- Viewport ---------- */
.chart-viewport {
  position: relative; overflow: hidden; height: clamp(320px, 62vh, 620px);
  background: #fff; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  outline: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
}
.chart-viewport:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); }
.chart-viewport.is-dragging { cursor: grabbing; }
.chart-viewport.is-over-ref { cursor: pointer; }
.chart-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; --inv: 1; }
.chart-stage.is-moving { will-change: transform; }
.chart-stage img { display: block; max-width: none; width: 9338px; height: 2316px; -webkit-user-drag: none; user-select: none; pointer-events: none; }

/* overlays are positioned in image pixels; borders and markers divide by the scale (--inv) */
.chart-refbox, .chart-focus, .chart-hover, .chart-symbol { position: absolute; pointer-events: none; border-radius: calc(3px * var(--inv)); }
/* Illustration outlines: thin gold line, barely-there fill; the printed chart stays readable underneath. */
.chart-symbol { display: none; box-shadow: inset 0 0 0 calc(1.5px * var(--inv)) rgba(160,125,69,.8); background: rgba(201,173,124,.07); }
.show-symbols .chart-symbol { display: block; }
.show-symbols .chart-symbol.is-tiny { display: none; }
.chart-symbol.is-active, .show-symbols .chart-symbol.is-active { display: block; box-shadow: inset 0 0 0 calc(2.5px * var(--inv)) var(--gold); background: rgba(201,173,124,.12); }
.chart-refbox { display: none; box-shadow: inset 0 calc(-2px * var(--inv)) 0 rgba(160,125,69,.75); background: rgba(201,173,124,.12); }
.show-refs .chart-refbox { display: block; }
.chart-refbox.is-active { display: block; }
.chart-hover { box-shadow: 0 0 0 calc(2px * var(--inv)) rgba(160,125,69,.9); background: rgba(201,173,124,.25); }
.chart-focus { box-shadow: 0 0 0 calc(3px * var(--inv)) var(--gold), 0 0 0 calc(9px * var(--inv)) rgba(201,173,124,.45); }
.chart-focus--ref { background: rgba(201,173,124,.3); }
.chart-focus--period, .chart-focus--theme { background: rgba(201,173,124,.08); }
.chart-focus--symbol { background: transparent; box-shadow: 0 0 0 calc(2.5px * var(--inv)) var(--gold), 0 0 0 calc(7px * var(--inv)) rgba(201,173,124,.4); }

.chart-marker {
  position: absolute; width: 44px; height: 44px; margin: 0; padding: 0;
  transform: translate(-50%, -50%) scale(var(--inv)); transform-origin: 50% 50%;
  border-radius: 50%; border: 2px solid #fff; background: var(--gold); color: #fff;
  font: 700 1rem/1 var(--sans); cursor: pointer; box-shadow: 0 2px 10px rgba(19,30,48,.45); pointer-events: auto;
}
.chart-marker:hover, .chart-marker.is-active { background: var(--navy); box-shadow: 0 0 0 4px rgba(201,173,124,.75), 0 4px 14px rgba(19,30,48,.5); }
.chart-marker:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.chart-marker[hidden] { display: none; }

.chart-loading, .chart-error {
  position: absolute; inset: auto 0 0 0; margin: .75rem; padding: .7rem 1rem; z-index: 3;
  background: rgba(255,252,245,.96); border: 1px solid var(--rule); border-left: 3px solid var(--gold); border-radius: var(--radius);
  font-family: var(--sans); font-size: .9rem; color: var(--navy);
}
.chart-error { inset: 0; margin: auto; height: fit-content; max-width: 30rem; }
.chart-error p { margin: 0 0 .6rem; }

/* ---------- Move pad + hint ---------- */
.chart-footer { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .6rem; border-top: 1px solid var(--rule); background: #f9f6ef; }
.chart-pad { display: grid; grid-template-columns: repeat(4, 44px); gap: .35rem; }
.chart-hint { flex: 1 1 14rem; margin: 0; font-family: var(--sans); font-size: .82rem; color: var(--muted); }

/* ---------- Explanation panel (beside the chart on wide screens, below it on phones) ---------- */
.chart-panel {
  background: var(--paper); border: 1px solid var(--rule); border-top: 3px solid var(--gold); border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.1rem; font-size: 1.02rem;
}
@media (min-width: 1100px) { .chart-panel { position: sticky; top: 104px; max-height: calc(100vh - 124px); overflow-y: auto; } }
.chart-panel__kicker { font-family: var(--sans); font-size: .74rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); margin: 0 0 .35rem; }
.chart-panel h2 { font-size: 1.45rem; margin: 0 0 .75rem; }
.chart-copy { color: var(--ink); line-height: 1.6; }
.chart-note { margin: 0 0 .9rem; padding: .2rem 0 .2rem 1rem; border-left: 3px solid var(--gold-soft); font-size: 1.05rem; line-height: 1.65; color: var(--navy); }
.chart-note p { margin: 0; }
.chart-subhead { font-family: var(--sans); font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 1rem 0 .5rem; }
.chart-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chart-chip { font-family: var(--sans); font-size: .88rem; padding: .35rem .65rem; border-radius: 999px; background: #eef1f5; color: var(--navy); border: 1px solid #d8dee8; }
.chart-source { font-family: var(--sans); font-size: .8rem; line-height: 1.5; color: var(--muted); border-top: 1px solid var(--rule); padding-top: .7rem; margin: .5rem 0 .4rem; }
.chart-meta { font-family: var(--sans); font-size: .8rem; color: var(--muted); margin: 0 0 .5rem; }
.chart-panel__nav { display: flex; align-items: center; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.chart-panel__nav [data-panel-pos] { font-family: var(--sans); font-size: .82rem; color: var(--muted); margin-right: auto; }
.chart-panel__head { position: relative; }
.chart-panel__tools { display: none; }
.chart-panel__grip { display: none; }
.chart-panel__lead { margin: 0 0 .9rem; line-height: 1.6; color: var(--ink); }
.chart-panel__lead .chart-note { margin-bottom: .2rem; }
.chart-panel__meaning { display: block; }
.chart-panel__label { display: block; font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: .2rem; }
.chart-printed { font-family: var(--sans); font-size: .82rem; letter-spacing: .02em; color: var(--navy); background: #f6f1e4; border: 1px dashed #d8c9a5; border-radius: var(--radius); padding: .45rem .6rem; margin: 0 0 .5rem; overflow-wrap: anywhere; }
.chart-excerpts { margin: 0 0 .9rem; }
.chart-excerpts .chart-note { margin-bottom: .45rem; font-size: 1rem; }
.chart-cite { font-family: var(--sans); font-size: .76rem; color: var(--muted); margin: 0 0 0 1.2rem; overflow-wrap: anywhere; }
/* Provenance (records, evidence) stays available, one tap away from the reading text. */
.chart-source-details { margin: .6rem 0; }
.chart-source-details > summary { cursor: pointer; min-height: 44px; padding: .7rem 0; font-family: var(--sans); font-size: .85rem; font-weight: 600; color: var(--navy); }
.chart-index .chart-source-details { margin: .5rem 0 0; }
.chart-index .chart-source-details > summary { padding: .6rem .8rem; }
.chart-records { list-style: none; margin: 0; padding: 0 .8rem .8rem; max-height: 20rem; overflow-y: auto; }
.chart-index .chart-source-details > p { padding: 0 .8rem .5rem; }
.chart-evidence { font-family: var(--sans); font-size: .8rem; line-height: 1.5; color: var(--navy); background: #eef1f5; border-radius: var(--radius); padding: .5rem .65rem; margin: .4rem 0 .5rem; }
.chart-fullnote-btn { margin: .3rem 0 .6rem; }
.chart-fullnote { border-left: 3px solid var(--rule); padding-left: .9rem; margin: 0 0 .8rem; font-size: .98rem; line-height: 1.6; }
.chart-fullnote p { margin: 0 0 .6rem; }
.chart-jump { margin-top: 1.25rem; }
.chart-jump select { width: 100%; min-height: 48px; font: inherit; font-size: 1rem; padding: .55rem .7rem; border: 1px solid #8a8170; border-radius: var(--radius); background: #fff; color: var(--ink); }

/* ---------- Bottom sheet (below 1100 px): the same panel, fixed to the bottom of the window ----------
   Not on phones held sideways (short and at least 560 px wide): there the notes sit beside the chart
   (see the end of this file). This query must match SHEET_QUERY in chart.js. */
@media (max-width: 1099px) and (orientation: portrait), (max-width: 1099px) and (min-height: 521px), (max-width: 559px) {
  .chart-app--enhanced .chart-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 220; margin: 0 auto; width: 100%; max-width: 720px;
    display: none; flex-direction: column; max-height: min(44vh, 22rem); padding: .35rem .9rem calc(.6rem + env(safe-area-inset-bottom));
    border: 1px solid var(--rule); border-top: 3px solid var(--gold); border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 28px rgba(19,30,48,.22); background: var(--paper); overscroll-behavior: contain;
  }
  .chart-app--enhanced .chart-panel.is-open { display: flex; animation: chart-sheet-in .18s ease-out; }
  .chart-app--enhanced .chart-panel.is-expanded { max-height: calc(100% - 56px); max-height: calc(100dvh - 56px); }
  .chart-panel__grip { display: block; width: 40px; height: 4px; border-radius: 2px; background: #d8ccb0; margin: .15rem auto .45rem; }
  .chart-panel__head { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .5rem; align-items: start; }
  .chart-panel__head .chart-panel__kicker { grid-column: 1; margin-bottom: .15rem; }
  .chart-panel__head h2 { grid-column: 1; font-size: 1.15rem; margin: 0 0 .35rem; }
  .chart-panel__tools { display: flex; gap: .35rem; grid-column: 2; grid-row: 1 / span 2; }
  .chart-panel__tools .chart-btn { padding: 0 .6rem; font-size: .8rem; }
  .chart-app--enhanced .chart-mobile-back { display: none; }
  .chart-panel__scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; min-height: 0; flex: 1 1 auto; }
  .chart-panel:not(.is-expanded) [data-panel-body] { display: none; }
  .chart-panel:not(.is-expanded) .chart-panel__lead {
    position: relative; max-height: 7.4em; overflow: hidden; margin-bottom: .3rem; font-size: .95rem; line-height: 1.5;
  }
  .chart-panel:not(.is-expanded) .chart-panel__lead::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1.5em; background: linear-gradient(rgba(255,252,245,0), var(--paper));
  }
  .chart-panel:not(.is-expanded) .chart-panel__lead .chart-note { font-size: .95rem; line-height: 1.5; margin: 0; }
  .chart-panel .chart-panel__nav { margin-top: .35rem; padding-top: .4rem; border-top: 1px solid var(--rule); background: var(--paper); flex-wrap: nowrap; gap: .35rem; }
  .chart-panel .chart-panel__nav .chart-btn { padding: 0 .55rem; }
  .chart-layout { padding-bottom: var(--sheet-space, 0px); }   /* full screen: see its padding below */
  .chart-layout.has-sheet .chart-hint { display: none; }        /* compact sheet open: room for the arrows */
  html.chart-sheet-modal, html.chart-sheet-modal body { overflow: hidden; }
  html.chart-sheet-modal .chart-app--enhanced .chart-layout::after {
    content: ""; position: fixed; inset: 0; z-index: 210; background: rgba(19,30,48,.28);
  }
}
@media (max-width: 380px) {
  .chart-panel .chart-panel__nav [data-panel-pos] { display: none; }
  .chart-panel .chart-panel__nav .chart-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
/* Keep geometry stable while JS reserves room for the notes; a translated entrance
   made the measured top 24px too low and left small-phone arrows underneath it. */
@keyframes chart-sheet-in { from { opacity: .6; } to { opacity: 1; } }

/* ---------- Search + index ---------- */
.chart-find { margin-top: 2rem; display: grid; gap: 1.5rem; }
@media (min-width: 900px) { .chart-find { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); align-items: start; } }
.chart-search { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.25rem; }
.chart-search h2, .chart-index h2 { font-size: 1.35rem; margin-bottom: .35rem; }
.chart-search label { display: block; font-family: var(--sans); font-size: .85rem; font-weight: 600; color: var(--navy); margin: .6rem 0 .4rem; }
.chart-search input[type="search"] { width: 100%; min-height: 48px; font: inherit; font-size: 1.05rem; padding: .6rem .9rem; border: 1px solid #8a8170; border-radius: var(--radius); background: #fff; color: var(--ink); }
.chart-search__count { font-family: var(--sans); font-size: .85rem; color: var(--muted); margin: .6rem 0; min-height: 1.2em; }
.chart-results { list-style: none; margin: 0; padding: 0; max-height: 28rem; overflow-y: auto; }
.chart-results li + li { border-top: 1px solid var(--rule); }
.chart-result {
  display: block; width: 100%; min-height: 44px; text-align: left; padding: .7rem .5rem; background: none; border: 0; cursor: pointer;
  font: inherit; color: var(--ink); border-radius: var(--radius);
}
.chart-result:hover { background: var(--parchment); }
.chart-result__kind { display: block; font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.chart-result__title { display: block; font-weight: 600; color: var(--navy); }
.chart-result__text { display: block; font-size: .92rem; color: var(--muted); line-height: 1.45; }

.chart-index details { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: .75rem; }
.chart-index summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; padding: .6rem 1rem; font-family: var(--sans); font-weight: 600; color: var(--navy); }
.chart-index summary small { font-weight: 400; color: var(--muted); margin-left: .4rem; }
.chart-index__list { list-style: none; margin: 0; padding: 0 1rem 1rem; max-height: 34rem; overflow-y: auto; }
.chart-index__list > li { padding: .7rem 0; border-top: 1px solid var(--rule); }
.chart-index__list a { font-weight: 600; display: inline-flex; align-items: center; min-height: 44px; }
.chart-index__list p { margin: .2rem 0 0; font-size: .95rem; color: var(--muted); }
.chart-index__list .chart-meta { margin-top: .3rem; }

/* ---------- About the chart ---------- */
.chart-about { display: grid; gap: 2rem; margin-top: 2.5rem; padding: clamp(1.25rem, 3vw, 2rem); background: #fff; border-top: 3px solid var(--gold); border-radius: var(--radius); }
@media (min-width: 900px) { .chart-about { grid-template-columns: 1.3fr .7fr; } }
.chart-about h2 { font-size: 1.6rem; }
.chart-credit { font-family: var(--sans); font-size: .85rem; color: var(--muted); }
.chart-cta { background: var(--navy); color: #e9e4d8; padding: 1.5rem; border-radius: var(--radius); }
.chart-cta h3 { color: #fff; }
.chart-cta :focus-visible { outline-color: var(--gold-soft); }

/* ---------- Full screen (native :fullscreen, or the in-page fallback .is-expanded) ----------
   Each state has its own rules: a selector list that mixes .is-expanded with :fullscreen or
   :-webkit-full-screen is dropped whole by a browser that lacks either pseudo-class (iPhone
   Safari before 16.4 has no :fullscreen), and iPhone is exactly where the in-page fallback runs. */
/* The bottom padding always includes --sheet-space (0 unless the compact sheet is open): a plain
   `padding` shorthand here would override the sheet room and leave nothing to scroll. */
.chart-layout:fullscreen { background: var(--ivory); padding: .75rem .75rem calc(.75rem + var(--sheet-space, 0px)); overflow: auto; overscroll-behavior: contain; }
.chart-layout:-webkit-full-screen { background: var(--ivory); padding: .75rem .75rem calc(.75rem + var(--sheet-space, 0px)); overflow: auto; width: 100%; height: 100%; }
.chart-layout.is-expanded { position: fixed; inset: 0; z-index: 200; background: var(--ivory); padding: .5rem .5rem calc(.5rem + var(--sheet-space, 0px)); overflow: auto; margin: 0; overscroll-behavior: contain; }
html.chart-expanded, html.chart-expanded body { overflow: hidden; }
.chart-layout:fullscreen .chart-viewport { height: calc(100vh - 190px); min-height: 260px; }
.chart-layout:-webkit-full-screen .chart-viewport { height: calc(100vh - 190px); min-height: 260px; }
.chart-layout.is-expanded .chart-viewport { height: calc(100vh - 190px); height: calc(100svh - 190px); min-height: 260px; }
/* Below 1100 px full screen is a bounded workspace: the picker, the controls, the chart and its move
   arrows exactly fill the screen above the compact sheet (--sheet-space). The chart takes whatever
   height is left, so the arrows and the toolbar (zoom, Exit full screen) are never under the sheet.
   dvh follows Safari's toolbar; vh is the fallback. */
@media (max-width: 1099px) {
  .chart-layout:fullscreen { grid-auto-rows: max-content; align-content: start; }
  .chart-layout:-webkit-full-screen { grid-auto-rows: max-content; align-content: start; }
  .chart-layout.is-expanded { grid-auto-rows: max-content; align-content: start; }
  .chart-layout:fullscreen .chart-viewer { display: flex; flex-direction: column; overflow: visible; height: calc(100vh - 1.5rem - var(--sheet-space, 0px)); }
  .chart-layout:-webkit-full-screen .chart-viewer { display: flex; flex-direction: column; overflow: visible; height: calc(100vh - 1.5rem - var(--sheet-space, 0px)); }
  .chart-layout.is-expanded .chart-viewer { display: flex; flex-direction: column; overflow: visible; height: calc(100vh - 1rem - var(--sheet-space, 0px)); height: calc(100dvh - 1rem - var(--sheet-space, 0px)); }
  .chart-layout:fullscreen .chart-viewer > * { flex: none; }
  .chart-layout:-webkit-full-screen .chart-viewer > * { flex: none; }
  .chart-layout.is-expanded .chart-viewer > * { flex: none; }
  .chart-layout:fullscreen .chart-viewer > .chart-viewport { flex: 1 1 0; height: auto; min-height: 100px; }
  .chart-layout:-webkit-full-screen .chart-viewer > .chart-viewport { flex: 1 1 0; height: auto; min-height: 100px; }
  .chart-layout.is-expanded .chart-viewer > .chart-viewport { flex: 1 1 0; height: auto; min-height: 100px; }
  /* While the compact sheet is open the sheet's Previous/Next replace the age picker. */
  .chart-layout.has-sheet:fullscreen .chart-mobile-picker { display: none; }
  .chart-layout.has-sheet:-webkit-full-screen .chart-mobile-picker { display: none; }
  .chart-layout.has-sheet.is-expanded .chart-mobile-picker { display: none; }
}
@media (min-width: 1100px) {
  .chart-layout:fullscreen .chart-panel { position: static; max-height: calc(100vh - 1.5rem); }
  .chart-layout.is-expanded .chart-panel { position: static; max-height: calc(100vh - 1.5rem); }
}

/* ---------- Without the script (or if it fails): a plain, scrollable original image ---------- */
.chart-app:not(.chart-app--enhanced) .chart-viewport { overflow: auto; touch-action: auto; cursor: auto; height: auto; max-height: 70vh; }
.chart-app:not(.chart-app--enhanced) .chart-stage { position: static; transform: none !important; }
.chart-app:not(.chart-app--enhanced) .chart-stage img { width: 2400px !important; height: auto !important; }
.chart-app:not(.chart-app--enhanced) .chart-marker,
.chart-app:not(.chart-app--enhanced) .chart-symbol,
.chart-app:not(.chart-app--enhanced) .chart-refbox,
.chart-app:not(.chart-app--enhanced) .chart-focus,
.chart-app:not(.chart-app--enhanced) .chart-hover,
.chart-app:not(.chart-app--enhanced) .chart-loading { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .period-track { scroll-behavior: auto; }
  .chart-marker { transition: none; }
  .chart-app--enhanced .chart-panel.is-open { animation: none; }
}
@media (forced-colors: active) {
  .chart-focus, .chart-hover { outline: 3px solid Highlight; }
  .chart-symbol { outline: 1px solid CanvasText; }
  .chart-marker { border: 2px solid ButtonText; }
}

/* Phone workspace: reach the chart immediately, with notes one tap away. */
@media (max-width: 640px) {
  .chart-hero { padding: 1.1rem 0; }
  .chart-hero .eyebrow, .chart-hero .lead { display: none; }
  .chart-hero h1 { font-size: 1.85rem; margin-bottom: .3rem; }
  .chart-mobile-intro { display: block; font: .9rem/1.45 var(--sans); margin: 0; color: #d3d6dc; }
  .chart-app { padding-top: .75rem; }
  .chart-app > .wrap { width: calc(100% - 24px); }
  .chart-app--enhanced .period-nav { display: none; }
  .chart-mobile-picker { display: block; padding: .65rem .6rem; background: #f9f6ef; border-bottom: 1px solid var(--rule); }
  .chart-mobile-picker label { display: block; margin-bottom: .3rem; font: 600 .75rem/1.3 var(--sans); color: var(--muted); }
  .chart-mobile-picker select { width: 100%; min-height: 44px; padding: .5rem 2rem .5rem .65rem; border: 1px solid #c9b993; border-radius: var(--radius); background: #fff; color: var(--navy); font: 600 16px/1.3 var(--sans); }
  .chart-toolbar { gap: .35rem; padding: .4rem .6rem; }
  .chart-toolbar__group { gap: .3rem; }
  .chart-toolbar__group > .chart-btn { width: 44px; padding: 0; }
  .chart-status { min-width: 0; font-size: .72rem; margin-left: .2rem; }
  .chart-toolbar__group--layers .chart-btn { width: auto; min-width: 0; font-size: .78rem; min-height: 44px; padding: 0 .4rem; gap: .25rem; line-height: 1.15; }
  .chart-viewport { height: clamp(230px, 39svh, 350px); }
  .chart-footer { padding: .4rem .6rem; gap: .4rem; justify-content: space-between; }
  .chart-pad { gap: .2rem; }
  .chart-mobile-notes { display: inline-flex; padding: 0 .6rem; font-size: .8rem; background: var(--navy); color: #fff; }
  .chart-hint { flex-basis: 100%; font-size: .72rem; line-height: 1.4; }
  .chart-viewer, .chart-panel { scroll-margin-top: 80px; }
  .chart-layout { gap: .75rem; }
  .chart-panel { padding: .9rem; }
  .chart-mobile-back { display: inline-flex; margin-bottom: .9rem; }
  .chart-panel__nav { background: var(--paper); padding: .5rem 0 max(.5rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); }
  .chart-find { margin-top: 1rem; gap: 1rem; }
  .chart-search { padding: 1rem; }
  /* Compact sheet: title and the first lines of the meaning only, so the chart and its controls fit above it. */
  .chart-app--enhanced .chart-panel--sheet:not(.is-expanded) .chart-panel__lead { max-height: 4.6em; }
}
/* Short screens (e.g. 320 x 568): two lines of the meaning in the compact sheet; More shows the rest. */
@media (max-height: 640px) {
  .chart-app--enhanced .chart-panel--sheet:not(.is-expanded) .chart-panel__lead { max-height: 3em; }
}

/* Phones held sideways (short screens): the sticky site header would take a fifth of the height. */
@media (max-width: 1099px) and (max-height: 520px) and (orientation: landscape) {
  .site-header { position: relative; }
  .chart-hero { padding: .9rem 0; }
  .chart-hero .lead { display: none; }
  .chart-viewer, .chart-panel { scroll-margin-top: 8px; }
}
/* Sideways and at least 560 px wide (e.g. 844 x 390): a bottom sheet cannot share 390 px with the
   chart and its arrows, so there is none (chart.js SHEET_QUERY). The notes sit beside the chart, as
   on wide screens, and the controls, the chart and the arrows exactly fill one screen height. */
@media (max-width: 1099px) and (min-width: 560px) and (max-height: 520px) and (orientation: landscape) {
  .chart-layout { grid-template-columns: minmax(0, 1fr) minmax(220px, 38%); gap: .75rem; }
  .chart-hint, .chart-mobile-notes, .chart-mobile-back { display: none; }
  .chart-toolbar { gap: .35rem; padding: .4rem .6rem; }
  .chart-toolbar__group > .chart-btn { width: 44px; padding: 0; }
  .chart-toolbar__group--layers { width: 100%; margin-left: 0; }
  .chart-toolbar__group--layers .chart-btn { flex: 1 1 0; width: auto; padding: 0 .3rem; font-size: .78rem; }
  .chart-toolbar .chart-btn__text--wide { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chart-status { min-width: 0; font-size: .72rem; }
  .chart-viewer { display: flex; flex-direction: column; height: calc(100vh - 16px); height: calc(100dvh - 16px); }
  .chart-viewer > * { flex: none; }
  .chart-viewer > .chart-viewport { flex: 1 1 0; height: auto; min-height: 100px; }
  .chart-panel { position: sticky; top: 8px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; padding: .8rem .9rem; }
  .chart-layout.is-expanded .chart-panel { position: static; max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); }
  .chart-layout:fullscreen .chart-panel { position: static; max-height: calc(100vh - 1.5rem); }
}
/* The smallest of those (e.g. 568 x 320): drop the hint line, the age picker and the Notes shortcut
   (the notes are already beside the chart) so the chart keeps a usable height. */
@media (max-width: 640px) and (min-width: 560px) and (max-height: 520px) and (orientation: landscape) {
  .chart-app--enhanced .chart-mobile-picker, .chart-hint, .chart-mobile-notes { display: none; }
}
@media (max-width: 360px) {
  .chart-toolbar__group--layers .chart-btn[aria-pressed="true"]::before { content: none; }
  .chart-toolbar__group--layers .chart-btn { font-size: .74rem; padding: 0 .3rem; }
  .chart-status { display: none; }
  .chart-pad { gap: 0; }
  .chart-mobile-notes { padding: 0 .4rem; }
}

/* Mobile has two separate modes: a native-scrolling page, and an explicit viewer.
   No chart pointer handlers or resize-driven page adjustments run in the preview. */
.chart-mobile:not(.chart-viewing) .chart-layout,
.chart-mobile .period-nav { display: none; }
.chart-mobile .chart-entry { display: block; background: var(--paper); border: 1px solid var(--rule); border-radius: .6rem; overflow: hidden; }
.chart-mobile .chart-entry > img { display: block; width: 100%; height: 200px; object-fit: cover; object-position: left; pointer-events: none; }
.chart-entry > div { padding: 1.2rem; }
.chart-entry h2 { margin: 0 0 .5rem; font-size: 1.5rem; }
.chart-entry p { margin: 0 0 1rem; }
.chart-entry .chart-entry__button { width: 100%; background: var(--navy); color: #fff; min-height: 52px; font-size: 1rem; }
.chart-entry .chart-entry__hint { font-size: .8rem; color: var(--muted); margin: .8rem 0 0; }
.chart-mobile.chart-viewing .chart-entry { display: none; }
.chart-mobile .chart-mobile-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .4rem .6rem; background: var(--navy); color: #fff; }
.chart-mobile-bar strong { font: 600 .95rem/1.2 var(--sans); }
.chart-mobile-bar .chart-btn { background: #fff; white-space: nowrap; }
.chart-mobile .chart-layout.is-expanded { top: var(--mobile-view-top, 0px); bottom: auto; height: var(--mobile-view-height, 100dvh); overscroll-behavior: none; }
.chart-mobile .chart-layout.is-expanded .chart-viewer { height: calc(var(--mobile-view-height, 100dvh) - var(--sheet-space, 0px) - 16px); display: flex; flex-direction: column; }
.chart-mobile .chart-layout.is-expanded .chart-viewport { flex: 1 1 0; height: auto; min-height: 80px; }
.chart-mobile .chart-toolbar { padding: .4rem .6rem; }
.chart-mobile .chart-toolbar__group { width: 100%; flex-wrap: nowrap; }
.chart-mobile .chart-toolbar [data-action='fullscreen'],
.chart-mobile .chart-status, .chart-mobile .chart-hint,
.chart-mobile .chart-mobile-notes { display: none; }
.chart-mobile .chart-toolbar .chart-btn__text--wide { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chart-mobile .chart-toolbar__group > .chart-btn { width: 44px; padding: 0; }
.chart-mobile .chart-toolbar [data-action='fit'] { width: auto; padding: 0 .6rem; }
.chart-mobile .chart-toolbar [data-action='fit'] svg { display: none; }
.chart-mobile .chart-mobile-fit { display: inline; }
.chart-mobile .chart-toolbar .chart-options-toggle { display: inline-flex; width: auto; padding: 0 .7rem; margin-left: auto; }
.chart-mobile .chart-toolbar__group--layers { display: none; }
.chart-mobile.chart-options-open .chart-toolbar__group--layers { display: flex; }
.chart-mobile .chart-toolbar__group--layers .chart-btn { flex: 1; width: auto; font-size: .78rem; padding: 0 .3rem; }
.chart-mobile .chart-footer { justify-content: center; padding: .4rem; }
.chart-mobile .chart-pad { gap: .6rem; }
.chart-mobile .chart-toolbar { order: -1; padding: .2rem; }
.chart-mobile .chart-toolbar__group { gap: .2rem; }
.chart-mobile .chart-toolbar .chart-options-toggle { margin-left: auto; padding: 0 .45rem; }
.chart-mobile .chart-toolbar .chart-done { display: inline-flex; width: auto; padding: 0 .45rem; background: var(--navy); color: white; }
.chart-mobile .chart-mobile-picker { padding: .2rem .4rem; }
.chart-mobile .chart-mobile-picker label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chart-mobile .chart-footer { display: none; }
/* A compact note is a short explanation, not a second toolbar. Its full source text
   and Previous/Next controls remain available under More. All buttons stay 44px. */
.chart-mobile .chart-panel--sheet:not(.is-expanded) { padding: .4rem .65rem calc(.4rem + env(safe-area-inset-bottom)); }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__kicker,
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__nav,
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__label { display: none; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__head { align-items: center; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__head h2 { font-size: 1.05rem; margin: 0; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__lead { max-height: none; overflow: visible; margin: .45rem 0 .15rem; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__lead::after { display: none; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) { touch-action: pan-x pinch-zoom; }
.chart-mobile .chart-panel--sheet .chart-panel__head,
.chart-mobile .chart-panel--sheet .chart-panel__grip { touch-action: pan-x pinch-zoom; }
.chart-mobile .chart-panel--sheet:not(.is-expanded) .chart-panel__grip { margin: 0 auto .2rem; flex-shrink: 0; }
.chart-mobile .chart-panel--sheet.is-expanded {
  top: 0; bottom: auto; width: 100%; max-width: none;
  height: var(--mobile-view-height, 100dvh); max-height: var(--mobile-view-height, 100dvh);
  padding-top: max(.35rem, env(safe-area-inset-top)); border-radius: 0;
}
.chart-mobile .chart-layout.has-sheet .chart-mobile-picker { display: none; }
@media (max-height: 520px) and (orientation: landscape) {
  .chart-mobile .chart-mobile-picker { display: none; }
  .chart-mobile .chart-mobile-bar strong { font-size: .8rem; }
}
