/* ═══════════════════════════════════════════════════════════════
   GCSE Notes Factory — Global Stylesheet
   Version: 1.0.0
   ═══════════════════════════════════════════════════════════════ */

/* ── Google Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;600;700&family=Nunito:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Fira+Code:wght@400;500&display=swap');

/* ── CSS Custom Properties ────────────────────────────────────── */
:root {
  /* Content colours */
  --col-critical:    #E53E3E;
  --col-definition:  #2F855A;
  --col-concept:     #2B6CB0;
  --col-exam-tip:    #6B46C1;
  --col-warning:     #C05621;
  --col-memory:      #B83280;

  /* Page */
  --col-page-bg:     #FFFEF7;
  --col-page-lines:  #E8E4D9;
  --col-card-bg:     #FFFFFF;
  --col-text:        #1A202C;
  --col-text-muted:  #718096;
  --col-border:      #E2E8F0;
  --col-shadow:      rgba(0, 0, 0, 0.08);

  /* Subject accents */
  --maths:      #667EEA;
  --biology:    #48BB78;
  --chemistry:  #F6AD55;
  --physics:    #4299E1;
  --english:    #FC8181;
  --history:    #B7791F;
  --geography:  #68D391;
  --cs:         #76E4F7;
  --business:   #FBD38D;
  --economics:  #9AE6B4;
  --psychology: #D6BCFA;

  /* Typography */
  --font-heading: 'Caveat', 'Patrick Hand', cursive;
  --font-body:    'Nunito', 'Quicksand', sans-serif;
  --font-code:    'Fira Code', 'Courier New', monospace;

  /* Type scale */
  --text-5xl: 2.8rem;
  --text-4xl: 2.0rem;
  --text-3xl: 1.6rem;
  --text-2xl: 1.3rem;
  --text-xl:  1.15rem;
  --text-base: 1rem;
  --text-sm:  0.875rem;
  --text-xs:  0.75rem;

  /* Spacing */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Border radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);

  /* Layout */
  --max-width: 900px;
  --sidebar-width: 260px;
}

/* ── Dark Mode ────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --col-page-bg:    #1A1A2E;
    --col-card-bg:    #16213E;
    --col-text:       #E2E8F0;
    --col-text-muted: #A0AEC0;
    --col-border:     #2D3748;
    --col-page-lines: #2D3748;
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--col-text);
  background-color: var(--col-page-bg);
  background-image:
    linear-gradient(var(--col-page-lines) 1px, transparent 1px);
  background-size: 100% 32px;
  background-attachment: local;
}

/* ── Typography ───────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  line-height: 1.3;
  color: var(--col-text);
  margin-bottom: var(--sp-3);
}

h1 { font-size: var(--text-5xl); font-weight: 700; }
h2 { font-size: var(--text-4xl); font-weight: 700; }
h3 { font-size: var(--text-3xl); font-weight: 600; }
h4 { font-size: var(--text-2xl); font-weight: 600; }

p { margin-bottom: var(--sp-4); }

a {
  color: var(--col-concept);
  text-decoration: none;
  transition: color 0.2s ease;
}
a:hover { color: var(--col-exam-tip); text-decoration: underline; }

strong { font-weight: 700; }
em { font-style: italic; }

code {
  font-family: var(--font-code);
  font-size: 0.9em;
  background: var(--col-border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

pre {
  font-family: var(--font-code);
  background: #1A202C;
  color: #E2E8F0;
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--sp-4);
}

/* ── Page Layout ──────────────────────────────────────────────── */
.page-wrapper {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--col-card-bg);
  border-right: 1px solid var(--col-border);
  padding: var(--sp-6);
}

.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
}

/* ── Navigation ───────────────────────────────────────────────── */
.site-nav {
  background: var(--col-card-bg);
  border-bottom: 1px solid var(--col-border);
  padding: var(--sp-3) var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--col-text);
}

.nav-links { display: flex; gap: var(--sp-4); }
.nav-links a { color: var(--col-text-muted); font-weight: 600; font-size: var(--text-sm); }
.nav-links a:hover { color: var(--col-text); }

/* ── Breadcrumbs ──────────────────────────────────────────────── */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--col-text-muted);
  margin-bottom: var(--sp-6);
}
.breadcrumbs a { color: var(--col-text-muted); }
.breadcrumbs a:hover { color: var(--col-text); }
.breadcrumbs .sep { color: var(--col-border); }

