/* Accessibility Tools Styles */

/* --- Variables --- */
:root {
  --a11y-bg-color: #000000;
  --a11y-text-color: #ffff00;
  --a11y-link-color: #00ffff;
  --a11y-btn-color: #ffff00;
  --a11y-border-color: #ffffff;
  --a11y-brand-color: #9f2380;
  --a11y-brand-hover: #831d69;
}

/* --- High Contrast Mode --- */
body.a11y-high-contrast {
  background-color: var(--a11y-bg-color) !important;
  color: var(--a11y-text-color) !important;
}

body.a11y-high-contrast * {
  background-color: var(--a11y-bg-color) !important;
  color: var(--a11y-text-color) !important;
  border-color: var(--a11y-border-color) !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

body.a11y-high-contrast a,
body.a11y-high-contrast a:hover,
body.a11y-high-contrast a:visited {
  color: var(--a11y-link-color) !important;
  text-decoration: underline !important;
}

body.a11y-high-contrast img {
  filter: grayscale(100%) contrast(120%);
}

body.a11y-high-contrast .btn,
body.a11y-high-contrast button {
  background-color: #333 !important;
  color: var(--a11y-btn-color) !important;
  border: 2px solid var(--a11y-btn-color) !important;
}

/* --- Font Size Adjustment --- */
html.a11y-font-increase-1 { font-size: 110% !important; }
html.a11y-font-increase-2 { font-size: 125% !important; }
html.a11y-font-increase-3 { font-size: 140% !important; }

/* --- Spacing Adjustment --- */
body.a11y-spacing * {
  line-height: 1.8 !important;
  letter-spacing: 0.1em !important;
  word-spacing: 0.2em !important;
}
body.a11y-spacing p {
  margin-bottom: 2em !important;
}

/* --- New: Highlight Links --- */
body.a11y-highlight-links a {
  background-color: #ffff00 !important;
  color: #000000 !important;
  text-decoration: underline !important;
  text-decoration-thickness: 3px !important;
  font-weight: bold !important;
  padding: 2px 4px !important;
  border-radius: 4px !important;
}

/* --- New: Dyslexia Friendly Font --- */
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@400;500;600&display=swap');

body.a11y-dyslexia * {
  font-family: 'Lexend', 'Comic Sans MS', sans-serif !important;
}

/* --- New: Large Cursor --- */
body.a11y-large-cursor,
body.a11y-large-cursor * {
  cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="black" stroke="white" stroke-width="2" d="M7 2l12 11.2-5.8.5 3.3 7.3-2.2.9-3.2-7.4-4.4 4.7z"/></svg>') 0 0, auto !important;
}

/* --- New: Reading Line --- */
#a11y-reading-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 4px;
  background-color: var(--a11y-brand-color);
  opacity: 0.6;
  z-index: 99999;
  pointer-events: none;
  transform: translateY(-50%);
  display: none;
  box-shadow: 0 0 10px rgba(159, 35, 128, 0.5);
}

body.a11y-reading-line #a11y-reading-guide {
  display: block;
}

body.a11y-high-contrast #a11y-reading-guide {
  background-color: var(--a11y-text-color) !important;
  opacity: 0.8 !important;
  box-shadow: 0 0 10px var(--a11y-text-color) !important;
}

/* --- New: TTS Magic Pointer Mode --- */
body.a11y-reading-mode {
  cursor: help !important;
}

body.a11y-reading-mode p:hover,
body.a11y-reading-mode h1:hover,
body.a11y-reading-mode h2:hover,
body.a11y-reading-mode h3:hover,
body.a11y-reading-mode h4:hover,
body.a11y-reading-mode h5:hover,
body.a11y-reading-mode h6:hover,
body.a11y-reading-mode li:hover,
body.a11y-reading-mode .card:hover {
  outline: 2px dashed var(--a11y-brand-color) !important;
  background-color: rgba(159, 35, 128, 0.05) !important;
  border-radius: 4px;
}

/* --- New: TTS Highlight Word/Sentence --- */
.a11y-speaking-highlight {
  background-color: var(--a11y-brand-color) !important;
  color: #fff !important;
  padding: 2px 4px;
  border-radius: 4px;
  outline: 3px solid var(--a11y-brand-color) !important;
  box-shadow: 0 0 10px rgba(159, 35, 128, 0.5);
}

/* --- Accessibility Focus Indicators --- */
body.a11y-focus-visible *:focus {
  outline: 3px solid #ffd700 !important;
  outline-offset: 3px !important;
}

/* --- Accessibility Widget UI --- */
#a11y-widget-trigger {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background-color: var(--a11y-brand-color);
  color: #fff;
  border: none;
  border-radius: 50px 0 0 50px;
  padding: 10px 15px 10px 20px;
  font-size: 26px;
  z-index: 9999;
  cursor: pointer;
  box-shadow: -4px 4px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

#a11y-widget-trigger.open {
  right: 320px;
}

#a11y-widget-trigger .a11y-shortcut-hint {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.9;
  letter-spacing: 0.5px;
}

