/* ============================================================
   Accessibility Widget — Shadcn UI Custom Build
   Font: Roboto (inherited or explicit)
   ============================================================ */

/* ─── Google Font: OpenDyslexic fallback via local ─── */
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@300;400;500;600&display=swap');

/* ─── CSS Custom Properties (Shadcn UI Monochrom Theme) ─── */
:root {
  --a11y-background: #ffffff;
  --a11y-foreground: #09090b; /* zinc-950 */
  --a11y-muted: #f4f4f5; /* zinc-100 */
  --a11y-muted-foreground: #71717a; /* zinc-500 */
  --a11y-popover: #ffffff;
  --a11y-popover-foreground: #09090b;
  --a11y-border: #e4e4e7; /* zinc-200 */
  --a11y-input: #e4e4e7;
  --a11y-primary: #7c3aed; /* violet-600 */
  --a11y-primary-foreground: #ffffff;
  --a11y-accent: #f4f4f5;
  --a11y-accent-foreground: #09090b;
  --a11y-ring: #7c3aed;
  --a11y-radius: 0.5rem; /* 8px */
  --a11y-btn-radius: 0.375rem; /* 6px */
  
  --a11y-z: 99999;
  --a11y-transition: 0.15s ease-in-out;
  
  /* Dynamic typography */
  --a11y-lh: 1.5;
  --a11y-ws: normal;
}

/* ─── Base Font (Ensure Roboto) ─── */
#a11y-panel, #a11y-trigger, #a11y-reading-badge, #a11y-virtual-scroll {
  font-family: 'Roboto', ui-sans-serif, system-ui, sans-serif !important;
  color: var(--a11y-foreground);
  box-sizing: border-box;
}

#a11y-panel *, #a11y-panel *::before, #a11y-panel *::after {
  box-sizing: inherit;
}

/* ─── Floating Trigger Button ─── */
#a11y-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--a11y-z);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--a11y-primary);
  color: var(--a11y-primary-foreground);
  border: 2px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--a11y-transition), box-shadow var(--a11y-transition);
  outline: none;
}

#a11y-trigger:hover {
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  transform: translateY(-2px);
}

#a11y-trigger:focus-visible {
  outline: 2px solid var(--a11y-ring);
  outline-offset: 2px;
}

#a11y-trigger svg {
  width: 24px;
  height: 24px;
}

/* ─── Panel ─── */
#a11y-panel {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: var(--a11y-z);
  width: 340px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--a11y-popover);
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-radius);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  transform: translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--a11y-transition), opacity var(--a11y-transition);
}

#a11y-panel.a11y-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Panel Header */
#a11y-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--a11y-border);
  background: var(--a11y-popover);
  border-radius: var(--a11y-radius) var(--a11y-radius) 0 0;
  flex-shrink: 0;
}

.a11y-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--a11y-foreground);
  display: flex;
  align-items: center;
  gap: 8px;
}

.a11y-header-title svg {
  width: 18px;
  height: 18px;
  color: var(--a11y-primary);
}

#a11y-close-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--a11y-btn-radius);
  color: var(--a11y-muted-foreground);
  display: flex;
  align-items: center;
  transition: background var(--a11y-transition), color var(--a11y-transition);
}

#a11y-close-btn:hover {
  background: var(--a11y-accent);
  color: var(--a11y-accent-foreground);
}

/* Panel Content (Scrollable) */
.a11y-panel-content {
  overflow-y: auto;
  padding: 16px 0;
}

/* Panel scrollbar */
.a11y-panel-content::-webkit-scrollbar { width: 6px; }
.a11y-panel-content::-webkit-scrollbar-track { background: transparent; }
.a11y-panel-content::-webkit-scrollbar-thumb { background: var(--a11y-border); border-radius: 3px; }

