/* ============================================================
   KidVerse — access.css
   ============================================================

   Everything an accessibility setting switches on. It is a separate
   sheet because type.css and theme.css are not this feature's to edit,
   and it is loaded after both so that where it has to win, it does.

   One rule governs the whole file, and it is the third rule of the
   brief: DEFAULTS CHANGE FOR NOBODY. Every block below is behind an
   attribute that access.js puts on <html> only when a parent or child
   has chosen it:

       data-kvcontrast="high"        high contrast
       data-kvreading="roomy|roomier" spacing for long text
       data-kvmotion="reduce"        calm, whatever the device says
       data-kvcapsize="large|…"      caption size
       data-kvscan="…"               single-switch scanning

   There are exactly two things in here that are not behind a choice,
   and each is argued for where it is:

       1. @media (prefers-reduced-motion: reduce) — a wish the device
          already states. Honoured straight away, with no script.
       2. The keyboard focus ring. See below.

   handoff/access-front.mjs reads this file and fails if any other rule
   is not behind one of those attributes.
   ============================================================ */


/* ------------------------------------------------------------
   The focus ring — the second thing that is on for everybody
   ------------------------------------------------------------
   theme.css draws the ring in --accent. Measured against each
   theme's own page, that is 4.5:1 in Press, 2.5:1 in Cut Paper and
   7.5:1 in Lamplight: Cut Paper's coral ring fails the 3:1 that
   WCAG 1.4.11 needs, and it is the calmest theme, the one a four-year-
   old and a bedtime are given. A keyboard child cannot be asked to
   find a setting to turn on a ring, and may not be able to reach the
   settings to do it, so this is not a preference.

   It only ever shows for :focus-visible — the keyboard, a switch, a
   screen reader moving about — so a child using a mouse never sees it.

   Two parts, so it survives any background it lands on: a gap in the
   page colour, then a ring in the text colour. Text colour against
   page colour is the best-measured pair each theme has (12.1, 11.6 and
   14.4:1), and the gap means the ring is never read against
   whatever the element itself happens to be painted.
   ------------------------------------------------------------ */
html[data-kvtheme] :focus-visible,
html :focus-visible {
  outline: 3px solid var(--text-main);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--surface);
}


/* ------------------------------------------------------------
   The button laid over a card
   ------------------------------------------------------------
   cloud.js draws a video card as a <div onclick>, which a keyboard
   cannot reach. access.js puts a real, named button over it (under the
   heart and the play badge, which are already above it) and its click
   bubbles to the card's own handler. Invisible, and the same size as
   the card, so a pointer sees nothing different. Behind data-kvx,
   which access.js sets when it has done the retrofit.
   ------------------------------------------------------------ */
html[data-kvx] .kvx-card { position: relative; }
html[data-kvx] .kvx-open {
  position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; background: transparent;
  border-radius: inherit; cursor: pointer; font-size: 0;
}

/* ------------------------------------------------------------
   Reduced motion
   ------------------------------------------------------------
   "No autoplaying animation, no parallax, no movement a child did
   not start." What that means here, concretely:

   · every CSS animation and transition is cut to a single frame
     (not removed: `animation: none` leaves anything that finishes on
     an `animationend` waiting for ever, and a toast that never
     leaves is worse than one that does not slide)
   · smooth scrolling is turned off, here for CSS and in access.js
     for the two places the page asks for it from script
   · a card that lifts when the pointer passes over it stays put
   · there is no parallax in KidVerse today. This file says so, and
     says that the rule above would cover it if one arrived: nothing
     moves on scroll.

   Written twice because a media query and an attribute cannot share a
   selector. The first needs no script at all, which is what makes the
   device's own preference honoured immediately.
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  html, html * , html *::before, html *::after {
    animation-duration: .001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  html .card:hover, html .baby-card:hover { transform: none !important; }
}
html[data-kvmotion="reduce"],
html[data-kvmotion="reduce"] *,
html[data-kvmotion="reduce"] *::before,
html[data-kvmotion="reduce"] *::after {
  animation-duration: .001ms !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  transition-delay: 0s !important;
  scroll-behavior: auto !important;
}
html[data-kvmotion="reduce"] .card:hover,
html[data-kvmotion="reduce"] .baby-card:hover { transform: none !important; }


/* ------------------------------------------------------------
   Reading space, for long text
   ------------------------------------------------------------
   There is no dyslexia font here, on purpose, and that is a decision
   worth writing down. The studies behind the fonts sold as dyslexia
   fonts (Wery & Diliberto 2017; Kuster et al. 2018; Marinus et al.
   2016) found no reliable gain in reading speed or accuracy over an
   ordinary clear face, and children often preferred the ordinary one.
   What does have support is space: Zorzi et al. (2012, PNAS) found
   extra letter spacing improved reading accuracy and speed in children
   with dyslexia, and the evidence on line length and a ragged right
   edge (no justified text, no hyphenation) is consistent. So this
   changes spacing, line height and measure, and leaves the typeface
   as it is. The library already reads in Andika, which was drawn for
   exactly this and which a child may already be used to.

   "roomier" meets the WCAG 1.4.12 text-spacing figures outright
   (letters .12em, words .16em, lines 1.5, paragraphs 2x) and goes past
   them. "roomy" is the gentler step for a child who finds that much
   air strange.

   The selectors are the long text that exists today. A module with its
   own long text puts data-kvlong on it and gets the same treatment.
   ------------------------------------------------------------ */