/* ── Chapter Cover ────────────────────────────────────────────── */
.chapter-cover {
  background: var(--col-card-bg);
  border-radius: var(--radius-xl);
  padding: var(--sp-10);
  margin-bottom: var(--sp-8);
  box-shadow: var(--shadow-md);
  border-top: 6px solid var(--subject-accent, var(--maths));
  position: relative;
  overflow: hidden;
}

.chapter-cover::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 200px;
  height: 200px;
  background: var(--subject-accent, var(--maths));
  opacity: 0.06;
  border-radius: 50%;
}

.subject-badge {
  display: inline-block;
  padding: var(--sp-1) var(--sp-3);
  background: var(--subject-accent, var(--maths));
  color: white;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-3);
}

.chapter-title {
  font-size: var(--text-5xl);
  font-weight: 700;
  color: var(--col-text);
  margin-bottom: var(--sp-3);
  line-height: 1.2;
}

.chapter-meta {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  color: var(--col-text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-6);
}

.difficulty-stars { color: #F6AD55; }

.learning-objectives {
  list-style: none;
  display: grid;
  gap: var(--sp-2);
}

.learning-objectives li {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
}

.learning-objectives li::before {
  content: '○';
  color: var(--subject-accent, var(--maths));
  font-weight: bold;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Section Headings ─────────────────────────────────────────── */
.section-heading {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  color: var(--col-definition);
  border-bottom: 3px solid currentColor;
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-6);
  margin-top: var(--sp-10);
}

/* ── Callout Boxes ────────────────────────────────────────────── */
.callout {
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-3);
  align-items: start;
}

.callout-icon {
  font-size: 1.3em;
  line-height: 1.4;
}

.callout-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--sp-1);
}

.callout-content { font-size: var(--text-base); }

/* Variants */
.callout-important {
  background: #FFF5F5;
  border-left: 4px solid var(--col-critical);
}
.callout-important .callout-title { color: var(--col-critical); }

.callout-definition {
  background: #F0FFF4;
  border-left: 4px solid var(--col-definition);
}
.callout-definition .callout-title { color: var(--col-definition); }

.callout-exam-tip {
  background: #FAF5FF;
  border-left: 4px solid var(--col-exam-tip);
}
.callout-exam-tip .callout-title { color: var(--col-exam-tip); }

.callout-warning {
  background: #FFFAF0;
  border-left: 4px solid var(--col-warning);
}
.callout-warning .callout-title { color: var(--col-warning); }

.callout-memory {
  background: #FFF5F7;
  border-left: 4px solid var(--col-memory);
}
.callout-memory .callout-title { color: var(--col-memory); }

.callout-example {
  background: #EBF8FF;
  border-left: 4px solid var(--col-concept);
}
.callout-example .callout-title { color: var(--col-concept); }

/* ── Formula Card ─────────────────────────────────────────────── */
.formula-card {
  background: var(--col-card-bg);
  border: 2px solid var(--col-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin: var(--sp-4) 0;
  box-shadow: var(--shadow-sm);
}

.formula-card-title {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  color: var(--col-text-muted);
  margin-bottom: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.formula-display {
  font-size: 1.4rem;
  text-align: center;
  padding: var(--sp-4);
  background: var(--col-page-bg);
  border-radius: var(--radius-md);
  margin: var(--sp-3) 0;
  font-family: var(--font-code);
}

.formula-variables {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--col-text-muted);
}

/* ── Tables ───────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-5) 0;
  background: var(--col-card-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

thead {
  background: var(--subject-accent, var(--maths));
  color: white;
}

th {
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 700;
  text-align: left;
}

td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--col-border);
  font-size: var(--text-sm);
}

tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: #F7FAFC; }

/* ── Flashcards ───────────────────────────────────────────────── */
.flashcard-container {
  perspective: 1000px;
  width: 380px;
  height: 220px;
  cursor: pointer;
  margin: var(--sp-4) auto;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.flashcard.flipped { transform: rotateY(180deg); }

.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  text-align: center;
  box-shadow: var(--shadow-md);
}

.flashcard-front {
  background: var(--col-card-bg);
  border: 2px solid var(--col-border);
}

.flashcard-back {
  background: var(--subject-accent, var(--maths));
  color: white;
  transform: rotateY(180deg);
}

.flashcard-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.6;
  margin-bottom: var(--sp-2);
}

.flashcard-text {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.4;
}

/* ── Flashcard Grid ───────────────────────────────────────────── */
.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--sp-6);
  padding: var(--sp-4) 0;
}

/* ── Progress Bar ─────────────────────────────────────────────── */
.progress-bar {
  background: var(--col-border);
  border-radius: var(--radius-full);
  height: 8px;
  overflow: hidden;
  margin-bottom: var(--sp-2);
}