#a11y-widget-trigger:hover, #a11y-widget-trigger:focus {
  background-color: var(--a11y-brand-hover);
  padding-right: 25px;
  outline: none;
}

#a11y-toolbar {
  position: fixed;
  top: 50%;
  right: -340px;
  transform: translateY(-50%);
  width: 320px;
  background-color: #ffffff;
  border-left: 6px solid var(--a11y-brand-color);
  box-shadow: -10px 10px 30px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  padding: 25px;
  transition: right 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  border-radius: 16px 0 0 16px;
  color: #333;
  max-height: 90vh;
  overflow-y: auto;
}

#a11y-toolbar.open {
  right: 0;
}

#a11y-toolbar .a11y-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 2px solid #f0f0f0;
  padding-bottom: 15px;
}

#a11y-toolbar h3 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--a11y-brand-color);
  font-weight: 700;
}

#a11y-toolbar .close-btn {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: #999;
  transition: color 0.2s;
}

#a11y-toolbar .close-btn:hover, #a11y-toolbar .close-btn:focus {
  color: var(--a11y-brand-color);
  outline: none;
}

#a11y-toolbar .a11y-section {
  margin-bottom: 25px;
}

#a11y-toolbar h4 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: #444;
  font-weight: 600;
}

#a11y-toolbar .a11y-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

#a11y-toolbar .a11y-btn {
  padding: 12px 8px;
  border: 1px solid #e0e0e0;
  background-color: #f8f9fa;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  color: #555;
  font-weight: 500;
}

#a11y-toolbar .a11y-btn:hover, #a11y-toolbar .a11y-btn:focus {
  background-color: #fff;
  border-color: var(--a11y-brand-color);
  color: var(--a11y-brand-color);
  box-shadow: 0 4px 8px rgba(159, 35, 128, 0.1);
  outline: none;
}

#a11y-toolbar .a11y-btn.active {
  background-color: var(--a11y-brand-color);
  color: #fff;
  border-color: var(--a11y-brand-color);
  box-shadow: 0 4px 10px rgba(159, 35, 128, 0.2);
}

#a11y-toolbar .a11y-btn i {
  font-size: 1.4rem;
}

/* Button override for reset */
#btn-reset {
  grid-column: span 2;
  flex-direction: row;
  background-color: #fce4ec;
  color: var(--a11y-brand-color);
  border-color: #fce4ec;
}

#btn-reset:hover {
  background-color: #f8bbd0;
  color: var(--a11y-brand-hover);
}

/* High Contrast Adjustments for Widget */
body.a11y-high-contrast #a11y-toolbar {
  background-color: #000;
  border-color: #fff;
  border-left: 5px solid #ffff00;
}

body.a11y-high-contrast #a11y-toolbar h3,
body.a11y-high-contrast #a11y-toolbar h4,
body.a11y-high-contrast #a11y-toolbar .close-btn {
  color: #ffff00;
}

body.a11y-high-contrast #a11y-toolbar .a11y-btn {
  background-color: #333;
  color: #ffff00;
  border-color: #fff;
}

body.a11y-high-contrast #a11y-toolbar .a11y-btn.active {
  background-color: #ffff00;
  color: #000;
  border-color: #fff;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
  #a11y-toolbar {
    top: 0;
    bottom: 0;
    height: 100vh;
    max-height: 100vh;
    width: 85vw;
    right: -90vw; /* fully hide */
    transform: none; /* Remove vertical centering */
    border-radius: 16px 0 0 16px;
    padding: 20px 15px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.2);
  }
  
  #a11y-toolbar.open {
    right: 0;
  }
  
  #a11y-widget-trigger {
    padding: 8px 12px 8px 16px;
  }

  #a11y-widget-trigger.open {
    right: 85vw;
  }
  
  #a11y-toolbar .a11y-btn {
    padding: 10px 5px;
    font-size: 0.8rem;
  }
  
  #a11y-toolbar .a11y-btn i {
    font-size: 1.2rem;
  }
}

/* ========================================================
   Animaciones y Resalte de Opciones de Accesibilidad
   ======================================================== */

@keyframes a11yPulseRings {
  0% {
    box-shadow: 0 0 0 0 rgba(159, 35, 128, 0.75), 0 0 0 0 rgba(245, 158, 11, 0.5), -4px 4px 15px rgba(0, 0, 0, 0.3);
  }
  40% {
    box-shadow: 0 0 0 22px rgba(159, 35, 128, 0.28), 0 0 0 12px rgba(245, 158, 11, 0.35), -6px 6px 20px rgba(0, 0, 0, 0.35);
  }
  80% {
    box-shadow: 0 0 0 45px rgba(159, 35, 128, 0), 0 0 0 26px rgba(245, 158, 11, 0), -4px 4px 15px rgba(0, 0, 0, 0.2);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(159, 35, 128, 0), 0 0 0 0 rgba(245, 158, 11, 0), -4px 4px 15px rgba(0, 0, 0, 0.2);
  }
}

