/**
 * File purpose: I.S.T accessibility widget — premium dark-luxury panel.
 *               Reads tokens from tokens.css. No token redefinition.
 *               Pairs with widget-a11y.js. Floating trigger + sectioned panel,
 *               mobile bottom sheet, reduced-motion aware.
 * Created:      2026-05-04
 * Safety notes: CSS only. No credentials. No logic. Avoids accessibility
 *               overclaim wording. Cookie banner remains above this widget
 *               (z-index 10000+).
 */

/* ─── Font-scale variable (driven by JS) ──────────────────────────────────── */
:root { --ist-font-scale: 1; }

html.ist-a11y-font-scaled body,
html.ist-a11y-font-scaled body * {
  font-size: calc(1em * var(--ist-font-scale, 1)) !important;
}

/* ─── Floating trigger button ─────────────────────────────────────────────── */
.ist-a11y-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ist-accent-cyan) 0%, var(--ist-accent-blue) 100%);
  color: var(--ist-text-inverse);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 0 0 rgba(34, 211, 238, 0);
  transition: transform var(--ist-transition),
              box-shadow var(--ist-transition),
              background var(--ist-transition);
  /* Ensure good tap target on mobile */
  -webkit-tap-highlight-color: transparent;
}

.ist-a11y-trigger::after {
  /* Larger 64px hit target on touch */
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
}

.ist-a11y-trigger:hover {
  transform: scale(1.06);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 24px rgba(34, 211, 238, 0.55);
}

.ist-a11y-trigger:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 4px;
}

.ist-a11y-trigger[aria-expanded="true"] {
  transform: scale(0.94);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 16px rgba(34, 211, 238, 0.4);
}

.ist-a11y-trigger svg {
  width: 28px;
  height: 28px;
  display: block;
}

/* Position-left option (configurable via root class) */
html.ist-a11y-pos-left .ist-a11y-trigger { right: auto; left: 24px; }
html.ist-a11y-pos-left .ist-a11y-panel   { right: auto; left: 24px; }

/* Hide on print */
@media print {
  .ist-a11y-trigger,
  .ist-a11y-panel,
  .ist-a11y-reading-guide { display: none !important; }
}

/* ─── Backdrop (mobile bottom-sheet only) ─────────────────────────────────── */
.ist-a11y-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(5, 7, 13, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ist-transition);
}

.ist-a11y-backdrop.ist-open {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 481px) {
  .ist-a11y-backdrop { display: none; }
}

/* ─── Panel ───────────────────────────────────────────────────────────────── */
.ist-a11y-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9999;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  background: var(--ist-bg-2);
  border: 1px solid var(--ist-border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  color: var(--ist-text);
  font-family: var(--ist-font-body);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--ist-transition),
              transform var(--ist-transition);
}

@supports (backdrop-filter: blur(16px)) {
  .ist-a11y-panel {
    background: rgba(11, 16, 32, 0.92);
    backdrop-filter: blur(18px) saturate(1.1);
    -webkit-backdrop-filter: blur(18px) saturate(1.1);
  }
}

.ist-a11y-panel.ist-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  .ist-a11y-panel,
  .ist-a11y-trigger,
  .ist-a11y-backdrop {
    transition: none !important;
  }
}

/* ─── Panel header ────────────────────────────────────────────────────────── */
.ist-a11y-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ist-border);
  flex: 0 0 auto;
}

.ist-a11y-title {
  margin: 0;
  font-family: var(--ist-font-heading);
  font-size: 1rem;
  font-weight: var(--ist-fw-semibold);
  color: var(--ist-text);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ist-a11y-title svg {
  width: 18px;
  height: 18px;
  color: var(--ist-accent-cyan);
}

.ist-a11y-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--ist-border);
  background: transparent;
  color: var(--ist-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: border-color var(--ist-transition), color var(--ist-transition), background var(--ist-transition);
}

.ist-a11y-close:hover {
  color: var(--ist-text);
  border-color: var(--ist-border-hover);
  background: var(--ist-card-hover);
}

.ist-a11y-close:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 2px;
}

/* Mobile drag handle (decorative — also acts as visual affordance) */
.ist-a11y-handle {
  display: none;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
  margin: 8px auto 0;
  flex: 0 0 auto;
}