.progress-fill {
  height: 100%;
  background: var(--subject-accent, var(--maths));
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ── Checklist ────────────────────────────────────────────────── */
.checklist {
  list-style: none;
  display: grid;
  gap: var(--sp-2);
}

.checklist li {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s ease;
}

.checklist li:hover { background: var(--col-border); }

.checklist-box {
  width: 20px;
  height: 20px;
  border: 2px solid var(--col-border);
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.checklist li.checked .checklist-box {
  background: var(--col-definition);
  border-color: var(--col-definition);
  color: white;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--subject-accent, var(--maths));
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  color: white;
}

.btn-secondary {
  background: var(--col-card-bg);
  color: var(--col-text);
  border: 2px solid var(--col-border);
}
.btn-secondary:hover { border-color: var(--col-text-muted); }

/* ── Search ───────────────────────────────────────────────────── */
.search-box {
  display: flex;
  align-items: center;
  background: var(--col-card-bg);
  border: 2px solid var(--col-border);
  border-radius: var(--radius-full);
  padding: var(--sp-2) var(--sp-4);
  gap: var(--sp-2);
  transition: border-color 0.2s ease;
}

.search-box:focus-within { border-color: var(--col-concept); }

.search-box input {
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--col-text);
  outline: none;
  width: 200px;
}

/* ── Accordion ────────────────────────────────────────────────── */
.accordion-item {
  border: 1px solid var(--col-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
  overflow: hidden;
}

.accordion-header {
  padding: var(--sp-4);
  background: var(--col-card-bg);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 600;
  user-select: none;
  transition: background 0.2s ease;
}

.accordion-header:hover { background: var(--col-border); }

.accordion-chevron {
  transition: transform 0.3s ease;
  font-size: 0.8em;
}

.accordion-item.open .accordion-chevron { transform: rotate(180deg); }

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, padding 0.3s ease;
  padding: 0 var(--sp-4);
}

.accordion-item.open .accordion-body {
  max-height: 2000px;
  padding: var(--sp-4);
}

/* ── Download Card ────────────────────────────────────────────── */
.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-3);
  margin: var(--sp-5) 0;
}

.download-card {
  background: var(--col-card-bg);
  border: 2px solid var(--col-border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  text-align: center;
  text-decoration: none;
  color: var(--col-text);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.download-card:hover {
  border-color: var(--subject-accent, var(--maths));
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.download-icon { font-size: 2rem; }
.download-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Subject Cards (Homepage) ─────────────────────────────────── */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-5);
  padding: var(--sp-5) 0;
}

.subject-card {
  background: var(--col-card-bg);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-md);
  border-top: 5px solid var(--accent);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  color: var(--col-text);
  display: block;
}

.subject-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
}

.subject-card-icon { font-size: 2.5rem; margin-bottom: var(--sp-3); }
.subject-card-name { font-family: var(--font-heading); font-size: var(--text-2xl); font-weight: 700; }
.subject-card-count { font-size: var(--text-xs); color: var(--col-text-muted); margin-top: var(--sp-1); }
.subject-card-progress { margin-top: var(--sp-3); }

/* ── Footer ───────────────────────────────────────────────────── */
.site-footer {
  background: var(--col-card-bg);
  border-top: 1px solid var(--col-border);
  padding: var(--sp-6);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--col-text-muted);
  margin-top: var(--sp-16);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .page-wrapper { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

@media (max-width: 768px) {
  :root { --text-5xl: 2rem; --text-4xl: 1.6rem; }
  .main-content { padding: var(--sp-5) var(--sp-4); }
  .flashcard-container { width: 100%; }
  .chapter-meta { flex-direction: column; }
  .nav-links { display: none; }
}

@media (max-width: 480px) {
  .flashcard-grid { grid-template-columns: 1fr; }
  .download-grid  { grid-template-columns: repeat(2, 1fr); }
  .subject-grid   { grid-template-columns: repeat(2, 1fr); }
}

/* ── Print ────────────────────────────────────────────────────── */
@media print {
  @page { size: A4; margin: 20mm; }

  body {
    background: white;
    background-image: none;
    font-size: 11pt;
    line-height: 1.5;
  }

  .site-nav, .sidebar, .breadcrumbs, .btn,
  .flashcard-controls, .search-box,
  .site-footer, .download-grid { display: none !important; }

  .main-content { max-width: 100%; padding: 0; }

  .chapter-cover { page-break-after: always; box-shadow: none; }
  .section-heading { page-break-after: avoid; }
  .callout { page-break-inside: avoid; }
  table { page-break-inside: avoid; }

  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  a[href]::after { content: ""; }
}
