/* =====================================================================
   QUÍMICA V21 · Tema cromático coherente
   Objetivo: todas las superficies de la interfaz siguen la preferencia
   Claro/Oscuro. Las fotografías, modelos, gráficas y simuladores externos
   conservan sus colores científicos originales.
   ===================================================================== */

/* Tokens únicos: claro — "papel de laboratorio" */
html[data-theme="light"] {
  color-scheme: light;
  --color-page: #f3f5ef;
  --color-surface: #ffffff;
  --color-surface-soft: #eef1ea;
  --color-surface-raised: #ffffff;
  --color-ink: #16212a;
  --color-ink-soft: #3a4a4f;
  --color-muted: #5d6a6c;
  --color-line: #dde3d9;
  --color-line-strong: #c3cdc0;
  --color-brand: #1d4e66;
  --color-brand-strong: #123244;
  --color-brand-soft: #e4edef;
  --color-accent: #8a5518;
  --color-accent-soft: #f7ead3;
  --color-success: #2f7a52;
  --color-focus: #8a5518;
  --ui-header: rgba(248, 249, 245, .96);
  --ui-panel: #ffffff;
  --ui-panel-soft: #eef1ea;
  --ui-panel-raised: #f8f9f4;
  --ui-panel-hover: #e7ece1;
  --ui-input: #ffffff;
  --ui-input-text: #16212a;
  --ui-hero-start: #eef2ea;
  --ui-hero-end: #e6efea;
  --ui-install-bg: #e4edef;
  --ui-install-text: #123244;
  --ui-install-border: #9bb7bf;
  --ui-shadow: 0 14px 34px rgba(22, 33, 42, .09);

  /* Variantes de texto de los colores de ensayo a la llama: mismo tono,
     calibradas a 4.5:1 sobre superficie clara. Los tokens --flame-* base
     (variables.css) se conservan para usos decorativos (barras, SVG). */
  --flame-copper-text: #1b8574;
  --flame-strontium-text: #b8402f;
  --flame-sodium-text: #9b6b24;
  --flame-potassium-text: #7c5fa3;
  --flame-barium-text: #547f37;
  --flame-lithium-text: #c23b6b;
}

/* Tokens únicos: oscuro — "laboratorio nocturno": vidrio y reactivos
   iluminados sobre superficies oscuras propias, no una inversión del claro. */
html[data-theme="dark"] {
  color-scheme: dark;
  --color-page: #0e1517;
  --color-surface: #161f22;
  --color-surface-soft: #1b2528;
  --color-surface-raised: #1f2b2e;
  --color-ink: #e9efe9;
  --color-ink-soft: #c6d2cc;
  --color-muted: #93a19c;
  --color-line: #2c3a3a;
  --color-line-strong: #3d4e4e;
  --color-brand: #6fb4c9;
  --color-brand-strong: #96cfdf;
  --color-brand-soft: #1b3038;
  --color-accent: #e0a24e;
  --color-accent-soft: #3a2c16;
  --color-success: #7bc99a;
  --color-focus: #e0a24e;
  --ui-header: rgba(14, 21, 23, .96);
  --ui-panel: #161f22;
  --ui-panel-soft: #1b2528;
  --ui-panel-raised: #1f2b2e;
  --ui-panel-hover: #223033;
  --ui-input: #111819;
  --ui-input-text: #e9efe9;
  --ui-hero-start: #10191c;
  --ui-hero-end: #10211f;
  --ui-install-bg: #1b3038;
  --ui-install-text: #d8f0ea;
  --ui-install-border: #4f7f86;
  --ui-shadow: 0 18px 46px rgba(0, 0, 0, .38);

  /* Variantes de texto de los colores de ensayo a la llama, calibradas a
     4.5:1 sobre la superficie oscura de las tarjetas (--ui-panel). */
  --flame-copper-text: #1f9a86;
  --flame-strontium-text: #d46556;
  --flame-sodium-text: #c98a2e;
  --flame-potassium-text: #947cb4;
  --flame-barium-text: #629541;
  --flame-lithium-text: #cf6188;
}

html[data-theme] {
  background: var(--color-page);
  color: var(--color-ink);
  color-scheme: light dark;
  transition: background-color .18s ease, color .18s ease;
}
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  color: var(--color-ink);
  background: var(--color-page);
  transition: background-color .18s ease, color .18s ease;
}
html[data-theme="light"] body::before {
  opacity: .16;
  background-image: radial-gradient(rgba(31, 58, 105, .18) .65px, transparent .65px);
}
html[data-theme="dark"] body::before {
  opacity: .22;
  background-image: radial-gradient(rgba(132, 185, 219, .20) .65px, transparent .65px);
}
::selection {
  color: var(--color-ink);
  background: var(--color-brand-soft);
}

