/* Practice studio comfort layer: text size, reading font, spacing, contrast, reading ruler, calm mode, and the
   earned-celebration toast. Every setting is a data-comfort-* attribute on <html>, so nothing here touches the
   studios' own markup. Loaded on every studio page, generated and hand-built. */

#comfort-btn {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 60;
  min-width: 48px;
  min-height: 48px;
  padding: 0 16px;
  border: 2px solid var(--brand, #2c4a68);
  border-radius: 999px;
  background: var(--surface, #fff);
  color: var(--ink, #1b2733);
  font: 700 1rem/1 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 8px 18px -10px rgba(0, 0, 0, 0.5);
}
#comfort-btn.top-btn {
  position: static;
  left: auto;
  bottom: auto;
  min-width: 0;
  box-shadow: none;
}
#comfort-btn:not(.top-btn) {
  width: 52px;
  padding: 0;
}
#comfort-btn:not(.top-btn) span:last-child {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
#comfort-btn:focus-visible {
  outline: 3px solid var(--sun, #f0bd4f);
  outline-offset: 3px;
}

/* text size: the whole page scales, like browser zoom, so layouts keep working */
html[data-comfort-size="2"] body {
  zoom: 1.15;
}
html[data-comfort-size="3"] body {
  zoom: 1.3;
}

/* larger text must never push the page sideways: rows wrap and cards shrink instead */
html:is([data-comfort-size="2"], [data-comfort-size="3"]) body :where(.field-row, .field-item, .dots-row, .stepper-bar, .header-actions, .tab-list, .banner-actions) {
  flex-wrap: wrap;
}
html:is([data-comfort-size="2"], [data-comfort-size="3"]) body :where(.stage-card, .field-item, .grid-card, .field-row) {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
html:is([data-comfort-size="2"], [data-comfort-size="3"]) body :where(input.num-input, .num-input) {
  min-width: 0;
  max-width: 100%;
}

/* reading fonts: both ship with the site */
html[data-comfort-font="lexend"] body,
html[data-comfort-font="lexend"] button,
html[data-comfort-font="lexend"] input,
html[data-comfort-font="lexend"] textarea,
html[data-comfort-font="lexend"] select {
  font-family: "Lexend", system-ui, sans-serif !important;
}
html[data-comfort-font="atkinson"] body,
html[data-comfort-font="atkinson"] button,
html[data-comfort-font="atkinson"] input,
html[data-comfort-font="atkinson"] textarea,
html[data-comfort-font="atkinson"] select {
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif !important;
}

/* roomy spacing: the settings reading-research recommends for slower or struggling readers */
html[data-comfort-space="roomy"] body {
  line-height: 1.85;
  letter-spacing: 0.03em;
  word-spacing: 0.14em;
}
html[data-comfort-space="roomy"] :where(p, li, dd, dt, label, .item-q, .item-sub, .choice-btn, .hint-list li) {
  line-height: 1.85;
}

/* high contrast: black on white, heavy edges, and the dark Challenge pages included */
html[data-comfort-contrast="high"] {
  color-scheme: light;
}
html[data-comfort-contrast="high"] body {
  --ink: #000 !important;
  --ink-muted: #111 !important;
  --ink-light: #1a1a1a !important;
  --surface: #fff !important;
  --surface-soft: #fff !important;
  --paper: #fff !important;
  --well: #f2f2f2 !important;
  --border: #000 !important;
  --border-strong: #000 !important;
  --brand: #003a8c !important;
  --brand-dark: #001f4d !important;
  --brand-tint: #e8f0ff !important;
  --brand-line: #000 !important;
  --ok: #005a2b !important;
  --bad: #a30000 !important;
  background: #fff !important;
  color: #000 !important;
}
html[data-comfort-contrast="high"] :where(button, input, textarea, select, .stage-card, .choice-btn) {
  border-color: #000 !important;
  border-width: 2px !important;
}
html[data-comfort-contrast="high"] :focus-visible {
  outline: 4px solid #000 !important;
  outline-offset: 3px !important;
}

/* calm mode: nothing moves, nothing sparkles */
html[data-comfort-calm="on"] *,
html[data-comfort-calm="on"] *::before,
html[data-comfort-calm="on"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* reading ruler: a band that follows the pointer or the focused control and dims the rest */
#comfort-ruler {
  position: fixed;
  left: 0;
  right: 0;
  top: -400px;
  height: 3.4em;
  z-index: 55;
  pointer-events: none;
  border-top: 2px solid var(--brand, #2c4a68);
  border-bottom: 2px solid var(--brand, #2c4a68);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.3);
}
html:not([data-comfort-ruler="on"]) #comfort-ruler {
  display: none;
}

/* the settings dialog */
.comfort-dialog {
  max-width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: 2px solid var(--brand, #2c4a68);
  border-radius: 18px;
  background: var(--surface, #fff);
  color: var(--ink, #1b2733);
}
.comfort-dialog::backdrop {
  background: rgba(10, 20, 30, 0.55);
}
.comfort-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border, #d5dce5);
}
.comfort-head h2 {
  margin: 0;
  font-size: 1.25rem;
}
.comfort-body {
  display: grid;
  gap: 14px;
  padding: 16px 18px 20px;
}
.comfort-body fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}
.comfort-body legend {
  margin-bottom: 6px;
  font-weight: 800;
}
.comfort-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.comfort-choices label,
.comfort-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border: 2px solid var(--border, #d5dce5);
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
}
.comfort-choices input:checked + span,
.comfort-toggle:has(input:checked) {
  color: var(--brand-dark, #12263a);
}
.comfort-choices label:has(input:checked),
.comfort-toggle:has(input:checked) {
  border-color: var(--brand, #2c4a68);
  background: var(--brand-tint, #e8eef5);
}
.comfort-choices label:has(input:focus-visible),
.comfort-toggle:has(input:focus-visible) {
  outline: 3px solid var(--sun, #f0bd4f);
  outline-offset: 2px;
}
.comfort-toggles {
  display: grid;
  gap: 8px;
}
.comfort-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.comfort-actions button {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--brand, #2c4a68);
  border-radius: 999px;
  background: var(--surface, #fff);
  color: var(--ink, #1b2733);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

/* earned-celebration toast and confetti */
#comfort-toast {
  position: fixed;
  left: 50%;
  bottom: 74px;
  z-index: 70;
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--brand-dark, #12263a);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 26px -12px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#comfort-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.comfort-confetti {
  position: fixed;
  inset: 0;
  z-index: 65;
  pointer-events: none;
  overflow: hidden;
}
.comfort-confetti i {
  position: absolute;
  top: -16px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  background: hsl(calc(var(--i) * 47), 85%, 58%);
  animation: comfort-fall 1.9s ease-in calc(var(--i) * 45ms) both;
}
@keyframes comfort-fall {
  to {
    transform: translateY(110vh) rotate(620deg);
    opacity: 0.2;
  }
}
@media (prefers-reduced-motion: reduce) {
  .comfort-confetti {
    display: none;
  }
  #comfort-toast {
    transition: none;
  }
}
@media print {
  #comfort-btn,
  #comfort-ruler,
  #comfort-toast,
  .comfort-confetti {
    display: none !important;
  }
}