/* Section labels */
.a11y-section-label {
  font-size: 12px !important;
  font-weight: 600 !important;
  color: var(--a11y-foreground) !important;
  margin: 20px 16px 12px !important;
  padding: 0 !important;
  border: none !important;
  letter-spacing: 0.05em;
}
.a11y-section-label:first-child {
  margin-top: 0 !important;
}

/* Feature buttons grid */
.a11y-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 16px;
}

/* Shadcn Toggle Button */
.a11y-feat-btn {
  background: transparent;
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-btn-radius);
  padding: 12px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--a11y-muted-foreground);
  transition: all var(--a11y-transition);
  text-align: center;
  line-height: 1.2;
}

.a11y-feat-btn:hover {
  background: var(--a11y-accent);
  color: var(--a11y-accent-foreground);
}

.a11y-feat-btn.a11y-active {
  background: var(--a11y-primary);
  color: var(--a11y-primary-foreground);
  border-color: var(--a11y-primary);
}

.a11y-feat-btn .a11y-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Font Size Control */
.a11y-font-control {
  margin: 0 16px 8px;
  background: transparent;
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-btn-radius);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.a11y-font-control > span {
  font-size: 13px;
  font-weight: 500;
  color: var(--a11y-foreground);
}

.a11y-font-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--a11y-muted);
  border-radius: var(--a11y-btn-radius);
  padding: 2px;
}

.a11y-font-actions button {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--a11y-foreground);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--a11y-transition);
}

.a11y-font-actions button:hover {
  background: var(--a11y-background);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.1);
}

#a11y-font-value {
  min-width: 32px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--a11y-foreground);
}

/* Sliders */
.a11y-slider-control {
  margin: 0 16px 12px;
}

.a11y-slider-control label {
  font-size: 13px;
  font-weight: 500;
  color: var(--a11y-foreground);
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.a11y-slider-control label span {
  color: var(--a11y-muted-foreground);
  font-weight: 400;
}

.a11y-slider-control input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--a11y-muted);
  outline: none;
  cursor: pointer;
}

.a11y-slider-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--a11y-primary);
  cursor: pointer;
  border: 2px solid var(--a11y-background);
  box-shadow: 0 0 0 1px var(--a11y-border);
  transition: transform 0.1s;
}

.a11y-slider-control input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

/* Select */
.a11y-select-wrapper {
  position: relative;
  margin: 0 16px 16px;
}

.a11y-select {
  width: 100%;
  appearance: none;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--a11y-border);
  border-radius: var(--a11y-btn-radius);
  background: transparent;
  font-size: 13px;
  color: var(--a11y-foreground);
  outline: none;
  cursor: pointer;
}

.a11y-select:focus {
  border-color: var(--a11y-ring);
  box-shadow: 0 0 0 1px var(--a11y-ring);
}

.a11y-select-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  pointer-events: none;
  color: var(--a11y-muted-foreground);
}

/* Reset button */
.a11y-footer {
  margin: 24px 16px 0;
  padding-top: 16px;
  border-top: 1px solid var(--a11y-border);
}

#a11y-reset-btn {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--a11y-btn-radius);
  color: var(--a11y-muted-foreground);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--a11y-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#a11y-reset-btn:hover {
  background: var(--a11y-accent);
  color: var(--a11y-foreground);
}

/* ─── TTS Hover Highlight ─── */
.a11y-tts-hover {
  outline: 2px solid var(--a11y-primary) !important;
  outline-offset: 2px !important;
  border-radius: 4px !important;
  cursor: pointer !important;
  transition: outline 0.1s ease !important;
}

/* ─── Reading Badge ─── */
#a11y-reading-badge {
  position: fixed;
  bottom: 84px;
  right: 24px;
  z-index: calc(var(--a11y-z) - 1);
  background: var(--a11y-primary);
  color: var(--a11y-primary-foreground);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  display: none;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  pointer-events: none;
}

#a11y-reading-badge.a11y-speaking {
  display: flex;
}

