// irikos — Irregular-Verbs drill (the Trainer's "Focused drill").
// DATA + checking logic are transcribed VERBATIM from the source trainer
// (irregular_verbs_trainer-2.html) — three sets of forms / spelling / gaps.
// Renders the three task-types inside the re-skinned dark practice card.
// Reuses globals from practice.jsx: useForceDark, PracticeMotif, ReportControl,
// formatDuration. Exposed: TrainerRun, buildVerbQueue.

const { useState: tvUseState, useEffect: tvUseEffect, useRef: tvUseRef } = React;

// ============ THREE SETS (verbatim) ============
const VERB_SETS = [
  /* SET 1 */
  {
    forms: [
      { base: "begin", past: "began", pp: "begun" },
      { base: "choose", past: "chose", pp: "chosen" },
      { base: "forget", past: "forgot", pp: ["forgotten", "forgot"] },
      { base: "hold", past: "held", pp: "held" },
      { base: "lead", past: "led", pp: "led" },
      { base: "rise", past: "rose", pp: "risen" },
      { base: "shake", past: "shook", pp: "shaken" },
      { base: "swear", past: "swore", pp: "sworn" },
      { base: "tear", past: "tore", pp: "torn" },
      { base: "weave", past: "wove", pp: "woven" },
      { base: "freeze", past: "froze", pp: "frozen" },
      { base: "strike", past: "struck", pp: ["struck", "stricken"] },
    ],
    spelling: [
      { base: "bite", past: "bit", pp: "bitten", hide: "pp" },
      { base: "creep", past: "crept", pp: "crept", hide: "past" },
      { base: "flee", past: "fled", pp: "fled", hide: "past" },
      { base: "grind", past: "ground", pp: "ground", hide: "pp" },
      { base: "hang", past: "hung", pp: "hung", hide: "past" },
      { base: "kneel", past: ["knelt", "kneeled"], pp: ["knelt", "kneeled"], hide: "pp" },
      { base: "seek", past: "sought", pp: "sought", hide: "past" },
      { base: "sew", past: "sewed", pp: ["sewn", "sewed"], hide: "pp" },
      { base: "split", past: "split", pp: "split", hide: "past" },
      { base: "swell", past: "swelled", pp: ["swollen", "swelled"], hide: "pp" },
    ],
    gaps: [
      { pre: "The meeting ", verb: "begin", post: " exactly on time, so we missed the introduction.", ans: ["began"], tag: "Past Simple" },
      { pre: "She ", verb: "already / finish", post: " the report and sent it to her manager.", ans: ["has already finished"], tag: "Present Perfect" },
      { pre: "The old bridge ", verb: "build", post: " more than a hundred years ago.", ans: ["was built"], tag: "Passive" },
      { pre: "I ", verb: "never / see", post: " such a beautiful sunset before this trip.", ans: ["have never seen"], tag: "Present Perfect" },
      { pre: "When the alarm rang, everyone ", verb: "leave", post: " the building calmly.", ans: ["left"], tag: "Past Simple" },
      { pre: "These letters ", verb: "write", post: " by a famous poet in the 19th century.", ans: ["were written"], tag: "Passive" },
      { pre: "They ", verb: "just / arrive", post: ", so dinner is still warm.", ans: ["have just arrived"], tag: "Present Perfect" },
      { pre: "The thieves ", verb: "catch", post: " by the police near the station.", ans: ["were caught"], tag: "Passive" },
      { pre: "He ", verb: "break", post: " his leg while skiing last winter.", ans: ["broke"], tag: "Past Simple" },
      { pre: "The new museum ", verb: "not / open", post: " to visitors yet.", ans: ["has not opened", "hasn't opened", "has not been opened", "hasn't been opened"], tag: "Present Perfect" },
      { pre: "The cake ", verb: "eat", post: " before the guests even sat down.", ans: ["was eaten"], tag: "Passive" },
      { pre: "We ", verb: "lose", post: " our way in the forest and returned home late.", ans: ["lost"], tag: "Past Simple" },
    ],
  },
  /* SET 2 */
  {
    forms: [
      { base: "bring", past: "brought", pp: "brought" },
      { base: "show", past: "showed", pp: ["shown", "showed"] },
      { base: "feel", past: "felt", pp: "felt" },
      { base: "fall", past: "fell", pp: "fallen" },
      { base: "drive", past: "drove", pp: "driven" },
      { base: "grow", past: "grew", pp: "grown" },
      { base: "throw", past: "threw", pp: "thrown" },
      { base: "ride", past: "rode", pp: "ridden" },
      { base: "sink", past: "sank", pp: "sunk" },
      { base: "steal", past: "stole", pp: "stolen" },
      { base: "hide", past: "hid", pp: "hidden" },
      { base: "wake", past: ["woke", "waked"], pp: ["woken", "waked"] },
    ],
    spelling: [
      { base: "deal", past: "dealt", pp: "dealt", hide: "past" },
      { base: "lend", past: "lent", pp: "lent", hide: "pp" },
      { base: "mean", past: "meant", pp: "meant", hide: "past" },
      { base: "spread", past: "spread", pp: "spread", hide: "past" },
      { base: "shoot", past: "shot", pp: "shot", hide: "pp" },
      { base: "spin", past: "spun", pp: "spun", hide: "past" },
      { base: "stick", past: "stuck", pp: "stuck", hide: "pp" },
      { base: "swing", past: "swung", pp: "swung", hide: "past" },
      { base: "tread", past: "trod", pp: ["trodden", "trod"], hide: "pp" },
      { base: "wind", past: "wound", pp: "wound", hide: "past" },
    ],
    gaps: [
      { pre: "The waiter ", verb: "bring", post: " us the wrong dishes by mistake.", ans: ["brought"], tag: "Past Simple" },
      { pre: "My grandmother ", verb: "grow", post: " these vegetables in her own garden for years.", ans: ["has grown"], tag: "Present Perfect" },
      { pre: "The painting ", verb: "steal", post: " from the gallery last night.", ans: ["was stolen"], tag: "Passive" },
      { pre: "We ", verb: "just / finish", post: " cleaning, so please take off your shoes.", ans: ["have just finished"], tag: "Present Perfect" },
      { pre: "He ", verb: "fall", post: " off his bicycle but luckily wasn't hurt.", ans: ["fell"], tag: "Past Simple" },
      { pre: "The keys ", verb: "hide", post: " under the doormat by my neighbour.", ans: ["were hidden"], tag: "Passive" },
      { pre: "I ", verb: "never / feel", post: " so nervous before an interview.", ans: ["have never felt"], tag: "Present Perfect" },
      { pre: "The driver ", verb: "show", post: " us a shorter route to the airport.", ans: ["showed"], tag: "Past Simple" },
      { pre: "Dinner ", verb: "already / cook", post: ", so we can sit down right away.", ans: ["has already been cooked"], tag: "Passive" },
      { pre: "The ship ", verb: "sink", post: " quickly after it hit the rocks.", ans: ["sank"], tag: "Past Simple" },
      { pre: "These photos ", verb: "take", post: " during our holiday in the mountains.", ans: ["were taken"], tag: "Passive" },
      { pre: "She ", verb: "not / decide", post: " which university to apply to yet.", ans: ["has not decided", "hasn't decided"], tag: "Present Perfect" },
    ],
  },
  /* SET 3 */
  {
    forms: [
      { base: "speak", past: "spoke", pp: "spoken" },
      { base: "wear", past: "wore", pp: "worn" },
      { base: "blow", past: "blew", pp: "blown" },
      { base: "draw", past: "drew", pp: "drawn" },
      { base: "swim", past: "swam", pp: "swum" },
      { base: "ring", past: "rang", pp: "rung" },
      { base: "bear", past: "bore", pp: ["borne", "born"] },
      { base: "forgive", past: "forgave", pp: "forgiven" },
      { base: "mistake", past: "mistook", pp: "mistaken" },
      { base: "overcome", past: "overcame", pp: "overcome" },
      { base: "withdraw", past: "withdrew", pp: "withdrawn" },
      { base: "undertake", past: "undertook", pp: "undertaken" },
    ],
    spelling: [
      { base: "bend", past: "bent", pp: "bent", hide: "past" },
      { base: "bleed", past: "bled", pp: "bled", hide: "pp" },
      { base: "breed", past: "bred", pp: "bred", hide: "past" },
      { base: "cling", past: "clung", pp: "clung", hide: "pp" },
      { base: "dig", past: "dug", pp: "dug", hide: "past" },
      { base: "feed", past: "fed", pp: "fed", hide: "pp" },
      { base: "light", past: ["lit", "lighted"], pp: ["lit", "lighted"], hide: "past" },
      { base: "slide", past: "slid", pp: "slid", hide: "pp" },
      { base: "strive", past: ["strove", "strived"], pp: ["striven", "strived"], hide: "pp" },
      { base: "weep", past: "wept", pp: "wept", hide: "past" },
    ],
    gaps: [
      { pre: "The teacher ", verb: "speak", post: " to us about the importance of teamwork.", ans: ["spoke"], tag: "Past Simple" },
      { pre: "The company ", verb: "recently / launch", post: " a new product line in Europe.", ans: ["has recently launched"], tag: "Present Perfect" },
      { pre: "The letter ", verb: "send", post: " to the wrong address by the post office.", ans: ["was sent"], tag: "Passive" },
      { pre: "I ", verb: "already / read", post: " this book, so I know how it ends.", ans: ["have already read"], tag: "Present Perfect" },
      { pre: "The wind ", verb: "blow", post: " so hard that several trees fell down.", ans: ["blew"], tag: "Past Simple" },
      { pre: "The bridge ", verb: "design", post: " by a young Italian architect.", ans: ["was designed"], tag: "Passive" },
      { pre: "They ", verb: "not / arrive", post: " yet, although the train was on time.", ans: ["have not arrived", "haven't arrived"], tag: "Present Perfect" },
      { pre: "She ", verb: "wear", post: " a bright red coat to the ceremony.", ans: ["wore"], tag: "Past Simple" },
      { pre: "The results ", verb: "announce", post: " on the school website this morning.", ans: ["were announced"], tag: "Passive" },
      { pre: "He ", verb: "swim", post: " across the river despite the cold water.", ans: ["swam"], tag: "Past Simple" },
      { pre: "The documents ", verb: "already / sign", post: ", so the deal is final.", ans: ["have already been signed"], tag: "Passive" },
      { pre: "We ", verb: "never / visit", post: " that part of the country before.", ans: ["have never visited"], tag: "Present Perfect" },
    ],
  },
];

