/*
 * Styling for the practice activity.
 *
 * No web fonts: the system stack is used so the page makes no external
 * request of any kind and there is nothing to self-host. Colors are chosen
 * against WCAG 2.2 AA (4.5:1 for text, 3:1 for borders and other non-text)
 * and checked rather than eyeballed; see tools/contrast.mjs.
 *
 * Correctness is never carried by color alone — every correct/incorrect
 * state also has a glyph and a words-out-loud label.
 */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --surface: #f1f4f8;
  --surface-edge: #748094;
  --ink: #141c28;
  --ink-muted: #45505f;

  --accent: #14459c;
  --accent-ink: #ffffff;
  --focus: #7a3ad6;

  --correct: #10603a;
  --correct-bg: #e8f4ed;
  --incorrect: #96202c;
  --incorrect-bg: #fceceb;
  --partial: #7a4a00;
  --partial-bg: #fdf1dd;

  --radius: 10px;
  --edge: 2px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101620;
    --surface: #1a2333;
    --surface-edge: #6e7f96;
    --ink: #eef2f8;
    --ink-muted: #b9c4d4;
    --accent: #9fc0ff;
    --accent-ink: #0b1220;
    --focus: #d3a6ff;
    --correct: #7ede9f;
    --correct-bg: #14301f;
    --incorrect: #ffa8a4;
    --incorrect-bg: #3a1a1c;
    --partial: #f4c87c;
    --partial-bg: #33260f;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* An author-sheet `display` beats the user-agent's [hidden] rule, so the
   flex/grid containers below would ignore the attribute without this. */
[hidden] {
  display: none !important;
}

html {
  /* Never below 100%: a fixed px root would break the 200% zoom criterion. */
  font-size: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
}

/* ---------------------------------------------------------------- */
/* focus — visible everywhere, never removed                         */
/* ---------------------------------------------------------------- */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Headings receive focus on phase changes; they are not interactive, so
   they get no persistent ring, only the one the browser draws on focus. */