.a11y-badge-dot {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  animation: a11y-pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes a11y-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ─── Accessibility Class Overrides ─── */

/* High Contrast */
html.a11y-high-contrast { filter: contrast(150%) brightness(1.1); }
/* Grayscale */
html.a11y-grayscale { filter: grayscale(100%); }
/* Both contrast + grayscale */
html.a11y-high-contrast.a11y-grayscale { filter: grayscale(100%) contrast(150%); }
/* Negative Contrast */
html.a11y-negative-contrast { filter: invert(85%) hue-rotate(180deg); }

/* Color Blindness Filters */
html.a11y-cb-protanopia { filter: url('#a11y-protanopia-filter'); }
html.a11y-cb-deuteranopia { filter: url('#a11y-deuteranopia-filter'); }
html.a11y-cb-tritanopia { filter: url('#a11y-tritanopia-filter'); }

/* Low Saturation */
html.a11y-desaturate { filter: saturate(0.3); }

/* Stop Animations */
html.a11y-stop-animations *,
html.a11y-stop-animations *::before,
html.a11y-stop-animations *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* Hide Images */
html.a11y-hide-images img,
html.a11y-hide-images video,
html.a11y-hide-images [style*="background-image"],
html.a11y-hide-images figure {
  visibility: hidden !important;
  background-image: none !important;
}

/* Reading Mask */
#a11y-reading-mask {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 99998;
  pointer-events: none;
  background: rgba(0,0,0,0.5);
}
html.a11y-reading-mask-active #a11y-reading-mask {
  display: block;
}

/* Keyboard Navigation Mode */
html.a11y-keyboard-nav *:focus,
html.a11y-keyboard-nav *:focus-visible {
  outline: 3px solid var(--a11y-primary) !important;
  outline-offset: 2px !important;
}

/* Left Align */
html.a11y-left-align,
html.a11y-left-align * {
  text-align: left !important;
}

/* Underline all links */
html.a11y-underline-links a {
  text-decoration: underline !important;
  text-underline-offset: 3px !important;
}

/* Dyslexia-friendly font */
html.a11y-dyslexia-font,
html.a11y-dyslexia-font * {
  font-family: 'Lexend', 'Arial', sans-serif !important;
}

/* Letter spacing */
html.a11y-letter-spacing,
html.a11y-letter-spacing * {
  letter-spacing: 0.12em !important;
}

/* Dynamic Line Height & Word Spacing */
html.a11y-dynamic-typography,
html.a11y-dynamic-typography * {
  line-height: var(--a11y-lh, inherit) !important;
  word-spacing: var(--a11y-ws, inherit) !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='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M8 2l16 12-8 1 5 11-3 1-5-11-5 5z' fill='%237c3aed' stroke='white' stroke-width='1.5'/%3E%3C/svg%3E") 4 2, auto !important;
}

/* Focus highlight */
html.a11y-focus-highlight *:focus,
html.a11y-focus-highlight *:focus-visible {
  outline: 3px solid var(--a11y-primary) !important;
  outline-offset: 2px !important;
}

/* TTS Active Mode Indicator on page */
body.a11y-tts-active::after {
  content: 'Mode Baca Aktif';
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--a11y-primary);
  color: var(--a11y-primary-foreground);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 999px;
  z-index: var(--a11y-z);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  pointer-events: none;
}

/* Virtual Scroll Buttons */
#a11y-virtual-scroll {
  display: none;
  position: fixed;
  right: 24px;
  bottom: 90px;
  z-index: calc(var(--a11y-z) - 2);
  flex-direction: column;
  gap: 8px;
}
html.a11y-virtual-scroll-active #a11y-virtual-scroll {
  display: flex;
}
.a11y-scroll-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--a11y-background);
  border: 2px solid #ffffff;
  color: var(--a11y-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  transition: all var(--a11y-transition);
}
.a11y-scroll-btn:hover {
  background: var(--a11y-accent);
}
