:root {
  --bg: #0b1020;
  --card: #12182b;
  --text: #e6e9f5;
  --muted: #9aa4c7;
  --brand: #6366f1;
  --accent: #22d3ee;
  --border: #1f2742;
}
:root[data-theme="light"] {
  --bg: #f7f8fc;
  --card: #ffffff;
  --text: #111827;
  --muted: #586179;
  --brand: #4f46e5;
  --accent: #06b6d4;
  --border: #e5e7eb;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}
a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}
.header,
.footer {
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.header .inner,
.footer .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand .logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  border-radius: 8px;
}
.nav a {
  margin: 0 0.5rem;
  font-weight: 600;
  color: var(--text);
  opacity: 0.9;
}
.nav a:hover {
  opacity: 1;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 0.6rem 0.9rem;
  border-radius: 0.8rem;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--brand);
}
.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  border: none;
}
.grid {
  display: grid;
  gap: 1rem;
}
.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.card h3 {
  margin: 0.2rem 0 0.6rem;
}
.card .meta {
  color: var(--muted);
  font-size: 0.9rem;
}
.hero {
  padding: 2rem 1rem;
  background: linear-gradient(
    180deg,
    rgba(99, 102, 241, 0.15),
    rgba(34, 211, 238, 0)
  );
  border-bottom: 1px solid var(--border);
}
.hero h1 {
  font-size: 2rem;
  margin: 0 0 0.4rem;
}
.hero p {
  color: var(--muted);
  margin: 0 0 1rem;
}
.search {
  display: flex;
  gap: 0.5rem;
}
.search input {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 0.7rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.search button {
  white-space: nowrap;
}
.badge {
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 0.5rem;
  background: rgba(99, 102, 241, 0.15);
  color: var(--brand);
  border: 1px solid var(--border);
}
.kicker {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.course-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  align-items: center;
}
.course-row img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: #0002;
}
.course-row .title {
  font-size: 1.05rem;
  font-weight: 700;
}
.course-row .desc {
  color: var(--muted);
  font-size: 0.92rem;
}
.course-row .tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.4rem;
  text-align: left;
}
.table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}
.input,
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 0.7rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
label {
  font-size: 0.9rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.25rem;
}
.notice {
  background: rgba(34, 211, 238, 0.12);
  border: 1px dashed var(--accent);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 0.8rem;
}
.footer {
  margin-top: 2rem;
  border-top: 1px solid var(--border);
}
.footer .inner {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.theme-toggle {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}
.theme-toggle span {
  font-size: 0.95rem;
}
@media (max-width: 900px) {
  .grid.cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 600px) {
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .course-row {
    grid-template-columns: 1fr;
  }
}

/* ===== Responsive Nav + Toggle ===== */

/* Base: keep things tidy */
.header .inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Hide the hamburger by default (desktop), show nav inline */
.menu-toggle {
  display: none;
  align-items: center;
  font-weight: bold;
  justify-content: center;
  width: 60px;
  height: 35px;
  border: 1px solid var(--border, #2a3353);
  border-radius: 0.7rem;
  background: var(--card, #12182b);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.menu-toggle:active {
  transform: scale(0.98);
}
.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text, #e6e9f5);
  margin: 3px 0;
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

/* Desktop nav remains as your current layout provides */
#primaryNav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* Active link helper (optional class JS can add) */
#primaryNav a.is-active {
  color: var(--brand, #7aa2ff);
}

/* ===== Breakpoint: mobile ===== */
@media (max-width: 900px) {
  /* Show hamburger, convert nav to a panel */
  .menu-toggle {
    display: inline-flex;
  }

  /* Keep brand from being squeezed (assuming .brand exists) */
  .brand {
    margin-right: auto;
  }

  /* Off-canvas style dropdown (below header) */
  #primaryNav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card, #12182b);
    border-bottom: 1px solid var(--border, #2a3353);
    display: grid;
    gap: 0.25rem;
    padding: 0.6rem;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 50;
  }

  /* Make header the positioning context */
  .header .inner {
    position: relative;
  }

  /* Full-width, tap-friendly links */
  #primaryNav a,
  #primaryNav .btn {
    display: block;
    padding: 0.8rem 1rem;
    border-radius: 0.6rem;
  }

  /* When open */
  .header.is-menu-open #primaryNav {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  /* Animate hamburger to X when open */
  .header.is-menu-open .menu-toggle span:nth-child(1) {
    transform: translateY(5px) rotate(45deg);
  }
  .header.is-menu-open .menu-toggle span:nth-child(2) {
    opacity: 0;
  }
  .header.is-menu-open .menu-toggle span:nth-child(3) {
    transform: translateY(-5px) rotate(-45deg);
  }
}

/* Even smaller screens */
@media (max-width: 600px) {
  #primaryNav {
    border-left: 0;
    border-right: 0;
  }
}

/* ===== Sticky header (desktop + mobile) ===== */
.header {
  position: sticky;
  top: 0; /* for iOS safe areas you can use: top: env(safe-area-inset-top); */
  z-index: 1000; /* keep above page content */
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

/* Make sure the mobile dropdown sits over content when open */
@media (max-width: 900px) {
  .header {
    z-index: 1100;
  }
  #primaryNav {
    z-index: 1200;
  } /* your mobile panel */
}

/* Optional: subtle shadow when page is scrolled */
body.scrolled .header {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  border-bottom-color: transparent;
}

/* Optional: anchor links don't hide under the sticky header */
html {
  scroll-padding-top: 72px;
} /* adjust if your header is taller */

/* ===== Course page: fix grid on small screens ===== */
@media (max-width: 900px) {
  /* Force the main grid to a single column (override inline style) */
  .container > .grid {
    grid-template-columns: 1fr !important;
    gap: 0.8rem !important;
  }

  /* Let the sidebar card stretch full width */
  .container > .grid > aside .card {
    width: 100%;
  }
}

/* Tight phones */
@media (max-width: 600px) {
  /* Make action buttons wrap and fill width nicely */
  .container > .grid > aside .card > div {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
  }
  #startCourse,
  #takeQuiz {
    flex: 1 1 180px; /* grow to half/full width as space allows */
    text-align: center; /* center label on narrow widths */
  }

  /* Give the course image a bit more height on very small screens */
  #courseImg {
    height: 200px; /* adjust as you like */
  }
}

/* Optional: if you want the sidebar to appear ABOVE the content on mobile,
   uncomment the order change below. By default it stays beneath. */
/*
@media (max-width: 900px) {
  .container > .grid > aside { order: -1; }
}
*/