[tabindex="-1"]:focus {
  outline: none;
}
[tabindex="-1"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip-link:focus {
  left: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- */
/* layout — reflows to 320px with no horizontal scrolling            */
/* ---------------------------------------------------------------- */

.shell {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

@media (min-width: 40em) {
  .shell {
    padding: 3rem 1.5rem 4rem;
  }
}

.title {
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  line-height: 1.2;
  margin: 0 0 0.75rem;
}

.lede {
  font-size: 1.125rem;
  margin: 0 0 1.75rem;
  max-width: 34rem;
}

.meta {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin: 1rem 0 0;
}

.prompt {
  font-size: clamp(1.25rem, 4vw, 1.6rem);
  line-height: 1.25;
  margin: 0 0 1rem;
}

/* ---------------------------------------------------------------- */
/* progress                                                          */
/* ---------------------------------------------------------------- */

.progress-wrap {
  margin: 0 0 1.5rem;
}

.progress {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
  font-variant-numeric: tabular-nums;
}

.bar {
  display: flex;
  gap: 3px;
}

.seg {
  flex: 1 1 0;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-edge);
}
.seg.done {
  background: var(--accent);
}
.seg.here {
  background: var(--accent);
  opacity: 0.55;
}

/* ---------------------------------------------------------------- */
/* the sentence                                                      */
/* ---------------------------------------------------------------- */

.sentence {
  font-size: clamp(1.2rem, 4.5vw, 1.55rem);
  line-height: 1.7;
  background: var(--surface);
  border: var(--edge) solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin: 0 0 1.5rem;
}

.sentence mark.target {
  background: transparent;
  color: inherit;
  font-weight: 700;
  /* Shape, not color: the marked word is legible without perceiving hue. */
  box-shadow: inset 0 -0.55em 0 rgba(122, 58, 214, 0.22);
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  padding: 0 0.1em;
}

/* ---------------------------------------------------------------- */
/* buttons — all comfortably past the 24x24 minimum                  */
/* ---------------------------------------------------------------- */

.btn {
  font: inherit;
  min-height: 44px;
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  border: var(--edge) solid transparent;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.btn--choice {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg);
  color: var(--ink);
  border-color: var(--surface-edge);
  font-weight: 600;
}

.choices--judge {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (hover: hover) {
  .btn--choice:hover {
    border-color: var(--accent);
    background: var(--surface);
  }
  .btn--primary:hover {
    filter: brightness(1.1);
  }
}

/* ---------------------------------------------------------------- */
/* word and replacement choices                                      */
/* ---------------------------------------------------------------- */

.group {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0; /* lets the fieldset shrink below its content at 320px */
}

.legend {
  padding: 0;
}
/* The visible prompt is the focused <h2>; the legend repeats it for the
   group's accessible name, so its visible copy is redundant on screen. */
.legend .prompt-inline {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.words {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  background: var(--surface);
  border: var(--edge) solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1.25rem;
  font-size: clamp(1.15rem, 4.2vw, 1.45rem);
  line-height: 1.6;
}

.word,
.option {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

.word-input,
.option-input {
  /* Kept in the accessibility tree and focusable; only painted off. */
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.word-text,
.option-text {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.25rem 0.6rem;
  border: var(--edge) dashed var(--surface-edge);
  border-radius: 8px;
}

/* Checked state is signalled by border weight and a glyph as well as by
   color, so it survives greyscale and color-vision differences. */
.word-input:checked + .word-text,
.option-input:checked + .option-text {
  border-style: solid;
  border-width: 3px;
  border-color: var(--accent);
  background: var(--bg);
  font-weight: 700;
}

.word-input:checked + .word-text::before,
.option-input:checked + .option-text::before {
  content: "✓";
  font-weight: 700;
  color: var(--accent);
}

.word-input:focus-visible + .word-text,
.option-input:focus-visible + .option-text {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

@media (hover: hover) {
  .word:hover .word-text,
  .option:hover .option-text {
    border-color: var(--accent);
  }
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1.25rem;
  font-size: clamp(1.15rem, 4.2vw, 1.45rem);
}

.options .option-text {
  padding: 0.4rem 1rem;
  border-style: solid;
}

/* ---------------------------------------------------------------- */
/* notices, hints and feedback                                       */
/* ---------------------------------------------------------------- */

.notice,
.hint {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0 0 1.25rem;
  border-left: 6px solid;
}

.notice--correct {
  background: var(--correct-bg);
  color: var(--correct);
  border-left-color: var(--correct);
}
.notice--incorrect,
.hint {
  background: var(--incorrect-bg);
  color: var(--incorrect);
  border-left-color: var(--incorrect);
}

.notice-mark {
  font-weight: 700;
  flex: none;
}

.feedback {
  border: var(--edge) solid;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 0 0 1.5rem;
}

.feedback--correct {
  border-color: var(--correct);
  background: var(--correct-bg);
}
.feedback--incorrect {
  border-color: var(--incorrect);
  background: var(--incorrect-bg);
}

/* Partly right: the student fixed the sentence but did not spot at first
   that it needed fixing. Distinct from both, because it is neither. */
.feedback--partial {
  border-color: var(--partial);
  background: var(--partial-bg);
}

.verdict {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
}
.feedback--correct .verdict {
  color: var(--correct);
}
.feedback--incorrect .verdict {
  color: var(--incorrect);
}
.feedback--partial .verdict {
  color: var(--partial);
}

.verdict-mark {
  font-size: 1.35rem;
  flex: none;
}

.corrected {
  font-size: 1.2rem;
  font-weight: 600;
  background: var(--bg);
  border: var(--edge) solid var(--surface-edge);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0 0 0.9rem;
  color: var(--ink);
}

.detail,
.explanation p {
  margin: 0 0 0.6rem;
  color: var(--ink);
}
.explanation p:last-child {
  margin-bottom: 0;
}

/* ---------------------------------------------------------------- */
/* results                                                           */
/* ---------------------------------------------------------------- */

.family-block {
  margin: 0 0 1.5rem;
  border: var(--edge) solid var(--surface-edge);
  border-left-width: 6px;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.family-block--strong {
  border-left-color: var(--correct);
}
.family-block--practice {
  border-left-color: var(--incorrect);
}

.family-heading {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.families {
  margin: 0;
  padding-left: 1.25rem;
}
.families li {
  margin-bottom: 0.25rem;
}
.family-name {
  font-weight: 600;
}
.family-count {
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- */
/* motion                                                            */
/* ---------------------------------------------------------------- */

/* There is no animation in this activity by design. This is a backstop for
   anything a future change might introduce, and for UA-level smooth
   scrolling. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------- */
/* words referred to inside feedback                                 */
/* ---------------------------------------------------------------- */

/* Feedback sentences are mostly *about* words, and an unmarked word
   disappears into the prose around it. Quotation marks come from the DOM;
   weight and a slight size bump come from here. Colour is deliberately not
   used, so this reads the same for everyone and inside every panel tone. */
.word-ref {
  font-weight: 700;
  font-size: 1.05em;
  white-space: nowrap;
}

/* The word that changed, inside the corrected sentence. Underlined rather
   than quoted: it is being read as part of a sentence, not named. */
.fixed-word {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

/* ---------------------------------------------------------------- */
/* reviewing answers after the round                                 */
/* ---------------------------------------------------------------- */

.results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.btn--secondary {
  background: var(--bg);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

@media (hover: hover) {
  .btn--secondary:hover {
    background: var(--surface);
  }
}

.review {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.review-item {
  border: var(--edge) solid var(--surface-edge);
  border-left-width: 6px;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 0 0 1rem;
}

/* Tone is carried by the edge, but never only by it: each entry also has a
   glyph and a worded headline. */
.review-item--correct {
  border-left-color: var(--correct);
}
.review-item--partial {
  border-left-color: var(--partial);
}
.review-item--incorrect {
  border-left-color: var(--incorrect);
}

.review-verdict {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.6rem;
}

.review-mark {
  font-weight: 700;
  flex: none;
}
.review-item--correct .review-mark {
  color: var(--correct);
}
.review-item--partial .review-mark {
  color: var(--partial);
}
.review-item--incorrect .review-mark {
  color: var(--incorrect);
}

.review-number {
  font-weight: 700;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.review-headline {
  font-weight: 600;
}

.review-sentence {
  font-size: 1.1rem;
  background: var(--surface);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin: 0 0 0.6rem;
}

.review-corrected {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
}
