/* Styles for starter pages. Load after main.css. Pairs with assets/js/starter.js. */

.starter { padding-bottom: 56px; }

/* Title block */
.spec-ref {
  display: table;
  margin: 20px 0 10px;
  padding: 4px 12px;
  border-radius: 6px;
  background: var(--level-colour, var(--accent));
  color: var(--on-level);
  font-size: 1rem;
  font-weight: 700;
}

.starter h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.lisc {
  margin: 0;
  padding: 14px 18px;
  background-color: var(--surface);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  border: var(--edge-w) solid var(--edge);
  border-left: 6px solid var(--level-colour, var(--accent));
  border-radius: var(--radius);
}
.lisc p { margin: 0; }
.lisc p + p { margin-top: 6px; }

/* Teacher toolbar: timer, show answers, reset */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
}
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 8px 16px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--pop-sm);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tool:active { transform: translate(3px, 3px); box-shadow: none; }
.tool[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--ink-text); }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 12px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--pop-sm);
}
.timer select {
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.timer-display {
  min-width: 4.2ch;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.timer .tool { border: 0; box-shadow: none; padding: 8px 12px; }
.timer.is-done { border-color: var(--bad); background: var(--bad-bg); }
.timer.is-done .timer-display { color: var(--bad); }

/* Question card. Questions are numbered only, with no difficulty labels, except the
   last one on every starter, which is a .q-challenge for pupils who finish early. */
.toolbar + .q { margin-top: 28px; }
.q {
  margin: 0 0 16px;
  padding: 20px 22px;
  background: var(--surface);
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--pop);
}
.q-prompt { margin: 0 0 14px; font-size: 1.25rem; font-weight: 600; }
.q-prompt .q-num { color: var(--level-colour, var(--muted)); font-family: var(--font-head); font-weight: 700; margin-right: 8px; }
/* Optional hint for questions likely to confuse: <details class="hint"><summary>Hint</summary><p>…</p></details> */
.hint { margin-top: 12px; }
.hint summary {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 8px 18px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--pop-sm);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.hint summary::-webkit-details-marker { display: none; }
.hint[open] > summary { background: var(--accent); border-color: var(--accent); box-shadow: none; color: var(--accent-text); }
.hint .hint { margin-top: 10px; }
.hint p {
  margin: 10px 0 0;
  padding: 12px 16px;
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  background: var(--bg);
}

.q-challenge { border: 2px solid var(--level-colour, var(--accent)); }
.q-tag {
  display: table;
  margin-bottom: 8px;
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--level-colour, var(--accent));
  color: var(--on-level);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Two columns by default (so four options make a 2 × 2 grid); .is-row puts three side by side */
.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.options.is-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.options.is-pair { max-width: 520px; }
@media (max-width: 600px) {
  .options, .options.is-row { grid-template-columns: minmax(0, 1fr); }
  .options.is-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.option,
.match-item,
.match-target {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 56px;
  padding: 12px 16px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--pop);
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.option { align-items: flex-start; text-align: left; }
.option:has(svg) { align-items: stretch; padding: 10px; }
.option:not(:disabled):active,
.match-target:not(:disabled):active { transform: translate(4px, 4px); box-shadow: none; }
.option:disabled, .match-item:disabled, .match-target:disabled { cursor: default; }
.option:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.55; }

.option.is-correct,
.match-item.is-matched,
.match-target.is-matched {
  border-color: var(--good);
  background: var(--good-bg);
}
.option.is-wrong,
.match-item.is-wrong,
.match-target.is-wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}
/* Words as well as colour, so feedback never depends on colour alone */
.option.is-correct::after { content: "Correct"; color: var(--good); }
.option.is-wrong::after   { content: "Not this one"; color: var(--bad); }
.option.is-correct::after,
.option.is-wrong::after { font-size: 0.85rem; font-weight: 700; }

/* Feedback line under each question */
.q-feedback:empty { display: none; }
.q-feedback {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 10px;
  border-left: 5px solid var(--border);
  background: var(--bg);
}
.q-feedback.is-good { border-left-color: var(--good); background: var(--good-bg); }
.q-feedback.is-bad  { border-left-color: var(--bad); background: var(--bad-bg); }
.q-feedback strong { margin-right: 4px; }
.q-explain { display: none; }

/* Tap-to-match */
.match {
  display: grid;
  gap: 16px;
}
.match-items, .match-targets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.match-items[hidden] { display: none; }

/* Dragging: the page must not scroll while a symbol is being dragged */
.match-item {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.match-item:disabled { cursor: default; }
.match-item.is-dragging {
  z-index: 10;
  cursor: grabbing;
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}
.match-col.is-over .match-slot { border-color: var(--accent); background: var(--bg); }
.match-col.is-over .match-target { border-color: var(--accent); }
.match-item svg { width: 96px; height: 64px; }
.match-item.is-selected,
.match-target.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent);
}
.match-item::after { font-size: 1rem; font-weight: 600; color: var(--good); }

