/* ===================================
   GCSE Computer Science - BeanWise Tuition
   Modern, youth-friendly design
   WCAG 2.1 AA · ADHD/Dyslexia-friendly
   =================================== */

/* --- CSS Custom Properties --- */
:root {
  /* Brand palette - vibrant but accessible */
  --color-bg: #f0f2f5;
  --color-text: #1a1a2e;
  --color-text-light: #555570;
  --color-white: #ffffff;
  --color-link: #4361ee;
  --color-link-hover: #3a0ca3;

  /* Gradient accents */
  --gradient-hero: linear-gradient(135deg, #4361ee 0%, #7209b7 50%, #f72585 100%);
  --gradient-blue: linear-gradient(135deg, #4361ee, #4cc9f0);
  --gradient-green: linear-gradient(135deg, #06d6a0, #1b9aaa);
  --gradient-orange: linear-gradient(135deg, #f77f00, #fcbf49);
  --gradient-pink: linear-gradient(135deg, #f72585, #b5179e);
  --gradient-purple: linear-gradient(135deg, #7209b7, #560bad);

  /* Section colours */
  --color-idea: #eef0ff;
  --color-idea-border: #4361ee;
  --color-explore: #e6f9f1;
  --color-explore-border: #06d6a0;
  --color-understand: #fff4e6;
  --color-understand-border: #f77f00;
  --color-practice: #eef0ff;
  --color-practice-border: #4361ee;
  --color-reflect: #fce4f3;
  --color-reflect-border: #f72585;

  /* Code colours */
  --color-code-bg: #1e1e2e;
  --color-code-text: #cdd6f4;
  --color-code-header: #313244;
  --color-output-bg: #f5f5f5;
  --color-output-border: #cccccc;
  --color-error: #e63946;

  /* Difficulty */
  --color-difficulty-1: #06d6a0;
  --color-difficulty-2: #f77f00;
  --color-difficulty-3: #f72585;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Typography */
  --font-body: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-heading: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-code: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-size-base: 1.05rem;
  --line-height: 1.7;
  --max-width: 860px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 20px rgba(67,97,238,0.15);

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  letter-spacing: 0.02em;
  color: var(--color-text);
  background-color: var(--color-bg);
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-lg);
  -webkit-font-smoothing: antialiased;
}

/* --- Focus Styles (keyboard navigation) --- */
:focus-visible {
  outline: 3px solid var(--color-idea-border);
  outline-offset: 3px;
  border-radius: 2px;
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: var(--font-heading);
  line-height: 1.25;
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
  color: var(--color-text);
  font-weight: 800;
}

h1 {
  font-size: 2.2rem;
  border-bottom: none;
  padding-bottom: 0;
}

h2 {
  font-size: 1.6rem;
  margin-top: var(--space-xl);
}

h3 {
  font-size: 1.3rem;
  font-weight: 700;
}

h4 {
  font-size: 1.1rem;
  font-weight: 700;
}

p {
  margin-bottom: var(--space-md);
}

section p {
  max-width: 70ch;
}

ul, ol {
  margin-bottom: var(--space-md);
  padding-left: var(--space-xl);
}

li {
  margin-bottom: var(--space-sm);
}

a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  text-decoration-skip-ink: auto;
  transition: color 0.2s;
}

a:hover {
  color: var(--color-link-hover);
}

a:focus-visible {
  outline: 3px solid var(--color-idea-border);
  outline-offset: 3px;
  border-radius: 2px;
}

strong {
  font-weight: 700;
}

/* --- Hero Header (index.html) --- */
.hero {
  background: var(--gradient-hero);
  color: var(--color-white);
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-2xl);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 60%);
  animation: hero-shimmer 8s ease-in-out infinite;
}

@keyframes hero-shimmer {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(10%, 10%); }
}

.hero h1 {
  color: var(--color-white);
  font-size: 2.6rem;
  margin: 0 0 var(--space-sm);
  position: relative;
}

.hero .subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: var(--space-lg);
  position: relative;
}

.hero .badge-row {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  position: relative;
}

