/* =====================================================
   乐学智研空间 — site.css  (全站自定义样式)
   ===================================================== */

/* ---------- CSS Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background .3s, color .3s;
}

a { color: var(--primary); text-decoration: none; transition: color .2s; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ---------- Layout Container ---------- */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---------- Theme Bar ---------- */
.theme-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: .3rem 0;
  font-size: .8rem;
}
.theme-bar .container {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.theme-bar span { color: var(--text-muted); margin-right: .3rem; }
.theme-btn {
  padding: .2rem .7rem;
  border-radius: 99px;
  border: 1.5px solid var(--border);
  background: none;
  font-size: .78rem;
  color: var(--text-muted);
  transition: all .2s;
}
.theme-btn:hover, .theme-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---------- Site Header ---------- */
.site-header {
  background: var(--bg-card);
  border-bottom: 2px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.header-inner {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  padding: .5rem 0;
  flex-wrap: nowrap;
}
.site-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-shrink: 0;
  text-decoration: none;
}
.site-brand .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.site-brand .brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.site-brand .brand-name { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.site-brand .brand-sub { font-size: .7rem; color: var(--text-muted); }

/* ---------- Main Nav ---------- */
.site-header { position: sticky; }
.header-inner { position: relative; }
/* site-brand vertically centered */
.site-brand { align-self: center; }
/* nav-toggle vertically centered */
.nav-toggle { align-self: center; }
.site-nav { flex: 1; display: flex; align-items: center; overflow: visible; }
.site-nav > ul,
.nav-list { display: flex; align-items: center; gap: .1rem; flex-wrap: nowrap; list-style: none; flex: 1; }
.nav-item {
  position: relative;
}
/* has-mega li stretches to fill full header-inner height so cursor never leaves the li area when sliding to mega-menu */
.nav-item.has-mega {
  position: static;
  align-self: stretch;
  display: flex;
  align-items: center;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: .3rem;
  padding: .4rem .65rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  transition: all .2s;
  white-space: nowrap;
}
.nav-link:hover, .nav-link.active {
  background: rgba(var(--primary-rgb), .1);
  color: var(--primary);
}
.nav-link i { font-size: .8rem; }

/* ---------- Standard Dropdown ---------- */
.nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: .5rem;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 300;
}
.nav-item:hover .nav-dropdown { display: block; }
.nav-dropdown a {
  display: block;
  padding: .4rem .8rem;
  border-radius: 8px;
  font-size: .88rem;
  color: var(--text);
  transition: all .2s;
}
.nav-dropdown a:hover { background: rgba(var(--primary-rgb), .1); color: var(--primary); }
.nav-dropdown a i { width: 1.2rem; }
.dropdown-head {
  padding: .3rem .8rem .15rem;
  font-size: .73rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  pointer-events: none;
  margin-top: .3rem;
}

/* ---------- Mega Menu ---------- */
.mega-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-top: 2px solid var(--primary);
  border-radius: 0 0 14px 14px;
  padding: 1.2rem 1.5rem 1.4rem;
  box-shadow: 0 16px 48px rgba(0,0,0,.14);
  z-index: 300;
}
.nav-item.has-mega:hover .mega-menu { display: block; }

/* Grid layout */
.mega-grid {
  display: grid;
  gap: 0;
  align-items: start;
}
.mega-cols-3  { grid-template-columns: repeat(3, 1fr); }
.mega-cols-6  { grid-template-columns: repeat(6, 1fr); }
.mega-cols-7  { grid-template-columns: repeat(7, 1fr); }

/* Column */
.mega-col {
  padding: 0 .8rem;
  border-right: 1px solid var(--border);
}
.mega-col:last-child { border-right: none; }

/* Column header (clickable) */
.mega-col-head {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0 0 .45rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .45rem;
  transition: color .2s;
}
.mega-col-head:hover { color: var(--primary-dark); }