@keyframes a11yAttentionWobble {
  0%, 100% {
    transform: translateY(-50%) rotate(0deg) scale(1);
  }
  15% {
    transform: translateY(-50%) translateX(-12px) rotate(-8deg) scale(1.12);
  }
  30% {
    transform: translateY(-50%) translateX(-8px) rotate(6deg) scale(1.1);
  }
  45% {
    transform: translateY(-50%) translateX(-10px) rotate(-4deg) scale(1.08);
  }
  60% {
    transform: translateY(-50%) translateX(-6px) rotate(2deg) scale(1.04);
  }
  75% {
    transform: translateY(-50%) translateX(-8px) rotate(-1deg) scale(1.06);
  }
  90% {
    transform: translateY(-50%) translateX(-6px) rotate(0deg) scale(1.02);
  }
}

@keyframes a11yIconBounce {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

/* Estado activo del botón trigger al llamar la atención */
#a11y-widget-trigger.a11y-attention-active {
  animation: a11yPulseRings 1.8s infinite ease-out, a11yAttentionWobble 2.6s ease-in-out;
  background-color: var(--a11y-brand-hover);
  right: 6px;
  z-index: 10001;
}

/* Globo Callout flotante */
.a11y-attention-callout {
  position: fixed;
  top: 50%;
  right: 76px;
  transform: translateY(-50%) translateX(25px) scale(0.92);
  width: 320px;
  max-width: calc(100vw - 90px);
  background: #ffffff;
  border-radius: 14px;
  border-left: 5px solid var(--a11y-brand-color);
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(159, 35, 128, 0.12);
  padding: 13px 15px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.4s cubic-bezier(0.165, 0.84, 0.44, 1),
              transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
              visibility 0.4s;
  user-select: none;
}

.a11y-attention-callout.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(-50%) translateX(0) scale(1);
}

.a11y-attention-callout:hover {
  transform: translateY(-50%) translateX(-4px) scale(1.02);
  box-shadow: 0 18px 40px -5px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(159, 35, 128, 0.25);
}

.a11y-callout-icon {
  width: 42px;
  height: 42px;
  min-width: 42px;
  background: linear-gradient(135deg, var(--a11y-brand-color), #7b1261);
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 10px rgba(159, 35, 128, 0.35);
  animation: a11yIconBounce 2s infinite ease-in-out;
}

.a11y-callout-body {
  flex: 1;
  min-width: 0;
}

.a11y-callout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.a11y-callout-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--a11y-brand-color);
  background: rgba(159, 35, 128, 0.08);
  padding: 2px 7px;
  border-radius: 20px;
}

.a11y-callout-kbd kbd {
  font-size: 10px;
  padding: 1px 5px;
  background: #f1f3f5;
  color: #495057;
  border: 1px solid #ced4da;
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.a11y-callout-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #212529;
  line-height: 1.25;
  margin-bottom: 3px;
}

.a11y-callout-desc {
  font-size: 11.5px;
  color: #6c757d;
  line-height: 1.35;
}

.a11y-callout-close {
  position: absolute;
  top: 5px;
  right: 7px;
  background: transparent;
  border: none;
  color: #adb5bd;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s, background-color 0.2s;
}

.a11y-callout-close:hover {
  color: #495057;
  background: rgba(0, 0, 0, 0.06);
}

.a11y-callout-arrow {
  position: absolute;
  top: 50%;
  right: -9px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 9px solid #ffffff;
  filter: drop-shadow(2px 0 1px rgba(0, 0, 0, 0.06));
}

/* Modo Móvil */
@media (max-width: 768px) {
  .a11y-attention-callout {
    top: auto;
    bottom: 85px;
    right: 14px;
    left: 14px;
    width: auto;
    max-width: none;
    transform: translateY(20px) scale(0.95);
  }

  .a11y-attention-callout.show {
    transform: translateY(0) scale(1);
  }

  .a11y-attention-callout .a11y-callout-arrow {
    display: none;
  }
}

/* Reducción de movimiento para accesibilidad */
@media (prefers-reduced-motion: reduce) {
  #a11y-widget-trigger.a11y-attention-active {
    animation: none !important;
    box-shadow: 0 0 0 6px rgba(159, 35, 128, 0.4) !important;
  }
  .a11y-attention-callout {
    transition: opacity 0.3s ease !important;
    transform: translateY(-50%) !important;
  }
  .a11y-attention-callout.show {
    transform: translateY(-50%) !important;
  }
  .a11y-callout-icon {
    animation: none !important;
  }
}

/* Compatibilidad con Alto Contraste */
body.a11y-high-contrast .a11y-attention-callout {
  background: #000000 !important;
  color: #ffff00 !important;
  border: 2px solid #ffff00 !important;
}
body.a11y-high-contrast .a11y-callout-title,
body.a11y-high-contrast .a11y-callout-desc,
body.a11y-high-contrast .a11y-callout-badge {
  color: #ffff00 !important;
  background: transparent !important;
}
