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

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-accent: #7c3aed;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.3; }
h1 { font-size: 2rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.5rem; margin: 2rem 0 1rem; }

/* === Header === */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.site-logo {
  font-size: 1.4rem;
  color: var(--color-text);
  letter-spacing: -0.5px;
}
.site-logo strong { color: var(--color-primary); }
.site-logo:hover { text-decoration: none; }

.site-nav { display: flex; gap: 1.5rem; }
.site-nav a {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.site-nav a:hover, .site-nav a.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  text-decoration: none;
}

.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 0.5rem; }
.nav-toggle span {
  display: block; width: 24px; height: 2px; background: var(--color-text);
  margin: 5px 0; transition: 0.3s;
}

/* === Hero === */
.hero {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-accent) 100%);
  color: white;
  padding: 4rem 0;
  text-align: center;
}
.hero h1 { font-size: 2.5rem; color: white; margin-bottom: 1rem; }
.hero p { font-size: 1.2rem; opacity: 0.95; max-width: 600px; margin: 0 auto 2rem; }

.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: white; color: var(--color-primary); }
.btn-primary:hover { background: #f0f4ff; }
.btn-secondary { background: transparent; color: white; border-color: rgba(255,255,255,0.5); }
.btn-secondary:hover { border-color: white; background: rgba(255,255,255,0.1); }
.btn-sm { padding: 0.4rem 1rem; font-size: 0.85rem; }

/* === Cards === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, transform 0.15s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.card h3 a { color: var(--color-text); }
.card h3 a:hover { color: var(--color-primary); text-decoration: none; }
.card-desc { font-size: 0.9rem; color: var(--color-text-muted); margin-bottom: 0.75rem; }

.card-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.chip {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-weight: 500;
}
.chip-grade { background: #dbeafe; color: #1e40af; }
.chip-subject { background: #f3e8ff; color: #6b21a8; }
.chip-author { background: #ecfdf5; color: #065f46; }
.chip-tag { background: #fef3c7; color: #92400e; font-size: 0.7rem; }

.card-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.5rem; }

/* === Taxonomy Grid === */
.taxonomy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1rem 0 2rem;
}

.taxonomy-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.taxonomy-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
  text-decoration: none;
}
.taxonomy-name { font-weight: 600; color: var(--color-text); font-size: 0.95rem; text-transform: capitalize; }
.taxonomy-count { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; }

/* === Filters === */
.filters {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.filter-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.filter-row:last-child { margin-bottom: 0; }

.filter-search {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
}
.filter-search:focus { outline: 2px solid var(--color-primary); border-color: transparent; }

.filters select {
  flex: 1;
  min-width: 180px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
}

.filter-count { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 0.5rem; }

/* === Lesson Detail === */
.lesson-header { margin-bottom: 1.5rem; }
.lesson-description { font-size: 1.1rem; color: var(--color-text-muted); margin-top: 0.5rem; }

.lesson-meta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.meta-item { font-size: 0.9rem; }
.meta-item strong { color: var(--color-text); }
.meta-item a { font-size: 0.9rem; }

.lesson-content { margin-bottom: 3rem; }
.lesson-content h2 { border-bottom: 1px solid var(--color-border); padding-bottom: 0.4rem; }
.lesson-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.lesson-content th, .lesson-content td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}
.lesson-content th { background: var(--color-bg); font-weight: 600; }

.lesson-footer { padding: 1.5rem 0; border-top: 1px solid var(--color-border); }
.back-link { font-weight: 500; }

/* === Page Content === */
.page-content { padding: 2rem 0; }
.page-content h1 { margin-bottom: 1.5rem; }

/* === Home sections === */
.home-intro { padding: 3rem 0; }
.intro-text { max-width: 800px; font-size: 1.05rem; }
.intro-text p { margin-bottom: 1rem; }

.home-browse { padding: 2rem 0; }
.home-recent { padding: 2rem 0 3rem; }
.see-all { text-align: center; margin-top: 1.5rem; font-weight: 500; }

/* === Explore Section (Homepage) === */
.home-explore { padding: 2rem 0 3rem; }
.section-subtitle { color: var(--color-text-muted); margin-bottom: 1.5rem; }

.explore-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
}

/* Filter Sidebar */
.filter-sidebar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-header h3 { font-size: 1.1rem; margin: 0; }

.btn-clear {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-clear:hover { text-decoration: underline; }

.filter-search-wrap { margin-bottom: 1rem; }
.filter-search-wrap .filter-search { width: 100%; }

.filter-group { margin-bottom: 1.25rem; border-bottom: 1px solid var(--color-border); padding-bottom: 1rem; }
.filter-group:last-of-type { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }

.filter-group-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.filter-group-count {
  background: var(--color-border);
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
}

.filter-options { display: flex; flex-direction: column; gap: 0.2rem; }

.filter-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
}
.filter-check:hover { background: var(--color-bg); }
.filter-check input[type="checkbox"] { accent-color: var(--color-primary); flex-shrink: 0; }

.filter-label { flex: 1; min-width: 0; text-transform: capitalize; }

.filter-badge {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  flex-shrink: 0;
}

.filter-check-empty { opacity: 0.45; }
.filter-check-empty .filter-badge { background: transparent; }

.btn-apply-mobile { display: none; width: 100%; margin-top: 1rem; }

/* Results Toolbar */
.results-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.results-count { font-size: 0.95rem; color: var(--color-text-muted); }
.results-count strong { color: var(--color-text); }

.results-actions { display: flex; gap: 0.75rem; align-items: center; }
.filter-toggle-btn { display: none; }

.sort-select {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--color-surface);
}

/* Active Filter Chips */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
  min-height: 0;
}

.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e40af;
  font-weight: 500;
}
.active-chip-subject { background: #f3e8ff; color: #6b21a8; }
.active-chip-domain { background: #dcfce7; color: #166534; }
.active-chip-tag { background: #fef3c7; color: #92400e; }

.active-chip button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  opacity: 0.7;
  padding: 0;
}
.active-chip button:hover { opacity: 1; }

.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}
.no-results p { margin-bottom: 0.5rem; }
.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
}

.chip-more { background: #f1f5f9; color: var(--color-text-muted); }

/* === Footer === */
.site-footer {
  margin-top: auto;
  background: var(--color-text);
  color: #94a3b8;
  padding: 2rem 0;
  text-align: center;
  font-size: 0.85rem;
}
.site-footer a { color: #93c5fd; }
.site-footer p { margin-bottom: 0.4rem; }

/* === Mobile === */
@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .site-nav {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--color-surface);
    flex-direction: column;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
  }
  .site-nav.open { display: flex; }
  .hero h1 { font-size: 1.8rem; }
  .hero p { font-size: 1rem; }
  .card-grid { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; }
  .filters select { min-width: auto; }
  .lesson-meta { grid-template-columns: 1fr; }

  /* Explore layout mobile */
  .explore-layout { grid-template-columns: 1fr; }
  .filter-sidebar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    border-radius: 0;
    max-height: 100vh;
    padding: 1.5rem;
    overflow-y: auto;
  }
  .filter-sidebar.open { display: block; }
  .btn-apply-mobile { display: block; }
  .filter-toggle-btn { display: inline-block; }
  body.filters-open { overflow: hidden; }
}
