/* Worksheet page: instructions, worked example, question cards and the answer panel */

/* ---------- Instructions and worked example ---------- */
.worksheet-instructions {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.how-to {
  margin: 0 0 1.25rem;
  border: 2px solid #bfdbfe;
  border-radius: var(--radius-lg);
  background-color: #eff6ff;
}

.how-to summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-weight: 700;
  color: #1e40af;
}

.how-to-body {
  padding: 0 1rem 1rem;
}

.how-to-body ol {
  margin: 0 0 0.75rem;
  padding-left: 1.5rem;
}

.how-to-body li {
  margin-bottom: 0.25rem;
}

.how-to-example {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background-color: white;
  font-size: 1.35rem;
}

.how-to-example-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

/* ---------- Question cards ---------- */
.question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
}

.answer-box.question-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  min-height: 130px;
  padding: 0.75rem;
  border: 2px solid var(--status-gray, #9ca3af);
  border-radius: var(--radius-md);
  background-color: white;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  scroll-margin-top: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.answer-box.question-card:hover,
.answer-box.question-card:focus-visible {
  border-color: var(--primary-color);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  outline: none;
}

.answer-box.question-card.active {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
  animation: none;
}

.question-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.question-card .question-number {
  color: var(--text-secondary);
}

.question-state {
  font-size: 0.85rem;
}

.question-line {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 1.6rem;
}

.question-line.stacked {
  flex-direction: column;
  gap: 0.4rem;
}

.question-equals {
  color: var(--text-secondary);
}

.question-card .answer-display {
  min-width: 2.5em;
  min-height: 2.2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.4rem;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
}

.question-card .answer-display.empty {
  border: 2px dashed #9ca3af;
  color: #9ca3af;
  font-size: 1.1rem;
}

/* State colours, with words so colour is never the only signal */
.answer-box.question-card.status-correct-green,
.answer-box.question-card.status-correct-amber {
  border-color: var(--status-green, #16a34a);
  background-color: var(--status-green-light, #dcfce7);
}

.answer-box.question-card.status-correct-green .question-state,
.answer-box.question-card.status-correct-amber .question-state {
  color: #15803d;
}

.answer-box.question-card.status-retry {
  border-color: var(--status-amber, #f59e0b);
  background-color: var(--status-amber-light, #fef3c7);
}

.answer-box.question-card.status-retry .question-state {
  color: #b45309;
}

/* ---------- Answer panel (inside the on-screen keyboard) ---------- */
.answer-panel {
  margin-bottom: 0.75rem;
}

.answer-panel-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--primary-color);
  border-radius: var(--radius-md);
  background-color: white;
  font-size: 1.6rem;
  min-height: 72px;
}

.answer-panel-number {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.answer-panel-equals {
  color: var(--text-secondary);
}

.answer-panel-answer {
  min-width: 2.5em;
  min-height: 2.2em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.4rem;
  border-radius: var(--radius-md);
  background-color: #eff6ff;
}

.answer-panel-answer.empty {
  border: 2px dashed #93c5fd;
  color: #93c5fd;
  font-size: 1.1rem;
}

.answer-panel-feedback {
  min-height: 1.5rem;
  margin-top: 0.5rem;
  font-weight: 600;
}

.answer-panel-feedback.correct {
  color: #15803d;
}

.answer-panel-feedback.retry {
  color: #b45309;
}

/* One keyboard for the whole worksheet: no tabs, and the typed text is
   already shown in the answer slot above */
.math-keyboard.single-mode .keyboard-tabs,
.math-keyboard .keyboard-input-display,
.math-keyboard .keyboard-preview {
  display: none;
}

.math-keyboard.single-mode .keyboard-header {
  justify-content: flex-end;
  padding-bottom: 0;
  margin-bottom: 0.25rem;
  border-bottom: 0;
}

/* Keys a worksheet does not need (the keyboard's own styles would show them) */
.math-keyboard .keyboard-key[hidden] {
  display: none;
}

/* Fractions with + - × hidden: a tidy 4 x 3 pad */
.math-keyboard.keys-trimmed .keyboard-mode.fraction-mode {
  grid-template-columns: repeat(4, 1fr);
}

.math-keyboard.keys-trimmed .fraction-mode [data-value="7"] { order: 1; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="8"] { order: 2; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="9"] { order: 3; }
.math-keyboard.keys-trimmed .fraction-mode [data-action="fraction"] { order: 4; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="4"] { order: 5; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="5"] { order: 6; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="6"] { order: 7; }
.math-keyboard.keys-trimmed .fraction-mode [data-action="backspace"] { order: 8; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="1"] { order: 9; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="2"] { order: 10; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="3"] { order: 11; }
.math-keyboard.keys-trimmed .fraction-mode [data-value="0"] { order: 12; }

/* While the panel is open, leave room to scroll every question above it */
body.keyboard-open {
  padding-bottom: 55vh;
}

/* ---------- Finished panel ---------- */
.done-lead {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.done-score {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1rem;
}

.done-breakdown {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.done-breakdown li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.done-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
}

.done-dot-green { background-color: var(--status-green, #16a34a); }
.done-dot-amber { background-color: var(--status-amber, #f59e0b); }

@media (max-width: 480px) {
  .question-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .question-line,
  .answer-panel-line {
    font-size: 1.35rem;
  }
}