/* ─── Body / scroll area ──────────────────────────────────────────────────── */
.ist-a11y-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 20px 16px;
  flex: 1 1 auto;
}

.ist-a11y-body::-webkit-scrollbar { width: 8px; }
.ist-a11y-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}
.ist-a11y-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ─── Section ─────────────────────────────────────────────────────────────── */
.ist-a11y-section { margin-top: 14px; }
.ist-a11y-section:first-child { margin-top: 4px; }

.ist-a11y-section-title {
  margin: 0 0 8px;
  font-family: var(--ist-font-heading);
  font-size: 0.7rem;
  font-weight: var(--ist-fw-semibold);
  color: var(--ist-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ─── Control row ─────────────────────────────────────────────────────────── */
.ist-a11y-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--ist-border);
  background: var(--ist-card);
  margin-bottom: 6px;
  transition: border-color var(--ist-transition), background var(--ist-transition);
}

.ist-a11y-row:hover {
  border-color: var(--ist-border-hover);
  background: var(--ist-card-hover);
}

.ist-a11y-row-label {
  font-size: 0.875rem;
  font-weight: var(--ist-fw-medium);
  color: var(--ist-text);
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ist-a11y-row-label-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--ist-text-muted);
}

/* ─── Toggle switch ───────────────────────────────────────────────────────── */
.ist-a11y-switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--ist-border);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  flex: 0 0 auto;
  padding: 0;
  transition: background var(--ist-transition), border-color var(--ist-transition);
}

.ist-a11y-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ist-text-muted);
  transition: transform var(--ist-transition), background var(--ist-transition);
}

.ist-a11y-switch[aria-pressed="true"] {
  background: var(--ist-accent-cyan-dim);
  border-color: var(--ist-accent-cyan);
}

.ist-a11y-switch[aria-pressed="true"]::before {
  transform: translateX(18px);
  background: var(--ist-accent-cyan);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.6);
}

.ist-a11y-switch:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 2px;
}

/* ─── Segmented choice (low/normal/high etc.) ─────────────────────────────── */
.ist-a11y-seg {
  display: flex;
  gap: 4px;
  border: 1px solid var(--ist-border);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 3px;
  flex: 0 0 auto;
}

.ist-a11y-seg button {
  border: none;
  background: transparent;
  color: var(--ist-text-muted);
  font-size: 0.75rem;
  font-weight: var(--ist-fw-medium);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: color var(--ist-transition), background var(--ist-transition);
  font-family: inherit;
}

.ist-a11y-seg button:hover { color: var(--ist-text); }

.ist-a11y-seg button[aria-pressed="true"] {
  background: var(--ist-accent-cyan);
  color: var(--ist-text-inverse);
}

.ist-a11y-seg button:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 2px;
}

/* ─── Stepper (text size −/value/+) ───────────────────────────────────────── */
.ist-a11y-step {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--ist-border);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 3px;
}

.ist-a11y-step button {
  border: none;
  background: transparent;
  color: var(--ist-text);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  font-family: inherit;
  font-weight: var(--ist-fw-semibold);
  transition: background var(--ist-transition);
}

.ist-a11y-step button:hover { background: var(--ist-card-hover); }

.ist-a11y-step button:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 2px;
}

.ist-a11y-step button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ist-a11y-step-value {
  min-width: 38px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--ist-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Footer (reset + report link) ────────────────────────────────────────── */
.ist-a11y-footer {
  border-top: 1px solid var(--ist-border);
  padding: 12px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}

.ist-a11y-reset {
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--ist-border);
  border-radius: 8px;
  color: var(--ist-text);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: var(--ist-fw-medium);
  font-family: inherit;
  transition: border-color var(--ist-transition), background var(--ist-transition), color var(--ist-transition);
}

.ist-a11y-reset:hover {
  border-color: var(--ist-accent-cyan);
  background: var(--ist-accent-cyan-dim);
  color: var(--ist-text);
}

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