/* Column items */
.mega-col ul { list-style: none; }
.mega-col ul li a {
  display: block;
  padding: .22rem 0;
  font-size: .8rem;
  color: var(--text-muted);
  transition: color .15s, padding-left .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mega-col ul li a:hover {
  color: var(--primary);
  padding-left: .4rem;
}

/* Wide mega-menu: bump to full container width; narrow ones adapt naturally */
.mega-menu.mega-wide {
  /* already left:0 right:0, just ensure min readable column width */
  min-width: 0;
}
.mega-menu.mega-wide .mega-col ul li a {
  font-size: .78rem;
}
.mega-menu.mega-wide .mega-col-head {
  font-size: .78rem;
}

/* ---------- Nav Search (inside nav, pushed right) ---------- */
.nav-search {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

/* ---------- Search Bar (legacy outer, kept for compatibility) ---------- */
.header-search { display: flex; align-items: center; gap: .4rem; }
.search-form {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color .2s;
}
.search-form:focus-within { border-color: var(--primary); }
.search-form input {
  padding: .35rem .8rem;
  border: none;
  background: none;
  font-size: .88rem;
  color: var(--text);
  width: 160px;
  outline: none;
}
.search-form button {
  padding: .35rem .7rem;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: .85rem;
  transition: background .2s;
}
.search-form button:hover { background: var(--primary-dark); }

/* ---------- Mobile Menu Toggle ---------- */
.nav-toggle {
  display: none;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: .4rem .6rem;
  color: var(--text);
  font-size: 1rem;
}

/* ---------- Breadcrumb ---------- */
.breadcrumb-bar {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  padding: .4rem 0;
  font-size: .82rem;
  color: var(--text-muted);
}
.breadcrumb-bar .container { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.breadcrumb-bar a { color: var(--text-muted); }
.breadcrumb-bar a:hover { color: var(--primary); }
.breadcrumb-bar .sep { color: var(--border); }

/* ---------- Hero Section ---------- */
.hero-section {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 4rem 0 3rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Ccircle cx='40' cy='40' r='30' fill='none' stroke='rgba(255,255,255,.06)' stroke-width='1'/%3E%3C/svg%3E");
}
.hero-section h1 { font-size: 2.5rem; font-weight: 900; margin-bottom: .5rem; position: relative; }
.hero-section p { font-size: 1.1rem; opacity: .9; margin-bottom: 1.5rem; position: relative; }
.hero-stats { display: flex; gap: 2rem; justify-content: center; flex-wrap: wrap; position: relative; }
.hero-stat { text-align: center; }
.hero-stat .num { font-size: 2rem; font-weight: 800; }
.hero-stat .label { font-size: .85rem; opacity: .8; }

/* ---------- Section Header ---------- */
.section-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1.5rem;
}
.section-header h2 { font-size: 1.3rem; font-weight: 800; color: var(--text); }
.section-header .section-line {
  flex: 1;
  height: 2px;
  background: linear-gradient(to right, var(--primary), transparent);
  border-radius: 2px;
}
.section-header a { font-size: .85rem; color: var(--primary); white-space: nowrap; }

/* ---------- Subject Grid ---------- */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.subject-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem 1rem;
  text-align: center;
  border: 2px solid var(--border);
  transition: all .25s;
  text-decoration: none;
  display: block;
}
.subject-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
.subject-card .icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(var(--primary-rgb), .12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--primary);
  margin: 0 auto .8rem;
  transition: background .2s;
}
.subject-card:hover .icon { background: var(--primary); color: #fff; }
.subject-card h3 { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: .2rem; }
.subject-card p { font-size: .78rem; color: var(--text-muted); }

/* ---------- Grade Nav ---------- */
.grade-nav { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0; }
.grade-group { display: flex; flex-direction: column; gap: .3rem; }
.grade-group-label { font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.grade-group-btns { display: flex; gap: .3rem; flex-wrap: wrap; }
.grade-btn {
  padding: .35rem .7rem;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  transition: all .2s;
  text-decoration: none;
  display: inline-block;
}
.grade-btn:hover, .grade-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---------- Article / Knowledge Cards ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.2rem;
  margin: 1rem 0;
}
.knowledge-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 1.2rem;
  border: 1.5px solid var(--border);
  transition: all .25s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  text-decoration: none;
}
.knowledge-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 20px rgba(0,0,0,.09);
  transform: translateY(-3px);
}
.knowledge-card .card-meta {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.knowledge-card .card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.knowledge-card:hover .card-title { color: var(--primary); }
.knowledge-card .card-summary {
  font-size: .85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.knowledge-card .card-tags { display: flex; gap: .3rem; flex-wrap: wrap; }

/* ---------- Experiment Cards ---------- */
.experiment-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.4rem;
  border: 1.5px solid var(--border);
  transition: all .25s;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  text-decoration: none;
  position: relative;
  overflow: hidden;
}
.experiment-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(to right, var(--primary), var(--accent));
}
.experiment-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(0,0,0,.1);
  transform: translateY(-4px);
}
.experiment-card .exp-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(var(--primary-rgb), .1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--primary);
}
.experiment-card h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.experiment-card:hover h3 { color: var(--primary); }
.experiment-card p { font-size: .85rem; color: var(--text-muted); flex: 1; }
.placeholder-badge {
  display: inline-block;
  padding: .15rem .5rem;
  background: #fef9c3;
  color: #92400e;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}

/* ---------- Content + Sidebar Layout ---------- */
.content-sidebar {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 2rem;
  align-items: start;
  margin: 2rem 0;
}
.content-main { min-width: 0; }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 1.2rem; }
.sidebar-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 1.2rem;
  border: 1.5px solid var(--border);
}
.sidebar-card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .8rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--border);
}
.sidebar-card-title i { color: var(--primary); }
.sidebar-article {
  display: flex;
  gap: .6rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  align-items: flex-start;
}
.sidebar-article:last-child { border-bottom: none; }
.sidebar-article .sno {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: .2rem;
}
.sidebar-article:hover .title { color: var(--primary); }
.sidebar-article .title { font-size: .85rem; color: var(--text); line-height: 1.4; }
.sidebar-article .date { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }

/* ---------- Ad Spaces ---------- */
.ad-space { width: 100%; margin: 1rem 0; }
.ad-placeholder {
  background: repeating-linear-gradient(
    45deg,
    var(--bg-alt),
    var(--bg-alt) 10px,
    var(--bg-card) 10px,
    var(--bg-card) 20px
  );
  border: 2px dashed var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  color: var(--text-muted);
  font-size: .82rem;
  padding: .8rem;
  text-align: center;
  min-height: 60px;
}
.ad-placeholder .ad-label { font-weight: 700; font-size: .9rem; }
.ad-desktop-only { display: block; }
.ad-mobile-only { display: none; }

/* ---------- Article Detail ---------- */
.article-detail-layout {
  display: grid;
  grid-template-columns: 160px 1fr 280px;
  gap: 2rem;
  align-items: start;
  margin: 1.5rem 0;
}
.left-sidebar-ad { position: sticky; top: 80px; }
.article-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 2rem;
  border: 1.5px solid var(--border);
  min-width: 0;
}
.article-header { margin-bottom: 1.5rem; }
.article-title { font-size: 1.8rem; font-weight: 800; color: var(--text); line-height: 1.3; margin-bottom: .8rem; }
.article-meta { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--text-muted); }
.article-meta i { color: var(--primary); }
.article-tags { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1rem 0; }
.article-body { line-height: 1.9; color: var(--text); }
.article-body h1,.article-body h2,.article-body h3,.article-body h4 {
  margin: 1.5rem 0 .7rem;
  color: var(--text);
  line-height: 1.3;
}
.article-body h2 { font-size: 1.3rem; border-bottom: 2px solid var(--border); padding-bottom: .4rem; }
.article-body h3 { font-size: 1.1rem; }
.article-body p { margin-bottom: 1rem; }
.article-body ul, .article-body ol { padding-left: 1.5rem; margin-bottom: 1rem; list-style: disc; }
.article-body ol { list-style: decimal; }
.article-body li { margin-bottom: .3rem; }
.article-body blockquote {
  border-left: 4px solid var(--primary);
  margin: 1rem 0;
  padding: .8rem 1rem;
  background: rgba(var(--primary-rgb), .06);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-style: italic;
}
.article-body code {
  background: var(--bg-alt);
  border-radius: 4px;
  padding: .1rem .4rem;
  font-size: .88rem;
  font-family: "Consolas", "Fira Code", monospace;
  color: var(--primary);
}
.article-body pre {
  background: #1e293b;
  border-radius: 10px;
  padding: 1.2rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.article-body pre code { background: none; color: #e2e8f0; padding: 0; }
.article-body table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .9rem; }
.article-body table th { background: rgba(var(--primary-rgb),.1); color: var(--text); padding: .5rem .8rem; text-align: left; }
.article-body table td { padding: .5rem .8rem; border-bottom: 1px solid var(--border); }
.article-body img { border-radius: 10px; max-width: 100%; margin: 1rem auto; }

.prev-next-nav {
  display: flex;
  gap: 1rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}
.prev-next-btn {
  flex: 1;
  min-width: 200px;
  padding: .8rem 1rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: .2rem;
  transition: all .2s;
  text-decoration: none;
}
.prev-next-btn:hover { border-color: var(--primary); background: rgba(var(--primary-rgb),.05); }
.prev-next-btn .pn-label { font-size: .75rem; color: var(--text-muted); }
.prev-next-btn .pn-title { font-size: .9rem; font-weight: 600; color: var(--text); }

/* ---------- Knowledge Nodes (Related) ---------- */
.knowledge-nodes { margin: 2rem 0; }
.knowledge-nodes h3 { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; }
.nodes-grid { display: flex; gap: .5rem; flex-wrap: wrap; }
.node-link {
  padding: .4rem .9rem;
  border-radius: 99px;
  border: 1.5px solid var(--primary);
  font-size: .85rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(var(--primary-rgb),.06);
  transition: all .2s;
  text-decoration: none;
}
.node-link:hover { background: var(--primary); color: #fff; }
.node-link.prerequisite { border-color: #f59e0b; color: #f59e0b; background: rgba(245,158,11,.06); }
.node-link.prerequisite:hover { background: #f59e0b; color: #fff; }
.node-link.extends { border-color: #10b981; color: #10b981; background: rgba(16,185,129,.06); }
.node-link.extends:hover { background: #10b981; color: #fff; }

/* ---------- Recommended Grid ---------- */
.recommended-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .8rem;
  margin: 1rem 0;
}
.rec-card {
  background: var(--bg-alt);
  border-radius: 10px;
  padding: .8rem;
  border: 1px solid var(--border);
  transition: all .2s;
  text-decoration: none;
}
.rec-card:hover { border-color: var(--primary); }
.rec-card .rc-title { font-size: .88rem; font-weight: 600; color: var(--text); margin-bottom: .2rem; }
.rec-card:hover .rc-title { color: var(--primary); }
.rec-card .rc-meta { font-size: .75rem; color: var(--text-muted); }

/* ---------- Tags ---------- */
.tag-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  background: rgba(var(--primary-rgb), .1);
  color: var(--primary);
  font-size: .8rem;
  font-weight: 600;
  text-decoration: none;
  transition: all .2s;
  border: 1px solid rgba(var(--primary-rgb), .2);
}
.tag-badge:hover { background: var(--primary); color: #fff; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: .4rem; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  gap: .3rem;
  justify-content: center;
  margin: 2rem 0;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: .88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 .6rem;
  transition: all .2s;
  text-decoration: none;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn.disabled { opacity: .4; pointer-events: none; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1.2rem; }
.form-label { display: block; font-size: .9rem; font-weight: 600; color: var(--text); margin-bottom: .4rem; }
.form-input {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  transition: border-color .2s;
  outline: none;
}
.form-input:focus { border-color: var(--primary); }
.form-input.error { border-color: #ef4444; }
.field-error { font-size: .82rem; color: #ef4444; margin-top: .25rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.4rem;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 600;
  border: none;
  transition: all .2s;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-outline { background: none; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ---------- Badges & Labels ---------- */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 700;
  background: rgba(var(--primary-rgb), .12);
  color: var(--primary);
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }

/* ---------- Alert / Flash ---------- */
.alert {
  padding: .8rem 1rem;
  border-radius: 10px;
  font-size: .9rem;
  margin-bottom: 1rem;
  border: 1.5px solid transparent;
}
.alert-success { background: #d1fae5; border-color: #6ee7b7; color: #065f46; }
.alert-error   { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.alert-info    { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg-card);
  border-top: 2px solid var(--border);
  padding: 3rem 0 1rem;
  margin-top: 4rem;
  color: var(--text-muted);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}
.footer-col h4 { font-size: 1rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; }
.footer-col ul li { margin-bottom: .5rem; }
.footer-col ul li a { font-size: .88rem; color: var(--text-muted); transition: color .2s; }
.footer-col ul li a:hover { color: var(--primary); }
.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  text-align: center;
  font-size: .82rem;
}
.footer-bottom a { color: var(--text-muted); }

/* ---------- Friend Links ---------- */
.friendlinks-container {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .8rem 0;
}
.friendlink-item {
  padding: .3rem .8rem;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: .82rem;
  color: var(--text-muted);
  background: var(--bg-alt);
  transition: all .2s;
  text-decoration: none;
}
.friendlink-item:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Experiment Lab ---------- */
.lab-header { text-align: center; margin-bottom: 2rem; }
.lab-header h1 { font-size: 1.8rem; font-weight: 800; color: var(--text); margin: .5rem 0; }
.lab-header p { color: var(--text-muted); font-size: 1rem; }
.exp-breadcrumb { font-size: .82rem; color: var(--text-muted); margin-bottom: .5rem; }
.exp-breadcrumb a { color: var(--text-muted); }
.exp-breadcrumb a:hover { color: var(--primary); }
.exp-badges { display: flex; gap: .4rem; justify-content: center; flex-wrap: wrap; margin-top: .8rem; }
.tab-btn {
  padding: .5rem 1.2rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  margin: .2rem;
  transition: all .2s;
}
.tab-btn:hover { border-color: var(--primary); color: var(--primary); }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Quiz UI */
.score-board {
  background: var(--bg-alt);
  border-radius: 12px;
  padding: .8rem 1.2rem;
  margin: 1rem 0;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}
.score { font-size: 1.4rem; color: var(--primary); font-weight: 800; }
.progress-bar-wrap { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.progress-bar-fill { height: 100%; background: linear-gradient(to right, var(--primary), var(--accent)); border-radius: 99px; transition: width .5s; }
.answer-options { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; justify-content: center; }
.opt-btn {
  padding: .55rem 1.2rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: .95rem;
  cursor: pointer;
  transition: all .2s;
  color: var(--text);
  min-width: 80px;
}
.opt-btn:hover { border-color: var(--primary); color: var(--primary); }
.feedback {
  border-radius: 10px;
  padding: .7rem 1rem;
  font-size: .95rem;
  margin-top: .8rem;
  display: none;
}
.feedback.show { display: block; }
.feedback.ok { background: #d1fae5; color: #065f46; }
.feedback.err { background: #fee2e2; color: #991b1b; }

.btn-game {
  padding: .55rem 1.3rem;
  border-radius: 10px;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  margin: .3rem;
  transition: all .2s;
  cursor: pointer;
}
.btn-check { background: var(--primary); color: #fff; }
.btn-check:hover { background: var(--primary-dark); }
.btn-reset { background: var(--bg-alt); color: var(--text); border: 1.5px solid var(--border); }
.btn-reset:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Admin ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  align-items: start;
  margin: 2rem 0;
}
.admin-sidebar {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 1rem;
  border: 1.5px solid var(--border);
  position: sticky;
  top: 80px;
}
.admin-sidebar h3 { font-size: .9rem; font-weight: 700; color: var(--text-muted); padding: .3rem .5rem; text-transform: uppercase; letter-spacing: .05em; }
.admin-nav-link {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem .8rem;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: all .2s;
}
.admin-nav-link:hover, .admin-nav-link.active {
  background: rgba(var(--primary-rgb), .1);
  color: var(--primary);
}
.admin-nav-link i { width: 1.1rem; color: var(--primary); }
.admin-card {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 1.5rem;
  border: 1.5px solid var(--border);
  margin-bottom: 1.5rem;
}
.admin-card h2 { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 1rem; border-bottom: 1.5px solid var(--border); padding-bottom: .6rem; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.stat-card {
  background: var(--bg-alt);
  border-radius: 12px;
  padding: 1.2rem;
  text-align: center;
  border: 1.5px solid var(--border);
}
.stat-card .sv { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-card .sl { font-size: .82rem; color: var(--text-muted); }

/* ---------- Back to Top ---------- */
#backToTop {
  position: fixed;
  bottom: 2rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all .3s;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
#backToTop.visible { opacity: 1; visibility: visible; }
#backToTop:hover { background: var(--primary-dark); transform: translateY(-2px); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .article-detail-layout { grid-template-columns: 1fr 260px; }
  .article-detail-layout .left-sidebar-ad { display: none; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { position: static; }
}
@media (max-width: 768px) {
  .hero-section h1 { font-size: 1.7rem; }
  .site-nav { display: none; }
  .site-nav.open { display: flex; flex-direction: column; width: 100%; order: 10; }
  .site-nav.open > ul,
  .site-nav.open > .nav-list { flex-direction: column; align-items: stretch; width: 100%; }
  .site-nav.open .nav-search { width: 100%; margin: .4rem 0 0; padding: 0 .5rem .4rem; }
  .site-nav.open .nav-search .search-form { width: 100%; border-radius: 8px; }
  .site-nav.open .nav-search .search-form input { width: 100%; }
  .site-nav.open .nav-dropdown { position: static; box-shadow: none; border: none; padding-left: 1rem; background: var(--bg-alt); }
  .site-nav.open .nav-item:hover .nav-dropdown { display: none; }
  .site-nav.open .nav-item.open .nav-dropdown { display: block; }
  /* Mega menu mobile: show as stacked list */
  .site-nav.open .mega-menu {
    position: static;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    padding: .5rem .5rem .5rem 1rem;
    background: var(--bg-alt);
    display: none;
  }
  .site-nav.open .nav-item.has-mega.open .mega-menu { display: block; }
  .site-nav.open .nav-item.has-mega:hover .mega-menu { display: none; }
  .site-nav.open .mega-grid { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .site-nav.open .mega-col { border-right: none; padding: .25rem 0; border-bottom: 1px solid var(--border); }
  .site-nav.open .mega-col:last-child { border-bottom: none; }
  .nav-toggle { display: flex; }
  .content-sidebar { grid-template-columns: 1fr; }
  .article-detail-layout { grid-template-columns: 1fr; }
  .article-content { padding: 1.2rem; }
  .article-title { font-size: 1.4rem; }
  .cards-grid { grid-template-columns: 1fr; }
  .subject-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .ad-desktop-only { display: none !important; }
  .ad-mobile-only { display: block !important; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .sort-categories { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .hero-stat .num { font-size: 1.4rem; }
  .hero-stats { gap: 1rem; }
  .subject-card { padding: 1rem .8rem; }
  .subject-card .icon { width: 40px; height: 40px; font-size: 1.1rem; }
  .tab-btn { padding: .4rem .8rem; font-size: .82rem; }
  .footer-grid { grid-template-columns: 1fr; }
}