// ============ checking (verbatim logic) ============
function vbNorm(s) { return String(s == null ? "" : s).trim().toLowerCase().replace(/\s+/g, " "); }
function vbMatches(val, ans) { const v = vbNorm(val); const list = Array.isArray(ans) ? ans : [ans]; return list.some((a) => vbNorm(a) === v); }
function vbCell(val) { return Array.isArray(val) ? val[0] : val; }
function vbShuffle(a) { const x = a.slice(); for (let i = x.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [x[i], x[j]] = [x[j], x[i]]; } return x; }

// Flatten the chosen task-types across all sets into a run queue.
function buildVerbQueue(types, len) {
  const items = [];
  VERB_SETS.forEach((set, si) => {
    if (types.includes("complete")) set.forms.forEach((f, i) => items.push({ kind: "complete", id: `c${si}-${i}`, ...f }));
    if (types.includes("spelling")) set.spelling.forEach((f, i) => items.push({ kind: "spelling", id: `s${si}-${i}`, ...f }));
    if (types.includes("brackets")) set.gaps.forEach((g, i) => items.push({ kind: "brackets", id: `b${si}-${i}`, ...g }));
  });
  const shuffled = vbShuffle(items);
  const endless = len === "Endless";
  const n = endless ? shuffled.length : Math.min(Number(len) || 20, shuffled.length);
  return { queue: shuffled.slice(0, n), endless };
}