.hero .badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(4px);
  padding: var(--space-xs) var(--space-md);
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* --- Chapter Header (chapter pages) --- */
.site-header {
  text-align: center;
  padding: var(--space-xl) 0;
  margin-bottom: var(--space-xl);
}

.site-header h1 {
  margin-top: 0;
  font-size: 2rem;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.site-header .subtitle {
  font-size: 1.15rem;
  color: var(--color-text-light);
  margin-top: var(--space-sm);
}

.site-header a {
  color: var(--color-link);
}

/* --- Section Heading with Icon --- */
.section-heading {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

.section-heading .icon {
  font-size: 1.6rem;
  line-height: 1;
}

/* --- Navigation --- */
nav {
  margin: var(--space-xl) 0;
}

.chapter-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-lg) 0;
  border-top: 2px solid #e0e0e0;
  margin-top: var(--space-2xl);
  gap: var(--space-sm);
}

.chapter-nav a {
  display: block;
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: var(--space-sm) var(--space-lg);
  background: var(--gradient-blue);
  color: var(--color-white);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chapter-nav a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--color-white);
}

.chapter-nav a:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 3px;
}

/* --- Sections --- */
section {
  margin: var(--space-2xl) 0;
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  border-left: 5px solid #ccc;
  box-shadow: var(--shadow-sm);
}

.idea {
  background-color: var(--color-idea);
  border-left-color: var(--color-idea-border);
}

.explore {
  background-color: var(--color-explore);
  border-left-color: var(--color-explore-border);
}

.understand {
  background-color: var(--color-understand);
  border-left-color: var(--color-understand-border);
}

.practice {
  background-color: var(--color-practice);
  border-left-color: var(--color-practice-border);
}

.reflect {
  background-color: var(--color-reflect);
  border-left-color: var(--color-reflect-border);
}

section h2 {
  margin-top: 0;
}

/* --- Section Labels --- */
.section-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-xs) var(--space-md);
  border-radius: 50px;
  margin-bottom: var(--space-md);
}

.idea .section-label {
  background: var(--gradient-blue);
  color: var(--color-white);
}

.explore .section-label {
  background: var(--gradient-green);
  color: var(--color-white);
}

.understand .section-label {
  background: var(--gradient-orange);
  color: var(--color-white);
}

.practice .section-label {
  background: var(--gradient-blue);
  color: var(--color-white);
}

.reflect .section-label {
  background: var(--gradient-pink);
  color: var(--color-white);
}

/* --- Code Blocks --- */
.code-block {
  margin: var(--space-md) 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: none;
  box-shadow: var(--shadow-md);
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-code-header);
  padding: var(--space-sm) var(--space-md);
}

.code-block-label {
  color: #999;
  font-size: 0.8rem;
  font-family: var(--font-code);
  font-weight: 600;
}

.code-block pre {
  margin: 0;
  padding: var(--space-lg);
  background: var(--color-code-bg);
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-code);
  font-size: 0.9rem;
  color: var(--color-code-text);
  line-height: 1.6;
  white-space: pre;
}

/* --- Editable Code --- */
.code-block code[contenteditable="true"] {
  display: block;
  outline: none;
  min-height: 3em;
  cursor: text;
}

.code-block code[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 2px var(--color-idea-border);
}

/* --- Buttons --- */
button, .button {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  text-transform: none;
  letter-spacing: 0;
}

button:hover, .button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active, .button:active {
  transform: translateY(0) scale(0.98);
}

.run-button {
  background: var(--gradient-green);
  color: var(--color-white);
}

