/* ==============================================
   Reverse Aging - Accessibility Widget & Features
   Standards: WCAG 2.1 AA | IS 5568 | Section 508 | EN 301 549
   All feature classes applied to <html> element
   ============================================== */

/* === CSS Variables === */
:root {
  --a11y-primary: #0a6e5c;
  --a11y-focus: #ff6600;
  --a11y-focus-kb: #0066ff;
  --a11y-panel-width: 340px;
  --a11y-btn-size: 56px;
  --a11y-z-btn: 10000;
  --a11y-z-panel: 10001;
  --a11y-z-overlay: 10002;
}

/* === Skip to Content Link === */
.a11y-skip-link {
  position: fixed;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100000;
  background: var(--a11y-primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: 0 0 8px 8px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s;
  white-space: nowrap;
}

.a11y-skip-link:focus {
  top: 0;
  outline: 3px solid var(--a11y-focus);
}

/* === Toggle Button === */
.a11y-toggle-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: var(--a11y-z-btn);
  width: var(--a11y-btn-size);
  height: var(--a11y-btn-size);
  border-radius: 50%;
  background: var(--a11y-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  padding: 0;
}

.a11y-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.a11y-toggle-btn:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 3px;
}

html[dir="ltr"] .a11y-toggle-btn {
  left: auto;
  right: 20px;
}

/* === Panel === */
.a11y-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--a11y-panel-width);
  max-width: 92vw;
  z-index: var(--a11y-z-panel);
  background: #fff;
  box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  direction: rtl;
  font-family: 'Heebo', Arial, sans-serif;
}

.a11y-panel.open {
  transform: translateX(0);
}

html[dir="ltr"] .a11y-panel {
  left: auto;
  right: 0;
  direction: ltr;
  transform: translateX(100%);
  box-shadow: -4px 0 24px rgba(0,0,0,0.2);
}

html[dir="ltr"] .a11y-panel.open {
  transform: translateX(0);
}

/* Panel Backdrop */
.a11y-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: calc(var(--a11y-z-panel) - 1);
  display: none;
}

.a11y-backdrop.open {
  display: block;
}

/* Panel Header */
.a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  background: var(--a11y-primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}

.a11y-panel-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.a11y-panel-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0;
}

.a11y-panel-close:hover {
  background: rgba(255,255,255,0.2);
}

.a11y-panel-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Panel Body */
.a11y-panel-body {
  padding: 12px 16px 24px;
}

/* Reset Button */
.a11y-reset-btn {
  width: 100%;
  padding: 10px;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #c00;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
  transition: background 0.2s;
  font-family: inherit;
}

.a11y-reset-btn:hover {
  background: #ffe0e0;
}

.a11y-reset-btn:focus-visible {
  outline: 2px solid var(--a11y-focus);
  outline-offset: 2px;
}

.a11y-reset-btn .a11y-icon {
  font-size: 1.2rem;
}

/* Section */
.a11y-section {
  margin-bottom: 16px;
}

.a11y-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding: 0 4px;
}

/* Option Button (toggle switch) */
.a11y-option {
  width: 100%;
  padding: 10px 12px;
  background: #f8f9fa;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
  font-size: 0.92rem;
  color: #333;
  text-align: start;
}

.a11y-option:hover {
  background: #eef7f5;
  border-color: var(--a11y-primary);
}

.a11y-option:focus-visible {
  outline: 2px solid var(--a11y-focus);
  outline-offset: 2px;
}

.a11y-option[aria-checked="true"] {
  background: #e0f2ef;
  border-color: var(--a11y-primary);
  color: var(--a11y-primary);
  font-weight: 600;
}

.a11y-option .a11y-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: #e8e8e8;
  border-radius: 6px;
}

.a11y-option[aria-checked="true"] .a11y-icon {
  background: var(--a11y-primary);
  color: #fff;
}

.a11y-option-text {
  flex: 1;
}

.a11y-toggle-indicator {
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 10px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

.a11y-toggle-indicator::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

html[dir="rtl"] .a11y-toggle-indicator::after,
.a11y-panel .a11y-toggle-indicator::after {
  left: auto;
  right: 2px;
}

.a11y-option[aria-checked="true"] .a11y-toggle-indicator {
  background: var(--a11y-primary);
}

.a11y-option[aria-checked="true"] .a11y-toggle-indicator::after {
  transform: translateX(-16px);
}

html[dir="rtl"] .a11y-option[aria-checked="true"] .a11y-toggle-indicator::after,
.a11y-panel .a11y-option[aria-checked="true"] .a11y-toggle-indicator::after {
  transform: translateX(16px);
}

/* Font Size Control */
.a11y-font-size-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #f8f9fa;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  margin-bottom: 6px;
}