const VB_TYPE_LABEL = { complete: "Complete the form", spelling: "Spelling", brackets: "Open the brackets" };

// a readable correct-answer string for feedback + reports
function vbCorrectText(it) {
  if (it.kind === "complete") return `${vbCell(it.past)} · ${vbCell(it.pp)}`;
  if (it.kind === "spelling") return vbCell(it.hide === "past" ? it.past : it.pp);
  return vbCell(it.ans);
}
function vbReportItem(it) {
  const sentence = it.kind === "brackets" ? `${it.pre}______${it.post} (${it.verb})`
    : it.kind === "spelling" ? `${it.base} · ${it.hide === "past" ? "______" : vbCell(it.past)} · ${it.hide === "pp" ? "______" : vbCell(it.pp)}`
    : `${it.base} → past simple / past participle`;
  return { id: it.id, type: "irregular", category: "irregular-verbs:" + it.kind, base: it.base, sentence, answer: vbCorrectText(it) };
}

// Registry of every verb item by id, so the Mistakes screen can resolve a drill
// mistake (verb items aren't in VOCAB). Drills carry category "irregular-verbs".
const VERB_MISTAKE_ITEMS = (() => {
  const reg = {};
  VERB_SETS.forEach((set, si) => {
    set.forms.forEach((f, i) => { reg[`c${si}-${i}`] = vbReportItem({ kind: "complete", id: `c${si}-${i}`, ...f }); });
    set.spelling.forEach((f, i) => { reg[`s${si}-${i}`] = vbReportItem({ kind: "spelling", id: `s${si}-${i}`, ...f }); });
    set.gaps.forEach((g, i) => { reg[`b${si}-${i}`] = vbReportItem({ kind: "brackets", id: `b${si}-${i}`, ...g }); });
  });
  return reg;
})();

