/* Bordered reading surfaces for the article pages.
   Keep this sheet after the shared theme and per-page article styles.
   Home, Protein Color Library, member portraits and media dialogs are excluded. */

html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel,
  .science-card,
  .science-note,
  .science-table-wrap,
  details,
  .hp-stage-chart-textbox,
  .hp-cycle__shot,
  .science-figure,
  .safety-figure,
  .sustain-quote
) {
  /* Local tokens keep every inherited article style legible on the light
     surface, including when the surrounding page is in the navy theme. */
  --ui-bg: #fbf8ef;
  --ui-ink: #183247;
  --ui-muted: #526573;
  --ui-accent: #6c4a89;
  --ui-surface: #fffcf5;
  --ui-soft: #f0eadc;
  --ui-border: #d2c19b;
  --ui-on-accent: #fffdf7;
  --navy: #183247;
  --ink: #183247;
  --muted: #526573;
  --cream: #fbf8ef;
  --cream-light: #fffcf5;
  --mustard: #6c4a89;
  color-scheme: light;
  color: var(--ui-ink);
  background: var(--ui-surface);
  border-color: var(--ui-border);
}

html[data-theme] body[data-theme] #main-content .science-story .reading-panel {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  margin: .9rem 0 1.65rem;
  padding: clamp(1.2rem, 2.7vw, 2rem);
  border: 1px solid #cbb784;
  border-radius: 18px;
  box-shadow: 0 7px 22px rgba(20, 39, 54, .075);
  overflow: visible;
  line-height: 1.8;
  text-align: start;
  isolation: auto;
}

html[data-theme="dark"] body[data-theme] #main-content .science-story .reading-panel {
  border-color: #c7af76;
  box-shadow: 0 9px 26px rgba(0, 8, 20, .18);
}

/* Keep the chapter and stage headings outside their reading surfaces. */
#main-content .science-story :is(h2, h3) + .reading-panel { margin-top: .85rem; }
#main-content .science-story .reading-panel > :first-child { margin-top: 0 !important; }
#main-content .science-story .reading-panel > :last-child { margin-bottom: 0 !important; }
#main-content .science-story .reading-panel :is(p, ul, ol, dl) { max-width: none; }
#main-content .science-story .reading-panel :is(ul, ol) { padding-inline-start: 1.4rem; }
#main-content .science-story .reading-panel li { padding-inline-start: .1rem; }
#main-content .science-story .reading-panel :is(p, li, dd) { color: var(--ui-ink); }
#main-content .science-story .reading-panel :is(strong, b, h4, h5, h6) { color: var(--ui-ink); }
#main-content .science-story .reading-panel .science-source { color: var(--ui-muted); }

/* Existing cards, figures and disclosures remain single surfaces; the markup
   script never adds a panel around their original structural containers. */
html[data-theme] body[data-theme] #main-content .science-story .science-card,
html[data-theme] body[data-theme] #main-content .science-story details,
html[data-theme] body[data-theme] #main-content .science-story .hp-stage-chart-textbox {
  border-radius: 16px;
  box-shadow: 0 5px 16px rgba(20, 39, 54, .055);
}
html[data-theme] body[data-theme] #main-content .science-story .science-card.is-current {
  background: #f9f2df;
  border-color: #a58b4d;
}
html[data-theme] body[data-theme] #main-content .science-story .science-note {
  border-left-color: #967540;
  border-radius: 0 12px 12px 0;
}
html[data-theme] body[data-theme] #main-content .science-story .science-table-wrap {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border-radius: 14px;
  box-shadow: 0 5px 16px rgba(20, 39, 54, .055);
}
html[data-theme] body[data-theme] #main-content .science-story .science-table th {
  color: #183247;
  background: #eee6d4;
}
html[data-theme] body[data-theme] #main-content .science-story .science-table td {
  color: #183247;
  background: #fffcf5;
}
html[data-theme] body[data-theme] #main-content .science-story .science-table tr:nth-child(even) td {
  background: #f7f2e7;
}

/* Figures keep their original aspect ratios and full, labelled compositions.
   No transforms, masks, filters, heights or cropping rules are introduced. */
html[data-theme] body[data-theme] #main-content .science-story :is(
  .science-figure figcaption,
  .safety-figure figcaption,
  .hp-cycle__shot figcaption
) { color: #526573; background: #fffcf5; }
html[data-theme] body[data-theme] #main-content .science-story :is(
  .science-figure figcaption strong,
  .safety-figure figcaption strong,
  .hp-cycle__shot figcaption strong
) { color: #183247; }

html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel, .science-card, .science-note, .science-table-wrap,
  details, .hp-stage-chart-textbox, .science-figure, .safety-figure, .hp-cycle__shot
) a {
  color: #664681;
  text-underline-offset: .17em;
  overflow-wrap: anywhere;
}
html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel, .science-card, .science-note, .science-table-wrap,
  details, .hp-stage-chart-textbox, .science-figure, .safety-figure, .hp-cycle__shot
) a:is(:hover, :focus-visible) { color: #203c53; }
html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel, .science-card, .science-note, .science-table-wrap,
  details, .hp-stage-chart-textbox
) :is(a, button, summary, input):focus-visible {
  outline: 2px solid #664681;
  outline-offset: 4px;
}
#main-content .science-story .reading-panel pre { max-width: 100%; overflow-x: auto; }
#main-content .science-story .reading-panel code { overflow-wrap: anywhere; }
#main-content .science-story .reading-panel hr { border-color: #d2c19b; opacity: 1; }