[data-kvreading="roomy"] .kvl-page,
[data-kvreading="roomy"] .kvbd-say,
[data-kvreading="roomy"] .kvr-qp,
[data-kvreading="roomy"] .kvdg-card,
[data-kvreading="roomy"] [data-kvlong] {
  letter-spacing: .06em;
  word-spacing: .12em;
  line-height: 1.9;
  max-width: 60ch;
  text-align: left;
  hyphens: none;
  -webkit-hyphens: none;
  text-justify: none;
}
[data-kvreading="roomier"] .kvl-page,
[data-kvreading="roomier"] .kvbd-say,
[data-kvreading="roomier"] .kvr-qp,
[data-kvreading="roomier"] .kvdg-card,
[data-kvreading="roomier"] [data-kvlong] {
  letter-spacing: .12em;
  word-spacing: .24em;
  line-height: 2.1;
  max-width: 52ch;
  text-align: left;
  hyphens: none;
  -webkit-hyphens: none;
  text-justify: none;
}
[data-kvreading="roomy"] .kvl-page p,
[data-kvreading="roomy"] [data-kvlong] p { margin: 0 0 1.3em; }
[data-kvreading="roomier"] .kvl-page p,
[data-kvreading="roomier"] [data-kvlong] p { margin: 0 0 2em; }


/* ------------------------------------------------------------
   Captions
   ------------------------------------------------------------
   The box is drawn by access.js under the video, never over it, so a
   child who needs large captions is not asked to give up the picture
   to read them. It reserves three lines of height so the player does
   not jump when a line arrives or leaves: movement the child did not
   start.
   ------------------------------------------------------------ */
#kvCaptions {
  box-sizing: border-box;
  width: 100%;
  min-height: 4.4em;
  padding: .55em 1em;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  background: var(--card-bg);
  color: var(--text-main);
  font-family: var(--font-read);
  font-size: 1.15rem;
  line-height: 1.5;
}
#kvCaptions[data-empty="true"] { color: var(--text-muted); }
[data-kvcapsize="large"]   #kvCaptions, [data-kvcapsize="large"]   .kvx-capdemo { font-size: 1.5rem; }
[data-kvcapsize="larger"]  #kvCaptions, [data-kvcapsize="larger"]  .kvx-capdemo { font-size: 1.95rem; }
[data-kvcapsize="largest"] #kvCaptions, [data-kvcapsize="largest"] .kvx-capdemo { font-size: 2.6rem; }


/* ------------------------------------------------------------
   Single-switch scanning
   ------------------------------------------------------------
   The highlight is a thick ring in the text colour, so it is a shape
   and not only a colour, and it reads on all three themes. A group
   (when there are too many things to step through one at a time) gets
   a dashed ring, so it is clear whether one press chooses a group or
   a button.
   ------------------------------------------------------------ */
[data-kvscan="on"] {
  outline: 6px solid var(--text-main) !important;
  outline-offset: 3px !important;
  box-shadow: 0 0 0 3px var(--surface) !important;
  position: relative;
  z-index: 2;
}
[data-kvscan="group"] {
  outline: 4px dashed var(--text-main) !important;
  outline-offset: 4px !important;
}
#kvScanHint {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  max-width: min(92vw, 34rem);
  padding: .6em 1.1em; border-radius: var(--r-card);
  background: var(--text-main); color: var(--surface);
  font-weight: 800; font-size: 1.05rem; text-align: center; z-index: 100000;
}
#kvScanHint[hidden] { display: none; }