/* Each name sits under an empty slot; a correct match moves the symbol into it */
.match-col { display: grid; gap: 8px; }
.match-slot {
  display: flex;
  min-height: 96px;
  border: 2px dashed var(--border);
  border-radius: 12px;
}
.match-slot:has(.match-item) { border-color: transparent; }
.match-slot { transition: border-color 0.3s; }
/* Left behind in the pool where an item used to be, so the others stay put */
.match-ghost {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}
.match-slot .match-item { flex: 1; }
.match-col:has(.is-matched) .match-target { font-weight: 700; }
.match-hint { margin: 0; color: var(--muted); font-size: 1rem; }

/* Sorting into groups (.match.is-sort): each group's slot stacks the items sorted into it */
.match.is-sort .match-items { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.match.is-sort .match-targets { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.match.is-sort .match-col { align-content: start; }
.match.is-sort .match-slot { flex-direction: column; gap: 8px; padding: 8px; min-height: 120px; }
.match.is-sort .match-slot:has(.match-item) { border-color: var(--border); }
.match.is-sort .match-slot .match-item { flex: none; min-height: 48px; font-size: 1.05rem; }
.match.is-sort .match-target { order: -1; font-weight: 700; }
.match-item.is-text { font-size: 1.05rem; }

/* Putting sentences in order (.match.is-order): one row per place, its number on the left */
.match.is-order .match-items { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.match.is-order .match-targets { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.match.is-order .match-item { justify-content: flex-start; align-items: flex-start; text-align: left; }
.match.is-order .match-col { grid-template-columns: 6.2em minmax(0, 1fr); align-items: stretch; }
.match.is-order .match-target { order: -1; padding: 8px; font-size: 1rem; font-weight: 700; }
.match.is-order .match-slot { flex-direction: column; gap: 8px; min-height: 60px; padding: 4px; }
.match.is-order .match-slot .match-item { flex: none; min-height: 48px; text-align: left; align-items: flex-start; }

/* Short words in order (.match.is-order.is-strip, with --steps set to the number of places): the places
   sit side by side in one row, so every card and its place fit on an iPad screen together */
.match.is-order.is-strip .match-items { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.match.is-order.is-strip .match-item { justify-content: center; align-items: center; text-align: center; }
.match.is-order.is-strip .match-targets { grid-template-columns: repeat(var(--steps, 6), minmax(0, 1fr)); gap: 6px; }
.match.is-order.is-strip .match-col { grid-template-columns: minmax(0, 1fr); align-content: start; }
.match.is-order.is-strip .match-target { min-height: 44px; padding: 6px 4px; font-size: 0.95rem; }
.match.is-order.is-strip .match-slot { min-height: 64px; }
.match.is-order.is-strip .match-slot .match-item { flex: 1; min-height: 56px; padding: 6px 4px; font-size: 0.9rem; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  .match.is-order.is-strip .match-items { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .match.is-order.is-strip .match-targets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Fill in the blanks (.match.is-blanks): the gaps sit inside the sentences, and a correct word
   drops into its gap in place of the dashed box. Spare words stay in the pool. */
.match.is-blanks .match-items { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.match.is-blanks .match-item { min-height: 48px; padding: 8px 12px; }
.match.is-blanks .match-targets { display: block; font-size: 1.2rem; line-height: 1.5; }
.match.is-blanks .match-targets > * { margin: 0 0 12px; }
.match.is-blanks .match-targets > :last-child { margin-bottom: 0; }
.match.is-blanks .match-col { display: inline-grid; vertical-align: middle; margin: 3px 2px; }
.match.is-blanks .match-col > * { grid-area: 1 / 1; }
.match.is-blanks .match-slot { min-height: 0; border: 0; }
.match.is-blanks .match-slot:empty { display: none; }
.match.is-blanks .match-target {
  min-width: 7em;
  min-height: 48px;
  padding: 4px 12px;
  border-style: dashed;
  box-shadow: none;
}
.match.is-blanks .match-col:has(.match-slot .match-item) .match-target { display: none; }
.match.is-blanks .match-slot .match-item { min-height: 48px; padding: 4px 14px; box-shadow: none; font-weight: 700; }
.q.is-solved .match.is-blanks .match-items .match-item:not(.is-matched) { opacity: 0.45; }

/* Type-in answers (.q-input) */
.answer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
}
.answer-label { font-weight: 700; }
.answer {
  width: 7.5em;
  min-height: 52px;
  padding: 8px 12px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}
.answer:focus { outline: 3px solid var(--accent); outline-offset: 1px; }
.answer.is-correct { border-color: var(--good); background: var(--good-bg); }
.answer.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.answer-unit { font-weight: 700; }
.q-check { min-height: 52px; }
.mistake { display: none; }

/* Working steps on a calculation (.steps in a .q-input): formula, substitute, solve.
   Each step's name sits beside it; a finished step keeps only the line that was right. */
.steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.step { display: grid; grid-template-columns: 7em minmax(0, 1fr); gap: 6px 12px; align-items: start; }
.step[hidden] { display: none; }
.step-name {
  padding-top: 16px;
  color: var(--level-colour, var(--muted));
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.step .options { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.step .option { font-variant-numeric: tabular-nums; }
.step.is-done .option:not(.is-correct) { display: none; }
.step.is-done .options { grid-template-columns: minmax(0, 1fr); }
.step.is-done .option { min-height: 48px; padding: 8px 16px; box-shadow: none; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
@media (max-width: 600px) {
  .step { grid-template-columns: minmax(0, 1fr); }
  .step-name { padding-top: 0; }
}
/* A relationship set out as on the relationships sheet. Wrap the whole line in .eq (a button lays
   its children out in a column, so loose text and fractions would stack), and build each fraction
   as <span class="frac"><span>top</span><span>bottom</span></span>. */
.eq { display: inline-block; line-height: 1.3; }
.frac { display: inline-flex; flex-direction: column; margin: 0 2px; vertical-align: middle; text-align: center; line-height: 1.2; }
.frac > span { padding: 1px 5px; }
.frac > span:first-child { border-bottom: 2px solid currentColor; }
.working .frac { font-size: 0.92em; }

/* Working laid out the SQA way: relationship, substitution, answer */
.working { margin: 0; padding: 0; list-style: none; font-variant-numeric: tabular-nums; }
.working li + li { margin-top: 2px; }

/* Data tables in questions */
.data-table {
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td { padding: 8px 14px; border: 1px solid var(--border); text-align: center; }
.data-table th { background: var(--bg); }

/* Truth tables (.q-truth) */
.truth {
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}
.truth th, .truth td { padding: 6px 14px; border: 1px solid var(--border); text-align: center; }
.truth th { background: var(--bg); }
.truth-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 52px;
  border: var(--edge-w) solid var(--edge);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--pop);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.truth-cell:not(:disabled):active { transform: translate(4px, 4px); box-shadow: none; }
.truth-cell:disabled { cursor: default; }
.truth-cell.is-correct { border-color: var(--good); background: var(--good-bg); }
.truth-cell.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.truth-cell.is-wrong::after { content: "Check"; color: var(--bad); font-size: 0.75rem; }

/* Circuit diagrams (symbols come from assets/js/circuit-symbols.js) */
.circuit {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  color: var(--text);
}
.circuit .wire { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.circuit .dot { fill: currentColor; }
.circuit .label { fill: currentColor; font-size: 18px; font-weight: 700; }
.figure {
  margin: 0 0 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 2px solid var(--border);
}
.figure .circuit { margin: 0 auto; }
.figure-caption { margin: 6px 0 0; text-align: center; font-weight: 700; }
.option .circuit { width: 100%; max-width: none; }

/* Revision starters: a heading per topic (.q-section) and a topic check at the end */
.q-section {
  margin: 36px 0 14px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--level-colour, var(--accent));
  font-size: 1.6rem;
}
.toolbar + .q-section { margin-top: 28px; }
.topic-check {
  margin: 32px 0 16px;
  padding: 20px 22px;
  background: var(--surface);
  border: 2px solid var(--level-colour, var(--accent));
  border-radius: var(--radius);
  box-shadow: var(--pop);
}
.topic-check h2 { margin: 0 0 6px; font-size: 1.5rem; }
.topic-check > p { margin: 0 0 12px; }
.topic-list { margin: 0; padding: 0; list-style: none; }
.topic {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.topic-name { font-size: 1.15rem; font-weight: 700; }
.topic-score { color: var(--muted); font-variant-numeric: tabular-nums; }
.topic-status {
  min-width: 9.5em;
  padding: 4px 12px;
  border: 2px solid currentColor;
  border-radius: 8px;
  font-weight: 700;
  text-align: center;
}
.topic.is-todo .topic-status { border-style: dashed; color: var(--muted); }
.topic.is-good .topic-status { color: var(--good); background: var(--good-bg); }
.topic.is-ok .topic-status   { color: var(--text); background: var(--bg); }
.topic.is-bad .topic-status  { color: var(--bad); background: var(--bad-bg); }
@media (max-width: 600px) {
  .topic { grid-template-columns: 1fr auto; }
  .topic-score { grid-column: 1 / -1; grid-row: 2; }
}

/* Show answers (teacher): reveal without marking anything as attempted */
.show-answers .option[data-correct] { border-color: var(--good); border-style: dashed; }
.show-answers .option[data-correct]::after {
  content: "Answer";
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--good);
}
.show-answers .match-item:not(.is-matched)::after { content: attr(data-label); }
.show-answers .q:not(.is-solved) .truth-cell { border-style: dashed; border-color: var(--good); }
.show-answers .q:not(.is-solved) .truth-cell::after { content: "Answer " attr(data-answer); color: var(--good); font-size: 0.75rem; }
.show-answers .q:not(.is-solved) .q-explain {
  display: block;
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 10px;
  border-left: 5px solid var(--good);
  background: var(--good-bg);
}

@media (prefers-reduced-motion: no-preference) {
  .is-wrong { animation: nudge 0.3s; }
  @keyframes nudge {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
  }
}