.run-button:hover {
  background: linear-gradient(135deg, #05c191, #168f7f);
}

.run-button:disabled {
  background: #888;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.copy-button {
  background: #555;
  color: var(--color-white);
  margin-right: var(--space-sm);
}

.copy-button:hover {
  background: #444;
}

.reset-button {
  background: #777;
  color: var(--color-white);
  margin-right: var(--space-sm);
}

.reset-button:hover {
  background: #555;
}

.button {
  display: inline-block;
  background: var(--gradient-blue);
  color: var(--color-white);
  text-decoration: none;
  text-align: center;
}

.button:hover {
  color: var(--color-white);
}

.button-outline {
  display: inline-block;
  background: transparent;
  color: var(--color-link);
  text-decoration: none;
  text-align: center;
  border: 2px solid var(--color-link);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
}

.button-outline:hover {
  background: var(--color-link);
  color: var(--color-white);
}

/* --- Output Box --- */
.output-box {
  padding: var(--space-md);
  background: var(--color-output-bg);
  border-top: 2px solid var(--color-output-border);
  font-family: var(--font-code);
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 2.5em;
  color: var(--color-text);
}

.output-box.empty {
  color: #999;
  font-style: italic;
}

.output-box.error {
  color: var(--color-error);
  background: #fff0f0;
  border-top-color: var(--color-error);
}

/* --- Exercises --- */
.exercise {
  background: var(--color-white);
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin: var(--space-lg) 0;
  transition: border-color 0.2s;
}

.exercise:hover {
  border-color: var(--color-idea-border);
}

.exercise-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: var(--space-sm);
}

.exercise-difficulty {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  padding: var(--space-xs) var(--space-md);
  border-radius: 50px;
  color: var(--color-white);
  margin-bottom: var(--space-md);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.difficulty-1 {
  background: var(--gradient-green);
}

.difficulty-2 {
  background: var(--gradient-orange);
}

.difficulty-3 {
  background: var(--gradient-pink);
}

/* --- Pseudocode --- */
.pseudocode {
  background: rgba(0,0,0,0.04);
  border: 2px dashed #bbb;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-md) 0;
  font-family: var(--font-body);
  line-height: 1.8;
}

.pseudocode-label {
  font-weight: 800;
  margin-bottom: var(--space-sm);
  color: var(--color-text-light);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

/* --- Hints --- */
.hint {
  margin: var(--space-md) 0;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.hint-title {
  padding: var(--space-sm) var(--space-md);
  background: #f8f8fa;
  cursor: pointer;
  font-weight: 700;
  user-select: none;
  transition: background 0.2s;
}

.hint-title:hover {
  background: #eeeef2;
}

.hint-content {
  display: none;
  padding: var(--space-md);
  background: var(--color-white);
  border-top: 1px solid #e0e0e0;
}

.hint-content.visible {
  display: block;
}

/* --- Key Concept / Callout --- */
.key-concept {
  background: linear-gradient(135deg, #fff9e6, #fff3cd);
  border: 2px solid #ffc107;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

.key-concept strong {
  display: block;
  margin-bottom: var(--space-xs);
}

.warning {
  background: linear-gradient(135deg, #fff5f5, #ffe0e0);
  border: 2px solid var(--color-error);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

/* --- Index Page: Sidebar Layout --- */
.index-page {
  max-width: 1200px;
}

.site-layout {
  display: flex;
  gap: var(--space-xl);
  align-items: flex-start;
}

/* --- Sidebar Navigation --- */
.sidebar {
  position: sticky;
  top: var(--space-lg);
  width: 280px;
  min-width: 280px;
  max-height: calc(100vh - 2 * var(--space-lg));
  overflow-y: auto;
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-md) 0;
}

.sidebar-toggle {
  display: none;
}

.sidebar-inner {
  padding: 0 var(--space-sm);
}

/* --- Navigation Groups --- */
.nav-group {
  margin-bottom: var(--space-xs);
}

.nav-group-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  user-select: none;
  transition: background 0.2s;
}

.nav-group-title:hover {
  background: var(--color-bg);
}

.nav-group-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.nav-chevron {
  margin-left: auto;
  flex-shrink: 0;
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid var(--color-text-light);
  border-bottom: 2px solid var(--color-text-light);
  transform: rotate(-45deg);
  transition: transform 0.2s;
}

.nav-group.open .nav-chevron {
  transform: rotate(45deg);
}

.nav-group-links {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.nav-group.open .nav-group-links {
  max-height: 600px;
}

.nav-group-links li {
  margin: 0;
}

.nav-group-links a {
  display: block;
  padding: var(--space-xs) var(--space-md) var(--space-xs) calc(var(--space-md) + 1.6rem);
  font-size: 0.85rem;
  color: var(--color-text-light);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
}

.nav-group-links a:hover {
  background: var(--color-idea);
  color: var(--color-link);
}

/* --- Main Content Area --- */
.main-content {
  flex: 1;
  min-width: 0;
}

/* --- Chapter List (kept for any remaining usage) --- */
.chapter-list {
  display: grid;
  gap: var(--space-lg);
  margin: var(--space-xl) 0;
}

.chapter-card {
  background: var(--color-white);
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.chapter-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient-blue);
  opacity: 0;
  transition: opacity 0.2s;
}

.chapter-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-idea-border);
}

.chapter-card:hover::before {
  opacity: 1;
}

.chapter-card h3 {
  margin-top: var(--space-xs);
  margin-bottom: var(--space-sm);
}

.chapter-card p {
  color: var(--color-text-light);
  margin-bottom: var(--space-md);
}

.chapter-number {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--color-idea-border);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-xs);
}

/* --- Theory Card Variants --- */
.chapter-card.theory-card::before {
  background: var(--gradient-purple);
}

.chapter-card.theory-card:hover {
  border-color: #7209b7;
}

.chapter-card.theory-card .chapter-number {
  color: #7209b7;
}

/* --- Pyodide Loading --- */
.loading-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--gradient-hero);
  color: var(--color-white);
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 1000;
  transition: transform 0.3s;
}

