/* Reading comfort (easy-read mode, spacing, contrast) and read-aloud controls.
   Settings > Reading comfort sets data-font, data-leading, data-measure, data-contrast and data-codesize on <html>
   (applyLook in js/app.js). The defaults (standard, normal, normal, normal, text) change nothing on screen.
   Fonts are the ones already on the device: no web fonts, no network. Code keeps its own code font and spacing. */

/* ------------------------------------------------------------------ reading font */
html[data-font="easy"],
html[data-font="dyslexia"] {
  --font-ui: Verdana, Tahoma, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-ui);
}
html[data-font="easy"] body { letter-spacing: .02em; word-spacing: .05em; }
html[data-font="dyslexia"] body { letter-spacing: .06em; word-spacing: .16em; }
/* Headings keep a little less tracking so they stay compact */
html[data-font="easy"] :is(h1, h2, h3, h4),
html[data-font="dyslexia"] :is(h1, h2, h3, h4) { letter-spacing: .01em; }

/* Code is never touched: its own font, no extra spacing */
html:is([data-font="easy"], [data-font="dyslexia"]) :is(pre, code, kbd, samp, textarea, .code, .out, .answer-input, .chip, .pline, .editor-hl, .editor-ta,
  .diff pre, .var, .feedback .answer, .schema, .trace-code, .trace-out, .qf-out, .result-table, .opt--code .opt-text, .inline-code) {
  letter-spacing: normal;
  word-spacing: normal;
}

/* Dyslexia-friendly: left-aligned, no slanted text, no hyphenation, a soft cream page in the day theme */
html[data-font="dyslexia"] :is(.md, p, li, summary, .opt-text) { text-align: left; hyphens: none; }
html[data-font="dyslexia"] :is(em, i, cite, dfn, address, blockquote, .muted, .small, .tiny, .result-table td.is-null) { font-style: normal; }
html[data-font="dyslexia"][data-theme="day"] {
  --bg: #f7f1e1;
  --bg-2: #fbf7ec;
  --surface: #fbf7ec;
  --surface-2: #efe7d2;
  --line: #ddd3b8;
  --line-2: #cbbf9f;
  --text: #1f2430;
  --text-2: #444a58;
  --text-3: #4f5563;
}
html[data-font="dyslexia"][data-theme="day"] .preview-frame { background: #fff; }

/* ------------------------------------------------------------------ line spacing (prose only) */
html[data-leading="roomy"] :is(.md, .opt-text, .set-row .grow, summary, .feedback, .help-note, li, p) { line-height: 1.8; }
html[data-leading="extra"] :is(.md, .opt-text, .set-row .grow, summary, .feedback, .help-note, li, p) { line-height: 2; }
html[data-leading="roomy"] .md p + p { margin-top: 1em; }
html[data-leading="extra"] .md p + p { margin-top: 1.25em; }
/* inline code inside roomy text must not stretch its line box */
html:is([data-leading="roomy"], [data-leading="extra"]) .md code { line-height: 1.2; }

/* ------------------------------------------------------------------ reading width: about 60 letters per line */
html[data-measure="narrow"] :is(.stage > .md, .stage > h2, .help-page .md, .set-group .grow > span, .md.small) { max-width: 60ch; }

/* ------------------------------------------------------------------ code text size */
html[data-codesize="large"] :is(.code, .opt--code .opt-text, .trace-code, .answer-input, .editor-hl, .editor-ta, .pline, .chip) { font-size: 1.12rem; }
html[data-codesize="large"] :is(.out, .trace-out, .var, .result-table th, .result-table td, .feedback .answer, .qf-out) { font-size: 1.02rem; }
html[data-codesize="large"] .md code { font-size: 1em; }

/* ------------------------------------------------------------------ high contrast (WCAG AAA 7:1 for text) */
html[data-contrast="high"][data-theme="night"] {
  --bg: #0a0c10;
  --bg-2: #0a0c10;
  --surface: #12151c;
  --surface-2: #1c212b;
  --line: #8e98ab;
  --line-2: #b4bccb;
  --text: #ffffff;
  --text-2: #e8ecf3;
  --text-3: #d3dae5;
  --accent-text: #bcd2ff;
  --ok-text: #8af0d3;
  --bad-text: #ffbccb;
  --info-text: #c6d8ff;
  --reward-text: #ffc088;
  --code-dim: #b9c3d8;
  --focus: #ffd84a;
}
html[data-contrast="high"][data-theme="day"] {
  --bg: #ffffff;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --line: #59637a;
  --line-2: #3b4457;
  --text: #000000;
  --text-2: #1d2431;
  --text-3: #2c3443;
  --ember: #000000;
  --ember-ink: #ffffff;
  --accent-text: #1b3fa8;
  --ok-text: #04594a;
  --bad-text: #8c1c38;
  --info-text: #1a3d9e;
  --reward-text: #7a3800;
  --code-dim: #b9c3d8;
  --focus: #0b2cc0;
}
/* the soft cream page of the dyslexia-friendly look stays, with the strong text colours on top */
html[data-contrast="high"][data-font="dyslexia"][data-theme="day"] {
  --bg: #f7f1e1;
  --bg-2: #fbf7ec;
  --surface: #fbf7ec;
  --surface-2: #efe7d2;
  --line: #5b6277;
  --line-2: #3b4457;
  --text: #000000;
  --text-2: #1d2431;
  --text-3: #2c3443;
}
html[data-contrast="high"] :focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
html[data-contrast="high"] :is(.opt, .btn--ghost, .seg, .set-row, .card, .input, .code, .out) { border-color: var(--line); }
html[data-contrast="high"] .btn--ghost { box-shadow: inset 0 0 0 2px var(--line-2); }
html[data-contrast="high"] .seg button.is-on { outline: 2px solid var(--text); outline-offset: -4px; }
html[data-contrast="high"] .tc { color: #a9c9c6; }
html[data-contrast="high"] .out::before { color: #b9c3d8; }

/* ------------------------------------------------------------------ read aloud */
.listen-btn { justify-self: start; align-self: flex-start; min-height: 40px; padding: 0 14px 0 10px; gap: 6px; }
.listen-btn .listen-ico { display: inline-grid; place-items: center; }
.listen-btn .listen-ico svg { width: 18px; height: 18px; }
.listen-btn.is-on { background: var(--ember); color: var(--ember-ink); border-color: var(--ember); }
.comfort-sample { padding: 10px 12px; border-radius: var(--r-m); background: var(--surface-2); border: 1px dashed var(--line-2); }
.set-row output { min-width: 3ch; font-variant-numeric: tabular-nums; }
.set-row input[type="range"] { width: min(220px, 60vw); min-height: 32px; accent-color: var(--accent-text, currentColor); }