/* ============================================================
   High contrast — WCAG 2.2 AAA, 7:1 for text
   ============================================================

   A position of each theme, not a fourth theme: the same paper, the
   same idea, with the middle tones taken out. Press stays warm paper
   with near-black ink; Cut Paper stays pale green-grey; Lamplight stays
   a warm dark with light ink. What changes is that nothing is grey
   any more.

   How it is defined. Every colour variable a theme defines is
   redefined here as one opaque value, because a translucent line
   (rgba .13) has a contrast that depends on what it sits on and
   cannot be measured as a pair. Each pair that is ever drawn together
   is listed in handoff/access-contrast.mjs, which reads THIS FILE,
   computes the WCAG ratio for each and fails below 7:1. Change a hex
   here and that script is the thing that tells you if you broke it.

   Pairs that carry the whole interface, and what each is for:
     --text-main  on every surface    body text
     --text-muted on every surface    secondary text (held to 7:1 too,
                                      not the 4.5 the standard asks)
     --on-accent  on accent, yes, maybe, no, away, warn, and the six
                  pastels            text inside a button or a label
     the six pastels on every surface the places they are used as ink
     --yes-ink    on page and card   "owned", "saved"
     --edge       on every surface   the edge of a control or a card;
                                     --line and --hair are the same ink
     hero ink on hero panel          the welcome panel

   Pastels: in the original palette they are used both as ink on a
   surface and as a background under white text, and no single colour
   can be 7:1 against a page and against white unless it is dark.
   So in Press and Cut Paper they are deep inks, and in Lamplight,
   where the page is dark, they are light and the few places that put
   white text on one are re-pointed at the accent below.

   No braces in the comments inside the blocks: the check script
   splits the file on them.
   ============================================================ */

html[data-kvtheme="press"][data-kvcontrast="high"] {
  --surface:    #FBF3E4;
  --bg-color:   #F5EAD6;
  --card-bg:    #FFFDF8;
  --inset:      #F5EBDA;
  --sidebar:    #EFE2CC;
  --quiet:      #E8D9C0;
  --text-main:  #1B120B;
  --text-muted: #3A2C20;
  --edge:       #3A2C20;
  --line:       #3A2C20;
  --hair:       #3A2C20;
  --accent:     #8E1F0F;
  --on-accent:  #FFFFFF;
  --yes:        #1A5235;  --yes-ink: #1A5235;
  --maybe:      #5F4000;
  --no:         #8E1F0F;
  --away:       #1B4F86;
  --warn:       #8E1F0F;
  --warn-wash:  #F7DDD3;
  --warn-line:  #8E1F0F;
  --pastel-blue: #1B4F86; --pastel-pink: #8A1F4E; --pastel-teal: #1A5235;
  --pastel-yellow: #5F4000; --pastel-purple: #5A3A8A; --pastel-orange: #8E1F0F;
}
html[data-kvtheme="press"][data-kvcontrast="high"] .hero {
  --hero-bg: #1B4F86; --hero-ink: #FFFFFF;
  --hero-cta-bg: #FFFFFF; --hero-cta-ink: #1B4F86;
}

html[data-kvtheme="cutpaper"][data-kvcontrast="high"] {
  --surface:    #EEF2E8;
  --bg-color:   #E4EADC;
  --card-bg:    #FFFFFF;
  --inset:      #F2F5EC;
  --sidebar:    #F7F9F2;
  --quiet:      #DDE5D2;
  --text-main:  #14201A;
  --text-muted: #2E3D34;
  --edge:       #2E3D34;
  --line:       #2E3D34;
  --hair:       #2E3D34;
  --accent:     #84300F;
  --on-accent:  #FFFFFF;
  --yes:        #1A5228;  --yes-ink: #1A5228;
  --maybe:      #5F4000;
  --no:         #7A2222;
  --away:       #523A6A;
  --warn:       #84300F;
  --warn-wash:  #F8E0D6;
  --warn-line:  #84300F;
  --pastel-blue: #1F4A78; --pastel-pink: #7F2748; --pastel-teal: #1A5228;
  --pastel-yellow: #5F4000; --pastel-purple: #523A6A; --pastel-orange: #84300F;
}
html[data-kvtheme="cutpaper"][data-kvcontrast="high"] .hero {
  --hero-bg: #1F4A78; --hero-ink: #FFFFFF;
  --hero-cta-bg: #FFFFFF; --hero-cta-ink: #1F4A78;
}

/* The page's own dark default, when no look has been chosen at all,
   gets Lamplight's position: it is the dark one. */