.a11y-control-label {
  font-size: 0.92rem;
  color: #333;
}

.a11y-font-size-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.a11y-font-size-buttons button {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  font-family: inherit;
  color: #333;
}

.a11y-font-size-buttons button:hover {
  background: #eef7f5;
  border-color: var(--a11y-primary);
}

.a11y-font-size-buttons button:focus-visible {
  outline: 2px solid var(--a11y-focus);
  outline-offset: 2px;
}

.a11y-font-size-value {
  min-width: 42px;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--a11y-primary);
}

/* Statement Link */
.a11y-statement-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eee;
  text-align: center;
}

.a11y-statement-link {
  display: inline-block;
  color: var(--a11y-primary);
  font-weight: 600;
  text-decoration: underline;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.a11y-contact-info {
  font-size: 0.8rem;
  color: #888;
  margin: 0;
}

.a11y-contact-info a {
  color: var(--a11y-primary);
}

/* Live Region (screen reader announcements) */
.a11y-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ========================================
   FEATURE STYLES
   All applied via classes on <html>
   ======================================== */

/* === Font Size Scaling === */
html[data-a11y-fontsize="1"] { font-size: 112.5%; }
html[data-a11y-fontsize="2"] { font-size: 125%; }
html[data-a11y-fontsize="3"] { font-size: 137.5%; }
html[data-a11y-fontsize="4"] { font-size: 150%; }
html[data-a11y-fontsize="5"] { font-size: 162.5%; }

/* === High Contrast === */
html.a11y-high-contrast {
  --bg-light: #ffffff;
  --bg-white: #ffffff;
  --bg-dark: #000000;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --text-dark: #000000;
  --text-primary: #ffffff;
  --text-secondary: #000000;
  --text-on-dark: #ffffff;
}

html.a11y-high-contrast body {
  background: #fff !important;
  color: #000 !important;
}

html.a11y-high-contrast .main-content {
  background: #fff;
}

html.a11y-high-contrast a {
  color: #000080 !important;
  text-decoration: underline !important;
}

html.a11y-high-contrast .article-card,
html.a11y-high-contrast .card-body {
  background: #fff !important;
  border: 2px solid #000 !important;
}

html.a11y-high-contrast .hero,
html.a11y-high-contrast .top-bar {
  background: #000 !important;
}

html.a11y-high-contrast .btn,
html.a11y-high-contrast button {
  border: 2px solid #000 !important;
}

/* === Inverted Colors (Dark Mode) === */
html.a11y-inverted-colors {
  filter: invert(1) hue-rotate(180deg);
}

html.a11y-inverted-colors img,
html.a11y-inverted-colors video,
html.a11y-inverted-colors picture,
html.a11y-inverted-colors .logo-img,
html.a11y-inverted-colors .article-featured-img,
html.a11y-inverted-colors .card-image img,
html.a11y-inverted-colors [style*="background-image"],
html.a11y-inverted-colors .a11y-toggle-btn,
html.a11y-inverted-colors .a11y-panel {
  filter: invert(1) hue-rotate(180deg);
}

/* === Grayscale === */
html.a11y-grayscale {
  filter: grayscale(1);
}

/* === Underline Links === */
html.a11y-underline-links a:not(.a11y-option):not(.a11y-toggle-btn):not(.a11y-panel-close):not(.a11y-reset-btn) {
  text-decoration: underline !important;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

/* === Readable Font === */
html.a11y-readable-font,
html.a11y-readable-font * {
  font-family: Arial, 'Segoe UI', Helvetica, sans-serif !important;
  letter-spacing: 0.03em;
}

/* === Text Spacing === */
html.a11y-text-spacing .main-content,
html.a11y-text-spacing .main-content * {
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}

/* === Line Height === */
html.a11y-line-height .main-content,
html.a11y-line-height .main-content p,
html.a11y-line-height .main-content li,
html.a11y-line-height .main-content span {
  line-height: 2.2 !important;
}

/* === Highlight Focus === */
html.a11y-highlight-focus *:focus {
  outline: 3px solid var(--a11y-focus) !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 6px rgba(255, 102, 0, 0.25) !important;
}

/* === Keyboard Navigation === */
html.a11y-keyboard-nav *:focus-visible {
  outline: 3px dashed var(--a11y-focus-kb) !important;
  outline-offset: 4px !important;
}

/* === Hide Images === */
html.a11y-hide-images img:not(.a11y-panel img),
html.a11y-hide-images picture,
html.a11y-hide-images video,
html.a11y-hide-images [role="img"] {
  opacity: 0.05 !important;
}

/* === Stop Animations === */
html.a11y-stop-animations *,
html.a11y-stop-animations *::before,
html.a11y-stop-animations *::after {
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}

html.a11y-stop-animations {
  scroll-behavior: auto !important;
}

/* === Big Cursor === */
html.a11y-big-cursor,
html.a11y-big-cursor * {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M8 4l28 20-12 2 8 16-6 3-8-16-10 9z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 2, auto !important;
}

/* === Reading Guide === */
.a11y-reading-guide-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 14px;
  background: rgba(255, 255, 0, 0.3);
  border-top: 2px solid rgba(255, 180, 0, 0.6);
  border-bottom: 2px solid rgba(255, 180, 0, 0.6);
  pointer-events: none;
  z-index: var(--a11y-z-overlay);
  transition: top 0.05s linear;
}

html.a11y-reading-guide .a11y-reading-guide-bar {
  display: block;
}

/* === Highlight Headings === */
html.a11y-highlight-headings .main-content h1,
html.a11y-highlight-headings .main-content h2,
html.a11y-highlight-headings .main-content h3,
html.a11y-highlight-headings .main-content h4,
html.a11y-highlight-headings .main-content h5,
html.a11y-highlight-headings .main-content h6 {
  outline: 2px solid #00bcd4 !important;
  outline-offset: 4px;
  background: rgba(0, 188, 212, 0.06);
  padding: 4px 8px;
}

/* === Highlight Links === */
html.a11y-highlight-links .main-content a:not(.a11y-option) {
  background-color: rgba(255, 255, 0, 0.3) !important;
  outline: 1px solid #ccaa00 !important;
  padding: 2px 4px;
  border-radius: 2px;
}

/* === Page Structure Overlay === */
.a11y-structure-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  max-width: 90vw;
  max-height: 100vh;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
  padding: 20px;
  z-index: var(--a11y-z-overlay);
  font-size: 14px;
  direction: rtl;
}

