/* ============================================================
   CSS CUSTOM PROPERTIES
   ============================================================ */

:root {
  /* Colour tokens — light mode */
  --bg:            #F8FAFC;
  --paper:         #FFFFFF;
  --rule:          #E2E8F0;
  --ink:           #0F172A;          /* Navy (primary) */
  --ink-soft:      #64748B;
  --accent:        #16A34A;          /* Green (secondary) */
  --accent-subtle: #E8F5E9;
  --good:          #16A34A;          /* Green for success */
  --mid:           #2563EB;          /* Blue (accent) */
  --weak:          #DC2626;          /* Red for weak */
  --shadow-card:   0 1px 4px rgba(0,0,0,0.07), 0 6px 16px rgba(0,0,0,0.05);
  --shadow-raise:  0 2px 8px rgba(0,0,0,0.10), 0 8px 24px rgba(0,0,0,0.07);

  /* Typefaces */
  --font-serif: 'Source Serif 4', Georgia, serif;
  --font-sans:  'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:  'IBM Plex Mono', 'Courier New', monospace;

  /* Brand font aliases */
  --font-heading: var(--font-serif);
  --font-body:    var(--font-sans);

  /* Brand colour aliases */
  --color-primary:   #0F172A;
  --color-secondary: #16A34A;
  --color-accent:    #2563EB;
  --color-neutral:   #F1F5F9;

  /* Layout */
  --sidebar-width: 232px;
}

html.dark body,
body.dark {
  --bg:            #111316;
  --paper:         #1A1D21;
  --rule:          #2B2F35;
  --ink:           #F1F5F9;          /* Light text */
  --ink-soft:      #CBD5E1;
  --accent:        #16A34A;          /* Green stays same */
  --accent-subtle: #072E1B;
  --good:          #4ADE80;          /* Brighter green for dark */
  --mid:           #60A5FA;          /* Brighter blue for dark */
  --weak:          #F87171;          /* Brighter red for dark */
  --shadow-card:   0 1px 4px rgba(0,0,0,0.30), 0 6px 16px rgba(0,0,0,0.22);
  --shadow-raise:  0 2px 8px rgba(0,0,0,0.35), 0 8px 24px rgba(0,0,0,0.28);
}

/* ============================================================
   RESET & BASE
   ============================================================ */

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

html,
body {
  height: 100%;
}

body {
  display: flex;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul,
ol {
  list-style: none;
}

hr.rule {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 20px 0;
}

/* ============================================================
   TYPOGRAPHY SCALE  13 / 14 / 16 / 18 / 22 / 28
   ============================================================ */

h1 {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h2 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
}

h3 {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

.text-sm {
  font-size: 13px;
  color: var(--ink-soft);
}

.text-mono {
  font-family: var(--font-mono);
  font-size: 14px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--paper);
  border-right: 1px solid var(--rule);
  box-shadow: 2px 0 16px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 0;
  transition: transform 0.25s ease;
  z-index: 100;
  overflow: hidden;
}

/* Dark mode: remove border, keep heavy shadow */
html.dark #sidebar,
body.dark #sidebar {
  border-right: none;
}

/* Light mode sidebar — override white-on-dark colours */
body:not(.dark) #sidebar #product-name {
  border-bottom-color: var(--rule);
}
body:not(.dark) #sidebar .brand-revision {
  color: var(--ink);
}
body:not(.dark) #sidebar .nav-item {
  color: var(--ink-soft);
}
body:not(.dark) #sidebar .nav-item:hover {
  color: var(--ink);
  background-color: rgba(0,0,0,0.05);
}
body:not(.dark) #sidebar .nav-item.active {
  color: var(--accent);
}
body:not(.dark) #sidebar #theme-control,
body:not(.dark) #sidebar .theme-label {
  color: var(--ink-soft);
}

/* Green glow bloom at the top of the sidebar */
#sidebar::before {
  content: '';
  position: absolute;
  top: -30px;
  left: -30px;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(22,163,74,0.22) 0%, transparent 68%);
  pointer-events: none;
  z-index: 0;
}

#sidebar-top,
#theme-control {
  position: relative;
  z-index: 1;
}

#sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 36px;
  padding: 0 24px;
}

#product-name {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-boost    { color: #4ADE80; }
.brand-revision { color: #FFFFFF; }

#main-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 15px;
  color: rgba(255,255,255,0.5);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-item:hover {
  color: #FFFFFF;
  background-color: rgba(255,255,255,0.07);
  text-decoration: none;
}

.nav-item.active {
  color: #4ADE80;
  font-weight: 500;
  background-color: rgba(74,222,128,0.12);
}

/* Subjects dropdown in sidebar */
.nav-subjects-group {
  position: relative;
}

.subjects-chevron {
  font-size: 10px;
  margin-left: 4px;
  display: inline-block;
  transition: transform 0.2s ease;
  vertical-align: middle;
}

#nav-generate[aria-expanded="true"] .subjects-chevron {
  transform: rotate(180deg);
}

.subjects-dropdown {
  margin-top: 2px;
  margin-left: 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-left: 2px solid rgba(74,222,128,0.25);
  padding-left: 10px;
}

.subjects-option {
  display: block;
  padding: 7px 10px;
  border-radius: 5px;
  font-size: 14px;
  color: rgba(255,255,255,0.55);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.subjects-option:hover {
  color: #FFFFFF;
  background-color: rgba(255,255,255,0.07);
  text-decoration: none;
}

.subjects-option.active {
  color: #4ADE80;
  background-color: rgba(74,222,128,0.10);
  font-weight: 500;
}

#attempt-badge {
  font-family: var(--font-mono);
  font-size: 13px;
  color: rgba(255,255,255,0.35);
}

/* Theme control row */
#theme-control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 24px;
  cursor: pointer;
}

#theme-label {
  font-size: 13px;
  color: rgba(255,255,255,0.4);
  user-select: none;
}

#theme-control:hover #theme-label {
  color: rgba(255,255,255,0.75);
}

/* Toggle switch pill */
#theme-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background-color: rgba(255,255,255,0.18);
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background-color 0.2s ease;
}

#theme-toggle[aria-checked="true"] {
  background-color: var(--accent);
}

#theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--paper);
  transition: transform 0.2s ease;
  pointer-events: none;
}

#theme-toggle[aria-checked="true"] .toggle-thumb {
  transform: translateX(16px);
}

/* Hamburger — hidden on desktop, shown on mobile */
#hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 400;
  background: #0F172A;
  border: none;
  border-radius: 6px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  font-size: 18px;
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

#main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 48px clamp(24px, 5vw, 72px);
  background: radial-gradient(ellipse 80% 60% at 10% 0%, color-mix(in srgb, var(--accent) 5%, transparent) 0%, transparent 70%);
}

.view {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   TOPIC SELECTOR
   ============================================================ */

#selector {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.selector-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selector-row[data-label]::before {
  content: attr(data-label);
  flex: 0 0 100%;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}

.row-label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.tile {
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 9px 18px;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  background-color: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.tile:hover {
  border-color: var(--accent);
  background-color: var(--accent-subtle);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(22,163,74,0.12);
}

.tile.selected {
  border-color: var(--accent);
  background-color: var(--accent-subtle);
  color: var(--accent);
  font-weight: 500;
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}

.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#generate-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

#counter {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
}

/* Selector slides up and fades when question generates */
#selector.slide-out {
  transform: translateY(-16px);
  opacity: 0;
  transition: transform 250ms ease-out, opacity 250ms ease-out;
  pointer-events: none;
}

/* ============================================================
   BUTTONS
   ============================================================ */

button {
  font-family: var(--font-sans);
  font-size: 15px;
  cursor: pointer;
}

/* Primary: accent-filled */
#btn-generate,
#btn-submit,
#btn-modal-close {
  background-color: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  padding: 11px 24px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: opacity 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

#btn-back-to-topics {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 11px 24px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

#btn-generate {
  flex: 1;
}

#btn-generate:hover:not(:disabled),
#btn-submit:hover:not(:disabled),
#btn-modal-close:hover {
  opacity: 0.90;
  box-shadow: 0 4px 14px rgba(22,163,74,0.35);
  transform: translateY(-1px);
}