/* The source note occasionally sits directly in the article between sections. */
html[data-theme] body[data-theme] #main-content .science-story > p.science-source {
  color: #526573;
  background: #fffcf5;
  border: 1px solid #d2c19b;
  border-radius: 14px;
  padding: 1.1rem 1.35rem;
}

@media (max-width: 600px) {
  html[data-theme] body[data-theme] #main-content .science-story .reading-panel {
    margin-bottom: 1.25rem;
    padding: 1.1rem 1rem;
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(20, 39, 54, .07);
  }
  #main-content .science-story :is(h2, h3) + .reading-panel { margin-top: .75rem; }
  #main-content .science-story .reading-panel :is(ul, ol) { padding-inline-start: 1.2rem; }
}

@media print {
  html[data-theme] body[data-theme] #main-content .science-story .reading-panel {
    background: #fff;
    color: #183247;
    border-color: #aaa;
    box-shadow: none;
    padding: 1rem;
  }
}

/* Full-width justified prose inside bordered article surfaces. */
html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel, .science-card, .science-note, details,
  .hp-stage-chart-textbox, .sustain-quote
) :is(p, ul, ol, dl) {
  max-width: none;
}
html[data-theme] body[data-theme] #main-content .science-story :is(
  .reading-panel, .science-card, .science-note, details,
  .hp-stage-chart-textbox, .sustain-quote
) :is(p, li, dd):not(:is(figcaption, table) *) {
  text-align: justify;
  text-align-last: start;
  hyphens: auto;
}

/* Dark mode follows the article cards as well as the surrounding page.
   Image pixels, dimensions, experimental colours and light mode are untouched. */
@media screen {
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, .science-table-wrap, details,
    .hp-stage-chart-textbox, .hp-cycle__shot, .science-figure, .safety-figure,
    .sustain-quote, .science-source
  ) {
    --ui-bg: #102b45;
    --ui-ink: #f3ede3;
    --ui-muted: #c7d4df;
    --ui-accent: #d2b9eb;
    --ui-surface: #173752;
    --ui-soft: #21455f;
    --ui-border: #55718a;
    --ui-on-accent: #102c40;
    --navy: var(--ui-ink);
    --ink: var(--ui-ink);
    --muted: var(--ui-muted);
    --cream: var(--ui-bg);
    --cream-light: var(--ui-surface);
    --mustard: var(--ui-accent);
    color-scheme: dark;
    color: var(--ui-ink);
    border-color: var(--ui-border);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, .science-table-wrap, details,
    .hp-stage-chart-textbox, .hp-cycle__shot, .safety-figure, .sustain-quote
  ) {
    background: var(--ui-surface);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story .science-card.is-current {
    background: #21455f;
    border-color: #9b88b8;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, details, .hp-stage-chart-textbox
  ) :is(p, li, dd, h2, h3, h4, h5, h6, strong, b, summary) {
    color: var(--ui-ink);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story .science-table :is(th, td) {
    color: var(--ui-ink);
    border-color: var(--ui-border);
    background: var(--ui-surface);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story .science-table th {
    background: #274c66;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story .science-table tr:nth-child(even) td {
    background: #1d405a;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .science-figure figcaption, .safety-figure figcaption, .hp-cycle__shot figcaption
  ) {
    color: var(--ui-muted);
    background: var(--ui-surface);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .science-figure figcaption strong, .safety-figure figcaption strong,
    .hp-cycle__shot figcaption strong
  ) {
    color: var(--ui-ink);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, .science-table-wrap, details,
    .hp-stage-chart-textbox, .science-figure, .safety-figure, .hp-cycle__shot
  ) a {
    color: var(--ui-accent);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, .science-table-wrap, details,
    .hp-stage-chart-textbox, .science-figure, .safety-figure, .hp-cycle__shot
  ) a:is(:hover, :focus-visible) {
    color: #f2e6ff;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .reading-panel, .science-card, .science-note, .science-table-wrap, details,
    .hp-stage-chart-textbox
  ) :is(a, button, summary, input):focus-visible {
    outline-color: var(--ui-accent);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story .reading-panel :is(hr, .science-source) {
    color: var(--ui-muted);
    border-color: var(--ui-border);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story > p.science-source {
    color: var(--ui-muted);
    background: var(--ui-surface);
    border-color: var(--ui-border);
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .science-story :is(
    .science-figure > a, .science-figure img, .safety-figure > a
  ) {
    background: transparent;
  }
  html:root[data-theme="dark"] body[data-theme].engineering-reading-page #main-content .engineering-evidence-group figure.science-figure,
  html:root[data-theme="dark"] body[data-theme] #main-content .word-manuscript .reading-panel .word-source-figure,
  html:root[data-theme="dark"] body[data-theme] #main-content .word-manuscript .reading-panel .word-source-figure figcaption {
    background: transparent;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .hp-stage-chart-hint {
    color: #e4d5f5;
    background: #21455f;
    border-color: #55718a;
  }
  html:root[data-theme="dark"] body[data-theme] #main-content .hp-stage-chart-textbox .hp-nail-handoff {
    color: var(--ui-muted);
  }
}
