/*
 * Shared accessibility styles — panel chrome, reading-mode floating
 * toolbar, and generic prose hooks (font-scale + line-height) wired by
 * `static/shared/accessibility.js`.
 *
 * Template-specific reading-mode hooks (which chrome to hide, which
 * containers to recenter) live in each template's own bundled CSS —
 * see docs/templates/04-widgets-and-accessibility.md.
 */

/* ── Panel ────────────────────────────────────────────────────────── */

.a11y-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.a11y-panel.is-open {
  opacity: 1;
  pointer-events: auto;
}
.a11y-panel.hidden,
.a11y-panel[hidden] { display: none; }

.a11y-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  cursor: pointer;
}

.a11y-panel-card {
  position: relative;
  width: 100%;
  max-width: 36rem;
  max-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  color: #1f1e1d;
  border-radius: 1rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  transform: translateY(8px);
  transition: transform 0.2s ease;
}
.a11y-panel.is-open .a11y-panel-card { transform: translateY(0); }
[data-theme="dark"] .a11y-panel-card,
html.dark .a11y-panel-card {
  background: #1d2030;
  color: #e7eaf2;
}

.a11y-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .a11y-panel-header,
html.dark .a11y-panel-header { border-bottom-color: rgba(255, 255, 255, 0.08); }

.a11y-panel-title {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}
.a11y-panel-sub {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: rgba(0, 0, 0, 0.6);
}
[data-theme="dark"] .a11y-panel-sub,
html.dark .a11y-panel-sub { color: rgba(231, 234, 242, 0.7); }

.a11y-panel-icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.a11y-panel-icon-btn:hover { background: rgba(0, 0, 0, 0.06); }
[data-theme="dark"] .a11y-panel-icon-btn:hover,
html.dark .a11y-panel-icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.a11y-panel-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  overflow-y: auto;
}

.a11y-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  user-select: none;
}
.a11y-row-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  cursor: default;
}
.a11y-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.a11y-row-label {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
}
.a11y-row-value {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: rgba(0, 0, 0, 0.55);
}
[data-theme="dark"] .a11y-row-value,
html.dark .a11y-row-value { color: rgba(231, 234, 242, 0.65); }

.a11y-checkbox {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #0d6e7a;
}

.a11y-range {
  width: 100%;
  accent-color: #0d6e7a;
  cursor: pointer;
}

.a11y-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .a11y-panel-footer,
html.dark .a11y-panel-footer { border-top-color: rgba(255, 255, 255, 0.08); }

.a11y-text-btn {
  background: transparent;
  border: none;
  color: rgba(0, 0, 0, 0.65);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  transition: color 0.15s;
}
.a11y-text-btn:hover { color: rgba(0, 0, 0, 0.95); }
[data-theme="dark"] .a11y-text-btn,
html.dark .a11y-text-btn { color: rgba(231, 234, 242, 0.7); }
[data-theme="dark"] .a11y-text-btn:hover,
html.dark .a11y-text-btn:hover { color: #ffffff; }

.a11y-primary-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  background: #0d6e7a;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.a11y-primary-btn:hover { opacity: 0.9; }

/* ── Trigger button ─────────────────────────────────────────────── */

.a11y-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1.05rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.a11y-trigger:hover {
  background: rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .a11y-trigger:hover,
html.dark .a11y-trigger:hover { background: rgba(255, 255, 255, 0.08); }
.a11y-trigger:focus-visible {
  outline: 2px solid #0d6e7a;
  outline-offset: 2px;
}

/* ── Reading-mode floating toolbar ─────────────────────────────── */

.a11y-reader-toolbar {
  position: fixed;
  left: 1.25rem;
  top: 7rem;
  z-index: 80;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
html.a11y-reading-mode .a11y-reader-toolbar {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}
.a11y-reader-toolbar[hidden] { display: block; }  /* style-only hide; opacity drives visibility */

.a11y-reader-toolbar-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(205, 211, 225, 0.24);
  background: #1d2030;
  color: #e7eaf2;
  box-shadow: 0 12px 28px rgba(7, 10, 18, 0.5);
}

.a11y-reader-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: background 0.15s ease;
}
.a11y-reader-btn:hover { background: rgba(255, 255, 255, 0.12); }
.a11y-reader-btn-text {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.a11y-reader-btn:focus-visible {
  outline: 2px solid #6fd5ff;
  outline-offset: 1px;
}

@media (max-width: 1023px) {
  html.a11y-reading-mode .a11y-reader-toolbar {
    top: auto;
    bottom: 1rem;
    left: 1rem;
  }
  .a11y-reader-toolbar-card {
    flex-direction: row;
    gap: 0.3rem;
  }
}

/* ── Generic prose hooks ────────────────────────────────────────────
   Templates that want font-scale / line-height to apply to their prose
   target their own selector (e.g. `.prose`). The defaults below cover
   the common case via attribute selectors so opting in is one line. */

[data-a11y-prose] {
  font-size: calc(1em * var(--a11y-font-scale, 1));
  line-height: var(--a11y-line-height, 1.7);
}
[data-a11y-prose] p,
[data-a11y-prose] li,
[data-a11y-prose] blockquote {
  line-height: var(--a11y-line-height, 1.7);
}

/* ── Reduce motion (universal) ─────────────────────────────────────
   Templates can layer their own per-class rules; this baseline neuters
   transitions/animations everywhere when the user opts in. Mirrors the
   `prefers-reduced-motion` media query that already runs unconditionally. */

html.a11y-reduce-motion *,
html.a11y-reduce-motion *::before,
html.a11y-reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* ── Always-underline-links (universal default) ──────────────────── */

html.a11y-link-underlines [data-a11y-prose] a,
html.a11y-link-underlines main a:not(.a11y-trigger):not(.a11y-reader-btn):not(.a11y-panel-icon-btn) {
  text-decoration: underline;
  text-underline-offset: 2px;
}