#btn-back-to-topics:hover {
  border-color: var(--ink-soft);
  opacity: 0.80;
}

#btn-generate:disabled,
#btn-submit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Loading state on generate */
#btn-generate.loading {
  font-family: var(--font-serif);
  font-style: italic;
  opacity: 0.75;
  cursor: wait;
}

/* Outlined */
#btn-reveal,
#btn-back-generate {
  background-color: transparent;
  color: var(--ink);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 11px 24px;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#btn-reveal:hover,
#btn-back-generate:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Touch active feedback */
button:active:not(:disabled) { opacity: 0.8; }

/* ============================================================
   QUESTION CARD
   ============================================================ */

#question-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

#link-change-topic {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  transition: opacity 0.15s ease;
}

#link-change-topic:hover {
  opacity: 0.75;
  text-decoration: none;
}

#breadcrumb {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}

/* Edexcel-style question paper card */
#question-card {
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 36px 40px;
  box-shadow: var(--shadow-raise);
}

#question-body {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 0 10px;
}

.question-number {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--accent);
  padding-top: 2px;
}

#question-text {
  font-family: var(--font-serif);
  font-size: 19px;
  line-height: 1.7;
}

/* Mechanics g-value note — bold, visually separated from question body */
.mechanics-note {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 14px;
  margin-bottom: 22px;
  letter-spacing: 0.01em;
}

/* Single-part structural paragraphs (context block + instruction block) */
#question-text p.question-para {
  display: block;
  margin-bottom: 18px;
  line-height: 1.8;
}

#question-text p.question-para:last-child {
  margin-bottom: 0;
}

/* Multi-part question parts */
#question-text > p {
  margin-bottom: 16px;
  line-height: 1.8;
}

#question-text > p:last-child {
  margin-bottom: 0;
}

/* Multi-part question: each part rendered as a <p> */
#question-text p {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 20px;
  margin-bottom: 16px;
}

#question-text p:last-child {
  margin-bottom: 0;
}

.part-left {
  flex: 1;
  min-width: 0;
}

.part-marks {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.7;
}

/* Exact Edexcel marks line format */
#marks-line {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  width: fit-content;
  margin-left: auto;
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

#reveal-row {
  display: flex;
}

/* Question fades in after MathJax typeset */
#question-panel.fade-in {
  animation: fadeUp 300ms ease-out forwards;
}

/* ============================================================
   MARK SCHEME PANEL
   ============================================================ */

#mark-scheme-panel {
  background-color: var(--accent-subtle);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: 28px 36px;
  margin-top: 4px;
  box-shadow: var(--shadow-card);
}

.ms-heading {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 16px;
}

#mark-scheme-rows {
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--rule);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

#mark-scheme-rows li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.6;
}

#mark-scheme-rows li:last-child {
  border-bottom: none;
}

.ms-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: baseline;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.ms-row:last-child {
  border-bottom: none;
}

/* Mark type badge */
.mark-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  border: none;
  display: inline-block;
  line-height: 1.4;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  background-color: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.ms-criterion {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.6;
}

.ms-total {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
  margin-top: 12px;
}

/* Worked solution */
#worked-solution-section {
  margin-top: 20px;
  padding: 20px 24px;
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

#worked-solution {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.8;
  margin-top: 10px;
}

.ws-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.ws-step:last-of-type { border-bottom: none; }

.ws-step-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 2px;
}

.ws-step-body {
  flex: 1;
  min-width: 0;
}

.ws-conclusion {
  margin-top: 12px;
  font-weight: 600;
  color: var(--ink);
}

/* Mark scheme fades in on reveal */
#mark-scheme-panel.fade-in {
  animation: fadeIn 200ms ease-out forwards;
}

/* ============================================================
   SELF-MARK SECTION
   ============================================================ */

#self-mark-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.self-mark-prompt {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#mark-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mark-btn {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  min-width: 44px;
  height: 44px;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.mark-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background-color: var(--accent-subtle);
}