/* Cabecera, marca y controles principales */
html[data-theme] .site-header {
  border-color: var(--color-line);
  background: var(--ui-header);
  box-shadow: 0 8px 28px rgba(10, 28, 52, .08);
}
html[data-theme] .brand-mark {
  border-color: var(--color-line);
  background: var(--ui-panel);
}
html[data-theme] .brand-copy strong,
html[data-theme] .brand-copy span,
html[data-theme] .header-note { color: var(--color-ink); }
html[data-theme] .brand-copy span,
html[data-theme] .header-note { color: var(--color-muted); }
html[data-theme] .button-secondary,
html[data-theme] .settings-open-button,
html[data-theme] .share-page-button {
  border-color: var(--color-line-strong);
  color: var(--color-ink);
  background: var(--ui-panel);
  box-shadow: 0 4px 12px rgba(10, 28, 52, .055);
}
html[data-theme] .button-secondary:hover,
html[data-theme] .settings-open-button:hover,
html[data-theme] .share-page-button:hover {
  border-color: var(--color-brand);
  color: var(--color-brand-strong);
  background: var(--ui-panel-hover);
}
html[data-theme] .button-primary {
  border-color: var(--color-brand-strong);
  color: #ffffff;
  background: var(--color-brand-strong);
}
html[data-theme="dark"] .button-primary {
  border-color: #347d7c;
  color: #071b26;
  background: #8adfd6;
}
html[data-theme="dark"] .button-primary:hover { background: #a8eee5; }
html[data-theme="light"] .button-primary:hover { background: #0f315f; }

/* Botón Instalar: no hereda el estilo ambiguo de button-secondary. */
#install-app-button[hidden] { display: none !important; }
html[data-theme] #install-app-button:not([hidden]) {
  display: inline-flex;
  min-height: 2.65rem;
  align-items: center;
  justify-content: center;
  padding: .58rem .88rem;
  border: 1px solid var(--ui-install-border);
  border-radius: .82rem;
  color: var(--ui-install-text);
  background: var(--ui-install-bg);
  box-shadow: 0 4px 14px rgba(10, 28, 52, .10);
  font: 780 .73rem/1.2 var(--font-sans);
  opacity: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
}
html[data-theme] #install-app-button:not([hidden]):hover {
  border-color: var(--color-brand);
  color: var(--color-ink);
  background: var(--ui-panel-hover);
  transform: translateY(-1px);
}
html[data-theme] #install-app-button:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}
html[data-theme] #install-app-button:disabled {
  cursor: not-allowed;
  opacity: .62;
  box-shadow: none;
}

