/* =====================================================================
   ACCESSIBILITY — read-aloud, font scaling, print view
   ===================================================================== */

/* Font-size scaling via CSS custom property */
html {
  --a11y-font-scale: 1;
}
body {
  font-size: calc(1rem * var(--a11y-font-scale));
}
html[data-a11y-size="l"] body { font-size: calc(1rem * 1.15); }
html[data-a11y-size="xl"] body { font-size: calc(1rem * 1.32); }
html[data-a11y-size="s"] body { font-size: calc(1rem * 0.88); }

html[data-a11y-size="l"] .triage-res-body-text,
html[data-a11y-size="l"] .funcmed-supp-card,
html[data-a11y-size="l"] .anat-item-desc,
html[data-a11y-size="l"] .nutri-mech-text,
html[data-a11y-size="l"] .com-post-content,
html[data-a11y-size="l"] .com-cmt-text { font-size: 1.08rem !important; line-height: 1.7 !important; }

html[data-a11y-size="xl"] .triage-res-body-text,
html[data-a11y-size="xl"] .funcmed-supp-card,
html[data-a11y-size="xl"] .anat-item-desc,
html[data-a11y-size="xl"] .nutri-mech-text,
html[data-a11y-size="xl"] .com-post-content,
html[data-a11y-size="xl"] .com-cmt-text { font-size: 1.22rem !important; line-height: 1.75 !important; }

/* Accessibility floating action button (FAB) — bottom right */
.a11y-fab {
  position: fixed;
  bottom: 78px;
  right: 16px;
  z-index: 9500;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
  font-family: 'Inter', 'Noto Serif KR', sans-serif;
}

.a11y-fab-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0d3880 0%, #00b8f0 100%);
  color: #fff;
  font-size: 1.6rem;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 24px rgba(13, 56, 128, 0.45);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: inherit;
  display: flex; align-items: center; justify-content: center;
}
.a11y-fab-toggle:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 12px 32px rgba(13, 56, 128, 0.6); }
.a11y-fab-toggle:active { transform: scale(0.95); }
.a11y-fab-toggle.open { transform: rotate(45deg); background: linear-gradient(135deg, #e74c3c, #c0392b); }

.a11y-fab-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.25s;
}
.a11y-fab-menu.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.a11y-fab-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
  background: #ffffff;
  border: 1.5px solid rgba(13, 56, 128, 0.25);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
  transition: all 0.15s;
  white-space: nowrap;
}
.a11y-fab-item:hover {
  background: #f0f9ff;
  border-color: rgba(13, 56, 128, 0.45);
  transform: translateX(-4px);
  box-shadow: 0 8px 24px rgba(13, 56, 128, 0.25);
}
.a11y-fab-item > span:first-child {
  font-size: 1.15rem;
}

.a11y-fab-item[data-state="playing"] {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border-color: #059669;
  animation: a11yPulse 1.4s infinite;
}
.a11y-fab-item[data-state="paused"] {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-color: #d97706;
}
@keyframes a11yPulse {
  0%, 100% { box-shadow: 0 6px 18px rgba(16, 185, 129, 0.40); }
  50% { box-shadow: 0 6px 28px rgba(16, 185, 129, 0.75); }
}

/* Toast */
.a11y-toast {
  position: fixed;
  bottom: 150px;
  right: 16px;
  padding: 10px 16px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #fff;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 10px;
  z-index: 10000;
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  font-family: inherit;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.a11y-toast.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Print styling — clean paper-friendly layout */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .a11y-fab,
  .lang-picker-wrap,
  .legal-footer,
  .home-bg,
  .home-footer,
  .nav-bar,
  .hero-stats,
  .mode-grid,
  .about-card,
  .hero-credential,
  .doctor-anim,
  .doctor-fallback,
  #install-prompt-banner,
  .triage-home-wrap,
  .com-react-row,
  .com-cmt-form,
  .funcmed-detail-tabs,
  .anat-detail-tabs,
  .nutri-detail-tabs,
  .triage-diff-card,
  .triage-result-cta {
    display: none !important;
  }
  .screen { display: block !important; background: white !important; }
  .screen:not(.active) { display: none !important; }
  .screen.active { padding: 0 !important; }
  img { max-width: 100% !important; page-break-inside: avoid; }
  h1, h2, h3 { page-break-after: avoid; color: #000 !important; }
  .funcmed-supp-card,
  .triage-res-section,
  .anat-item-card,
  .nutri-substance-card {
    page-break-inside: avoid;
    background: #fff !important;
    border: 1px solid #ccc !important;
    color: #000 !important;
  }
  a[href]:after { content: " (" attr(href) ")"; font-size: 0.8rem; color: #666; }
  a[href^="#"]:after,
  a[href^="javascript"]:after { content: ""; }
}

body.a11y-printing {
  background: #fff !important;
  color: #000 !important;
}

/* Mobile: narrower FAB */
@media (max-width: 480px) {
  .a11y-fab {
    bottom: 70px;
    right: 12px;
  }
  .a11y-fab-toggle {
    width: 50px;
    height: 50px;
    font-size: 1.4rem;
  }
  .a11y-fab-item {
    padding: 8px 14px;
    font-size: 0.82rem;
  }
}

/* On AI Chat screen: place the a11y FAB at the far top-right corner
   and shift the trash can left (they swap compared to v53). This keeps
   the chat-input Send arrow unobstructed. */
body:has(#screen-ai-chat.active) .a11y-fab {
  top: 10px;
  right: 12px;
  bottom: auto;
  flex-direction: column;   /* toggle on top, menu dropping downward */
}
body:has(#screen-ai-chat.active) .a11y-fab-toggle {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  border-width: 1.5px;
}
body:has(#screen-ai-chat.active) .a11y-fab-menu {
  transform: translateY(-12px);
}
body:has(#screen-ai-chat.active) .a11y-fab-menu.open {
  transform: translateY(0);
}
/* Shift the trash can button left so the a11y FAB (now at right:12px)
   does not overlap it. */
#screen-ai-chat .nav-bar .nav-back:last-child {
  margin-right: 48px;
}
@media (max-width: 480px) {
  body:has(#screen-ai-chat.active) .a11y-fab {
    top: 8px;
    right: 10px;
  }
  body:has(#screen-ai-chat.active) .a11y-fab-toggle {
    width: 36px;
    height: 36px;
    font-size: 1.05rem;
  }
  #screen-ai-chat .nav-bar .nav-back:last-child {
    margin-right: 42px;
  }
}