html[dir="ltr"] .a11y-structure-overlay {
  left: auto;
  right: 0;
  direction: ltr;
}

html.a11y-page-structure .a11y-structure-overlay {
  display: block;
}

.a11y-structure-overlay h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #555;
  color: #00bcd4;
}

.a11y-structure-overlay ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.a11y-structure-overlay li {
  margin-bottom: 4px;
}

.a11y-structure-overlay a {
  color: #ddd;
  text-decoration: none;
  display: block;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.15s;
}

.a11y-structure-overlay a:hover,
.a11y-structure-overlay a:focus {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.a11y-structure-overlay .a11y-h1 { padding-right: 0; font-weight: 700; }
.a11y-structure-overlay .a11y-h2 { padding-right: 16px; }
.a11y-structure-overlay .a11y-h3 { padding-right: 32px; font-size: 0.9em; }
.a11y-structure-overlay .a11y-h4 { padding-right: 48px; font-size: 0.85em; }
.a11y-structure-overlay .a11y-h5 { padding-right: 64px; font-size: 0.8em; }
.a11y-structure-overlay .a11y-h6 { padding-right: 80px; font-size: 0.8em; }

html[dir="ltr"] .a11y-structure-overlay .a11y-h1 { padding-right: 0; padding-left: 0; }
html[dir="ltr"] .a11y-structure-overlay .a11y-h2 { padding-right: 0; padding-left: 16px; }
html[dir="ltr"] .a11y-structure-overlay .a11y-h3 { padding-right: 0; padding-left: 32px; }
html[dir="ltr"] .a11y-structure-overlay .a11y-h4 { padding-right: 0; padding-left: 48px; }
html[dir="ltr"] .a11y-structure-overlay .a11y-h5 { padding-right: 0; padding-left: 64px; }
html[dir="ltr"] .a11y-structure-overlay .a11y-h6 { padding-right: 0; padding-left: 80px; }

.a11y-structure-close {
  position: absolute;
  top: 10px;
  left: 10px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

html[dir="ltr"] .a11y-structure-close {
  left: auto;
  right: 10px;
}

.a11y-structure-close:hover {
  color: #fff;
}

/* === Responsive === */
@media (max-width: 768px) {
  .a11y-toggle-btn {
    width: 48px;
    height: 48px;
    bottom: 14px;
    left: 14px;
  }

  html[dir="ltr"] .a11y-toggle-btn {
    left: auto;
    right: 14px;
  }

  .a11y-panel {
    width: 100%;
    max-width: 100vw;
  }
}

/* === Print === */
@media print {
  .a11y-toggle-btn,
  .a11y-panel,
  .a11y-backdrop,
  .a11y-skip-link,
  .a11y-reading-guide-bar,
  .a11y-structure-overlay {
    display: none !important;
  }
}