.ist-a11y-report {
  font-size: 0.75rem;
  color: var(--ist-text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-align: center;
  transition: color var(--ist-transition);
}

.ist-a11y-report:hover {
  color: var(--ist-accent-cyan);
}

.ist-a11y-report:focus-visible {
  outline: 2px solid var(--ist-accent-cyan);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ─── Live region (visually hidden) ───────────────────────────────────────── */
.ist-a11y-live {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ─── Reading guide ───────────────────────────────────────────────────────── */
.ist-a11y-reading-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--ist-accent-cyan);
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.6),
              0 -40px 0 rgba(5, 7, 13, 0.0),
              0 40px 0 rgba(5, 7, 13, 0.0);
  pointer-events: none;
  z-index: 9997;
  transform: translateY(-50%);
  display: none;
}

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

/* ─── Mobile bottom sheet ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .ist-a11y-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }

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

  .ist-a11y-handle { display: block; }

  .ist-a11y-trigger {
    bottom: 16px;
    right: 16px;
    width: 64px;
    height: 64px;
  }

  html.ist-a11y-pos-left .ist-a11y-trigger { left: 16px; }
}

/* ─── Effect classes (toggled on <html>) ──────────────────────────────────── */

/* High contrast */
html.ist-a11y-high-contrast {
  filter: contrast(1.45) saturate(1.1);
}

/* Inverted colors */
html.ist-a11y-invert {
  filter: invert(1) hue-rotate(180deg);
}
html.ist-a11y-invert img,
html.ist-a11y-invert video,
html.ist-a11y-invert picture,
html.ist-a11y-invert iframe,
html.ist-a11y-invert svg[data-no-invert] {
  filter: invert(1) hue-rotate(180deg);
}

/* Combined invert + high-contrast */
html.ist-a11y-invert.ist-a11y-high-contrast {
  filter: invert(1) hue-rotate(180deg) contrast(1.45);
}

/* Grayscale */
html.ist-a11y-grayscale { filter: grayscale(1); }
html.ist-a11y-grayscale.ist-a11y-high-contrast { filter: grayscale(1) contrast(1.45); }
html.ist-a11y-grayscale.ist-a11y-invert        { filter: grayscale(1) invert(1) hue-rotate(180deg); }

/* Readable font (Atkinson Hyperlegible if available, else system stack) */
html.ist-a11y-readable-font,
html.ist-a11y-readable-font body,
html.ist-a11y-readable-font body * {
  font-family: 'Atkinson Hyperlegible', 'Verdana', 'Tahoma', system-ui, -apple-system, sans-serif !important;
  letter-spacing: 0.01em;
}

/* Line-height variants */
html.ist-a11y-lh-low body,
html.ist-a11y-lh-low body * { line-height: 1.2 !important; }
html.ist-a11y-lh-high body,
html.ist-a11y-lh-high body * { line-height: 2 !important; }

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

/* Word-spacing wide */
html.ist-a11y-word-wide body,
html.ist-a11y-word-wide body * {
  word-spacing: 0.32em !important;
}

/* Highlight links */
html.ist-a11y-highlight-links a {
  text-decoration: underline !important;
  text-underline-offset: 3px !important;
  text-decoration-thickness: 2px !important;
  outline: 1px dashed var(--ist-accent-cyan) !important;
  outline-offset: 3px !important;
  border-radius: 2px;
}

/* Highlight headings */
html.ist-a11y-highlight-headings :is(h1, h2, h3, h4, h5, h6) {
  outline: 2px dashed var(--ist-accent-cyan) !important;
  outline-offset: 4px !important;
  border-radius: 2px;
}

/* Big cursor */
html.ist-a11y-big-cursor,
html.ist-a11y-big-cursor * {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'><path d='M4 2 L4 32 L13 24 L18 36 L23 34 L18 22 L30 22 Z' fill='white' stroke='black' stroke-width='2' stroke-linejoin='round'/></svg>") 2 2, auto !important;
}

html.ist-a11y-big-cursor a,
html.ist-a11y-big-cursor button,
html.ist-a11y-big-cursor [role="button"] {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'><path d='M14 4 L14 24 L19 21 L23 30 L27 28 L23 19 L30 18 Z' fill='%2322D3EE' stroke='black' stroke-width='2' stroke-linejoin='round'/></svg>") 14 4, pointer !important;
}

/* Pause animations — base is in tokens.css; reinforce here for any !important rule */
html.ist-a11y-pause-motion *,
html.ist-a11y-pause-motion *::before,
html.ist-a11y-pause-motion *::after {
  animation-play-state: paused !important;
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}