/* Portada: la superficie y la tipografía también cambian de tema. */
html[data-theme="light"] .hero-grid {
  border-color: #d1dfed;
  color: var(--color-ink);
  background: linear-gradient(116deg, var(--ui-hero-start), #edf4fc 54%, var(--ui-hero-end));
  box-shadow: 0 24px 64px rgba(24, 48, 82, .09), inset 0 1px 0 rgba(255,255,255,.8);
}
html[data-theme="light"] .hero-grid::before {
  background-image: linear-gradient(rgba(40, 78, 125, .055) 1px, transparent 1px), linear-gradient(90deg, rgba(40, 78, 125, .055) 1px, transparent 1px);
}
html[data-theme="light"] .hero-grid::after {
  border-color: rgba(20, 125, 130, .17);
  box-shadow: 0 0 0 42px rgba(20, 125, 130, .025), 0 0 0 86px rgba(37, 99, 235, .018);
}
html[data-theme="light"] .hero .eyebrow,
html[data-theme="light"] .hero .section-kicker { color: #176b73; }
html[data-theme="light"] .hero .eyebrow::before { background: #b7792c; }
html[data-theme="light"] .hero h1,
html[data-theme="light"] .hero .hero-title-main { color: #142e4b !important; text-shadow: none; }
html[data-theme="light"] .hero h1 span { color: #087f79; text-shadow: none; }
html[data-theme="light"] .hero-description { color: #4c627b; }
html[data-theme="light"] .scope-strip { border-color: #d3dfed; background: rgba(255,255,255,.72); }
html[data-theme="light"] .scope-item + .scope-item { border-color: #d6e1ee; }
html[data-theme="light"] .scope-item strong { color: #173d70; }
html[data-theme="light"] .scope-item span { color: #586e87; }
html[data-theme="light"] .hero-panel {
  border-color: #d2e0ed;
  background: linear-gradient(145deg, #ffffff, #edf5f8);
  box-shadow: var(--ui-shadow);
}
html[data-theme="light"] .hero-panel .panel-label,
html[data-theme="light"] .hero-panel .panel-foot { color: #5d7188; }
html[data-theme="light"] .hero-panel .element-display { border-color: #d1dfeb; background: #ffffff; }
html[data-theme="light"] .hero-panel .element-number { color: #60748a; }
html[data-theme="light"] .hero-panel .element-name { color: #264560; }
html[data-theme="light"] .hero-actions .button-secondary { border-color: #b8c9dc; color: #173d70; background: rgba(255,255,255,.78); }
html[data-theme="light"] .hero-actions .button-secondary:hover { background: #ffffff; }

html[data-theme="dark"] .hero-grid {
  border-color: #25435f;
  color: var(--color-ink);
  background: linear-gradient(116deg, #08182d 0%, #102b4b 53%, #0b3b3e 100%);
}
html[data-theme="dark"] .hero .eyebrow,
html[data-theme="dark"] .hero .section-kicker { color: #8ce7df; }
html[data-theme="dark"] .hero h1,
html[data-theme="dark"] .hero .hero-title-main { color: #f0f6ff !important; }
html[data-theme="dark"] .hero h1 span { color: #80e4dc; }
html[data-theme="dark"] .hero-description { color: #c3d3e5; }
html[data-theme="dark"] .hero-panel { border-color: #38516b; background: linear-gradient(145deg, rgba(24,45,68,.96), rgba(15,31,49,.96)); }
html[data-theme="dark"] .hero-panel .element-display { border-color: #3c5872; background: #132941; }
html[data-theme="dark"] .hero-panel .element-name { color: #d7e5f2; }
html[data-theme="dark"] .scope-strip { border-color: #2b4963; background: rgba(10,24,41,.68); }
html[data-theme="dark"] .scope-item strong { color: #eff8ff; }
html[data-theme="dark"] .scope-item span { color: #b7c9dc; }

/* Superficies generales y secciones que antes mezclaban paletas. */
html[data-theme] .feature-section,
html[data-theme] .nexus-section {
  border-color: var(--color-line);
  background: var(--color-page);
}
html[data-theme] .discipline-card,
html[data-theme] .feature-item,
html[data-theme] .table-preview,
html[data-theme] .lab-card,
html[data-theme] .phet-card,
html[data-theme] .simulation-viewer,
html[data-theme] .library-card,
html[data-theme] .course-objectives,
html[data-theme] .course-progress-card,
html[data-theme] .course-lesson-card,
html[data-theme] .course-assessment,
html[data-theme] .course-sources,
html[data-theme] .lab3d-benefit-card {
  border-color: var(--color-line);
  color: var(--color-ink);
  background: var(--ui-panel);
  box-shadow: var(--ui-shadow);
}
html[data-theme] .discipline-card h3,
html[data-theme] .feature-item strong,
html[data-theme] .lab-card h3,
html[data-theme] .phet-card h3,
html[data-theme] .library-card h3,
html[data-theme] .course-objectives h3,
html[data-theme] .course-progress-card h3,
html[data-theme] .course-assessment h3,
html[data-theme] .lab3d-benefit-card h3 { color: var(--color-ink); }
html[data-theme] .section-heading p,
html[data-theme] .discipline-card p,
html[data-theme] .feature-item span:last-child,
html[data-theme] .lab-card p,
html[data-theme] .phet-card p,
html[data-theme] .library-card p,
html[data-theme] .lab3d-benefit-card p { color: var(--color-muted); }
html[data-theme] .feature-item { background: var(--ui-panel-raised); }
html[data-theme] .lab-note,
html[data-theme] .planned-simulations .lab-card,
html[data-theme] .availability-pill { border-color: var(--color-line); color: var(--color-muted); background: var(--ui-panel-soft); }
html[data-theme] .feature-number,
html[data-theme] .course-lesson-number,
html[data-theme] .lab3d-benefit-icon { border-color: var(--color-line); color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .feature-section { border-block: 1px solid var(--color-line); }
html[data-theme] .closing {
  border-color: var(--color-line);
  color: var(--color-ink);
  background: var(--ui-panel-soft);
  box-shadow: var(--ui-shadow);
}
html[data-theme] .closing h2 { color: var(--color-ink); }
html[data-theme] .closing p { color: var(--color-ink-soft); }
html[data-theme] .site-footer,
html[data-theme] .footer-inner { border-color: var(--color-line); color: var(--color-muted); }
html[data-theme] .section-kicker,
html[data-theme] .eyebrow { color: var(--color-brand-strong); }
html[data-theme] .text-link,
html[data-theme] .viewer-attribution a,
html[data-theme] .library-reference-citation,
html[data-theme] .library-source-link { color: var(--color-brand-strong); }

/* LAB3D: el panel informativo cambia de tema; la ilustración 3D se conserva. */
html[data-theme] .lab3d-page { border-color: var(--color-line); background: var(--color-page); }
html[data-theme] .lab3d-benefit-card { border-color: var(--color-line); }
html[data-theme] .lab3d-benefit-card h3 { color: var(--color-ink); }
html[data-theme] .lab3d-benefit-card p { color: var(--color-muted); }
html[data-theme="light"] .lab3d-portal-card { border-color: #cbd9e8; background: var(--ui-panel); }
html[data-theme="light"] .lab3d-portal-info { color: var(--color-ink); background: linear-gradient(145deg, #ffffff, #edf4fb); }
html[data-theme="light"] .lab3d-portal-info h3 { color: #173452; }
html[data-theme="light"] .lab3d-portal-info > p,
html[data-theme="light"] .lab3d-feature-list span { color: #52677f; }
html[data-theme="light"] .lab3d-chip { border-color: #b8ddd8; color: #126a68; background: #e9f6f3; }
html[data-theme="light"] .lab3d-portal-metrics > div { border-color: #d7e3ef; background: #f5f8fc; }
html[data-theme="light"] .lab3d-portal-metrics strong { color: #176f75; }
html[data-theme="light"] .lab3d-portal-metrics span,
html[data-theme="light"] .lab3d-status { color: #637991 !important; }
html[data-theme="dark"] .lab3d-portal-card { border-color: #294661; background: #091a2d; }
html[data-theme="dark"] .lab3d-portal-info { color: #e3edf8; background: linear-gradient(145deg, #0d223a, #0a1a2e 72%); }

/* Nexus: panel informativo temático; arte y juego incrustado mantienen su diseño. */
html[data-theme="light"] .nexus-portal-info { color: #243d58; background: linear-gradient(145deg, #ffffff, #edf4fb); }
html[data-theme="light"] .nexus-portal-info h3 { color: #173452; }
html[data-theme="light"] .nexus-portal-info > p { color: #556c84; }
html[data-theme="light"] .nexus-overline { color: #087f83; }
html[data-theme="light"] .nexus-world-list span { color: #435b75; }
html[data-theme="light"] .nexus-world-list span b { color: #087f83; }
html[data-theme="light"] .nexus-card-footer { border-color: #d6e1ed; }
html[data-theme="light"] .nexus-progress-summary { color: #61758c; }
html[data-theme="light"] .nexus-local-note { color: #687c91 !important; }
html[data-theme="light"] .nexus-game-toolbar { border-color: var(--color-line); background: var(--ui-panel-soft); }
html[data-theme="light"] .nexus-game-toolbar h3 { color: var(--color-ink); }
html[data-theme="light"] .nexus-game-toolbar p { color: var(--color-muted); }
html[data-theme="light"] .nexus-game-actions .button { border-color: var(--color-line-strong); color: var(--color-ink); background: var(--ui-panel); }
html[data-theme="light"] .nexus-frame-caption { border-color: var(--color-line); color: var(--color-muted); background: var(--ui-panel-soft); }
html[data-theme="dark"] .nexus-portal-info { color: #e2e8f0; background: linear-gradient(145deg, #0d223a, #0a1a2e); }
html[data-theme="dark"] .nexus-portal-info h3 { color: #f8fafc; }
html[data-theme="dark"] .nexus-portal-info > p { color: #b9c7d7; }
html[data-theme="dark"] .nexus-game-toolbar { border-color: #193244; background: linear-gradient(110deg, #0c1b2c, #0b1421); }
html[data-theme="dark"] .nexus-game-toolbar h3 { color: #f1f5f9; }
html[data-theme="dark"] .nexus-game-toolbar p { color: #94a3b8; }

/* Tabla periódica y ficha: capas y controles siguen los tokens de tema. */
html[data-theme] .periodic-workbench {
  border-color: var(--color-line);
  color: var(--color-ink);
  background: var(--ui-panel);
}
html[data-theme] .periodic-workbench .periodic-workbench-head {
  border-color: var(--color-line);
  background: linear-gradient(115deg, var(--ui-panel-soft), var(--ui-panel) 64%, var(--ui-panel-soft));
}
html[data-theme] .periodic-workbench .periodic-workbench-head h3,
html[data-theme] .periodic-workbench .v11-detail-heading h3,
html[data-theme] .periodic-workbench .v11-tool-heading h3 { color: var(--color-ink); }
html[data-theme] .periodic-workbench .periodic-workbench-head p,
html[data-theme] .periodic-workbench .v11-detail-hint,
html[data-theme] .periodic-workbench .v11-data-note,
html[data-theme] .periodic-workbench .v11-table-legend,
html[data-theme] .periodic-workbench .v11-legend-note { color: var(--color-muted); }
html[data-theme] .periodic-workbench .periodic-app-nav,
html[data-theme] .periodic-workbench .v11-detail-tabs { border-color: var(--color-line); background: var(--ui-panel-soft); }
html[data-theme] .periodic-workbench .periodic-app-tab,
html[data-theme] .periodic-workbench .v11-detail-tabs button { color: var(--color-ink-soft); }
html[data-theme] .periodic-workbench .periodic-app-tab.is-active,
html[data-theme] .periodic-workbench .v11-detail-tabs button.is-active { color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .periodic-workbench .v11-series-wrap,
html[data-theme] .periodic-workbench .v11-element-detail,
html[data-theme] .periodic-workbench .v11-atom-card,
html[data-theme] .periodic-workbench .v11-property-card,
html[data-theme] .periodic-workbench .v11-ion-card,
html[data-theme] .periodic-workbench .v11-quiz-shell,
html[data-theme] .periodic-workbench .v11-question-card,
html[data-theme] .periodic-workbench .v12-atom-card,
html[data-theme] .periodic-workbench .v13-atom-card,
html[data-theme] .periodic-workbench .v11-fact-box,
html[data-theme] .periodic-workbench .v11-config-short,
html[data-theme] .periodic-workbench .v11-config-value,
html[data-theme] .periodic-workbench .v11-mini-facts > div,
html[data-theme] .periodic-workbench .v12-nucleus-stats > div,
html[data-theme] .periodic-workbench .v13-nucleus-stats > div {
  border-color: var(--color-line);
  color: var(--color-ink);
  background: var(--ui-panel-soft);
}
html[data-theme] .periodic-workbench .v11-source-panel,
html[data-theme] .periodic-workbench .v11-compare-table-wrap,
html[data-theme] .periodic-workbench .v11-quiz-start,
html[data-theme] .periodic-workbench .v11-quiz-end { border-color: var(--color-line); background: var(--ui-panel); color: var(--color-ink); }
html[data-theme] .periodic-workbench .v11-compare-table th,
html[data-theme] .periodic-workbench .v11-compare-table td { border-color: var(--color-line); color: var(--color-ink-soft); }
html[data-theme] .periodic-workbench .v11-compare-table thead th { background: var(--ui-panel-soft); color: var(--color-ink); }
html[data-theme] .periodic-workbench .v11-element-photo,
html[data-theme] .periodic-workbench .v13-element-photo,
html[data-theme] .detail-image-wrap,
html[data-theme] .gallery-image-wrap { border-color: var(--color-line); background: var(--ui-panel-soft); }
html[data-theme] .periodic-workbench .v11-photo-placeholder,
html[data-theme] .gallery-image-unavailable,
html[data-theme] .gallery-license-details { color: var(--color-muted); }
html[data-theme] .periodic-workbench .v11-controls-row input,
html[data-theme] .periodic-workbench .v11-controls-row select,
html[data-theme] .periodic-workbench .v11-compare-selectors select,
html[data-theme] .periodic-workbench .periodic-controls-v11 input,
html[data-theme] .periodic-workbench .periodic-controls-v11 select,
html[data-theme] .periodic-workbench .v12-orbital-select select,
html[data-theme] .periodic-workbench .v13-orbital-select select {
  border-color: var(--color-line-strong);
  color: var(--ui-input-text);
  background: var(--ui-input);
  color-scheme: inherit;
}
html[data-theme="dark"] .periodic-workbench .v11-canvas-wrap { border-color: #29485c; background: radial-gradient(circle at 50% 45%, #183d50, #0b1a2b 84%); }
html[data-theme="light"] .periodic-workbench .v11-canvas-wrap { border-color: #d3e0ec; background: radial-gradient(circle at 50% 45%, #edf7fa, #dfeaf4 84%); }

/* Formularios compartidos, controles y tablas: evitar campos blancos aislados. */
html[data-theme] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not([type="file"]),
html[data-theme] select,
html[data-theme] textarea {
  border-color: var(--color-line-strong);
  color: var(--ui-input-text);
  background-color: var(--ui-input);
  color-scheme: inherit;
}
html[data-theme] input::placeholder,
html[data-theme] textarea::placeholder { color: var(--color-muted); opacity: 1; }
html[data-theme] .field-with-unit input { border: 0; color: var(--ui-input-text); background: transparent; }
html[data-theme] .field-with-unit,
html[data-theme] .titration-volume-control,
html[data-theme] .titration-control-panel,
html[data-theme] .titration-analysis-panel,
html[data-theme] .titration-result-grid > div,
html[data-theme] .titration-model-note,
html[data-theme] .titration-card-footer,
html[data-theme] .course-quiz-shell,
html[data-theme] .course-feedback,
html[data-theme] .course-answer-option {
  border-color: var(--color-line);
  color: var(--color-ink-soft);
  background: var(--ui-panel-soft);
}
html[data-theme] .titration-card-heading {
  border-color: var(--color-line);
  background: linear-gradient(115deg, var(--ui-panel-soft), var(--ui-panel), var(--color-brand-soft));
}
html[data-theme] .titration-card-heading h3,
html[data-theme] .titration-result-grid strong,
html[data-theme] .equivalence-readout strong { color: var(--color-ink); }
html[data-theme] .titration-card-heading p,
html[data-theme] .titration-field,
html[data-theme] .instrument-panel-label,
html[data-theme] .readout-caption,
html[data-theme] .equivalence-readout > span { color: var(--color-muted); }
html[data-theme] .instrument-step-button,
html[data-theme] .instrument-reset-button,
html[data-theme] .instrument-export-button,
html[data-theme] .library-export-button,
html[data-theme] .library-category,
html[data-theme] .v11-small-button,
html[data-theme] .v11-clear,
html[data-theme] .v11-answer-option {
  border-color: var(--color-line-strong);
  color: var(--color-ink-soft);
  background: var(--ui-panel);
}
html[data-theme] .instrument-equivalence-button { border-color: var(--color-accent); color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .library-category.is-active { border-color: var(--color-brand); color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .course-example { border-color: var(--color-line); background: var(--color-accent-soft); }
html[data-theme] .course-caution { border-color: var(--color-line); background: var(--ui-panel-soft); }
html[data-theme] .course-answer-option { background: var(--ui-panel); }
html[data-theme] .course-answer-option.is-correct { border-color: var(--color-success); background: color-mix(in srgb, var(--color-success) 10%, var(--ui-panel)); }
html[data-theme] .course-answer-option.is-wrong { border-color: #b65b53; background: color-mix(in srgb, #b65b53 9%, var(--ui-panel)); }
html[data-theme] table,
html[data-theme] th,
html[data-theme] td { border-color: var(--color-line); }
html[data-theme] th { color: var(--color-ink); background: var(--ui-panel-soft); }
html[data-theme] td { color: var(--color-ink-soft); background: var(--ui-panel); }

/* Biblioteca, diálogo de ajustes y menú. */
html[data-theme] .library-search,
html[data-theme] .library-export-button,
html[data-theme] .library-category { border-color: var(--color-line-strong); color: var(--color-ink); background: var(--ui-panel); }
html[data-theme] .library-results-line,
html[data-theme] .library-disclaimer,
html[data-theme] .library-no-results { color: var(--color-muted); }
html[data-theme] .settings-dialog,
html[data-theme] .navigation-dialog { border-color: var(--color-line-strong); color: var(--color-ink); background: var(--ui-panel); }
html[data-theme] .settings-dialog-header,
html[data-theme] .settings-dialog-footer,
html[data-theme] .settings-group,
html[data-theme] .navigation-dialog-header,
html[data-theme] .navigation-dialog-footer { border-color: var(--color-line); background: var(--ui-panel-soft); }
html[data-theme] .settings-dialog-header h2,
html[data-theme] .settings-group-heading h3,
html[data-theme] .settings-switch-row strong,
html[data-theme] .navigation-dialog-heading h2 { color: var(--color-ink); }
html[data-theme] .settings-group-heading p,
html[data-theme] .settings-switch-row small,
html[data-theme] .settings-local-note,
html[data-theme] .navigation-dialog-description { color: var(--color-muted); }
html[data-theme] .settings-field,
html[data-theme] .settings-reset-button { color: var(--color-ink-soft); }
html[data-theme] .settings-field select,
html[data-theme] .settings-icon-button,
html[data-theme] .navigation-dialog-close { border-color: var(--color-line-strong); color: var(--color-ink); background: var(--ui-input); }
html[data-theme] .navigation-menu-link { border-color: var(--color-line); color: var(--color-ink); background: var(--ui-panel); }
html[data-theme] .navigation-menu-index { border-color: var(--color-line); color: var(--color-muted); background: var(--ui-panel-soft); }
html[data-theme] .navigation-menu-link[aria-current="page"] { border-color: var(--color-brand); color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .navigation-dialog::backdrop,
html[data-theme] .settings-dialog::backdrop { background: rgba(4, 13, 25, .56); }
html[data-theme] .share-status { border-color: var(--color-brand); color: var(--color-ink); background: var(--ui-panel-raised); }

/* Oscuro: cubrir también superficies heredadas que no usan variables. */
html[data-theme="dark"] .discipline-card,
html[data-theme="dark"] .table-preview,
html[data-theme="dark"] .lab-card,
html[data-theme="dark"] .phet-card,
html[data-theme="dark"] .simulation-viewer,
html[data-theme="dark"] .library-card,
html[data-theme="dark"] .course-objectives,
html[data-theme="dark"] .course-progress-card,
html[data-theme="dark"] .course-lesson-card,
html[data-theme="dark"] .course-assessment,
html[data-theme="dark"] .course-sources,
html[data-theme="dark"] .lab3d-benefit-card { background: var(--ui-panel); }
html[data-theme="dark"] .available-label { border-color: #2a6859; color: #a9ebcf; background: #15382f; }
html[data-theme="dark"] .gallery-image-wrap,
html[data-theme="dark"] .detail-image-wrap,
html[data-theme="dark"] .periodic-workbench .v11-element-photo { background: #14243a; }
html[data-theme="dark"] .gallery-image-wrap.image-not-loaded,
html[data-theme="dark"] .gallery-image-unavailable { color: #b8c9dc; background: #14243a; }
html[data-theme="dark"] .v11-element-photo small { color: #b9c9dc; background: #1a3048; }
html[data-theme="dark"] .periodic-workbench .v11-source-panel,
html[data-theme="dark"] .periodic-workbench .v11-quiz-start,
html[data-theme="dark"] .periodic-workbench .v11-quiz-end { background: #101e30; }
html[data-theme="dark"] .course-example { border-color: #5b4a2f; background: rgba(189, 135, 72, .13); }
html[data-theme="dark"] .course-caution { border-color: #344b65; background: #14243a; }
html[data-theme="dark"] .instrument-step-button,
html[data-theme="dark"] .instrument-reset-button,
html[data-theme="dark"] .instrument-export-button,
html[data-theme="dark"] .library-export-button,
html[data-theme="dark"] .library-category,
html[data-theme="dark"] .v11-small-button,
html[data-theme="dark"] .v11-clear,
html[data-theme="dark"] .v11-answer-option { border-color: #3a5470; color: #d0deee; background: #172b43; }
html[data-theme="dark"] .instrument-equivalence-button { border-color: #276c6a; color: #9be5d9; background: #143c3b; }
html[data-theme="dark"] .library-category.is-active { border-color: #37668f; color: #b5e1f2; background: #183a52; }
html[data-theme="dark"] .titration-card-heading h3 { color: #e4efff; }
html[data-theme="dark"] .titration-card-heading p { color: #a6bad2; }
html[data-theme="dark"] .field-with-unit,
html[data-theme="dark"] .titration-volume-control,
html[data-theme="dark"] .titration-control-panel,
html[data-theme="dark"] .titration-analysis-panel,
html[data-theme="dark"] .titration-result-grid > div,
html[data-theme="dark"] .titration-model-note,
html[data-theme="dark"] .titration-card-footer,
html[data-theme="dark"] .course-quiz-shell,
html[data-theme="dark"] .course-feedback { border-color: #2b405a; color: #c5d4e5; background: #14243a; }
html[data-theme="dark"] .field-with-unit input { color: #e8f0fa; background: transparent; }
html[data-theme="dark"] .share-status { border-color: #347a79; color: #dffcf6; background: #123a3a; }

/* Modo claro: ni las tarjetas de producto ni las bandas de contenido quedan oscuras. */
html[data-theme="light"] .discipline-card,
html[data-theme="light"] .feature-item,
html[data-theme="light"] .table-preview,
html[data-theme="light"] .lab-card,
html[data-theme="light"] .phet-card,
html[data-theme="light"] .simulation-viewer,
html[data-theme="light"] .library-card,
html[data-theme="light"] .course-objectives,
html[data-theme="light"] .course-progress-card,
html[data-theme="light"] .course-lesson-card,
html[data-theme="light"] .course-assessment,
html[data-theme="light"] .course-sources,
html[data-theme="light"] .lab3d-benefit-card { color: var(--color-ink); background: #ffffff; }
html[data-theme="light"] .feature-section,
html[data-theme="light"] .lab3d-page,
html[data-theme="light"] .nexus-section { background: #f3f6fb; }
html[data-theme="light"] .titration-lab-card,
html[data-theme="light"] .titration-control-panel,
html[data-theme="light"] .titration-analysis-panel,
html[data-theme="light"] .course-quiz-shell { color: var(--color-ink); background: #ffffff; }

/* Alto contraste: mantiene el contrato de accesibilidad sobre ambos temas. */
html[data-contrast="high"][data-theme="light"] #install-app-button:not([hidden]) {
  border: 2px solid #10243b;
  color: #10243b;
  background: #ffffff;
  box-shadow: none;
}
html[data-contrast="high"][data-theme="dark"] #install-app-button:not([hidden]) {
  border: 2px solid #ffffff;
  color: #ffffff;
  background: #000000;
  box-shadow: none;
}
html[data-contrast="high"] :is(.discipline-card, .feature-item, .table-preview, .lab-card, .phet-card, .simulation-viewer, .library-card, .course-objectives, .course-progress-card, .course-lesson-card, .course-assessment, .course-sources, .settings-dialog, .navigation-dialog) {
  border-width: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html[data-theme], body { transition: none; }
  html[data-theme] #install-app-button:not([hidden]) { transition: none; }
}

/* Cierre de superficies secundarias: curso, instrumentos, ajustes y juegos. */
html[data-theme] .course-section,
html[data-theme] .library-toolbar,
html[data-theme] .titration-lab-card,
html[data-theme] .nexus-game-shell {
  color: var(--color-ink);
  border-color: var(--color-line);
}
html[data-theme] .nexus-game-shell { background: var(--ui-panel); box-shadow: var(--ui-shadow); }
html[data-theme] .nexus-iframe-wrap { background: var(--color-page); }
html[data-theme] .course-lesson-card details > summary { color: var(--color-ink); }
html[data-theme] .course-lesson-card details > summary:hover { background: var(--ui-panel-hover); }
html[data-theme] .course-lesson-content,
html[data-theme] .course-lesson-heading strong,
html[data-theme] .course-progress-message,
html[data-theme] .course-quiz-result p { color: var(--color-ink-soft); }
html[data-theme] .course-lesson-heading small,
html[data-theme] .course-lessons-heading > p,
html[data-theme] .course-quiz-progress,
html[data-theme] .course-quiz-hint,
html[data-theme] .course-storage-status { color: var(--color-muted); }
html[data-theme] .course-progress-track,
html[data-theme] .course-quiz-track { background: var(--ui-panel-hover); }
html[data-theme] .course-complete-button,
html[data-theme] .course-quiz-button {
  border-color: var(--color-brand);
  color: var(--color-brand-strong);
  background: var(--ui-panel);
}
html[data-theme] .course-complete-button:hover,
html[data-theme] .course-quiz-button:hover:not(:disabled) {
  border-color: var(--color-brand-strong);
  color: var(--color-page);
  background: var(--color-brand-strong);
}
html[data-theme] .course-quiz-shell .course-quiz-button {
  border-color: var(--color-brand-strong);
  color: var(--color-page);
  background: var(--color-brand-strong);
}
html[data-theme] .course-quiz-shell .course-quiz-button:disabled { opacity: .55; }
html[data-theme] .course-quiz-result.is-not-passed .course-result-score { color: #c65c58; }
html[data-theme="dark"] .course-quiz-result.is-not-passed .course-result-score { color: #ffaaa2; }
html[data-theme] .course-sources { color: var(--color-ink-soft); }
html[data-theme] .course-sources a { color: var(--color-brand-strong); }

html[data-theme] .titration-lab-card {
  background: var(--ui-panel);
  box-shadow: var(--ui-shadow);
}
html[data-theme] .titration-live-status {
  border-color: color-mix(in srgb, var(--color-success) 45%, var(--color-line));
  color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 12%, var(--ui-panel));
}
html[data-theme] .ph-interpretation {
  border-color: var(--color-line-strong);
  color: var(--color-brand-strong);
  background: var(--color-brand-soft);
}
html[data-theme] .instrument-panel-divider { background: var(--color-line); }
html[data-theme] .titration-chart-wrap { border-color: var(--color-line); background: var(--ui-panel); }
html[data-theme] .chart-axis-x,
html[data-theme] .chart-axis-y,
html[data-theme] .titration-readout-row,
html[data-theme] .readout-caption { color: var(--color-muted); }
html[data-theme] .titration-readout-row strong,
html[data-theme] .equivalence-readout strong { color: var(--color-ink); }

html[data-theme] .library-card-top,
html[data-theme] .library-formula,
html[data-theme] .library-constant-value,
html[data-theme] .library-reference-card details,
html[data-theme] .library-reference-card summary { color: var(--color-ink-soft); }
html[data-theme] .library-card-icon,
html[data-theme] .library-search-shortcut { border-color: var(--color-line); color: var(--color-brand-strong); background: var(--color-brand-soft); }
html[data-theme] .library-reference-card summary { color: var(--color-brand-strong); }
html[data-theme] .library-reference-card details p,
html[data-theme] .library-disclaimer { color: var(--color-muted); }

html[data-theme] .settings-reset-button,
html[data-theme] .settings-icon-button { border-color: var(--color-line-strong); color: var(--color-ink-soft); background: var(--ui-panel); }
html[data-theme] .settings-reset-button:hover,
html[data-theme] .settings-icon-button:hover { border-color: var(--color-brand); color: var(--color-brand-strong); background: var(--ui-panel-hover); }
html[data-theme] .settings-switch { background: var(--color-line-strong); }
html[data-theme] .settings-switch-row input:checked + .settings-switch { background: var(--color-brand); }
html[data-theme] .settings-switch::after { background: var(--ui-panel); box-shadow: 0 1px 4px rgba(0,0,0,.25); }

/* Los botones de acción secundaria y el instalador comparten la misma lógica
   de contraste. El instalador conserva un acento propio, legible en ambos temas. */
html[data-theme="light"] #install-app-button:not([hidden]) { box-shadow: 0 4px 14px rgba(23, 61, 112, .10); }
html[data-theme="dark"] #install-app-button:not([hidden]) { box-shadow: 0 4px 18px rgba(0, 0, 0, .28); }
html[data-theme] #install-app-button:not([hidden]):active { transform: translateY(0); }
html[data-theme] #install-app-button:focus-visible { outline-offset: 4px; }

/* Los marcos de PhET, el videojuego y las visualizaciones científicas son
   contenido embebido/ilustrativo: conservan su paleta propia, no la del chrome. */
html[data-theme="light"] .nexus-game-toolbar,
html[data-theme="light"] .nexus-frame-caption { color-scheme: light; }
html[data-theme="dark"] .nexus-game-toolbar,
html[data-theme="dark"] .nexus-frame-caption { color-scheme: dark; }

/* V21.1 · Ajustes tras la inspección de contraste en navegador. */
html[data-theme] #install-app-button:not([hidden]) span,
html[data-theme] #install-app-button:not([hidden]) [data-i18n] {
  color: inherit !important;
}
html[data-theme] .status-dot { color: var(--color-success); }
html[data-theme] .scope-item strong { color: var(--color-ink); }
html[data-theme] .lab-subheading h3 { color: var(--color-ink); }
html[data-theme] .lab-subheading > p { color: var(--color-muted); }
html[data-theme] .phet-index,
html[data-theme] .planned-simulations .lab-card > span,
html[data-theme] .library-card-tag { color: var(--color-brand-strong); }
html[data-theme] .periodic-workbench .v11-quiz-icon { color: var(--color-brand-strong); }
html[data-theme] .periodic-workbench .v11-detail-hint,
html[data-theme] .periodic-workbench .v11-data-note,
html[data-theme] .periodic-workbench .v11-table-legend,
html[data-theme] .periodic-workbench .v11-legend-note,
html[data-theme] .periodic-workbench .v11-question-note,
html[data-theme] .periodic-workbench .v11-property-label { color: var(--color-muted); }
html[data-theme] .field-with-unit b,
html[data-theme] .range-scale,
html[data-theme] .chart-axis-x,
html[data-theme] .chart-axis-y,
html[data-theme] .readout-caption,
html[data-theme] .equivalence-readout > span { color: var(--color-muted); }
html[data-theme] .navigation-dialog-kicker,
html[data-theme] .navigation-dialog-mark { color: var(--color-accent); }
html[data-theme] .navigation-dialog-description,
html[data-theme] .navigation-dialog-footer,
html[data-theme] .settings-kicker { color: var(--color-muted); }
html[data-theme] .lab3d-status { color: var(--color-muted) !important; }

/* La vista previa de LAB3D es una ilustración de interfaz, no una foto:
   adopta también la paleta clara para que no parezca un bloque oscuro aislado. */
html[data-theme="light"] .lab3d-portal-visual {
  background: radial-gradient(ellipse at 51% 42%, #e8f4f7 0%, #dceaf3 42%, #cfdeec 78%, #c8d8e8 100%);
}
html[data-theme="light"] .lab3d-portal-visual::before {
  background: linear-gradient(135deg, rgba(42, 135, 153, .08), transparent 42%),
              linear-gradient(0deg, rgba(255, 255, 255, .24), transparent 55%);
}
html[data-theme="light"] .lab3d-visual-grid {
  background-image: linear-gradient(rgba(42, 86, 128, .13) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(42, 86, 128, .13) 1px, transparent 1px);
}
html[data-theme="light"] .lab3d-visual-orbit { border-color: rgba(28, 112, 132, .42); }
html[data-theme="light"] .lab3d-visual-orbit-b { border-color: rgba(54, 105, 164, .34); }
html[data-theme="light"] .lab3d-visual-orbit-c { border-color: rgba(158, 105, 37, .34); }
html[data-theme="light"] .lab3d-visual-readout {
  border-color: #b7cbdc;
  background: rgba(255, 255, 255, .91);
  box-shadow: 0 8px 24px rgba(37, 65, 93, .12);
  backdrop-filter: blur(12px);
}
html[data-theme="light"] .lab3d-visual-readout small { color: #49647e; }
html[data-theme="light"] .lab3d-visual-readout strong { color: #173d70; }
html[data-theme="light"] .lab3d-visual-label { color: #405b76; }
html[data-theme="light"] .lab3d-visual-flask::before,
html[data-theme="light"] .lab3d-visual-flask::after { border-color: rgba(55, 103, 139, .72); }

html[data-theme="dark"] .feature-section :is(h2, h3, h4),
html[data-theme="dark"] .lab-subheading :is(h2, h3, h4) { color: var(--color-ink); }
html[data-theme="dark"] .phet-index,
html[data-theme="dark"] .planned-simulations .lab-card > span,
html[data-theme="dark"] .library-card-tag { color: #a9caff; }
html[data-theme="dark"] .status-dot { color: #77dcb0; }
html[data-theme="dark"] .navigation-dialog-kicker,
html[data-theme="dark"] .navigation-dialog-mark { color: #8ce7df; }
html[data-theme="dark"] .navigation-dialog-description,
html[data-theme="dark"] .navigation-dialog-footer,
html[data-theme="dark"] .settings-kicker { color: #b8c9dc; }
html[data-theme="dark"] .lab3d-visual-readout {
  border-color: rgba(164, 220, 239, .28);
  background: rgba(5, 20, 37, .72);
}
html[data-theme="dark"] .lab3d-visual-readout small { color: #a8d6e5; }
html[data-theme="dark"] .lab3d-visual-readout strong { color: #f0f8ff; }
html[data-theme="dark"] .lab3d-visual-label { color: #b5dbe6; }

/* El instalador comparte estilos de .button-secondary en hojas antiguas.
   Este selector explícito tiene prioridad para evitar que herede colores viejos. */
html[data-theme="light"] button#install-app-button.button.button-secondary:not([hidden]) {
  border-color: #a9c0df !important;
  color: #173d70 !important;
  background: #e5eefb !important;
}
html[data-theme="dark"] button#install-app-button.button.button-secondary:not([hidden]) {
  border-color: #3f8588 !important;
  color: #d9fbf5 !important;
  background: #173a4a !important;
}
html[data-theme="light"] button#install-app-button.button.button-secondary:not([hidden]) span,
html[data-theme="dark"] button#install-app-button.button.button-secondary:not([hidden]) span {
  color: inherit !important;
}
html[data-theme="light"] button#install-app-button.button.button-secondary:not([hidden]):hover {
  color: #172b45 !important;
  background: #e8f1fa !important;
}
html[data-theme="dark"] button#install-app-button.button.button-secondary:not([hidden]):hover {
  color: #e8f0fa !important;
  background: #1b354d !important;
}
html[data-contrast="high"][data-theme="light"] button#install-app-button.button.button-secondary:not([hidden]) {
  border-color: #10243b !important;
  color: #10243b !important;
  background: #ffffff !important;
}
html[data-contrast="high"][data-theme="dark"] button#install-app-button.button.button-secondary:not([hidden]) {
  border-color: #ffffff !important;
  color: #ffffff !important;
  background: #000000 !important;
}
html[data-contrast="high"] button#install-app-button.button.button-secondary:not([hidden]) span {
  color: inherit !important;
}
