/* THE BALANCE: component-level night palette. Header geometry is not changed.
 * Screen only: the existing printable assessment / diary layouts remain separate.
 * Shared selectors also apply to content created after the initial page load. */
@media screen {
  html.balance-night {
    --bn-canvas:#0f1412;--bn-surface:#111714;--bn-card:#171f1b;--bn-raised:#24342b;
    --bn-button:#35473d;--bn-text:#f3efe6;--bn-muted:#bec8c0;--bn-gold:#d5ba83;
    --bn-line:#46574b;--bn-control:#8c9c90;--bn-error:#ffbeb0;--bn-on-gold:#111714;
  }
  html.balance-night body #primary-content { --balance-deep-sage:var(--bn-button);--balance-focus:var(--bn-gold); }

  /* Button fills and foregrounds must be a pair, not independently inverted. */
  html.balance-night body #primary-content :is(.btn,.btn.dark,.wp-block-button__link) { background:var(--bn-button)!important;color:var(--bn-text)!important;border-color:var(--bn-control)!important; }
  html.balance-night body #primary-content :is(.btn.gold,.btn.light-btn,.btn-style_fill) { background:var(--bn-gold)!important;color:var(--bn-on-gold)!important;border-color:var(--bn-gold)!important; }
  html.balance-night body #primary-content :is(.btn,.btn-style_fill,.wp-block-button__link) :is(span,b,strong,svg) { color:inherit!important; }
  html.balance-night body #primary-content :is(.btn,.wp-block-button__link):is(:hover,:focus-visible) { background:var(--bn-raised)!important;color:var(--bn-text)!important; }
  html.balance-night body #primary-content :is(.btn.gold,.btn.light-btn,.btn-style_fill):is(:hover,:focus-visible) { background:#e6cca0!important;color:var(--bn-on-gold)!important; }
  html.balance-night body #primary-content :is(a,button,summary,input,select,textarea):focus-visible { outline:2px solid var(--bn-gold)!important;outline-offset:4px; }

  /* Keep the arrow glyph pointing in the actual navigation direction. */
  #primary-content .child-nav__arrow { transform:translateY(-50%);line-height:1; }
  #primary-content .child-nav__arrow--right { background-image:linear-gradient(270deg,rgba(248,245,238,.98) 65%,transparent); }
  html[dir=rtl] #primary-content .child-nav__arrow { transform:translateY(-50%) scaleX(-1); }

  /* Horizontal category navigation: remove the light edge gradients. */
  html.balance-night body #primary-content .child-nav__arrow { background:var(--bn-surface)!important;color:var(--bn-gold)!important;box-shadow:0 0 12px 7px var(--bn-surface); }
  html.balance-night body #primary-content .child-nav__arrow:is(:hover,:focus-visible) { background:var(--bn-raised)!important; }
  html.balance-night body #primary-content .child-nav__arrow:focus-visible { outline-offset:-4px; }
  html.balance-night body #primary-content .child-nav__disabled { color:var(--bn-muted)!important; }

  /* Tools and condition-test directories, and the whole private tool templates. */
  html.balance-night body :is(.bt-page,.ba-page) {
    --paper:var(--bn-surface);--cream:var(--bn-card);--sand:var(--bn-raised);
    --ink:var(--bn-text);--gold:var(--bn-gold);--line:var(--bn-line);
    --balance-deep-sage:var(--bn-button);--balance-gold-text:var(--bn-gold);
    background:var(--bn-canvas)!important;color:var(--bn-text)!important;color-scheme:dark;
  }
  html.balance-night body :is(.bt-page,.ba-page) :is(p,small,dt,dd,label,legend,.bt-small,.bt-state,.bt-status-line,.ba-facts,.ba-subtitle,.ba-timeframe,.ba-note,.ba-source-note,.ba-card-top) { color:var(--bn-muted)!important; }
  html.balance-night body :is(.bt-page,.ba-page) :is(h1,h2,h3,h4,strong,legend,label>span,.bt-number,.btc-metric,.ba-result-score strong) { color:var(--bn-text)!important; }
  html.balance-night body :is(.bt-page,.ba-page) :is(.section-kicker,.ba-kicker,.ba-numbered article>span) { color:var(--bn-gold)!important; }
  html.balance-night body :is(.bt-section,.bt-sources,.ba-section,.ba-wrap,.ba-care,.ba-understand) { background:var(--bn-canvas)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body :is(.bt-section--sand,.ba-preview-note) { background:var(--bn-raised)!important;color:var(--bn-muted)!important; }
  html.balance-night body :is(.bt-feature,.bt-input-panel,.bt-assessment-card,.ba-card,.ba-hub-cards>a) { background:var(--bn-card)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body :is(.bt-card,.bt-grid,.bt-assessments,.bt-settings,.bt-drink,.bt-feature-figure,.bt-note,.ba-side-rule,.ba-card-foot,.ba-actions,.ba-impact,.ba-understand article,.ba-numbered,.ba-numbered article) { border-color:var(--bn-line)!important; }
  html.balance-night body :is(.bt-assessment-card,.ba-hub-cards>a):is(:hover,:focus-visible) { background:var(--bn-raised)!important; }
  html.balance-night body .ba-hub-cards { background:var(--bn-line)!important;border-color:var(--bn-line)!important; }
  html.balance-night body .ba-hub-cards :is(small,span) { color:var(--bn-muted)!important; }
  html.balance-night body .bt-feature-figure small { color:var(--bn-muted)!important; }
  html.balance-night body .bt-filter button,html.balance-night body .bt-action { background:var(--bn-card)!important;color:var(--bn-text)!important;border-color:var(--bn-control)!important; }
  html.balance-night body .bt-filter button:is([aria-pressed=true],:hover,:focus-visible) { background:var(--bn-raised)!important;color:var(--bn-gold)!important;border-color:var(--bn-gold)!important; }
  html.balance-night body :is(.bt-remove,.bt-link,.btc-link,.ba-quiet-button) { color:var(--bn-text)!important;background:transparent!important; }
  html.balance-night body :is(.bt-results,.btc-output) { background:var(--bn-raised)!important;color:var(--bn-text)!important; }
  html.balance-night body :is(.bt-results,.btc-output) :is(p,small,dt,dd,li,.bt-small,.btc-metric-label,.bt-result-label) { color:var(--bn-muted)!important; }
  html.balance-night body :is(.bt-results,.btc-output) :is(h3,h4,strong,.bt-number) { color:var(--bn-text)!important; }
  html.balance-night body :is(.bt-results,.btc-output) :is(dl,dl>div,.btc-controls) { border-color:var(--bn-control)!important; }
  html.balance-night body :is(.bt-results,.btc-output) .section-kicker { color:var(--bn-gold)!important; }
  html.balance-night body :is(.bt-results,.btc-output) :is(.bt-action,.btc-link) { color:var(--bn-text)!important;border-color:var(--bn-control)!important; }

  /* Generated calculators, diaries and planners: labels, hints, errors and outputs. */
  html.balance-night body .btc-tool { --btc-border:var(--bn-control);color:var(--bn-text)!important; }
  html.balance-night body :is(.btc-form,.btc-breath-panel,.bt-formula) { background:var(--bn-card)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body .btc-field small,html.balance-night body :is(.btc-status,.btc-breath-caption,.btc-ground-help) { color:var(--bn-muted)!important; }
  html.balance-night body :is(.btc-form legend,.btc-field>span,.btc-check>span,.btc-ground-step) { color:var(--bn-text)!important; }
  html.balance-night body :is(.btc-form,.btc-tool) :is(.btc-row,.btc-plan-fieldset,.btc-table-scroll) { border-color:var(--bn-line)!important; }
  html.balance-night body .btc-breath-circle { background:var(--bn-button)!important;color:var(--bn-text)!important;border:1px solid var(--bn-control); }
  html.balance-night body :is(.bt-page,.ba-page) :is(.btc-error,.bt-error,.ba-error) { color:var(--bn-error)!important;border-color:var(--bn-error)!important; }
  html.balance-night body :is(.bt-page,.ba-page) :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]),select,textarea) { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-control)!important;color-scheme:dark; }
  html.balance-night body :is(.bt-page,.ba-page) :is(input,textarea)::placeholder { color:var(--bn-muted)!important;opacity:1; }
  html.balance-night body :is(.bt-page,.ba-page) :is(input,select,textarea)[aria-invalid=true] { border-color:var(--bn-error)!important; }
  html.balance-night body :is(.bt-page,.ba-page) :is(input[type=checkbox],input[type=radio]) { accent-color:var(--bn-gold);color-scheme:dark; }
  html.balance-night body .ba-option { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-control)!important; }
  html.balance-night body .ba-page .ba-option :is(span,input:checked+span) { background:transparent!important;color:inherit!important;box-shadow:none!important;border:0; }
  html.balance-night body .ba-option:has(input:checked) { background:var(--bn-raised)!important;color:var(--bn-text)!important;border-color:var(--bn-gold)!important;box-shadow:inset 0 0 0 1px var(--bn-gold)!important; }
  html.balance-night body .ba-option:has(input:focus-visible) { outline:2px solid var(--bn-gold)!important;outline-offset:3px; }
  html.balance-night body .ba-option:hover { border-color:var(--bn-gold)!important; }
  html.balance-night body .ba-result .ba-result-context { background:var(--bn-raised)!important;color:var(--bn-muted)!important; }
  html.balance-night body .ba-result-score :is(span,bdi) { color:var(--bn-muted)!important; }
  html.balance-night body :is(.ba-card,.btc-tool) progress { color:var(--bn-gold);accent-color:var(--bn-gold);background:var(--bn-line); }
  html.balance-night body :is(.ba-card,.btc-tool) progress::-webkit-progress-bar { background:var(--bn-line); }
  html.balance-night body :is(.ba-card,.btc-tool) progress::-webkit-progress-value { background:var(--bn-gold); }
  html.balance-night body :is(.ba-card,.btc-tool) progress::-moz-progress-bar { background:var(--bn-gold); }

  /* Native / Gutenberg / generated tables, including nested text and row headers. */
  html.balance-night body #primary-content :is(table,.wp-block-table,.bt-table-wrap,.btc-table-scroll) { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content table :is(thead,tbody,tfoot,tr,col,colgroup) { background:transparent!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content table :is(th,td) { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content table tr:nth-child(even)>td { background:var(--bn-card)!important; }
  html.balance-night body #primary-content table th { background:var(--bn-raised)!important;color:var(--bn-text)!important; }
  html.balance-night body #primary-content table :is(th,td) :is(p,span,strong,b,em,small,li,div) { color:inherit!important; }
  html.balance-night body #primary-content table :is(caption,a) { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .wp-block-table figcaption { color:var(--bn-muted)!important; }

  /* Resource discovery and start-here blocks keep a distinguishable dark surface. */
  html.balance-night body #primary-content :is(.balance-tools-discovery,.balance-tools-note,.balance-start-here,.balance-related-care) { background:var(--bn-card)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content .balance-tools-discovery--hub { background:var(--bn-raised)!important; }
  html.balance-night body #primary-content :is(.balance-tools-discovery,.balance-tools-note,.balance-start-here,.balance-related-care) :is(h2,h3,a,strong,.balance-start-here__guides a>span) { color:var(--bn-text)!important; }
  html.balance-night body #primary-content :is(.balance-tools-discovery,.balance-tools-note,.balance-start-here,.balance-related-care) :is(p,small) { color:var(--bn-muted)!important; }
  html.balance-night body #primary-content :is(.balance-tools-discovery,.balance-tools-note,.balance-start-here,.balance-related-care) :is(.section-kicker,b,.text-link>span[aria-hidden]) { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content :is(.balance-tools-discovery__grid,.balance-tools-discovery__card,.balance-start-here__guides li,.balance-related-care__links a) { background:transparent!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content .balance-tools-discovery--sleep .balance-tools-discovery__card+.balance-tools-discovery__card { background:var(--bn-surface)!important; }
  html.balance-night body #primary-content .balance-start-here__guides li::before { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .balance-tools-discovery .btn.gold { background:var(--bn-gold)!important;color:var(--bn-on-gold)!important; }
  html.balance-night body #primary-content .balance-tools-discovery .btn.gold span { color:inherit!important; }
  html.balance-night body #primary-content .balance-tool-context-link a { color:var(--bn-gold)!important; }

  /* Diagrams: surface, line, node and label colors are explicitly paired. */
  html.balance-night body #primary-content :is(.signature-graphic,.model-graphic) { background:var(--bn-card)!important;color:var(--bn-text)!important; }
  html.balance-night body #primary-content :is(.signature-graphic,.model-graphic) :is(h2,h3,strong) { color:var(--bn-text)!important; }
  html.balance-night body #primary-content :is(.signature-graphic,.model-graphic) p { color:var(--bn-muted)!important; }
  html.balance-night body #primary-content :is(.signature-graphic,.model-graphic) .section-kicker { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .signature-flow li span { background:var(--bn-card)!important;color:var(--bn-gold)!important;border-color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .signature-flow::before,html.balance-night body #primary-content .model-map::before { border-color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .model-node { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-control)!important; }
  html.balance-night body #primary-content .model-node.center { background:var(--bn-button)!important; }
  html.balance-night body #balance-care-infographic .balance-center { background:var(--bn-gold)!important; }
  html.balance-night body #balance-care-infographic .balance-center :is(.balance-you,.balance-you-copy,p,strong) { color:var(--bn-on-gold)!important; }

  /* Podcast component variables must be overridden on their own root. */
  html.balance-night body .podcast-page { --podcast-paper:var(--bn-surface);--podcast-ink:var(--bn-text);--podcast-muted:var(--bn-muted);--podcast-gold:var(--bn-gold);--podcast-line:var(--bn-line);--podcast-sage:var(--bn-card); }
  html.balance-night body #primary-content .podcast-media__modes button { background:transparent!important;color:var(--bn-muted)!important;border-bottom-color:transparent!important; }
  html.balance-night body #primary-content .podcast-media__modes button[aria-pressed=true] { background:transparent!important;color:var(--bn-gold)!important;border-bottom-color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .podcast-media__modes button span { color:inherit!important; }
  html.balance-night body #primary-content .podcast-media__modes button:is(:hover,:focus-visible) { color:var(--bn-text)!important; }
  html.balance-night body #primary-content :is(.podcast-more>summary,.podcast-chapter time,.podcast-chapter b,.podcast-metadata,.podcast-platforms>span) { color:var(--bn-muted)!important; }
  html.balance-night body #primary-content .podcast-more>summary::after { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .podcast-more>summary { background:transparent!important; }
  html.balance-night body #primary-content .podcast-section-nav a[aria-current=true],html.balance-night body #primary-content .podcast-chapter[aria-current=true] { color:var(--bn-gold)!important;border-color:var(--bn-gold)!important;background:var(--bn-card)!important; }
  html.balance-night body #primary-content :is(.podcast-audio__transport>button,.podcast-video__poster>span) { background:var(--bn-gold)!important;color:var(--bn-on-gold)!important; }
  html.balance-night body #primary-content .podcast-audio__options button { background:transparent!important;color:var(--bn-text)!important; }
  html.balance-night body #primary-content .podcast-audio__transport input[type=range] { background:transparent!important;accent-color:var(--bn-gold); }
  html.balance-night body #primary-content .podcast-reader__paragraph>button { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .podcast-reader mark { background:var(--bn-gold)!important;color:var(--bn-on-gold)!important; }
  html.balance-night body #primary-content :is(.podcast-copy,.podcast-reader,.podcast-notice) :is(p,li) { color:var(--bn-muted)!important; }

  /* The actual evidence-ledger classes, not the earlier sources-panel guesses. */
  html.balance-night body #primary-content .article-sources { background:var(--bn-surface)!important;color:var(--bn-text)!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content .article-sources :is(.article-sources__head,.article-source,.article-sources__reviewer) { background:transparent!important;border-color:var(--bn-line)!important; }
  html.balance-night body #primary-content .article-sources__review { background:var(--bn-card)!important; }
  html.balance-night body #primary-content .article-sources :is(h2,h3,cite,a) { color:var(--bn-text)!important; }
  html.balance-night body #primary-content .article-sources :is(p,.article-sources__reviewer span) { color:var(--bn-muted)!important; }
  html.balance-night body #primary-content .article-sources :is(.section-kicker,.article-source__number,.external-link-icon) { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .article-sources__more>summary { background:var(--bn-button)!important;color:var(--bn-text)!important; }
  html.balance-night body #primary-content .article-sources__more>summary span { color:inherit!important; }
  html.balance-night body #primary-content .article-sources__more>summary::after { color:var(--bn-gold)!important; }
  html.balance-night body #primary-content .article-sources__more>summary:is(:hover,:focus-visible) { background:var(--bn-raised)!important; }
}