.mark-btn.selected {
  background-color: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

.mark-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   POST-MARK SECTION
   ============================================================ */

#post-mark-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

#score-display {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#score-display.score-good { color: var(--good); }
#score-display.score-mid  { color: var(--mid); }
#score-display.score-weak { color: var(--weak); }

#post-mark-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

/* ============================================================
   WEAK AREAS VIEW
   ============================================================ */

#weak-areas-content {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

#weak-areas-header h1 {
  margin-bottom: 0;
}

#weak-areas-footer {
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

.wa-group {
  display: flex;
  flex-direction: column;
}

.wa-group-heading {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent-subtle);
}

.wa-topic-row {
  display: grid;
  grid-template-columns: 1fr 160px 60px 88px auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.wa-topic-row:last-child {
  border-bottom: none;
}

.wa-topic-name {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
}

.bar-container {
  height: 8px;
  background-color: var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-fill.fill-good { background-color: var(--good); }
.bar-fill.fill-mid  { background-color: var(--mid); }
.bar-fill.fill-weak { background-color: var(--weak); }

.wa-pct {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  text-align: right;
}

.wa-attempts {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

.wa-practise {
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
}

.wa-empty {
  font-family: var(--font-serif);
  font-size: 16px;
  font-style: italic;
  color: var(--ink-soft);
  padding: 32px 0;
}

.wa-topic-breadcrumb {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
  font-weight: 400;
}

.wa-practise-btn {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-subtle);
  border: 1.5px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.wa-practise-btn:hover {
  background-color: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
}

.wa-early-note {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--mid);
  padding: 10px 14px;
  background-color: color-mix(in srgb, var(--mid) 10%, transparent);
  border-left: 3px solid var(--mid);
  border-radius: 3px;
}

.wa-gated {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 0;
}

/* ============================================================
   HERO / LANDING SECTION
   ============================================================ */

#hero-content {
  display: flex;
  flex-direction: column;
  gap: 48px;
  padding-bottom: 40px;
}

#hero-headline {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

#hero-title {
  font-family: var(--font-heading);
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
}

#hero-sub {
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 520px;
}

#hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn-hero-subject {
  background: linear-gradient(135deg, #16A34A 0%, #15803D 100%);
  color: #FFFFFF;
  border: none;
  border-radius: 10px;
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 16px rgba(22,163,74,0.30);
  transition: opacity 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  cursor: pointer;
}

.btn-hero-subject:hover {
  opacity: 0.92;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(22,163,74,0.45);
}

.btn-hero-subject:active {
  opacity: 0.85;
  transform: translateY(0);
}

#hero-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.hero-card {
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.hero-card:hover {
  box-shadow: var(--shadow-raise);
  transform: translateY(-2px);
}

.hero-card--link {
  cursor: pointer;
}

.hero-card--link:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-raise), 0 0 0 2px rgba(22,163,74,0.15);
}

.hero-card--link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hero-card-icon {
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}

.hero-card-icon .ti {
  font-size: 28px;
}

.hero-card-title {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}

.hero-card-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-soft);
}

#hero-why {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--accent) 6%, var(--paper)) 0%,
    color-mix(in srgb, var(--mid) 6%, var(--paper)) 100%
  );
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 20px 24px;
}

#hero-why p {
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink-soft);
  font-style: italic;
}

/* Responsive hero */
@media (max-width: 767px) {
  #hero-cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #hero-cta-row {
    flex-direction: column;
  }

  .btn-hero-subject {
    width: 100%;
    text-align: center;
    padding: 16px 24px;
  }

  #hero-title {
    font-size: 28px;
  }

  #hero-content {
    gap: 32px;
  }
}

@media (min-width: 768px) and (max-width: 960px) {
  #hero-cards {
    grid-template-columns: 1fr 1fr;
  }

  .hero-card:last-child {
    grid-column: 1 / -1;
  }
}

/* ============================================================
   DAILY LIMIT MODAL
   ============================================================ */

#modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  z-index: 200;
  backdrop-filter: blur(2px);
}

#limit-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 201;
  width: calc(100% - 32px);
  max-width: 380px;
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-top: 4px solid var(--accent);
  border-radius: 6px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-raise);
}

#modal-heading {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
}

