/* Austin knowledge atlas — shared dark chrome.
   Every rule is opt-in. Diagram palettes, image pixels and canvas drawing stay local. */
body[data-knowledge-theme="dark"] {
  --dark-bg: #0b1019;
  --dark-panel: #121b29;
  --dark-raised: #172335;
  --dark-text: #e6edf6;
  --dark-muted: #a4b3c7;
  --dark-line: #29384c;
  --dark-cyan: #65d9ec;
  --dark-soft: #163040;
  --paper: var(--dark-bg);
  --paper-deep: #101925;
  --paper-light: var(--dark-raised);
  --canvas: var(--dark-bg);
  --bg: var(--dark-bg);
  --card: var(--dark-panel);
  --panel: var(--dark-panel);
  --panel-2: var(--dark-raised);
  --surface: var(--dark-panel);
  --sheet: var(--dark-panel);
  --ink: var(--dark-text);
  --muted: var(--dark-muted);
  --dim: var(--dark-muted);
  --line: var(--dark-line);
  --line-soft: #223043;
  --soft: var(--dark-soft);
  --accent: var(--dark-cyan);
  --accent-2: #94b9ff;
  --pine: var(--dark-cyan);
  --pine-soft: var(--dark-soft);
  --cyan: var(--dark-cyan);
  --green: #87d6ad;
  --red: #ff9b9e;
  --cinnabar: #ffb3a4;
  --gold: #efc77f;
  --mu: #92d59a;
  --huo: #ffac98;
  --tu: #dfbe81;
  --jin: #f5d888;
  --shui: #91bfff;
  --bs-paper: var(--dark-bg);
  --bs-sheet: var(--dark-panel);
  --bs-ink: var(--dark-text);
  --bs-muted: var(--dark-muted);
  --bs-line: var(--dark-line);
  --bs-jade: var(--dark-cyan);
  --bs-jade-soft: var(--dark-soft);
  --bs-red: #ff9b9e;
  --bs-gold: #efc77f;
  --bs-code: #0c1724;
  --shadow: 0 12px 40px rgba(0, 0, 0, .18);
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --display: var(--sans);
  --r: 16px;
  --r-sm: 10px;
  --r-seal: 16px;
  color-scheme: dark;
  min-width: 0;
  color: var(--dark-text);
  background: radial-gradient(ellipse at 88% 0%, rgba(44, 118, 159, .1), transparent 42rem), var(--dark-bg);
  background-attachment: scroll;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Keep the existing night-reading toggle useful within the dark site theme. */
body[data-knowledge-theme="dark"]:is([data-night="true"], [data-theme="night"]) {
  --dark-bg: #070c13;
  --dark-panel: #0d1622;
  --dark-raised: #142031;
  --dark-text: #d8e2ee;
  --dark-muted: #a1afc2;
  --dark-cyan: #8dc8d5;
}
body[data-knowledge-theme="dark"]::before { opacity: .12; }
body[data-knowledge-theme="dark"] ::selection { color: #08131d; background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(h1, h2, h3) { text-wrap: pretty; }
body[data-knowledge-theme="dark"] :is(button, input, select, textarea) { font-family: inherit; }
body[data-knowledge-theme="dark"] :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--dark-cyan); outline-offset: 3px;
}
body[data-knowledge-theme="dark"] :is(input, textarea)::placeholder { color: #8496af; opacity: 1; }
body[data-knowledge-theme="dark"] .skip-link { color: #08131d; background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] header .stats { background: var(--dark-panel); border-color: var(--dark-line); }

/* Subject headers and the common navigation keep the same geometry. */
body[data-knowledge-theme="dark"] > header:not(.topic-hero):not(.series-bar) h1 {
  color: var(--dark-text); font-family: var(--sans); letter-spacing: .015em;
}
body[data-knowledge-theme="dark"] > header:not(.topic-hero):not(.series-bar) h1::after {
  background: var(--dark-cyan); opacity: .6; width: 42px;
}
body[data-knowledge-theme="dark"] :is(.topic-hero, .review-hero, .hero) {
  background: radial-gradient(ellipse at 80% 8%, rgba(56, 131, 174, .13), transparent 38rem), var(--dark-bg);
  border-color: var(--dark-line);
}
body[data-knowledge-theme="dark"] :is(.topic-hero h1, .hero h1, .series-hero h1,
  .review-hero h1, .section-heading h2, .session-heading h2, .memory-model h2) { font-family: var(--sans); }
body[data-knowledge-theme="dark"] :is(.hero-kicker, .section-kicker, .eyebrow, .series-eyebrow,
  .review-hero h1 em, .side-kicker, .session-heading p) { color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.course-nav, .study-nav, .series-bar) {
  background: rgba(11, 16, 25, .94); border-color: var(--dark-line);
}
body[data-knowledge-theme="dark"] :is(nav button, #pages button, button.chip, .tab-btn,
  .group-tabs button, .continent-filters button, .hero-meta span, header .stats) {
  color: var(--dark-muted); background: var(--dark-panel); border-color: var(--dark-line); border-radius: 10px;
}
body[data-knowledge-theme="dark"] :is(nav button, #pages button, button.chip, .tab-btn,
  .group-tabs button, .continent-filters button):hover {
  color: var(--dark-text); background: var(--dark-raised); border-color: #4a7087;
}
body[data-knowledge-theme="dark"] :is(nav button.on, nav button.is-active, #pages button.on,
  button.chip.on, .tab-btn.is-active, .group-tabs button.on, .continent-filters button.on,
  .series-bar__nav a[aria-current="page"]) {
  color: #08131d; background: var(--dark-cyan); border-color: var(--dark-cyan); box-shadow: none;
}
body[data-knowledge-theme="dark"] .series-bar__nav a:hover { color: var(--dark-cyan); background: var(--dark-soft); }
body[data-knowledge-theme="dark"] .nav-inner button { border-radius: 0; background: transparent; }
body[data-knowledge-theme="dark"] .nav-inner button.on { color: var(--dark-cyan); background: transparent; }

/* Only known reading containers are recolored, never images or diagram nodes. */
body[data-knowledge-theme="dark"] :is(.card:not(.mastered):not(.right):not(.wrong):not(.correct):not(.incorrect),
  .panel, .info-card, .module-card, .progress-panel, .reader, .side-panel, .map-card, .story-card,
  .fc, .q-body, .verse, .fc-face, .quiz-card, .quiz-finish, .quiz-shell, .dialog, .learn-card,
  .review-card, .session-finish, .memory-model, .coverage-card, .privacy-card, .control-bar,
  .planet-card, .derived-card, .prefix-card, .country-card, .painting-card, .artifact-card,
  .timeline-node, .compare-grid > article, .definition-strip, .twrap, .kj, .notice) {
  color: var(--dark-text); background: var(--dark-panel); border-color: var(--dark-line);
  border-radius: 16px; box-shadow: 0 8px 30px rgba(0, 0, 0, .12);
}
body[data-knowledge-theme="dark"] .card.mastered {
  background: #1c2830; border-color: #877451; border-radius: 16px;
}
body[data-knowledge-theme="dark"] :is(.card:not(.mastered), .planet-card, .country-card,
  .painting-card, .artifact-card):hover { border-color: #47647e; box-shadow: var(--shadow); }
body[data-knowledge-theme="dark"] :is(.planet-card.active, .artifact-card.active) {
  border-color: var(--dark-cyan); box-shadow: 0 0 0 1px var(--dark-cyan);
}
body[data-knowledge-theme="dark"] .timeline-node.on { background: var(--dark-soft); border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.planet-detail > div, .review-hero .hero-stats div) { background: var(--dark-panel); }
body[data-knowledge-theme="dark"] :is(.fc .aci, .fc .acd, .note, .guide-body) { color: #c4d0df; }
body[data-knowledge-theme="dark"] :is(.ftable, .tbl) tr:hover td { background: var(--dark-raised); }
body[data-knowledge-theme="dark"] :is(.toolbar input, .search input, .field input, .field select,
  input[type="text"], input[type="search"], input[type="number"], textarea, select, #search, #empSearch,
  .answer-row input) {
  color: var(--dark-text); background: #0e1724; border-color: var(--dark-line); border-radius: 10px;
}
body[data-knowledge-theme="dark"] :is(.toolbar input, .search input, input[type="text"],
  input[type="search"], #search, #empSearch):focus { background: #0e1724; border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(input[type="checkbox"], input[type="radio"], input[type="range"]) { accent-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.btn:not(.red):not(.green), .primary-btn, .complete-btn,
  .primary-button, .answer-row button, .object-link, .quiz-card [data-quiz-next], .quiz-finish button,
  .session-finish button) { color: #08131d; background: var(--dark-cyan); border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.btn.ghost, .secondary-btn, .ghost-btn, .export-btn) {
  color: var(--dark-text); background: var(--dark-panel); border-color: var(--dark-line);
}
body[data-knowledge-theme="dark"] .btn:is(.red, .green) { color: #09131b; }
body[data-knowledge-theme="dark"] :is(.opt, .quiz-option, .quiz-options button, .rating-grid button) {
  color: var(--dark-text); background: var(--dark-raised); border-color: var(--dark-line);
}
body[data-knowledge-theme="dark"] .opt:hover:not(.dim) { background: #20324a; }
body[data-knowledge-theme="dark"] .quiz-options button:hover:not(:disabled) { background: #20324a; }
body[data-knowledge-theme="dark"] :is(.opt.right, .opt.correct, .quiz-option.correct, .quiz-option.is-right, .quiz-options button.correct, .bit.good) {
  color: #a5ebc3; background: #16342e; border-color: #65b98d;
}
body[data-knowledge-theme="dark"] :is(.opt.wrong, .opt.incorrect, .quiz-option.wrong, .quiz-option.is-wrong, .quiz-options button.wrong, .bit.bad) {
  color: #ffb3b6; background: #3b232d; border-color: #cc7883;
}
body[data-knowledge-theme="dark"] .mask { background: rgba(3, 8, 16, .72); }
body[data-knowledge-theme="dark"] :is(.progress-track, .session-track) { background: #243246; }
body[data-knowledge-theme="dark"] .session-track span { background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] .review-hero .brand > span { color: #08131d; background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.quiz-feedback, .topic-hero ~ main .source-note) { background: var(--dark-raised); border-color: var(--dark-line); }
body[data-knowledge-theme="dark"] :is(.model-list > div, .coverage-item) { background: var(--dark-raised); }
body[data-knowledge-theme="dark"] .privacy-card > span { color: #08131d; }

/* Binary experiments: light input cells, carry bits and calculator keys are separate states. */
body[data-knowledge-theme="dark"].binary-series .lesson-grid > * { min-width: 0; }
body[data-knowledge-theme="dark"].binary-series :is(.bit-cell, .pipeline div) { background: var(--dark-raised); border-color: var(--dark-line); }
body[data-knowledge-theme="dark"].binary-series .bit-cell:is(.is-on, .is-one) { background: var(--dark-soft); color: var(--dark-cyan); border-color: #417c8e; }
body[data-knowledge-theme="dark"].binary-series .bit-cell.is-carry { background: #3b232d; color: #ffb3b6; border-color: #cc7883; }
body[data-knowledge-theme="dark"].binary-series :is(.calculator-shell, .alu-log) { background: #0d1725; }
body[data-knowledge-theme="dark"].binary-series .key-btn { background: #19283c; color: var(--dark-text); }
body[data-knowledge-theme="dark"].binary-series .key-btn.op { background: #1e4053; color: var(--dark-cyan); }
body[data-knowledge-theme="dark"].binary-series .key-btn.equal { background: var(--dark-cyan); color: #08131d; }
body[data-knowledge-theme="dark"][data-subject="binary-practice"] .learn-card h3 .lno { color: #08131d; }

/* Categorical pastel palettes remain faithful and get their own dark text. */
body[data-knowledge-theme="dark"][data-subject="periodic-table"] .cell { color: #1c2d36; }
body[data-knowledge-theme="dark"][data-subject="periodic-table"] .cell .z { color: #42535c; }
body[data-knowledge-theme="dark"][data-subject="periodic-table"] .cell .got { color: #6b531c; }
body[data-knowledge-theme="dark"][data-subject="periodic-table"] .ph { border-color: #516075; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .tile span { color: #465660; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .tile.sel :is(b, span) { color: #fff !important; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .tile.right { background: #16342e !important; border-color: #65b98d !important; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .tile.wrong { background: #3b232d !important; border-color: #cc7883 !important; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .tgl.on { background: var(--dark-soft); color: var(--dark-cyan); border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"][data-subject="china-map"] .ftable .chip { color: #172c35 !important; }
body[data-knowledge-theme="dark"][data-subject="china-map"] .info-card .tag { color: var(--dark-text) !important; }
body[data-knowledge-theme="dark"][data-subject="world-map"] .map-stage { background: #122130; }
body[data-knowledge-theme="dark"][data-subject="world-map"] .country-detail { background: #15263a; }
body[data-knowledge-theme="dark"][data-subject="world-map"] .country-card .continent-dot { color: #08131d; }
body[data-knowledge-theme="dark"][data-subject="jiazi60"] .method table { display: block; max-width: 100%; overflow-x: auto; }

/* Reading controls use the blue atlas palette; original text retains its reading typeface. */
body[data-knowledge-theme="dark"] :is(.reading-paper, .secondary-panel, .search-wrap, .search-box) {
  background: var(--dark-panel); border-color: var(--dark-line); box-shadow: var(--shadow);
}
body[data-knowledge-theme="dark"] :is(.brand-mark, .catalog-filters button[aria-pressed="true"],
  .collection-filters button[aria-pressed="true"], .version-switch button[aria-pressed="true"],
  .speaker-button.is-playing) { color: #08131d; background: var(--dark-cyan); border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.catalog-item[aria-current="true"], .chapter-item[aria-current="true"],
  .chapter-btn.is-active, .poem-segment.is-current, .text-segment.is-current) {
  background: var(--dark-soft); border-color: #3e697c;
}
body[data-knowledge-theme="dark"] :is(.catalog-filters, .reading-tools) { background: #0e1724; border-color: var(--dark-line); }
body[data-knowledge-theme="dark"] .text-segment:hover { background: var(--dark-raised); }
body[data-knowledge-theme="dark"] .reading-view-btn.is-active { color: #08131d; background: var(--dark-cyan); }
body[data-knowledge-theme="dark"][data-subject="zhuangzi-notes"] :is(.fulltext-intro, .fulltext-document,
  .passage, .source-card) { color: var(--dark-text); background: var(--dark-panel); border-color: var(--dark-line); }
body[data-knowledge-theme="dark"][data-subject="zhuangzi-notes"] :is(.paragraph-annotation, .annotation) { background: var(--dark-raised); border-color: var(--dark-line); }
body[data-knowledge-theme="dark"][data-subject="zhuangzi-notes"] .fulltext-no { color: #9bb2cc; }
body[data-knowledge-theme="dark"][data-subject="zhuangzi-notes"] .notice-mark { color: #08131d; }
body[data-knowledge-theme="dark"] :is(.search-wrap input, .search-box input) { background: transparent; border: 0; box-shadow: none; }
body[data-knowledge-theme="dark"] .audio-dock { background: #14283b; color: var(--dark-text); border: 1px solid #34516b; box-shadow: 0 12px 40px rgba(0, 0, 0, .34); }
body[data-knowledge-theme="dark"] .audio-progress span { background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] :is(.audio-symbol, .audio-track [role="status"], .audio-selection, .voice-badge) { color: #aac1d5; }
body[data-knowledge-theme="dark"] :is(.audio-buttons .primary-play, .audio-buttons #dock-play) { background: var(--dark-cyan); color: #08131d; }
body[data-knowledge-theme="dark"] .audio-buttons #dock-stop { color: var(--dark-text); background: transparent; }

/* The dictionary embeds this same CSS in its HTML so saved offline copies retain it. */
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] :is(.result-item, .offline-panel,
  .favorite-button, .definition-label, .collection-tabs button span) { background: var(--dark-panel); border-color: var(--dark-line); }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] :is(.result-item:hover, .result-item[aria-current="true"],
  .favorite-button[aria-pressed="true"]) { background: var(--dark-soft); border-color: #3e697c; }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] :is(.result-glyph, .result-pinyin,
  .character-pinyin, .source-panel summary, .intro-note > span, .eyebrow) { color: var(--dark-cyan); }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] :is(.tagline, .variant-note,
  .search-hint, .definition-label, .site-footer, .site-footer span) { color: var(--dark-muted); }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] .primary-button { color: #08131d; background: var(--dark-cyan); border-color: var(--dark-cyan); }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] .primary-button:hover:not(:disabled) { background: #a2eaf4; }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] .filter-row { border-color: var(--dark-line); }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] .offline-status { color: #87d6ad !important; }
body[data-knowledge-theme="dark"][data-subject="hanzi-dictionary"] :is(.noscript, .error-box) { background: #362b24; color: #efc77f; border-color: #70583c; }

body[data-knowledge-theme="dark"] .site-knowledge-dock { color: var(--dark-text); background: rgba(17, 29, 44, .96); border-color: #344b65; box-shadow: 0 8px 28px rgba(0, 0, 0, .3); backdrop-filter: blur(14px); }
body[data-knowledge-theme="dark"] .site-knowledge-dock a { color: var(--dark-text); background: transparent; }
body[data-knowledge-theme="dark"] .site-knowledge-dock .site-review-link { color: var(--dark-cyan); background: #1d3548; }
body[data-knowledge-theme="dark"] .site-knowledge-dock a:hover,
body[data-knowledge-theme="dark"] .site-knowledge-dock a[aria-current="page"] { color: #08131d; background: var(--dark-cyan); }
body[data-knowledge-theme="dark"] .site-knowledge-dock a:focus-visible { outline: 2px solid var(--dark-cyan); outline-offset: -2px; }

@media (max-width: 800px) {
  body[data-knowledge-theme="dark"].binary-series .lesson-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  body[data-knowledge-theme="dark"] #xunList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  body[data-knowledge-theme="dark"] { color: #172331; background: #fff; --ink: #172331; --muted: #455362; --paper: #fff; --panel: #fff; --card: #fff; --line: #b8c3ce; }
  body[data-knowledge-theme="dark"] :is(.reading-paper, .secondary-panel, .reader) { color: #172331; background: #fff; box-shadow: none; }
}
