/* Maths chapters 1–8 */
const mc = (q, opts, a, why) => ({ type: 'mc', q, opts, a, why });
const inp = (q, accept, why, suffix) => ({ type: 'input', q, accept: [].concat(accept).map(String), why, suffix });
const ord = (q, items, order, why) => ({ type: 'order', q, items, order, why });
const DONE = [['Complete every round', s => s.done]];
window.QH = { mc, inp, ord, DONE };

window.BOOK = window.BOOK || [];
BOOK.push(
{ id: 'm1', subj: 'maths', n: 1, title: 'Negative numbers, indices and roots', strand: 'Number', codes: ['8Ni.02', '8Ni.06', '8Ni.07', '8Ni.05'],
  secs: [
    { n: '1.1', t: 'Multiplying and dividing positive and negative integers', w: 'intmul',
      intro: 'Choose two integers and watch the jumps on the number line. Notice what happens to the sign of the answer.',
      tasks: [['Multiply two negative numbers', s => s.op === '×' && s.a < 0 && s.b < 0], ['Get a negative answer with ×', s => s.op === '×' && s.p < 0], ['Switch to ÷ and divide a negative by a negative', s => s.op === '÷' && s.p < 0 && s.b < 0]],
      notice: [<>Same signs give a <b>positive</b> answer: (−4) × (−3) = 12.</>, <>Different signs give a <b>negative</b> answer: (−4) × 3 = −12.</>, <>Division follows the <b>same sign rules</b>, because it undoes multiplication.</>],
      check: [mc('(−6) × (−7) = ?', ['−42', '42', '−13', '13'], 1, 'Same signs give a positive answer: 6 × 7 = 42.'), inp('(−48) ÷ 6 = ?', '-8', 'Different signs give a negative answer: 48 ÷ 6 = 8, so −8.')] },
    { n: '1.2', t: 'Squares, cubes and roots of positive and negative numbers', w: 'powers',
      intro: 'Change n and switch between squaring and cubing. Compare what happens to negative numbers.',
      tasks: [['Square a negative number', s => s.mode === 'square' && s.n < 0], ['Cube a negative number', s => s.mode === 'cube' && s.n < 0], ['Find the cube of −4', s => s.mode === 'cube' && s.n === -4]],
      notice: [<>The square of any non-zero number is <b>positive</b>: (−5)² = 25.</>, <>So every positive number has <b>two square roots</b>: √25 = 5 or −5.</>, <>A cube keeps the sign: (−3)³ = −27, so <b>∛(−27) = −3</b>.</>],
      check: [mc('What is (−4)³?', ['64', '−64', '−12', '12'], 1, '(−4) × (−4) = 16, then 16 × (−4) = −64.'), mc('Which are the square roots of 81?', ['9 only', '−9 only', '9 and −9', '40.5'], 2, 'Both 9² and (−9)² equal 81.')] },
    { n: '1.3', t: 'The index laws', w: 'indices',
      intro: 'Multiply and divide powers of the same base. Count the factors and see which ones cancel.',
      tasks: [['Multiply two powers', s => s.op === '×' && s.m > 0 && s.n > 0], ['Divide so the answer is a power of 0', s => s.op === '÷' && s.r === 0 && s.m > 0], ['Divide to get 2⁴', s => s.op === '÷' && s.r === 4]],
      notice: [<>When you multiply powers of the same base, <b>add the indices</b>: aᵐ × aⁿ = aᵐ⁺ⁿ.</>, <>When you divide, <b>subtract the indices</b>: aᵐ ÷ aⁿ = aᵐ⁻ⁿ.</>, <>Anything (except 0) to the power 0 is <b>1</b>, because aⁿ ÷ aⁿ = 1.</>],
      check: [inp('Simplify 5³ × 5⁴. Give the answer as a power of 5: 5^?', '7', 'Add the indices: 3 + 4 = 7, so 5⁷.'), mc('What is 7⁰?', ['0', '7', '1', '70'], 2, 'Any non-zero number to the power 0 equals 1.')] },
  ],
  practice: [inp('(−3) × 5 × (−2) = ?', '30', '(−3) × 5 = −15; (−15) × (−2) = 30.'), mc('∛(−125) = ?', ['5', '−5', '±5', '−25'], 1, '(−5)³ = −125.'), inp('Simplify 2⁹ ÷ 2⁶ as a power of 2: 2^?', '3', '9 − 6 = 3.'), mc('Which is largest?', ['(−2)³', '(−3)²', '−3²', '2³'], 1, '(−3)² = 9, 2³ = 8, (−2)³ = −8 and −3² = −9.')],
  challenge: [mc('Ana says (−1)¹⁰⁰ is negative because −1 is negative. Is she correct?', ['Yes', 'No: an even number of negatives gives a positive, so it is 1', 'No: it is 0', 'No: it is −100'], 1, 'Pairs of (−1) × (−1) make 1. With 100 factors there are 50 pairs.'), inp('Find n if 3ⁿ × 3² = 3⁹ ÷ 3', '6', '3⁹ ÷ 3 = 3⁸. n + 2 = 8, so n = 6.')],
  recap: { points: ['Same signs → positive; different signs → negative (× and ÷).', 'Positive numbers have two square roots (±). Cube roots keep the sign.', 'aᵐ × aⁿ = aᵐ⁺ⁿ, aᵐ ÷ aⁿ = aᵐ⁻ⁿ, a⁰ = 1.'], terms: [['Index', 'The small raised number showing how many times to multiply.'], ['Cube root ∛', 'The number that cubes to give the value.'], ['Integer', 'A whole number: positive, negative or zero.']] } },

{ id: 'm2', subj: 'maths', n: 2, title: '2D and 3D shapes', strand: 'Geometry', codes: ['8Gg.01', '8Gg.09', '8Gg.05', '8Gg.02'],
  secs: [
    { n: '2.1', t: 'Quadrilaterals', w: 'quad',
      intro: 'Drag the corners. The shape names itself and lists the properties it has. Find as many types as you can.',
      tasks: [['Make a rectangle that is not a square', s => s.name === 'Rectangle'], ['Make a trapezium', s => s.name === 'Trapezium'], ['Find at least 5 different types', s => s.seen.length >= 5]],
      notice: [<>Quadrilaterals form a <b>hierarchy</b>: a square is a special rectangle AND a special rhombus.</>, <>Every rectangle and rhombus is a <b>parallelogram</b>.</>, <>A trapezium needs <b>at least one</b> pair of parallel sides.</>],
      check: [mc('Which statement is true?', ['Every rectangle is a square', 'Every square is a rhombus', 'Every kite is a parallelogram', 'Every trapezium is a parallelogram'], 1, 'A square has 4 equal sides, so it meets the definition of a rhombus.'), mc('A quadrilateral has two pairs of parallel sides and four equal sides, but no right angles. What is it?', ['Square', 'Rectangle', 'Rhombus', 'Kite'], 2, 'Four equal sides and no right angles make a rhombus.')] },
    { n: '2.2', t: 'Polygon symmetry', w: 'polysym',
      intro: 'Change the number of sides and rotate the regular polygon. Count the mirror lines and how often it fits onto itself.',
      tasks: [['Rotate a shape until it lands back where it started', s => s.turns >= s.n], ['Explore an octagon', s => s.n === 8]],
      notice: [<>A regular polygon with n sides has <b>n lines of symmetry</b>.</>, <>It also has <b>rotational symmetry of order n</b>.</>, <>Each turn that fits is <b>360° ÷ n</b>.</>],
      check: [inp('How many lines of symmetry does a regular hexagon have?', '6', 'A regular polygon has as many lines of symmetry as sides.'), inp('What angle does a regular pentagon need to turn to fit onto itself?', '72', '360° ÷ 5 = 72°.', '°')] },
    { n: '2.3', t: '3D shapes', w: 'euler',
      intro: 'Turn each solid. Count its vertices, faces and edges, then check Euler\'s formula.',
      tasks: [['Look at 4 different solids', s => s.seen.length >= 4]],
      notice: [<>Euler's formula: <b>V + F − E = 2</b> for these solids.</>, <>A prism has the <b>same cross-section</b> all along its length. A pyramid comes to a point.</>, <>If you know two of V, F and E, you can <b>find the third</b>.</>],
      check: [inp('A solid has 12 vertices and 8 faces. How many edges?', '18', 'V + F − E = 2 → 12 + 8 − E = 2 → E = 18.'), mc('How many faces does a hexagonal prism have?', ['6', '7', '8', '12'], 2, '6 rectangular sides + 2 hexagonal ends = 8.')] },
    { n: '2.4', t: 'Circumference of a circle', w: 'circum',
      intro: 'Roll the circle along the ruler for one full turn. Compare the distance to the diameter.',
      tasks: [['Roll a circle one full turn', s => s.roll >= 0.98], ['Try a different diameter and roll again', (s, H) => H('d', 2) || H('d', 3) || H('d', 1.5)]],
      notice: [<>The circumference is always about <b>3.14 times</b> the diameter. That number is <b>π</b>.</>, <><b>C = πd</b>, or C = 2πr because d = 2r.</>, <>π is the ratio circumference ÷ diameter, the same for every circle.</>],
      check: [inp('Find the circumference of a circle with diameter 10 cm. Use π = 3.14.', '31.4', 'C = πd = 3.14 × 10 = 31.4 cm.', 'cm'), inp('A circle has radius 5 m. Find C to 1 d.p. (π = 3.142).', '31.4', 'd = 10, so C = 3.142 × 10 = 31.42 ≈ 31.4 m.', 'm')] },
  ],
  practice: [mc('Which quadrilateral has exactly one pair of parallel sides?', ['Kite', 'Trapezium', 'Rhombus', 'Rectangle'], 1, 'A trapezium has at least one pair of parallel sides; a kite has none.'), inp('Order of rotational symmetry of a regular nonagon?', '9', 'n sides → order n.'), inp('A square-based pyramid: how many edges?', '8', '4 around the base + 4 up to the apex.'), inp('Wheel diameter 60 cm. Distance in one turn? (π = 3.14)', '188.4', 'C = 3.14 × 60 = 188.4 cm.', 'cm')],
  challenge: [mc('Sam says, "A square is not a rectangle because its sides are all equal." Which reply is best?', ['He is right', 'A rectangle needs four right angles. A square has them, so it IS a rectangle', 'Squares are rhombuses only', 'Rectangles must have unequal sides'], 1, 'A definition sets minimum properties. A square has all the properties of a rectangle.'), inp('A circular pond has circumference 44 m. Find the diameter to the nearest metre (π ≈ 3.14).', '14', 'd = C ÷ π = 44 ÷ 3.14 ≈ 14.01 → 14 m.', 'm')],
  recap: { points: ['Quadrilaterals form a hierarchy: square ⊂ rectangle, rhombus ⊂ parallelogram ⊂ trapezium.', 'Regular n-gon: n lines of symmetry, rotational order n.', 'Euler: V + F − E = 2.', 'C = πd = 2πr.'], terms: [['π (pi)', 'Circumference ÷ diameter ≈ 3.14159.'], ['Prism', 'A solid with the same cross-section throughout its length.'], ['Hierarchy', 'An ordering in which some types are special cases of others.']] } },

{ id: 'm3', subj: 'maths', n: 3, title: 'Collecting data', strand: 'Statistics', codes: ['8Ss.01', '8Ss.02'],
  secs: [
    { n: '3.1', t: 'Data collection methods', w: 'sort',
      cfg: { bins: ['Categorical', 'Discrete', 'Continuous'], items: [['Favourite sport', 0], ['Eye colour', 0], ['Number of siblings', 1], ['Goals scored', 1], ['Shoe size', 1], ['Height', 2], ['Time to run 100 m', 2], ['Mass of a bag', 2], ['Type of pet', 0]] },
      intro: 'Sort each variable by its type of data. The type affects how you collect and display it.',
      tasks: DONE,
      notice: [<><b>Categorical</b> data is words or categories. <b>Discrete</b> data is counted values.</>, <><b>Continuous</b> data is measured and can take any value in a range.</>, <>Choose a method that fits: a questionnaire, an observation, an experiment, or secondary data (collected by someone else).</>],
      check: [mc('The time it takes students to get to school is…', ['Categorical', 'Discrete', 'Continuous', 'Primary only'], 2, 'Time is measured, so it can take any value: continuous.'), mc('Which is secondary data?', ['A survey you write', 'Your own experiment', 'Census figures from a website', 'Counting cars yourself'], 2, 'Someone else collected it.')] },
    { n: '3.2', t: 'Sampling methods', w: 'sampling',
      intro: 'A school has 120 students, 60% in Year 7. Try each sampling method and compare the sample mean with the true mean.',
      tasks: [['Try all four methods', (s, H) => ['random', 'systematic', 'stratified', 'convenience'].every(m => H('method', m))], ['Take a sample of 30 or more', s => s.n >= 30]],
      notice: [<>A <b>sample</b> is used when surveying everyone would be too costly or slow.</>, <><b>Random</b>, <b>systematic</b> and <b>stratified</b> sampling reduce bias. A <b>convenience</b> sample often has bias.</>, <><b>Bigger samples</b> usually give more reliable results.</>],
      check: [mc('Why might asking only your friends be biased?', ['It is too big', 'They may share similar opinions, so the sample is not representative', 'It takes too long', 'It is random'], 1, 'A convenience sample may not represent the whole population.'), mc('A sample has 60% Year 7 and 40% Year 8, matching the school. What method is this?', ['Simple random', 'Systematic', 'Stratified', 'Convenience'], 2, 'Stratified sampling matches the proportions of each group.')] },
  ],
  practice: [mc('Number of pets is…', ['Continuous', 'Discrete', 'Categorical', 'Qualitative'], 1, 'Pets are counted.'), mc('Choosing every 10th name on a register is…', ['Random', 'Systematic', 'Stratified', 'Convenience'], 1, 'A regular interval is systematic.'), mc('An advantage of a larger sample is…', ['It is quicker', 'Results are more reliable', 'It is always unbiased', 'It costs less'], 1, 'More data reduces the effect of chance.')],
  challenge: [mc('A survey about school lunches is handed out only to students in the canteen. Explain the problem.', ['The sample is too large', 'Students who bring packed lunches elsewhere are missed, so the sample is biased', 'It is stratified', 'Canteen data is continuous'], 1, 'Part of the population cannot be selected.'), mc('A club has 200 boys and 300 girls. A stratified sample of 50 is needed. How many girls?', ['25', '30', '20', '50'], 1, 'Girls are 300/500 = 60% of the club. 60% of 50 = 30.')],
  recap: { points: ['Categorical (words), discrete (counted), continuous (measured).', 'Primary data: you collect it. Secondary data: someone else did.', 'Random, systematic and stratified samples reduce bias; larger samples are more reliable.'], terms: [['Population', 'Everyone or everything being studied.'], ['Bias', 'A result that is unfairly influenced in one direction.'], ['Stratified', 'Sampling in proportion to the groups in the population.']] } },

{ id: 'm4', subj: 'maths', n: 4, title: 'Factors and rational numbers', strand: 'Number', codes: ['8Ni.03', '8Ni.04'],
  secs: [
    { n: '4.1', t: 'Prime factors', w: 'factree',
      intro: 'Break each number down by dividing by primes until you reach 1. Wrong primes will shake.',
      tasks: DONE,
      notice: [<>Every whole number above 1 can be written as a <b>product of prime factors</b> in exactly one way.</>, <>Use <b>index notation</b> for repeats: 60 = 2² × 3 × 5.</>, <>Prime factors give the <b>HCF</b> (shared primes) and the <b>LCM</b> (all primes, with shared ones counted once).</>],
      check: [mc('Which is 72 as a product of primes?', ['8 × 9', '2³ × 3²', '2 × 36', '2² × 3³'], 1, '72 = 2 × 2 × 2 × 3 × 3 = 2³ × 3².'), inp('Find the HCF of 24 and 36.', '12', '24 = 2³×3, 36 = 2²×3². Shared: 2²×3 = 12.')] },
    { n: '4.2', t: 'Rational numbers', w: 'sort',
      cfg: { bins: ['Natural number', 'Integer (not natural)', 'Rational (not integer)'], items: [['7', 0], ['120', 0], ['−3', 1], ['0', 1], ['−50', 1], ['½', 2], ['−0.75', 2], ['2.3', 2], ['−4⅓', 2]] },
      intro: 'Sort each number into the smallest set it belongs to. (Here we count natural numbers as 1, 2, 3, …)',
      tasks: DONE,
      notice: [<><b>Natural numbers</b> 1, 2, 3, … sit inside the <b>integers</b> …, −2, −1, 0, 1, 2, …</>, <>Integers sit inside the <b>rational numbers</b>: any number that can be written as a fraction a/b.</>, <>So every integer is rational (7 = 7/1), but <b>not every rational number is an integer</b>.</>],
      check: [mc('Which is rational but not an integer?', ['−6', '0', '3/4', '12'], 2, '3/4 is a fraction but not a whole number.'), mc('Is −5 a rational number?', ['No', 'Yes, it can be written as −5/1', 'Only if positive', 'Only as a decimal'], 1, 'Every integer is rational.')] },
  ],
  practice: [inp('LCM of 6 and 8?', '24', '6 = 2×3, 8 = 2³ → 2³×3 = 24.'), inp('Write 90 as a product of primes in the form 2 × 3^a × 5. a = ?', '2', '90 = 2 × 3² × 5.'), mc('0.25 is…', ['Natural', 'An integer', 'Rational', 'Not a number'], 2, '0.25 = 1/4.')],
  challenge: [inp('Two lighthouses flash every 12 s and 18 s. They flash together now. After how many seconds will they next flash together?', '36', 'LCM(12, 18) = 36.', 's'), inp('Tiles of the largest possible equal square size cover a 48 cm × 60 cm board with no gaps. Side length?', '12', 'HCF(48, 60) = 12.', 'cm')],
  recap: { points: ['Write numbers as products of primes using index notation.', 'HCF = product of shared primes; LCM = product of all primes, counting shared ones once.', 'Natural ⊂ integers ⊂ rational numbers.'], terms: [['Prime', 'A number with exactly two factors: 1 and itself.'], ['HCF', 'Highest common factor.'], ['Rational', 'Can be written as a fraction of two integers.']] } },

{ id: 'm5', subj: 'maths', n: 5, title: 'Expressions', strand: 'Algebra', codes: ['8Ae.01', '8Ae.02', '8Ae.03', '8Ae.04'],
  secs: [
    { n: '5.1', t: 'Expressions, equations and formulae', w: 'sort',
      cfg: { bins: ['Expression', 'Equation', 'Formula'], items: [['3x + 5', 0], ['2(a − b)', 0], ['4y²', 0], ['3x + 5 = 20', 1], ['2y = y + 7', 1], ['x/4 = 3', 1], ['A = lw', 2], ['v = u + at', 2], ['P = 2(l + w)', 2]] },
      intro: 'Letters do different jobs in expressions, equations and formulae. Sort each one.',
      tasks: DONE,
      notice: [<>An <b>expression</b> has no equals sign: 3x + 5.</>, <>An <b>equation</b> is true only for certain values: 3x + 5 = 20, so x = 5.</>, <>A <b>formula</b> links quantities that can vary: A = lw.</>],
      check: [mc('Which is an equation?', ['5n − 2', 'n + 4 = 11', 'V = lwh', '7n'], 1, 'It has an equals sign and is true only for n = 7.'), mc('In the formula A = lw, A, l and w are…', ['fixed unknowns', 'variables', 'expressions', 'constants'], 1, 'They can take many values.')] },
    { n: '5.2', t: 'Algebraic operations and substitution', w: 'subst',
      intro: 'Pick an expression and change a and b, including negative values. Follow the order of operations.',
      tasks: [['Use a negative value for b', s => s.b < 0], ['Make a² − b equal 20', s => s.ei === 1 && s.v === 20], ['Try every expression', (s, H) => [0, 1, 2, 3].every(i => H('ei', i))]],
      notice: [<>Order of operations applies in algebra: <b>brackets, indices, × ÷, then + −</b>.</>, <>Write negative values in <b>brackets</b>: if a = −3, then a² = (−3)² = 9.</>, <>ab means a × b, and 3a² means 3 × a × a, not (3a)².</>],
      check: [inp('Find 2x² when x = −3.', '18', 'x² = 9, then 2 × 9 = 18.'), inp('Find 5a − b when a = 2 and b = −4.', '14', '10 − (−4) = 14.')] },
    { n: '5.3', t: 'Expanding and factorising', w: 'expand',
      intro: 'Use the area model to multiply out a bracket, then switch to factorise and take out the highest common factor.',
      tasks: [['Expand a bracket with a negative term', s => s.mode === 'expand' && s.c < 0], ['Factorise an expression', s => s.mode === 'fact']],
      notice: [<><b>Expanding</b>: multiply the outside term by each term inside. 3(2x + 4) = 6x + 12.</>, <><b>Factorising</b> is the reverse: find the <b>HCF</b> and put it outside. 6x + 12 = 6(x + 2).</>, <>Always take out the <b>highest</b> common factor so the bracket can't be simplified further.</>],
      check: [mc('Expand 4(3y − 5).', ['12y − 5', '12y − 20', '7y − 9', '12y + 20'], 1, '4 × 3y = 12y, 4 × (−5) = −20.'), mc('Fully factorise 8x + 12.', ['2(4x + 6)', '4(2x + 3)', '8(x + 12)', 'x(8 + 12)'], 1, 'The HCF of 8 and 12 is 4.')] },
    { n: '5.4', t: 'Forming expressions', w: 'match',
      cfg: { h: ['Words', 'Expression'], pairs: [['Three more than n', 'n + 3'], ['Three times n', '3n'], ['n shared between 3', 'n/3'], ['Three less than n', 'n − 3'], ['n less than three', '3 − n'], ['Half of n, plus 4', 'n/2 + 4']] },
      intro: 'Match each description to its algebraic expression. Watch out for the order of subtraction!',
      tasks: DONE,
      notice: [<>"3 less than n" is <b>n − 3</b>, but "n less than 3" is <b>3 − n</b>.</>, <>Write numbers before letters: 3n, not n3.</>, <>Fractional coefficients are fine: half of n can be written <b>n/2</b> or <b>½n</b>.</>],
      check: [mc('Pens cost p cents each. Cost of 5 pens and a 40 c ruler?', ['5p + 40', '45p', '5(p + 40)', 'p + 45'], 0, '5 lots of p, plus 40.'), mc('Mia is m years old; her brother is 4 years younger. His age in 3 years?', ['m − 1', 'm + 7', 'm − 7', '4m + 3'], 0, '(m − 4) + 3 = m − 1.')] },
  ],
  practice: [inp('Find 3(p + q) when p = 4, q = −1', '9', '3 × 3 = 9.'), mc('Expand −2(x − 6).', ['−2x − 12', '−2x + 12', '2x + 12', '−2x − 6'], 1, '−2 × −6 = +12.'), mc('Factorise 15a − 10.', ['5(3a − 2)', '5(3a − 10)', '15(a − 10)', '3(5a − 10)'], 0, 'The HCF is 5.')],
  challenge: [mc('A rectangle has sides 3x and (x + 4). Which is its perimeter?', ['8x + 8', '4x + 4', '3x² + 12x', '6x + 8'], 0, '2(3x + x + 4) = 2(4x + 4) = 8x + 8.'), mc('Kim says 2(x + 5) = 2x + 5. What is her mistake?', ['None', 'She did not multiply 5 by 2', 'She should subtract', 'She multiplied x by 5'], 1, 'Every term inside the bracket must be multiplied.')],
  recap: { points: ['Expression (no =), equation (solvable), formula (relationship).', 'Substitute with brackets for negatives and follow BIDMAS.', 'Expand by multiplying every term; factorise by taking out the HCF.'], terms: [['Coefficient', 'The number in front of a letter.'], ['Term', 'Part of an expression separated by + or −.'], ['Factorise', 'Write as a product using brackets.']] } },

{ id: 'm6', subj: 'maths', n: 6, title: 'Angles', strand: 'Geometry', codes: ['8Gg.11', '8Gg.10', '8Gp.01'],
  secs: [
    { n: '6.1', t: 'Special angles', w: 'parallel',
      intro: 'A transversal crosses two parallel lines. Choose a pair of angles and move the transversal. Which pairs stay equal?',
      tasks: [['Look at all four angle pairs', (s, H) => ['corresponding', 'alternate', 'co-interior', 'vertically opposite'].every(p => H('pair', p))], ['Change the transversal angle', (s, H) => s.t !== 60]],
      notice: [<><b>Corresponding</b> angles (F shape) are equal.</>, <><b>Alternate</b> angles (Z shape) are equal, and <b>vertically opposite</b> angles are equal.</>, <><b>Co-interior</b> angles (C shape) add up to <b>180°</b>.</>],
      check: [mc('Two angles in a Z shape between parallel lines are…', ['Corresponding, equal', 'Alternate, equal', 'Co-interior, add to 180°', 'Vertically opposite'], 1, 'Z means alternate angles, which are equal.'), inp('One co-interior angle is 115°. Find the other.', '65', '180 − 115 = 65°.', '°')] },
    { n: '6.2', t: 'Angles of a triangle', w: 'triangle',
      intro: 'Drag the corners of the triangle. Watch the interior angles and the exterior angle at B.',
      tasks: [['Make an obtuse triangle', s => Math.max(s.a, s.b, s.c) > 90], ['Make an exterior angle of more than 120°', s => s.ext > 120]],
      notice: [<>Interior angles of a triangle add to <b>180°</b>.</>, <>The <b>exterior angle</b> equals the sum of the two <b>interior opposite</b> angles.</>, <>That works because the exterior angle and its neighbour make a straight line (180°).</>],
      check: [inp('Two interior angles are 48° and 67°. Find the exterior angle at the third vertex.', '115', '48 + 67 = 115°.', '°'), inp('An exterior angle is 130° and one interior opposite angle is 75°. Find the other one.', '55', '130 − 75 = 55°.', '°')] },
    { n: '6.3', t: 'Bearings', w: 'bearing',
      intro: 'Change the bearing of B from A. Watch the three-figure bearing and the back bearing.',
      tasks: [['Set a bearing between 180° and 270°', s => s.b > 180 && s.b < 270], ['Find a bearing whose back bearing is 045°', s => s.back === 45]],
      notice: [<>Bearings are measured <b>from North</b>, <b>clockwise</b>.</>, <>Always write <b>three figures</b>: 070°, not 70°.</>, <>Back bearing = bearing <b>± 180°</b>.</>],
      check: [mc('Write a bearing due West.', ['090°', '180°', '270°', '360°'], 2, 'West is three quarters of a turn clockwise from North.'), inp('The bearing of B from A is 060°. Find the bearing of A from B.', ['240', '240°'], '60 + 180 = 240°.', '°')] },
  ],
  practice: [inp('Angles on a straight line: 3x and 120°. Find x.', '20', '3x = 60.'), inp('Triangle with angles x, 2x and 3x. Find x.', '30', '6x = 180.'), inp('Bearing of Q from P is 310°. Bearing of P from Q?', '130', '310 − 180 = 130°.', '°')],
  challenge: [mc('Which reason proves that the angles in a triangle add to 180°?', ['Draw a line parallel to the base through the top vertex; the alternate angles make a straight line', 'Measure with a protractor', 'Exterior angles add to 360°', 'Opposite angles are equal'], 0, 'The three angles at the top vertex make a straight line (180°) and equal the triangle\'s angles.'), inp('A ship sails on a bearing of 135° and then turns to sail due North. Through how many degrees does it turn (smaller turn)?', '135', 'From 135° to 360° clockwise is 225°, so the smaller turn is anticlockwise: 135°.', '°')],
  recap: { points: ['Corresponding and alternate angles are equal; co-interior angles add to 180°.', 'Exterior angle of a triangle = sum of the interior opposite angles.', 'Bearings: from North, clockwise, three figures; back bearing ± 180°.'], terms: [['Transversal', 'A line crossing two or more other lines.'], ['Exterior angle', 'Angle between one side and the extension of the next.'], ['Bearing', 'A direction measured clockwise from North.']] } },

{ id: 'm7', subj: 'maths', n: 7, title: 'Place value, rounding and decimals', strand: 'Number', codes: ['8Np.01', '8Np.02', '8Nf.08', '8Nf.09'],
  secs: [
    { n: '7.1', t: 'Multiplying and dividing by 0.1 and 0.01', w: 'placeval',
      intro: 'Apply each operation and watch the digits move across the place-value columns.',
      tasks: [['Multiply by 0.01', (s, H) => s.hist.includes('× 0.01')], ['Divide by 0.1', (s, H) => s.hist.includes('÷ 0.1')], ['Get back to 37.5 after using at least two operations', s => s.v === 37.5 && s.hist.length >= 2]],
      notice: [<><b>× 0.1</b> is the same as ÷ 10, and <b>× 0.01</b> is the same as ÷ 100.</>, <><b>÷ 0.1</b> is the same as × 10, and <b>÷ 0.01</b> is the same as × 100.</>, <>The <b>digits move</b>; the decimal point stays still.</>],
      check: [inp('45 × 0.01 = ?', ['0.45', '.45'], '× 0.01 = ÷ 100.'), inp('3.6 ÷ 0.1 = ?', '36', '÷ 0.1 = × 10.')] },
    { n: '7.2', t: 'Rounding to significant figures', w: 'sigfig',
      intro: 'Pick a number and a number of significant figures. Spot the decider digit.',
      tasks: [['Round a number less than 1', s => s.x < 1], ['Round to 1 significant figure', s => s.sf === 1], ['Try every number', (s, H) => [0, 1, 2, 3].every(i => H('ni', i))]],
      notice: [<>The first significant figure is the <b>first non-zero digit</b>.</>, <><b>Leading zeros</b> (0.00…) are not significant, but zeros between other digits are.</>, <>Keep the place value: 4836 to 2 s.f. is <b>4800</b>, not 48.</>],
      check: [inp('Round 0.003 482 to 2 significant figures.', ['0.0035', '.0035'], 'The first two s.f. are 3 and 4; the decider is 8, so round up.'), inp('Round 62 549 to 3 significant figures.', ['62500', '62 500', '62,500'], '6, 2, 5; the decider is 4, so keep 625 → 62 500.')] },
    { n: '7.3', t: 'Multiplying and dividing with integers and decimals', w: 'decmul',
      intro: 'Choose two decimals. Estimate first, then use whole numbers and adjust.',
      tasks: [['Multiply by a number less than 1', s => s.op === '×' && s.b < 1], ['Divide by a number less than 1', s => s.op === '÷' && s.b < 1]],
      notice: [<><b>Estimate</b> first by rounding to 1 s.f.</>, <>Multiplying by a number <b>less than 1</b> makes it smaller; dividing by one makes it bigger.</>, <>To divide by a decimal, multiply <b>both numbers by 10</b> so you divide by a whole number.</>],
      check: [inp('0.6 × 0.4 = ?', ['0.24', '.24'], '6 × 4 = 24; ÷ 100.'), inp('7.2 ÷ 0.3 = ?', '24', '72 ÷ 3 = 24.')] },
  ],
  practice: [inp('0.8 × 0.01 = ?', ['0.008', '.008'], 'Move the digits 2 places right.'), inp('Round 0.07059 to 3 s.f.', ['0.0706', '.0706'], '7, 0, 5; the decider is 9 → 706.'), inp('2.5 × 1.2 = ?', '3', '25 × 12 = 300; ÷ 100 = 3.')],
  challenge: [mc('Leo says 6 ÷ 0.5 = 3. Is he right?', ['Yes', 'No: there are 12 halves in 6', 'No: 0.3', 'No: 30'], 1, 'Dividing by 0.5 means "how many halves?"'), inp('Estimate 41.8 × 0.19 to 1 significant figure.', '8', '40 × 0.2 = 8.')],
  recap: { points: ['× 0.1 = ÷ 10; ÷ 0.1 = × 10 (and similarly for 0.01 and 100).', 'Significant figures start at the first non-zero digit; keep the place value.', 'Estimate first; use whole numbers then adjust by powers of 10.'], terms: [['Significant figure', 'A digit that carries meaning in the precision of a number.'], ['Estimate', 'An approximate answer using rounded numbers.'], ['Decider', 'The digit after the last one you keep.']] } },

{ id: 'm8', subj: 'maths', n: 8, title: 'Presenting and interpreting data 1', strand: 'Statistics', codes: ['8Ss.03'],
  secs: [
    { n: '8.1', t: 'Frequency tables and diagrams', w: 'freq',
      intro: 'Group 40 running times into classes. Change the class width and watch the frequency diagram.',
      tasks: [['Try all three class widths', (s, H) => [5, 10, 25].every(w => H('w', w))]],
      notice: [<>Continuous data is grouped into <b>class intervals</b> like 30 ≤ t &lt; 40.</>, <>A frequency diagram for continuous data has <b>no gaps</b> between bars.</>, <>Choose 4–8 classes so the shape is clear.</>],
      check: [mc('In which class does 40 go: 30 ≤ t < 40 or 40 ≤ t < 50?', ['30 ≤ t < 40', '40 ≤ t < 50', 'Both', 'Neither'], 1, '40 is not less than 40, so it goes in the second class.'), mc('Why are there no gaps between the bars?', ['It looks nicer', 'The data is continuous', 'There are too many bars', 'The frequencies are equal'], 1, 'Continuous data has no gaps between values.')] },
    { n: '8.2', t: 'Dual and compound bar charts', w: 'bars',
      intro: 'Change the data and switch between dual and compound bars. Which is better for which question?',
      tasks: [['Switch to a compound bar chart', s => s.type === 'compound'], ['Make packed lunches outnumber hot on one day', s => s.A.some((a, i) => s.B[i] > a)]],
      notice: [<>A <b>dual</b> bar chart is best for comparing two groups category by category.</>, <>A <b>compound</b> bar chart shows the parts AND the total for each category.</>, <>Always include a <b>key</b>.</>],
      check: [mc('Which chart makes it easiest to see the total each day?', ['Dual', 'Compound', 'Pie', 'Line'], 1, 'Stacked bars show the total height.'), mc('Which makes it easiest to compare hot and packed lunches on Wednesday?', ['Dual', 'Compound', 'Either is equally good', 'Neither'], 0, 'Side-by-side bars start from zero.')] },
    { n: '8.3', t: 'Stem-and-leaf diagrams', w: 'stemleaf',
      intro: 'Place each value into the stem-and-leaf diagram, then read off the median, mode and range.',
      tasks: DONE,
      notice: [<>The <b>stem</b> is the tens digit and the <b>leaf</b> is the units digit. Leaves are written <b>in order</b>.</>, <>Always include a <b>key</b>, e.g. 3 | 1 = 31.</>, <>Because the data is ordered, the <b>median</b> is easy to find.</>],
      check: [mc('Key 4 | 7 = 47. What does 2 | 3 5 mean?', ['2, 3, 5', '23 and 25', '235', '2.35'], 1, 'Stem 2 with leaves 3 and 5 → 23 and 25.'), mc('Why must the leaves be in order?', ['It looks neat', 'So the median and range can be read easily', 'It is optional', 'To find the mean'], 1, 'Ordered data shows the middle value.')] },
  ],
  practice: [inp('Data: 12, 15, 15, 18, 21. Median?', '15', 'The middle value.'), mc('Compound bars stack…', ['side by side', 'on top of each other', 'in a circle', 'as lines'], 1, 'Stacked bars.'), inp('Stem-leaf: 5 | 0 2 8. Range?', '8', '58 − 50.')],
  challenge: [mc('A frequency table has classes 0–10, 10–20, 20–30. What is the problem?', ['Too few classes', 'The boundaries overlap, so 10 could go in two classes', 'Classes must be width 5', 'Nothing'], 1, 'Use inequalities like 0 ≤ x < 10.'), inp('Stem-and-leaf with 15 values: in which position is the median?', '8', '(15 + 1) ÷ 2 = 8th.')],
  recap: { points: ['Group continuous data with inequalities; frequency diagrams have no gaps.', 'Dual bars compare groups; compound bars show totals.', 'Stem-and-leaf diagrams keep the data and order it; always give a key.'], terms: [['Class interval', 'A group of values, e.g. 20 ≤ t < 30.'], ['Key', 'Explains how to read a chart.'], ['Median', 'The middle value of ordered data.']] } },
);