#limit-modal p {
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ============================================================
   DIFFICULTY TILE COLOURS
   ============================================================ */

#row-difficulty .tile[data-value="AS"] {
  border-color: color-mix(in srgb, var(--mid) 45%, transparent);
  color: var(--mid);
}
#row-difficulty .tile[data-value="AS"]:hover,
#row-difficulty .tile[data-value="AS"].selected {
  background-color: color-mix(in srgb, var(--mid) 10%, transparent);
  border-color: var(--mid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mid) 15%, transparent);
}

#row-difficulty .tile[data-value="A2"] {
  border-color: color-mix(in srgb, #7C3AED 45%, transparent);
  color: #7C3AED;
}
#row-difficulty .tile[data-value="A2"]:hover,
#row-difficulty .tile[data-value="A2"].selected {
  background-color: color-mix(in srgb, #7C3AED 10%, transparent);
  border-color: #7C3AED;
  box-shadow: 0 0 0 3px color-mix(in srgb, #7C3AED 15%, transparent);
}

#row-difficulty .tile[data-value="Challenge"] {
  border-color: color-mix(in srgb, #D97706 45%, transparent);
  color: #D97706;
}
#row-difficulty .tile[data-value="Challenge"]:hover,
#row-difficulty .tile[data-value="Challenge"].selected {
  background-color: color-mix(in srgb, #D97706 10%, transparent);
  border-color: #D97706;
  box-shadow: 0 0 0 3px color-mix(in srgb, #D97706 15%, transparent);
}

/* ============================================================
   SKELETON LOADER
   ============================================================ */

#question-skeleton {
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: fadeUp 200ms ease-out forwards;
}

.skel-header {
  height: 44px;
  border-radius: 8px;
  background-color: var(--paper);
  border: 1px solid var(--rule);
}

.skel-card {
  background-color: var(--paper);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--rule);
  border-radius: 10px;
  padding: 36px 40px;
  box-shadow: var(--shadow-raise);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.skel-line {
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(
    90deg,
    var(--rule) 25%,
    color-mix(in srgb, var(--rule) 50%, var(--paper)) 50%,
    var(--rule) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skel-line--marks {
  width: 30%;
  height: 14px;
  align-self: flex-end;
  margin-top: 8px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scoreGlow {
  0%   { text-shadow: none; }
  35%  { text-shadow: 0 0 18px rgba(74,222,128,0.75), 0 0 4px rgba(74,222,128,0.5); }
  100% { text-shadow: none; }
}

#score-display.score-good {
  animation: scoreGlow 0.9s ease-out;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   OVERFLOW & MATH RENDERING — prevents content escaping containers
   on any screen width, especially with MathJax display math.
   ============================================================ */

/* All prose text containers: wrap long tokens and LaTeX strings */
#question-text,
#question-text p,
#question-text p.question-para,
.part-left,
.ms-criterion,
#mark-scheme-rows li,
.ms-row,
#worked-solution,
.ws-step,
.ws-step-body,
.ws-conclusion,
#worked-solution-section,
.hero-card-body,
.hero-card-title,
#hero-sub {
  overflow-wrap: break-word;
  word-break:    break-word;
  max-width:     100%;
}

/* MathJax inline and display containers */
mjx-container {
  max-width:  100%;
  overflow-x: auto;
  overflow-y: visible;
  display:    block;
}

/* Inline math stays inline but still clips if truly enormous */
mjx-container[jax="CHTML"][display="false"] {
  display:        inline-block;
  vertical-align: middle;
}

/* Cards and panels: ensure they never overflow their column */
#question-card,
#mark-scheme-panel,
#worked-solution-section {
  width:    100%;
  overflow: hidden;
  min-width: 0;
}

/* The grid cell that holds question text */
#question-body {
  min-width: 0;
  overflow:  hidden;
}

/* Mark scheme list: clamp to panel width */
#mark-scheme-rows {
  width:    100%;
  overflow: hidden;
}

/* ============================================================
   UTILITIES
   ============================================================ */

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================================
   RESPONSIVE — TABLET (768px – 960px)
   ============================================================ */