.loading-banner.hidden {
  transform: translateY(-100%);
}

/* --- Try This --- */
.try-this {
  background: linear-gradient(135deg, #e6f9f1, #d0f0e0);
  border: 2px solid var(--color-explore-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-md) 0;
}

.try-this strong {
  color: var(--color-explore-border);
}

/* --- Inline Code --- */
code:not([class]) {
  background: rgba(67,97,238,0.1);
  padding: 0.15em 0.45em;
  border-radius: var(--radius-sm);
  font-family: var(--font-code);
  font-size: 0.85em;
  color: #4361ee;
  font-weight: 600;
}

/* Inline code within dark-bg sections */
.code-block code {
  background: none;
  padding: 0;
  color: var(--color-code-text);
  font-weight: 400;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-md) 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

th, td {
  border: 1px solid #e0e0e0;
  padding: var(--space-sm) var(--space-md);
  text-align: left;
}

th {
  background: var(--color-idea);
  font-weight: 700;
}

tr:nth-child(even) {
  background: #f8f8fa;
}

/* --- Video Resource Cards --- */
.video-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.video-card {
  background: var(--color-white);
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.video-card:hover {
  border-color: #e63946;
  box-shadow: var(--shadow-md);
}

.video-card .play-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.video-card .video-info {
  font-size: 0.9rem;
  color: var(--color-text);
  font-weight: 600;
}

.video-card .video-info small {
  display: block;
  font-weight: 400;
  color: var(--color-text-light);
  font-size: 0.8rem;
}

/* --- Past Paper Questions --- */
.past-paper {
  background: var(--color-white);
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-md);
  margin: var(--space-md) 0;
  overflow: hidden;
}

.past-paper summary {
  padding: var(--space-md);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.past-paper summary:hover {
  background: #f8f8fa;
}

.past-paper .mark-badge {
  display: inline-block;
  background: var(--gradient-purple);
  color: var(--color-white);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 50px;
  margin-left: var(--space-sm);
}

.past-paper .mark-scheme {
  padding: var(--space-md);
  border-top: 1px solid #e0e0e0;
  background: #f8faf8;
}

/* --- Info Boxes (Did You Know, Case Study, Exam Tip) --- */
.did-you-know {
  background: linear-gradient(135deg, #e8f4fd, #d1ecf9);
  border: 2px solid #4cc9f0;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

.did-you-know strong:first-child {
  display: block;
  margin-bottom: var(--space-xs);
  color: #0077b6;
}

.case-study {
  background: linear-gradient(135deg, #f3e8ff, #ede5ff);
  border: 2px solid #7209b7;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

.case-study strong:first-child {
  display: block;
  margin-bottom: var(--space-xs);
  color: #7209b7;
}

.exam-tip {
  background: linear-gradient(135deg, #e6f9f1, #d0f0e0);
  border: 2px solid #06d6a0;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

.exam-tip strong:first-child {
  display: block;
  margin-bottom: var(--space-xs);
  color: #06a080;
}

/* --- Vocabulary Tables --- */
.vocab-table th {
  background: linear-gradient(135deg, #4361ee, #4cc9f0);
  color: var(--color-white);
  font-weight: 700;
}

.vocab-table td:first-child {
  font-weight: 700;
  white-space: nowrap;
}

/* --- Interactive Exercises --- */
.interactive-exercise {
  background: linear-gradient(135deg, #f0f7ff, #e8f0fe);
  border: 2px solid var(--color-link);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
}

.interactive-exercise h3 {
  margin-top: 0;
  color: var(--color-link);
}

.exercise-problem {
  font-size: 1.3rem;
  font-weight: 700;
  margin: var(--space-md) 0;
  font-family: var(--font-code);
}

.exercise-controls {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
  margin: var(--space-md) 0;
}

.exercise-input {
  font-family: var(--font-code);
  font-size: 1.1rem;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid #ccc;
  border-radius: var(--radius-sm);
  width: 200px;
}

.exercise-input:focus {
  border-color: var(--color-link);
  outline: none;
}

.check-btn,
.new-btn {
  padding: var(--space-sm) 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.check-btn {
  background: var(--color-link);
  color: var(--color-white);
}

.check-btn:hover {
  background: var(--color-link-hover);
}

.new-btn {
  background: #06d6a0;
  color: var(--color-white);
}

.new-btn:hover {
  background: #05b384;
}

.feedback {
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: none;
}

.feedback.correct {
  background: #e6f9f1;
  color: #087f5b;
  border: 1px solid #06d6a0;
  display: block;
}

.feedback.incorrect {
  background: #fff5f5;
  color: #c92a2a;
  border: 1px solid var(--color-error);
  display: block;
}

.score-display {
  font-weight: 600;
  color: var(--color-link);
  margin-top: var(--space-sm);
}

/* --- Extra Resources --- */
.extra-resources {
  background: var(--color-white);
  border: 2px solid var(--color-explore-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-sm);
}

.extra-resources h3 {
  margin-top: 0;
  margin-bottom: var(--space-sm);
  color: var(--color-explore-border);
}

.extra-resources ul {
  list-style: none;
  padding-left: 0;
}

.extra-resources li {
  margin-bottom: var(--space-sm);
  padding-left: var(--space-lg);
  position: relative;
}

.extra-resources li::before {
  content: '\2192';
  position: absolute;
  left: 0;
  color: var(--color-explore-border);
  font-weight: 700;
}

.extra-resources a {
  font-weight: 700;
}

/* --- Resource Cards (index.html) --- */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.resource-card {
  background: var(--color-white);
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.resource-card:hover {
  transform: translateY(-3px);
  border-color: var(--color-explore-border);
  box-shadow: var(--shadow-lg);
}

.resource-card .card-icon {
  font-size: 2rem;
  margin-bottom: var(--space-sm);
  display: block;
}

.resource-card h4 {
  margin-top: 0;
  margin-bottom: var(--space-xs);
  font-size: 1rem;
}

.resource-card p {
  font-size: 0.85rem;
  color: var(--color-text-light);
  margin-bottom: var(--space-md);
}

/* --- Stats Bar --- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-md);
  margin: var(--space-xl) 0;
  text-align: center;
}

.stat {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: var(--space-lg) var(--space-md);
  box-shadow: var(--shadow-sm);
}

.stat-number {
  font-size: 2rem;
  font-weight: 800;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: block;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Theory Section --- */
.theory-section {
  background: linear-gradient(135deg, #f3e8ff, #ede5ff);
  border: 2px solid #7209b7;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin: var(--space-xl) 0;
}

.theory-section h2 {
  margin-top: 0;
  color: #7209b7;
}

/* --- Footer --- */
.site-footer {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  margin-top: var(--space-2xl);
  border-top: 2px solid #e0e0e0;
  color: var(--color-text-light);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--color-link);
}

/* --- Responsive Design --- */

/* Sidebar collapses on tablets/mobile */
@media (max-width: 900px) {
  .index-page {
    max-width: 100%;
  }

  .site-layout {
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    top: 0;
    width: 100%;
    min-width: 0;
    max-height: none;
    overflow: visible;
    padding: 0;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
  }

  .sidebar-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    background: var(--color-white);
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-md);
    cursor: pointer;
    padding: 0;
    margin-bottom: var(--space-sm);
    transition: border-color 0.2s;
  }

  .sidebar-toggle:hover {
    border-color: var(--color-link);
  }

  .sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
  }

  .sidebar-toggle.active span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .sidebar-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  .sidebar-toggle.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .sidebar-inner {
    display: none;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-sm);
    margin-bottom: var(--space-lg);
  }

  .sidebar-inner.open {
    display: block;
  }
}

@media (max-width: 600px) {
  body {
    padding: var(--space-md);
    font-size: 1rem;
  }

  .hero {
    padding: var(--space-xl) var(--space-md);
    border-radius: var(--radius-lg);
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  section {
    padding: var(--space-lg);
    margin: var(--space-lg) 0;
  }

  .code-block-header {
    flex-direction: column;
    gap: var(--space-sm);
    align-items: flex-start;
  }

  .resource-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stats-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 400px) {
  .resource-grid {
    grid-template-columns: 1fr;
  }
}

/* --- PRIMM Predict Box --- */
.predict-box {
  background: linear-gradient(135deg, #f0e6ff, #e8daff);
  border: 2px solid #7209b7;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0 var(--space-xs) 0;
}

.predict-box strong {
  display: block;
  margin-bottom: var(--space-xs);
  color: #7209b7;
}

.predict-box .predict-toggle {
  display: inline-block;
  margin-top: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--gradient-purple);
  color: var(--color-white);
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.predict-box .predict-answer {
  display: none;
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: rgba(255,255,255,0.6);
  border-radius: var(--radius-sm);
  font-family: var(--font-code);
  font-size: 0.9rem;
}

.predict-box .predict-answer.visible {
  display: block;
}

/* --- Comment-First Box --- */
.comment-first-box {
  background: linear-gradient(135deg, #e8f4fd, #d1ecf9);
  border: 2px solid #4cc9f0;
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
}

.comment-first-box strong {
  display: block;
  margin-bottom: var(--space-xs);
  color: #0077b6;
}

/* --- Pause Point - cognitive break marker --- */
.pause-point {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-left: 4px solid #0ea5e9;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-radius: 0 8px 8px 0;
  font-size: 0.95rem;
}
.pause-point strong {
  color: #0369a1;
  display: block;
  margin-bottom: 0.25rem;
}

/* --- Reference Table --- */
.reference-table {
  background: var(--color-white, #fff);
  border: 1px solid var(--color-output-border, #e2e8f0);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1.5rem 0;
  overflow-x: auto;
}
.reference-table h4 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  color: var(--color-text, #1a1a2e);
}
.reference-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.reference-table th,
.reference-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-output-border, #e2e8f0);
  text-align: left;
}
.reference-table th {
  background: #f8fafc;
  font-weight: 600;
}
.reference-table tr:nth-child(even) {
  background: #f8fafc;
}
.reference-table code {
  background: #f1f5f9;
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.88em;
}

/* --- Chapter Progress Bar --- */
.chapter-progress {
  background: var(--color-white, #fff);
  border: 1px solid var(--color-output-border, #e2e8f0);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin: 1rem 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.chapter-progress .progress-text {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--color-text, #1a1a2e);
}
.chapter-progress .progress-bar {
  flex: 1;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}
.chapter-progress .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* --- Breadcrumb Navigation --- */
.breadcrumb {
  font-size: 0.85rem;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
  color: var(--color-text-light, #6b7280);
}
.breadcrumb a {
  color: var(--color-link, #2563eb);
  text-decoration: none;
}
.breadcrumb a:hover {
  text-decoration: underline;
}

/* --- Page Table of Contents --- */
.page-toc {
  background: #f8fafc;
  border: 1px solid var(--color-output-border, #e2e8f0);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
}
.page-toc h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--color-text, #1a1a2e);
}
.page-toc ul {
  margin: 0;
  padding-left: 1.25rem;
  list-style: disc;
}
.page-toc li {
  margin: 0.25rem 0;
  font-size: 0.9rem;
}
.page-toc a {
  color: var(--color-link, #2563eb);
  text-decoration: none;
}
.page-toc a:hover {
  text-decoration: underline;
}

/* --- Output Box Running State --- */
.output-box.running {
  color: var(--color-text-light);
  font-style: italic;
}

/* --- Output Box Success (no output) State --- */
.output-box.success-empty {
  color: #6b7280;
  font-style: italic;
}

/* ===================================
   Youth-friendly visual enhancements
   Playful but still WCAG 2.1 AA clean.
   All animations are disabled automatically
   via the prefers-reduced-motion block below.
   =================================== */

/* Floating blob decorations for the hero */
.hero {
  isolation: isolate;
}
.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.18) 0, transparent 22%),
    radial-gradient(circle at 85% 75%, rgba(255,255,255,0.14) 0, transparent 25%),
    radial-gradient(circle at 70% 15%, rgba(247,37,133,0.25) 0, transparent 18%),
    radial-gradient(circle at 20% 85%, rgba(6,214,160,0.22) 0, transparent 20%);
  pointer-events: none;
  z-index: -1;
  animation: hero-drift 14s ease-in-out infinite alternate;
}

@keyframes hero-drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(2%, -1.5%, 0) scale(1.05); }
  100% { transform: translate3d(-1.5%, 2%, 0) scale(0.98); }
}

/* Animated gradient title — only on the hero */
.hero h1 {
  background: linear-gradient(90deg, #ffffff, #ffe9f4, #d7f4ff, #ffffff);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: sheen 6s ease-in-out infinite;
  letter-spacing: -0.02em;
}
@keyframes sheen {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

/* Floating emoji decorations (optional, opt-in via .hero-floaties) */
.hero-floaties {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.hero-floaties span {
  position: absolute;
  font-size: 1.6rem;
  opacity: 0.55;
  animation: float-up 9s ease-in-out infinite;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.15));
}
.hero-floaties span:nth-child(1) { left: 8%;  top: 70%; animation-delay: 0s;    }
.hero-floaties span:nth-child(2) { left: 22%; top: 30%; animation-delay: 1.5s;  font-size: 1.3rem; }
.hero-floaties span:nth-child(3) { left: 55%; top: 80%; animation-delay: 3s;    font-size: 1.9rem; }
.hero-floaties span:nth-child(4) { left: 78%; top: 25%; animation-delay: 4.5s;  }
.hero-floaties span:nth-child(5) { left: 90%; top: 60%; animation-delay: 2s;    font-size: 1.4rem; }
.hero-floaties span:nth-child(6) { left: 40%; top: 15%; animation-delay: 5.5s;  font-size: 1.2rem; }

@keyframes float-up {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-18px) rotate(8deg); }
}

/* Hero badges — gentle bounce on hover */
.hero .badge {
  transition: transform 0.25s ease, background 0.25s ease;
  border: 1px solid rgba(255,255,255,0.3);
}
.hero .badge:hover {
  transform: translateY(-3px) scale(1.05);
  background: rgba(255,255,255,0.32);
}

/* Section label — bouncier with subtle glow */
.section-label {
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.section-label:hover {
  transform: translateY(-2px) rotate(-1deg);
  box-shadow: 0 6px 14px rgba(67,97,238,0.25);
}

/* 3D-ish lift + coloured glow on all cards */
.chapter-card,
.resource-card {
  transition:
    transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 0.35s ease,
    border-color 0.25s ease;
  will-change: transform;
}
.chapter-card:hover {
  transform: translateY(-6px) scale(1.015);
  box-shadow:
    0 18px 40px -15px rgba(67, 97, 238, 0.35),
    0 8px 16px -8px rgba(114, 9, 183, 0.25);
}
.chapter-card::before {
  height: 5px;
  background: var(--gradient-hero);
  background-size: 300% 100%;
  animation: bar-slide 6s linear infinite;
}
@keyframes bar-slide {
  0%   { background-position: 0% 0%; }
  100% { background-position: 300% 0%; }
}

.resource-card {
  position: relative;
  overflow: hidden;
}
.resource-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%),
              rgba(67,97,238,0.15), transparent 45%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.resource-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow:
    0 16px 36px -14px rgba(6, 214, 160, 0.35),
    0 6px 14px -6px rgba(247, 37, 133, 0.2);
}
.resource-card:hover::after { opacity: 1; }
.resource-card .card-icon {
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: inline-block;
}
.resource-card:hover .card-icon {
  transform: scale(1.25) rotate(-8deg);
}

/* Stat tiles get a little lift + rainbow edge on hover */
.stat {
  position: relative;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
}
.stat::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px;
  background: var(--gradient-hero);
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.stat:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 28px -14px rgba(114,9,183,0.3);
}
.stat:hover::before { opacity: 1; }
.stat-number {
  animation: pop-in 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
@keyframes pop-in {
  0%   { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

/* Playful, bouncy buttons */
.run-button,
.copy-button,
.reset-button,
.button {
  transition:
    transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.25),
    box-shadow 0.18s ease,
    filter 0.18s ease;
}
.run-button:hover,
.copy-button:hover,
.reset-button:hover,
.button:hover {
  transform: translateY(-2px) scale(1.03);
  filter: saturate(1.15);
  box-shadow: 0 8px 20px -6px rgba(67,97,238,0.4);
}
.run-button:active,
.copy-button:active,
.reset-button:active,
.button:active {
  transform: translateY(0) scale(0.97);
}

/* Attention-grabbing pulse for primary Run buttons on idle */
.run-button:not(:disabled) {
  animation: soft-pulse 3.5s ease-in-out infinite;
}
@keyframes soft-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(6, 214, 160, 0.0); }
  50%      { box-shadow: 0 0 0 6px rgba(6, 214, 160, 0.12); }
}

/* Difficulty badges - add a wobble on hover */
.difficulty-badge,
[class^="difficulty-"] {
  transition: transform 0.2s ease;
}
.difficulty-badge:hover,
[class^="difficulty-"]:hover {
  transform: rotate(-3deg) scale(1.08);
}

/* Scroll reveal — opt-in with .reveal on any element */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Confetti overlay (used by celebrate() JS helper) */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall 2.6s cubic-bezier(0.25, 0.85, 0.4, 1) forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(105vh)  rotate(720deg); opacity: 0.2; }
}

/* Gentle focus rings that still feel fun */
a:focus-visible,
button:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 3px solid #f72585;
  outline-offset: 3px;
  border-radius: 4px;
}

/* --- Print Styles --- */
@media print {
  .run-button,
  .copy-button,
  .reset-button,
  .loading-banner,
  .chapter-nav,
  .hero,
  .stats-bar {
    display: none;
  }

  body {
    max-width: 100%;
    color: #000;
    background: #fff;
  }

  section {
    break-inside: avoid;
    box-shadow: none;
  }

  .chapter-card {
    box-shadow: none;
  }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }

  html {
    scroll-behavior: auto;
  }

  .chapter-card:hover,
  .resource-card:hover,
  .stat:hover,
  .hero .badge:hover,
  .section-label:hover,
  .difficulty-badge:hover,
  button:hover,
  .button:hover {
    transform: none;
  }

  .hero-floaties,
  .confetti-layer {
    display: none !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}