html[data-kvtheme="lamplight"][data-kvcontrast="high"],
html:not([data-kvtheme])[data-kvcontrast="high"] {
  --surface:    #0F0C0A;
  --bg-color:   #16120F;
  --card-bg:    #1E1814;
  --inset:      #130F0C;
  --sidebar:    #130F0C;
  --quiet:      #2B231D;
  --text-main:  #FFF4E2;
  --text-muted: #E6D6BE;
  --edge:       #E6D6BE;
  --line:       #E6D6BE;
  --hair:       #E6D6BE;
  --accent:     #FFC25C;
  --on-accent:  #1A1005;
  --yes:        #8FD19A;  --yes-ink: #8FD19A;
  --maybe:      #FFD27A;
  --no:         #FF9A9F;
  --away:       #9CC2FF;
  --warn:       #FFD27A;
  --warn-wash:  #3A2A12;
  --warn-line:  #FFD27A;
  --pastel-blue: #9CC2FF; --pastel-pink: #FFA3C2; --pastel-teal: #8FD19A;
  --pastel-yellow: #FFD27A; --pastel-purple: #CDB4FF; --pastel-orange: #FFB070;
}
/* The welcome panel sets its own colours on itself in theme.css, which
   beats anything set higher up, so it has to be answered on the panel. */
html[data-kvtheme="lamplight"][data-kvcontrast="high"] .hero,
html:not([data-kvtheme])[data-kvcontrast="high"] .hero {
  --hero-bg: #26190E; --hero-ink: #FFF4E2;
  --hero-cta-bg: #FFF4E2; --hero-cta-ink: #26190E;
}

/* What is the same in all three positions. Everything here points at
   the variables above, so the pair that is measured is the pair that
   is drawn. */
html[data-kvcontrast="high"] {
  --card-edge: 2px solid var(--edge);
  --shadow-soft: none;
  --shadow-hover: none;
  --surf-1: var(--inset);
  --surf-2: var(--quiet);
  --sunk: var(--inset);
}
html[data-kvcontrast="high"] body { background: var(--surface); color: var(--text-main); }
html[data-kvcontrast="high"] .card,
html[data-kvcontrast="high"] .kvr-card,
html[data-kvcontrast="high"] .settings-panel,
html[data-kvcontrast="high"] .modal-content,
html[data-kvcontrast="high"] .baby-card,
html[data-kvcontrast="high"] .live-class-card,
html[data-kvcontrast="high"] .assignment-card {
  border: 2px solid var(--edge);
  background-image: none;
  box-shadow: none;
}
html[data-kvcontrast="high"] input,
html[data-kvcontrast="high"] select,
html[data-kvcontrast="high"] textarea {
  background: var(--card-bg); color: var(--text-main); border: 2px solid var(--edge);
}
html[data-kvcontrast="high"] ::placeholder { color: var(--text-muted); opacity: 1; }
html[data-kvcontrast="high"] a { color: var(--text-main); text-decoration: underline; }
html[data-kvcontrast="high"] .btn-primary,
html[data-kvcontrast="high"] .kvr-btn,
html[data-kvcontrast="high"] .kvl-btn,
html[data-kvcontrast="high"] .admin-table th,
html[data-kvcontrast="high"] .auth-tab.active,
html[data-kvcontrast="high"] .kv-heart.on {
  background: var(--accent); color: var(--on-accent); border: 2px solid var(--edge);
}
html[data-kvcontrast="high"] .btn-secondary,
html[data-kvcontrast="high"] .kvr-btn.ghost,
html[data-kvcontrast="high"] .kvl-btn.ghost {
  background: var(--card-bg); color: var(--text-main); border: 2px solid var(--edge);
}
/* A label laid over a picture cannot be measured against a picture it
   has never seen, so it carries its own solid ground. */
html[data-kvcontrast="high"] .kv-tag { background: var(--text-main); color: var(--surface); }
html[data-kvcontrast="high"] .kv-new { background: var(--accent); color: var(--on-accent); }
/* index.html gives .tag a fixed pale grey, which is unreadable under
   Lamplight's light ink. */
html[data-kvcontrast="high"] .tag { background: var(--quiet); color: var(--text-main); }
html[data-kvcontrast="high"] .kvl-done { background: var(--yes); color: var(--on-accent); }
/* The reading page was cream with brown ink whatever the theme. In
   high contrast it takes the theme's own card and ink, so the pair
   that is measured is the pair that is drawn. */
html[data-kvcontrast="high"] .kvl-page { background: var(--card-bg); color: var(--text-main); border: 2px solid var(--edge); }
html[data-kvcontrast="high"] .hero { border: 2px solid var(--edge); }
html[data-kvcontrast="high"] .hero #heroGreeting { color: var(--hero-ink); }
html[data-kvcontrast="high"] .kvi,
html[data-kvcontrast="high"] .kvi.warn { border-width: 2px; }
