/* ═══════════════════════════════════════════════════════════════
   accessibility.css — Shared across all pages
   WCAG 2.1 AA compliance layer
   ═══════════════════════════════════════════════════════════════ */

/* ── 1. MUTED COLOR FIX (ratio was ~4.2:1 → now 4.6:1) ───────── */
:root {
  --muted: #8892b8;   /* was #7a85a8 — bumped for WCAG AA 4.5:1 on dark bg */
}

/* ── 2. DYSLEXIA FONT ─────────────────────────────────────────── */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/fonts/OpenDyslexic-Regular.otf') format('opentype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/fonts/OpenDyslexic-Bold.otf') format('opentype');
  font-weight: 700;
  font-display: swap;
}

body.dyslexia-font,
body.dyslexia-font * {
  font-family: 'OpenDyslexic', sans-serif !important;
  letter-spacing: 0.05em;
  word-spacing: 0.12em;
  line-height: 1.9 !important;
}

/* ── 3. TEXT SCALING ──────────────────────────────────────────── */
html.text-scale-110 { font-size: 110%; }
html.text-scale-125 { font-size: 125%; }
html.text-scale-150 { font-size: 150%; }
html.text-scale-175 { font-size: 175%; }
html.text-scale-200 { font-size: 200%; }

/* Ensure nothing breaks at 200% */
html.text-scale-150 body,
html.text-scale-175 body,
html.text-scale-200 body {
  overflow-x: hidden;
}
html.text-scale-150 nav,
html.text-scale-175 nav,
html.text-scale-200 nav {
  height: auto;
  min-height: var(--nav-h);
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

/* ── 4. HIGH CONTRAST THEMES ──────────────────────────────────── */

/* Theme A: High contrast dark (stronger blacks & whites) */
body.hc-dark {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface2: #111111;
  --border: rgba(255,255,255,0.35);
  --border-hi: rgba(255,255,255,0.6);
  --text: #ffffff;
  --muted: #d0d4e8;
  --accent: #ffe033;
  --accent2: #80b8ff;
  background: #000 !important;
  color: #fff !important;
}
body.hc-dark .panel,
body.hc-dark .viz-card,
body.hc-dark .controls,
body.hc-dark .noc-card,
body.hc-dark .module-card,
body.hc-dark .mission-card {
  border-width: 2px !important;
  border-color: rgba(255,255,255,0.5) !important;
}
body.hc-dark a:not(.btn-primary):not(.btn-secondary):not(.module-card):not(.nav-back) {
  color: #80b8ff !important;
  text-decoration: underline !important;
}

/* Theme B: High contrast light */
body.hc-light {
  --bg: #ffffff;
  --surface: #f0f0f0;
  --surface2: #e0e0e0;
  --border: rgba(0,0,0,0.4);
  --border-hi: rgba(0,0,0,0.7);
  --text: #000000;
  --muted: #1a1a1a;
  --accent: #8b5c00;
  --accent2: #00318c;
  background: #fff !important;
  color: #000 !important;
}
body.hc-light #star-canvas { opacity: 0 !important; }

/* Titres hardcodés en #fff dans les pages */
body.hc-light h1,
body.hc-light h2,
body.hc-light h3,
body.hc-light h4,
body.hc-light .section-title,
body.hc-light .panel h2,
body.hc-light .mission-card h3,
body.hc-light .noc-card h3,
body.hc-light .module-body h3,
body.hc-light .mod-body h3,
body.hc-light .noc-card h3 { color: #000 !important; }

/* Textes muted et corps */
body.hc-light .panel p,
body.hc-light .steps li p,
body.hc-light .section-body,
body.hc-light .module-body p,
body.hc-light .mod-body p,
body.hc-light .noc-desc { color: #111 !important; }

/* Fonds de cartes */
body.hc-light .panel { background: #f5f5f5 !important; }
body.hc-light .module-card,
body.hc-light .mod-card,
body.hc-light .mission-card,
body.hc-light .noc-card,
body.hc-light .partner-card { background: #e8e8e8 !important; }

/* strong hardcodés en #fff */
body.hc-light strong,
body.hc-light b { color: #000 !important; }

/* viz-col : carte orrery + contrôles (solar_system et pages similaires) */
body.hc-light .viz-card,
body.hc-light .controls { background: #e8e8e8 !important; border-color: rgba(0,0,0,0.3) !important; }

body.hc-light .viz-card h2,
body.hc-light .ctrl-row label,
body.hc-light .legend-item { color: #000 !important; }

body.hc-light .legend-item:hover { background: rgba(0,0,0,0.07) !important; }

body.hc-light .status-strip { background: #d8d8d8 !important; border-color: rgba(0,0,0,0.25) !important; }
body.hc-light .status-strip span { color: #111 !important; }

body.hc-light .orrery-wrap { background: radial-gradient(circle at 50% 50%, #c8ccd8 0%, #a0a8b8 100%) !important; }

/* Tooltip planète */
body.hc-light #planet-tooltip { background: #fff !important; border-color: rgba(0,0,0,0.4) !important; color: #000 !important; }
body.hc-light #planet-tooltip strong { color: #8b5c00 !important; }

body.hc-light #sel-popup { background: #fff !important; }
body.hc-light #phase-desc , body.hc-light #play-txt{ color: #fff !important; }

/* Nav : fond blanc, textes noirs */
body.hc-light nav { background: #fff !important; border-bottom-color: rgba(0,0,0,0.3) !important; }
body.hc-light .nav-logo,
body.hc-light .nav-links a { color: #000 !important; }

/* Theme C: Yellow on Black (optimised for low-vision) */
body.hc-yellow {
  --bg: #000000;
  --surface: #111100;
  --surface2: #1a1a00;
  --border: rgba(255,255,0,0.45);
  --border-hi: rgba(255,255,0,0.75);
  --text: #ffff00;
  --muted: #ffff99;
  --accent: #ffff00;
  --accent2: #00ffff;
  background: #000 !important;
  color: #ff0 !important;
}
body.hc-yellow * { color: #ffff00 !important; }
body.hc-yellow a,
body.hc-yellow .accent-yellow,
body.hc-yellow .section-label,
body.hc-yellow .mod-tag { color: #ffff00 !important; }
body.hc-yellow .accent-blue,
body.hc-yellow .nav-badge,
body.hc-yellow .tts-btn,
body.hc-yellow .step-num { color: #00ffff !important; }
body.hc-yellow .panel,
body.hc-yellow .viz-card,
body.hc-yellow .module-card,
body.hc-yellow .noc-card,
body.hc-yellow .mission-card {
  background: #000 !important;
  border: 2px solid #ffff00 !important;
}
body.hc-yellow .btn-primary {
  background: #ffff00 !important;
  color: #000 !important;
}
body.hc-yellow .skip-link {
  background: #ffff00 !important;
  color: #000 !important;
}

/* ── 5. REDUCE MOTION ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #star-canvas { display: none !important; }
}

/* Applied by JS toggle (animations-paused class on body) */
body.animations-paused *,
body.animations-paused *::before,
body.animations-paused *::after {
  animation-play-state: paused !important;
  transition: none !important;
}
body.animations-paused #star-canvas { opacity: 0; }

/* ── 6. ACCESSIBILITY CONTROL PANEL ──────────────────────────── */
#a11y-panel-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent, #f5c842);
  color: #04081a;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  transition: transform 0.2s, box-shadow 0.2s;
  font-size: 22px;
  line-height: 1;
}
#a11y-panel-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.6); }
#a11y-panel-toggle:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
#a11y-panel-toggle[aria-expanded="true"] { background: var(--accent2, #5b9cf6); color: #fff; }
/* Tooltip on panel toggle button */
#a11y-panel-toggle::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  background: rgba(4,8,26,0.95);
  color: #e8eaf6;
  font-family: var(--font-b, 'DM Sans', sans-serif);
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.12);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 9001;
}
#a11y-panel-toggle:hover::after,
#a11y-panel-toggle:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}
[dir="rtl"] #a11y-panel-toggle::after {
  right: auto;
  left: 0;
}


/* Adjust position when TTS bar is visible */
body[data-tts-open="true"] #a11y-panel-toggle { bottom: 90px; }

#a11y-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 8999;
  width: 290px;
  background: #07102e;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 16px 56px rgba(0,0,0,0.7);
  display: none;
  flex-direction: column;
  gap: 18px;
  backdrop-filter: blur(24px);
}
body[data-tts-open="true"] #a11y-panel { bottom: 154px; }
#a11y-panel.open { display: flex; }

/* Panel inner styles */
#a11y-panel h3 {
  font-family: var(--font-d, 'Outfit', sans-serif);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted, #8892b8);
  margin: 0 0 2px;
}

.a11y-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Contrast buttons */
.a11y-contrast-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.a11y-contrast-btns button {
  flex: 1;
  min-width: 60px;
  padding: 7px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
  line-height: 1.3;
  text-align: center;
}
.a11y-contrast-btns button:hover { transform: translateY(-1px); }
.a11y-contrast-btns button:focus-visible { outline: 3px solid var(--accent, #f5c842); outline-offset: 2px; }
.a11y-contrast-btns button.active { border-width: 2px; }

.btn-hc-default { background: #1a2a4a; color: #e8eaf6; }
.btn-hc-default.active { border-color: #e8eaf6 !important; background: #2a3f6e; }
.btn-hc-dark    { background: #000; color: #fff; }
.btn-hc-dark.active { border-color: #fff !important; }
.btn-hc-light   { background: #fff; color: #000; }
.btn-hc-light.active { border-color: #000 !important; }
.btn-hc-yellow  { background: #000; color: #ff0; }
.btn-hc-yellow.active { border-color: #ff0 !important; }

/* Text scale slider */
.a11y-scale-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.a11y-scale-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent, #f5c842);
  height: 4px;
  cursor: pointer;
}
.a11y-scale-val {
  font-family: var(--font-d, sans-serif);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent, #f5c842);
  min-width: 38px;
  text-align: right;
}

/* Toggle switches */
.a11y-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.a11y-toggle-row label {
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text, #e8eaf6);
  cursor: pointer;
}
.a11y-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.a11y-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.a11y-switch-track {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 11px;
  border: 1px solid rgba(255,255,255,0.2);
  transition: background 0.2s;
  cursor: pointer;
}
.a11y-switch input:checked ~ .a11y-switch-track {
  background: var(--accent, #f5c842);
  border-color: transparent;
}
.a11y-switch-knob {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
  pointer-events: none;
}
.a11y-switch input:checked ~ .a11y-switch-knob {
  transform: translateX(18px);
}
.a11y-switch input:focus-visible ~ .a11y-switch-track {
  outline: 3px solid var(--accent, #f5c842);
  outline-offset: 2px;
}

/* Reset link */
#a11y-reset {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted, #8892b8);
  font-size: 0.76rem;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  width: 100%;
  transition: border-color 0.2s, color 0.2s;
}
#a11y-reset:hover { border-color: rgba(255,255,255,0.3); color: var(--text, #e8eaf6); }
#a11y-reset:focus-visible { outline: 3px solid var(--accent, #f5c842); outline-offset: 2px; }

/* RTL adjustments */
[dir="rtl"] #a11y-panel-toggle,
[dir="rtl"] #a11y-panel {
  right: auto;
  left: 24px;
}

.a11y-keynav-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0 2px;
  border-top: 1px solid rgba(255,255,255,0.07);
  margin-top: 4px;
}
.a11y-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  border-bottom-width: 3px;
  border-radius: 5px;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1;
  flex-shrink: 0;
}
.a11y-keynav-label {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.3;
}