@media (min-width: 768px) and (max-width: 960px) {
  :root {
    --sidebar-width: 180px;
  }

  #sidebar-top,
  #theme-control {
    padding: 0 16px;
  }

  #main {
    padding: 32px 20px;
  }

  #question-card {
    padding: 24px 28px;
  }

  #mark-scheme-panel {
    padding: 20px 24px;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE (< 768px)
   ============================================================ */

@media (max-width: 767px) {

  /* ── Layout ── */
  body { flex-direction: column; }

  /* ── Sidebar: slide off-screen; sit above overlay (JS sets overlay z-index 200) ── */
  #sidebar {
    transform: translateX(-100%);
    z-index: 300;
  }
  #sidebar.open { transform: translateX(0); }

  /* ── Hamburger ── */
  #hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Main content ── */
  #main {
    margin-left: 0;
    padding: 64px 16px 40px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .view { max-width: 100%; }

  /* ── Selector: more compact, tiles full-width ── */
  #selector { gap: 20px; }

  .selector-row { gap: 6px; }

  .tile {
    width: 100%;
    padding: 13px 16px;
    text-align: left;
    font-size: 15px;
    border-radius: 8px;
  }

  /* Difficulty tiles stay side-by-side (short labels: AS / A2 / Challenge) */
  #row-difficulty .tile {
    width: auto;
    flex: 1;
    text-align: center;
  }

  /* Active tile feedback on touch */
  .tile:active { opacity: 0.75; }

  /* Generate row: button above counter, full width */
  #generate-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding-top: 12px;
  }

  #btn-generate {
    width: 100%;
    text-align: center;
    padding: 14px 24px;
    font-size: 16px;
  }

  #counter { text-align: center; }

  /* ── Question header: stack change-topic / breadcrumb ── */
  #question-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 14px;
  }

  #breadcrumb {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* ── Question card ── */
  #question-card {
    padding: 20px 18px;
    border-left-width: 3px;
    border-radius: 8px;
  }

  #question-body {
    grid-template-columns: 22px 1fr;
    gap: 0 8px;
  }

  #question-text {
    font-size: 17px;
    line-height: 1.65;
  }

  /* ── Reveal button: sticky at bottom of viewport ── */
  #reveal-row {
    position: sticky;
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0px);
    background: linear-gradient(to top, var(--bg) 75%, transparent);
    padding: 20px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    margin-top: 8px;
  }

  #btn-reveal {
    width: 100%;
    text-align: center;
    padding: 14px 24px;
    font-size: 16px;
  }

  /* ── Mark scheme ── */
  #mark-scheme-panel {
    padding: 18px 16px;
    border-left-width: 3px;
    border-radius: 8px;
  }

  #mark-scheme-rows li {
    padding: 12px 14px;
    font-size: 14px;
  }

  /* ── Self-mark buttons: bigger touch targets ── */
  .mark-btn {
    min-width: 48px;
    height: 48px;
    font-size: 16px;
  }

  #btn-submit,
  #btn-back-to-topics {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
    text-align: center;
  }

  /* ── Post-mark ── */
  #post-mark-actions { flex-direction: column; }

  /* ── Worked solution steps: label above body on small screens ── */
  .ws-step {
    flex-direction: column;
    gap: 4px;
  }

  /* ── Overflow guard on mobile (math equations may be wide) ── */
  #question-card,
  #mark-scheme-panel,
  #worked-solution-section {
    overflow-x: auto;
  }

  mjx-container {
    overflow-x: auto;
    max-width:  calc(100vw - 48px); /* viewport minus card padding (2 × 18px) + safe gap */
  }

  /* ── Skeleton loader ── */
  .skel-card { padding: 20px 18px; }
  .skel-header { height: 56px; }

  /* ── Weak areas ── */
  .wa-topic-row {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px 0;
  }

  .bar-container,
  .wa-attempts { display: none; }

  .wa-pct { font-size: 15px; }

  #btn-back-generate {
    width: 100%;
    text-align: center;
    padding: 14px 24px;
  }

  /* ── Modal ── */
  #limit-modal {
    bottom: env(safe-area-inset-bottom, 0px);
  }
}
