/* Shared preference controls. Theme rules are screen-only so exports stay readable. */
:root { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
button[data-theme-toggle] {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; width: auto; padding: .45rem .65rem; border: 1px solid #82968b;
  border-radius: 7px; background: #fffefa; color: #214c3e;
  font: 650 .85rem/1.2 system-ui,sans-serif; white-space: nowrap; cursor: pointer;
}
button[data-theme-toggle]:hover:not(:disabled) { background: #e8f1eb; color: #16372d; }
button[data-theme-toggle]:focus-visible { outline: 3px solid #b78335; outline-offset: 3px; }
body[data-workbench] > header { flex-wrap:wrap; }
@media (max-width:540px) {
  button[data-theme-toggle] { font-size: .75rem; padding: .4rem .5rem; min-height: 40px; }
  .hlt-header { flex-wrap: wrap; }
  .hlt-header nav { width:100%; justify-content:space-between; margin-bottom: 0; padding-bottom: 0; border: 0; }
  .hlt-menu-links { width:min(290px,calc(100vw - 32px)); }
  .hlt-header~main .input-card,.hlt-header~main .result-panel { top:7rem; }
  #hlt-main { scroll-margin-top:7rem; }
  .hlt-menu summary { padding-inline: 8px; font-size: .8rem; }
}
@media screen {
  html[data-theme="dark"] {
    --ink: #edf4ef; --muted: #b9c9c0; --green: #a1dfbe; --green-dark: #c1efd4;
    --mint: #304c3d; --cream: #131b18; --paper: #1d2822; --card: #1d2822;
    --line: #4a5d51; --gold: #e5b867; --error: #ffb5a9; --sage: #304c3d;
    background: #131b18; color: #edf4ef;
  }
  html[data-theme="dark"] body { background: #131b18; color: #edf4ef; }
  html[data-theme="dark"] .home-tool-card { background: #1d2822; color: #edf4ef; border-color: #4a5d51; }
  html[data-theme="dark"] .home-tool-card:first-child { background: #263c30; border-color: #57725f; }
  html[data-theme="dark"] :is(.home-tool-icon,.home-tool-card:first-child .home-tool-icon) { background: #304c3d; color: #c1efd4; }
  html[data-theme="dark"] :is(.home-lead,.home-category,.home-tool-card p,.home-section-heading p) { color: #b9c9c0; }
  html[data-theme="dark"] :is(.home-open,.home-facts) { color: #a1dfbe; }
  html[data-theme="dark"] .home-main > p[style] { background: #263c30 !important; border-color: #57725f !important; }
  html[data-theme="dark"] :is(h1,h2,h3,h4) { color: #edf4ef; }
  html[data-theme="dark"] a { color: #a1dfbe; }
  html[data-theme="dark"] :is(.hlt-header,.hlt-footer,.hlt-menu-links,.hlt-menu summary) {
    background: #1d2822; color: #edf4ef; border-color: #4a5d51;
  }
  html[data-theme="dark"] :is(.hlt-header,.hlt-footer) a { color: #c1efd4; }
  html[data-theme="dark"] .hlt-footer p { color: #b9c9c0; }
  html[data-theme="dark"] .hlt-skip { background:#1d2822; color:#c1efd4; }
  html[data-theme="dark"] .hlt-menu-links a:is(:hover,[aria-current="page"]) { background: #304c3d; }
  html[data-theme="dark"] :is(.input-card,.result-card,.method-section,.panel,.card,.backup,.entry-card,.compare-record,.plan,.cutting-comparison,.drill-row,.selection-row,.summary-item,.compare-panel,.audio-box,dialog) {
    background: #1d2822; color: #edf4ef; border-color: #4a5d51;
  }
  html[data-theme="dark"] :is(input,select,textarea,.input-with-unit) {
    background: #131b18; color: #edf4ef; border-color: #71877a;
  }
  html[data-theme="dark"] input::placeholder,html[data-theme="dark"] textarea::placeholder { color: #a7b8ae; }
  html[data-theme="dark"] :is(.unit-note,.privacy-note,.privacy-callout,.limits-note,.limit-note,.example,.example-callout,.schema-note,.overflow-note,.warning,.print-instructions,.storage-status.unsaved,.drill-row.is-current) {
    background: #3a3020; color: #f3d8a8; border-left-color: #e5b867;
  }
  html[data-theme="dark"] :is(.unit-note,.privacy-note,.limits-note,.warning,.example) :is(p,h3) { color: inherit; }
  html[data-theme="dark"] :is(.storage-status,.result-summary,.notice,#status,.answer-key,.economy-plan) { background: #263c30; color: #d5eddd; border-color: #57725f; }
  html[data-theme="dark"] :is(.hint,.muted,.metrics,.kicker,.filebox p,footer,.tag) { color: #b9c9c0; }
  html[data-theme="dark"] :is(code,pre) { background: #29382f; color: #edf4ef; }
  html[data-theme="dark"] :is(.badge,.entry-tag,.state-pill,.change-badge,.done) { background: #304c3d; color: #d5eddd; }
  html[data-theme="dark"] :is(.error,.danger-text,button.danger,#status.error) { color: #ffb5a9; }
  html[data-theme="dark"] #status.error { background: #452b26; }
  html[data-theme="dark"] :is(th,td,hr,.stepedit,.comparison-field,nav,footer) { border-color: #4a5d51; }
  html[data-theme="dark"] button:not([data-theme-toggle]) { background: #315840; color: #f1fff6; border-color: #71877a; }
  html[data-theme="dark"] button:not([data-theme-toggle]):hover:not(:disabled) { background: #406b50; color:#f1fff6; }
  html[data-theme="dark"] :is(button.secondary,.secondary-button,.text-button,.open) { background: #1d2822; color: #a1dfbe; border-color: #71877a; }
  html[data-theme="dark"] :is(.filebox button,.primary) { background: #315840; color: #f1fff6; border-color: #71877a; }
  html[data-theme="dark"] nav button[aria-pressed="true"] { background: #315840; color: #f1fff6; border-color: #a1dfbe; }
  html[data-theme="dark"] body[data-workbench] nav button[aria-pressed="false"] { background:#1d2822; color:#b9c9c0; }
  html[data-theme="dark"] button[data-theme-toggle] { background: #304c3d; color: #edf4ef; border-color: #71877a; }
  html[data-theme="dark"] button[data-theme-toggle]:hover:not(:disabled) { background: #406b50; color: #edf4ef; }
  /* Drawings and paper previews retain their calibrated light surface and ink. */
  html[data-theme="dark"] :is(.bolt-diagram,.assembly-diagram,.diagram-wrap,canvas) { background: #fffefa; border-radius: 6px; }
  html[data-theme="dark"] .diagram-wrap { color: #192a25; }
  html[data-theme="dark"] .diagram-wrap .diagram-caption { color: #53645d; }
  html[data-theme="dark"] .diagram-legend strong { color:#192a25; }
  html[data-theme="dark"] .image-frame.empty { background: #29382f; }
  html[data-theme="dark"] body[data-workbench] .brand { color: white; }
}
@media print {
  html[data-theme] { color-scheme: light; --ink:#192a25; --muted:#53645d; --green:#214c3e; --green-dark:#16372d; --mint:#d9ebe1; --cream:white; --paper:white; --card:white; --line:#777; --gold:#b78335; --error:#9c2f25; }
  button[data-theme-toggle] { display: none !important; }
}