// Full verb items by id — TrainerRun needs the complete shape (past/pp/pre/post/…),
// not the trimmed report shape — so the Mistakes screen can re-run the exact verbs
// you got wrong as a focused drill.
const VERB_FULL_ITEMS = (() => {
  const reg = {};
  VERB_SETS.forEach((set, si) => {
    set.forms.forEach((f, i) => { reg[`c${si}-${i}`] = { kind: "complete", id: `c${si}-${i}`, ...f }; });
    set.spelling.forEach((f, i) => { reg[`s${si}-${i}`] = { kind: "spelling", id: `s${si}-${i}`, ...f }; });
    set.gaps.forEach((g, i) => { reg[`b${si}-${i}`] = { kind: "brackets", id: `b${si}-${i}`, ...g }; });
  });
  return reg;
})();

// Build a drill run from explicit item ids (Mistakes → "Practice" on the Drills filter).
function buildVerbQueueFromIds(ids, len) {
  const items = (ids || []).map((id) => VERB_FULL_ITEMS[id]).filter(Boolean);
  const shuffled = vbShuffle(items);
  const n = len ? Math.min(Number(len), shuffled.length) : shuffled.length;
  return { queue: shuffled.slice(0, n), endless: false };
}

// =====================================================================
// THE RUN
// =====================================================================
function TrainerRun({ config, onExit, onFinish, recordAnswer }) {
  useForceDark();
  const { queue, endless } = config;
  const total = queue.length;
  const [idx, setIdx] = tvUseState(0);
  const [a1, setA1] = tvUseState("");
  const [a2, setA2] = tvUseState("");
  const [feedback, setFeedback] = tvUseState(null);
  const [score, setScore] = tvUseState(0);
  const [streak, setStreak] = tvUseState(0);
  const [correct, setCorrect] = tvUseState(0);
  const [answered, setAnswered] = tvUseState(0);
  const [done, setDone] = tvUseState(false);
  const [missed, setMissed] = tvUseState([]);
  const [finalMs, setFinalMs] = tvUseState(0);
  const [qStart, setQStart] = tvUseState(() => Date.now());
  const [elapsed, setElapsed] = tvUseState(0);
  const firstRef = tvUseRef(null);
  const secondRef = tvUseRef(null);   // 'complete the form' has two boxes; Enter jumps 1→2
  const sessionStartRef = tvUseRef(null);
  if (sessionStartRef.current === null) sessionStartRef.current = Date.now();

  tvUseEffect(() => { if (done) return; const t = setInterval(() => setElapsed(Date.now() - qStart), 250); return () => clearInterval(t); }, [qStart, done]);
  tvUseEffect(() => { if (firstRef.current && !feedback) firstRef.current.focus(); }, [idx, feedback]);

  if (!total) { onExit && onExit(); return null; }
  const it = queue[idx];
  const accuracy = answered ? Math.round((correct / answered) * 100) : 0;
  const progressPct = ((idx + (feedback ? 1 : 0)) / total) * 100;

  const grade = () => {
    let ok;
    if (it.kind === "complete") ok = vbMatches(a1, it.past) && vbMatches(a2, it.pp);
    else if (it.kind === "spelling") ok = vbMatches(a1, it.hide === "past" ? it.past : it.pp);
    else ok = vbMatches(a1, it.ans);
    return ok;
  };
  const submit = () => {
    if (feedback) return;
    const ok = grade();
    setFeedback({ ok, answer: vbCorrectText(it) });
    setAnswered((n) => n + 1);
    if (recordAnswer) recordAnswer(vbReportItem(it), ok, null);   // global stats + Mistakes
    if (ok) { setCorrect((n) => n + 1); setScore((s) => s + 6); setStreak((s) => s + 1); if (window.haptic) window.haptic("success"); }
    else { setStreak(0); setMissed((m) => [...m, it]); if (window.haptic) window.haptic("error"); }
  };
  const advance = () => {
    if (idx + 1 >= total) {
      const dur = Date.now() - (sessionStartRef.current || Date.now());
      setFinalMs(dur);
      setDone(true);
      if (onFinish) onFinish({ correct, total, score, durationMs: dur });
      return;
    }
    setIdx((i) => i + 1); setA1(""); setA2(""); setFeedback(null); setQStart(Date.now());
  };
  const canCheck = it.kind === "complete" ? (a1.trim() && a2.trim()) : a1.trim();

  const restart = () => {
    setIdx(0); setA1(""); setA2(""); setFeedback(null); setScore(0); setStreak(0);
    setCorrect(0); setAnswered(0); setMissed([]); setDone(false);
    setQStart(Date.now()); sessionStartRef.current = Date.now();
  };

  if (done) {
    const secs = Math.round(finalMs / 1000);
    const timeStr = `${Math.floor(secs / 60)}:${String(secs % 60).padStart(2, "0")}`;
    return (
      <div className="t-run">
        <div className="t-run-body">
          <div className="t-run-shell" style={{ gap: 16 }}>
            <header className="t-block" style={{ textAlign: "center" }}>
              <h1 className="t-page-title">Run complete</h1>
              <p className="t-facts" style={{ marginTop: 4 }}>Irregular Verbs</p>
            </header>
            <div className="t-statstrip" style={{ borderRadius: "var(--radius-lg)" }}>
              <div className="t-statcell is-accent"><span className="t-stat-v">{score}</span><span className="t-stat-l">Score</span></div>
              <div className="t-statcell"><span className="t-stat-v">{correct}/{total}</span><span className="t-stat-l">Correct</span></div>
              <div className="t-statcell"><span className="t-stat-v">{accuracy}%</span><span className="t-stat-l">Accuracy</span></div>
              <div className="t-statcell"><span className="t-stat-v">{timeStr}</span><span className="t-stat-l">Time</span></div>
            </div>
            {missed.length > 0 && (
              <section className="t-block" style={{ marginTop: 4 }}>
                <div className="t-head"><h2>Review · {missed.length} missed</h2></div>
                <ul className="cat-list">
                  {missed.map((m, i) => (
                    <li className="cat-row" key={i} style={{ alignItems: "flex-start" }}>
                      <span className="status-dot" style={{ background: "var(--no)", marginTop: 7 }} />
                      <span style={{ flex: 1, minWidth: 0 }}>
                        <span className="cat-name" style={{ display: "block" }}>{m.base || VB_TYPE_LABEL[m.kind]}</span>
                        <span className="t-facts" style={{ display: "block", marginTop: 2 }}>Answer: <b style={{ color: "var(--accent-ink)" }}>{vbCorrectText(m)}</b></span>
                      </span>
                    </li>
                  ))}
                </ul>
              </section>
            )}
            <div style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 14, marginTop: 8, paddingBottom: 8 }}>
              <button className="link-btn" onClick={restart}>Practice again</button>
              <button className="cta-primary" onClick={() => onExit && onExit()}><span>Back to Trainer</span><span className="cta-arrow">→</span></button>
            </div>
          </div>
        </div>
      </div>
    );
  }

  return (
    <div className="t-run">
      <PracticeMotif />
      <div className="t-run-body">
        <div className="t-run-shell t-prac-shell">
          <div className="t-prac-top">
            <button className="t-prac-end" onClick={() => onExit && onExit()}>← End</button>
            <span className="t-prac-track"><span style={{ width: `${progressPct}%` }} /></span>
            <span className="t-prac-count">{idx + 1} / {total}</span>
          </div>

          <main className="qcard" data-feedback={feedback ? (feedback.ok ? "ok" : "no") : ""}>
            <div className="qcard-eyebrow">
              <span className="task-tag" data-task="irregular">{VB_TYPE_LABEL[it.kind]}</span>
              <span className="dot-sep">·</span><span className="eyebrow-source">Irregular Verbs</span>
            </div>

            {it.kind === "complete" && (
              <>
                <p className="t-cue">{it.base}</p>
                <div className="t-twofields">
                  <label className="t-field"><span className="t-field-label">Past simple</span>
                    <input ref={firstRef} className="answer-input" value={a1} onChange={(e) => setA1(e.target.value)} disabled={!!feedback}
                      onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); if (feedback) advance(); else if (secondRef.current) secondRef.current.focus(); } }}
                      autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck={false} /></label>
                  <label className="t-field"><span className="t-field-label">Past participle</span>
                    <input ref={secondRef} className="answer-input" value={a2} onChange={(e) => setA2(e.target.value)} disabled={!!feedback}
                      onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); (feedback ? advance() : submit()); } }}
                      autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck={false} /></label>
                </div>
              </>
            )}

            {it.kind === "spelling" && (
              <>
                <p className="t-cue">{it.base} · {it.hide === "past" ? <span className="blank" /> : vbCell(it.past)} · {it.hide === "pp" ? <span className="blank" /> : vbCell(it.pp)}</p>
                <label className="t-field" style={{ marginTop: 18 }}><span className="t-field-label">{it.hide === "past" ? "Past simple" : "Past participle"}</span>
                  <input ref={firstRef} className="answer-input" value={a1} onChange={(e) => setA1(e.target.value)} disabled={!!feedback}
                    onKeyDown={(e) => { if (e.key === "Enter") (feedback ? advance() : submit()); }}
                    autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck={false} /></label>
              </>
            )}

            {it.kind === "brackets" && (
              <>
                <h2 className="qprompt">{it.pre}<span className="blank" /> <span className="t-bracket">({it.verb})</span>{it.post}</h2>
                <span className="t-tense">{it.tag}</span>
                <input ref={firstRef} className="answer-input" style={{ marginTop: 18 }} value={a1} onChange={(e) => setA1(e.target.value)} disabled={!!feedback}
                  onKeyDown={(e) => { if (e.key === "Enter") (feedback ? advance() : submit()); }}
                  autoComplete="off" autoCorrect="off" autoCapitalize="off" spellCheck={false} />
              </>
            )}

            {feedback && (
              <div className="vb-feedback" data-ok={feedback.ok ? "1" : "0"}>
                {feedback.ok ? "Correct." : <>Answer: <b>{feedback.answer}</b></>}
              </div>
            )}
          </main>

          <div className="t-prac-foot">
            <div className="t-foot-content">
              <div className="t-statstrip">
                <div className="t-statcell is-accent"><span className="t-stat-v">{score}</span><span className="t-stat-l">Score</span></div>
                <div className="t-statcell"><span className="t-stat-v">{streak}</span><span className="t-stat-l">Streak</span></div>
                <div className="t-statcell"><span className="t-stat-v">{accuracy}%</span><span className="t-stat-l">Accuracy</span></div>
                <div className="t-statcell"><span className="t-stat-v">{formatDuration(elapsed)}</span><span className="t-stat-l">Time</span></div>
              </div>
              <ReportControl key={it.id} item={vbReportItem(it)} userAnswer={it.kind === "complete" ? `${a1} / ${a2}` : a1} />
            </div>
          </div>
        </div>
      </div>

      <div className="t-run-actions" data-feedback={feedback ? "1" : "0"}>
        {!feedback ? (
          <>
            <button className="link-btn" onClick={submit}>I don't know</button>
            <button className="primary-btn" onClick={submit} disabled={!canCheck}>Check<span className="kbd-hint">↵</span></button>
          </>
        ) : (
          <>
            <span className="action-summary">{feedback.ok ? "Nice" : "Keep going"}</span>
            <button className="primary-btn" onClick={(e) => { if (window.tapFeedback) window.tapFeedback("medium", e); advance(); }}>
              {idx + 1 >= total ? "See results" : "Next"}<span className="kbd-hint">↵</span>
            </button>
          </>
        )}
      </div>
    </div>
  );
}

Object.assign(window, { TrainerRun, buildVerbQueue, buildVerbQueueFromIds, VERB_SETS, VERB_MISTAKE_ITEMS, VERB_FULL_ITEMS });
