/* ============================================
   CodeWisdom Academy — Design System
   Professional, clean, developer-grade UI
   ============================================ */

/* --- CSS Variables (Design Tokens) --- */
:root {
	/* Colors */
	--color-primary:       #EA580C;   /* Codverra orange (orange-600) */
	--color-primary-dark:  #C2410C;
	--color-primary-light: #FFF7ED;
	--color-secondary:     #0EA5E9;   /* Sky-500 */
	--color-success:       #10B981;
	--color-warning:       #F59E0B;
	--color-danger:        #EF4444;
	--color-neutral-50:    #F8FAFC;
	--color-neutral-100:   #F1F5F9;
	--color-neutral-200:   #E2E8F0;
	--color-neutral-300:   #CBD5E1;
	--color-neutral-400:   #94A3B8;
	--color-neutral-500:   #64748B;
	--color-neutral-600:   #475569;
	--color-neutral-700:   #334155;
	--color-neutral-800:   #1E293B;
	--color-neutral-900:   #0F172A;

	/* Surface (flips in dark mode) */
	--color-surface:        #ffffff;
	--color-surface-raised: #ffffff;

	/* Typography */
	--font-sans:  'Inter', system-ui, -apple-system, sans-serif;
	--font-mono:  'JetBrains Mono', 'Fira Code', monospace;
  
	/* Spacing scale */
	--space-1:  0.25rem;
	--space-2:  0.5rem;
	--space-3:  0.75rem;
	--space-4:  1rem;
	--space-5:  1.25rem;
	--space-6:  1.5rem;
	--space-8:  2rem;
	--space-10: 2.5rem;
	--space-12: 3rem;
	--space-16: 4rem;
	--space-20: 5rem;
  
	/* Border radius */
	--radius-sm:  0.375rem;
	--radius-md:  0.5rem;
	--radius-lg:  0.75rem;
	--radius-xl:  1rem;
	--radius-full: 9999px;
  
	/* Shadows */
	--shadow-sm:  0 1px 2px 0 rgb(0 0 0 / 0.05);
	--shadow-md:  0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
	--shadow-lg:  0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
	--shadow-xl:  0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.05);
  
	/* Transitions */
	--transition-fast:   150ms ease;
	--transition-normal: 250ms ease;
	--transition-slow:   400ms ease;
  
	/* Layout */
	--max-width:        1200px;
	--nav-height:       64px;
	--sidebar-width:    260px;
  }
  
  /* --- Reset --- */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  
  html { font-size: 16px; -webkit-text-size-adjust: 100%; }

  /* Stop off-canvas drawers (mobile lesson sidebar / nav menu) that sit at a
     negative translateX from becoming horizontally scrollable — swiping right
     was revealing them and widening the page. `clip` clips without creating a
     scroll container, so the sticky headers keep working; `hidden` is the
     fallback for browsers without `overflow: clip`. */
  html, body { overflow-x: hidden; }
  @supports (overflow: clip) { html, body { overflow-x: clip; } }

  body {
	font-family: var(--font-sans);
	color: var(--color-neutral-800);
	background: var(--color-neutral-50);
	line-height: 1.6;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
  }
  
  main#main-content { flex: 1; }
  
  img, svg { display: block; max-width: 100%; }
  a { color: inherit; text-decoration: none; }
  ul[role="list"] { list-style: none; }
  button { cursor: pointer; font-family: inherit; border: none; background: none; }
  input, textarea, select { font-family: inherit; }
  
  /* --- Typography --- */
  h1, h2, h3, h4, h5, h6 {
	font-weight: 600;
	line-height: 1.3;
	color: var(--color-neutral-900);
  }
  h1 { font-size: clamp(1.875rem, 4vw, 2.75rem); }
  h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
  h3 { font-size: clamp(1.25rem, 2.5vw, 1.5rem); }
  h4 { font-size: 1.125rem; }
  
  p { color: var(--color-neutral-600); max-width: 70ch; }
  
  code, kbd, samp, pre {
	font-family: var(--font-mono);
	font-size: 0.875em;
  }
  
  /* --- Layout Utilities --- */
  .container {
	width: 100%;
	max-width: var(--max-width);
	margin: 0 auto;
	padding: 0 var(--space-6);
  }
  
  /* --- Buttons --- */
  .btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	padding: 0.625rem 1.25rem;
	font-size: 0.9375rem;
	font-weight: 500;
	border-radius: var(--radius-md);
	transition: all var(--transition-fast);
	white-space: nowrap;
	line-height: 1;
	cursor: pointer;
	text-decoration: none;
  }
  
  .btn--primary {
	background: var(--color-primary);
	color: #fff;
	box-shadow: var(--shadow-sm);
  }
  .btn--primary:hover {
	background: var(--color-primary-dark);
	box-shadow: var(--shadow-md);
	transform: translateY(-1px);
  }
  
  .btn--secondary {
	background: var(--color-neutral-100);
	color: var(--color-neutral-700);
	border: 1px solid var(--color-neutral-200);
  }
  .btn--secondary:hover {
	background: var(--color-neutral-200);
  }
  
  .btn--light {
	background: transparent;
	color: var(--color-primary-light);
  }

  .btn--ghost {
	background: transparent;
	color: var(--color-neutral-600);
  }
  .btn--ghost:hover {
	background: var(--color-neutral-100);
	color: var(--color-neutral-800);
  }
  
  .btn--danger {
	background: var(--color-danger);
	color: #fff;
  }
  .btn--danger:hover { background: #DC2626; }
  
  .btn--sm { padding: 0.5rem 1rem; font-size: 0.875rem; }
  .btn--lg { padding: 0.875rem 1.75rem; font-size: 1.0625rem; }
  
  .btn--full { width: 100%; }
  .btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
  .btn--loading { position: relative; color: transparent; }
  .btn--loading::after {
	content: '';
	position: absolute;
	width: 16px; height: 16px;
	border: 2px solid #fff;
	border-top-color: transparent;
	border-radius: 50%;
	animation: spin 0.6s linear infinite;
  }
  
  /* --- Form Elements --- */
  .form-group {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
	margin-bottom: var(--space-5);
  }
  
  .form-label {
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--color-neutral-700);
  }
  
  .form-label--required::after {
	content: ' *';
	color: var(--color-danger);
  }
  
  .form-input,
  .form-select,
  .form-textarea {
	width: 100%;
	padding: 0.625rem 0.875rem;
	font-size: 0.9375rem;
	color: var(--color-neutral-800);
	background: var(--color-surface);
	border: 1.5px solid var(--color-neutral-200);
	border-radius: var(--radius-md);
	transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
	outline: none;
  }
  
  .form-input:focus,
  .form-select:focus,
  .form-textarea:focus {
	border-color: var(--color-primary);
	box-shadow: 0 0 0 3px rgb(79 70 229 / 0.12);
  }
  
  .form-input--error,
  .form-select--error,
  .form-textarea--error {
	border-color: var(--color-danger);
  }
  
  .form-textarea { resize: vertical; min-height: 120px; }
  
  .form-hint {
	font-size: 0.8125rem;
	color: var(--color-neutral-400);
  }
  
  .form-error {
	font-size: 0.8125rem;
	color: var(--color-danger);
	display: flex;
	align-items: center;
	gap: var(--space-1);
  }
  
  /* --- Cards --- */
  .card {
	background: var(--color-surface);
	border: 1px solid var(--color-neutral-200);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-sm);
	overflow: hidden;
  }
  
  .card--hover {
	transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  }
  .card--hover:hover {
	box-shadow: var(--shadow-lg);
	transform: translateY(-2px);
  }
  
  .card__header {
	padding: var(--space-6);
	border-bottom: 1px solid var(--color-neutral-100);
  }
  
  .card__body { padding: var(--space-6); }
  
  .card__footer {
	padding: var(--space-4) var(--space-6);
	background: var(--color-neutral-50);
	border-top: 1px solid var(--color-neutral-100);
  }
  
  /* --- Navigation ---
     The header/nav (app/Views/partials/nav.php) is styled entirely
     with Tailwind utility classes, not this BEM system. */

  /* --- Footer --- */
  .site-footer {
	position: relative;
	overflow: hidden;
	background: linear-gradient(180deg, #0B1220 0%, var(--color-neutral-900) 100%);
	color: var(--color-neutral-400);
	margin-top: auto;
	border-top: 1px solid rgba(148,163,184,.12);
  }
  /* soft brand glow along the top edge */
  .site-footer__glow {
	position: absolute; top: -60%; left: 50%; transform: translateX(-50%);
	width: 900px; height: 340px; pointer-events: none;
	background: radial-gradient(50% 50% at 50% 50%, rgba(79,70,229,.22), transparent 70%);
  }
  .footer-container {
	position: relative;
	max-width: var(--max-width);
	margin: 0 auto;
	padding: var(--space-16) var(--space-6) var(--space-10);
	display: grid;
	grid-template-columns: 1.4fr 2fr;
	gap: var(--space-12);
  }
  .footer-brand__logo {
	font-size: 1.125rem;
	font-weight: 700;
	color: #fff;
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	margin-bottom: var(--space-4);
  }
  .footer-brand__logo-img { width: 34px; height: 34px; object-fit: contain; border-radius: var(--radius-sm); }
  .footer-brand__tagline { font-size: 0.9375rem; line-height: 1.7; color: var(--color-neutral-500); max-width: 300px; margin-bottom: var(--space-5); }

  .footer-brand__parent {
	display: inline-flex; align-items: center; gap: .5rem;
	padding: .4rem .75rem; border-radius: var(--radius-full);
	background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08);
	font-size: .8125rem; color: var(--color-neutral-400);
	transition: border-color var(--transition-fast), background var(--transition-fast);
  }
  .footer-brand__parent:hover { background: rgba(255,255,255,.07); border-color: rgba(249,115,22,.4); }
  .footer-brand__parent img { width: 20px; height: 20px; object-fit: contain; }
  .footer-brand__parent strong { color: #F97316; font-weight: 700; }

  .footer-social { display: flex; gap: .6rem; margin-top: var(--space-5); }
  .footer-social__link {
	width: 38px; height: 38px; border-radius: 10px;
	display: inline-flex; align-items: center; justify-content: center;
	background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08);
	color: var(--color-neutral-400);
	transition: all var(--transition-fast);
  }
  .footer-social__link:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; transform: translateY(-2px); }
  .footer-social__link i { width: 18px; height: 18px; }

  .footer-nav {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--space-8);
  }
  .footer-nav__heading {
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: #fff;
	margin-bottom: var(--space-4);
  }
  .footer-nav ul { display: flex; flex-direction: column; gap: var(--space-3); }
  .footer-nav__link {
	font-size: 0.9375rem;
	color: var(--color-neutral-500);
	transition: color var(--transition-fast), padding var(--transition-fast);
  }
  .footer-nav__link:hover { color: #fff; padding-left: 4px; }

  .footer-bottom {
	position: relative;
	border-top: 1px solid rgba(148,163,184,.12);
	max-width: var(--max-width);
	margin: 0 auto;
	padding: var(--space-5) var(--space-6);
	display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
	font-size: 0.875rem;
	color: var(--color-neutral-500);
  }
  .footer-bottom__copy { color: var(--color-neutral-500); margin: 0; }
  .footer-bottom__copy strong { color: var(--color-neutral-300); }
  .footer-bottom__top {
	display: inline-flex; align-items: center; gap: .4rem;
	font-size: .8125rem; font-weight: 600; color: var(--color-neutral-400);
	transition: color var(--transition-fast);
  }
  .footer-bottom__top:hover { color: #fff; }
  .footer-bottom__top i { width: 15px; height: 15px; }

  @media (max-width: 768px) {
	.footer-container { grid-template-columns: 1fr; gap: var(--space-10); padding-top: var(--space-12); }
	.footer-nav { grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
	.footer-bottom { justify-content: center; text-align: center; }
  }
  @media (max-width: 480px) {
	.footer-nav { grid-template-columns: 1fr 1fr; }
  }
  
  /* --- Flash messages --- */
  .flash {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--space-3) var(--space-6);
	font-size: 0.9375rem;
	font-weight: 500;
  }
  .flash--success { background: #D1FAE5; color: #065F46; border-bottom: 1px solid #A7F3D0; }
  .flash--error   { background: #FEE2E2; color: #991B1B; border-bottom: 1px solid #FECACA; }
  .flash__close   { font-size: 1.25rem; cursor: pointer; opacity: 0.6; line-height: 1; }
  .flash__close:hover { opacity: 1; }
  
  /* --- Badges --- */
  .badge {
	display: inline-flex;
	align-items: center;
	padding: 0.25rem 0.625rem;
	font-size: 0.75rem;
	font-weight: 600;
	border-radius: var(--radius-full);
	line-height: 1;
  }
  .badge--primary { background: var(--color-primary-light); color: var(--color-primary-dark); }
  .badge--success { background: #D1FAE5; color: #065F46; }
  .badge--warning { background: #FEF3C7; color: #92400E; }
  .badge--neutral { background: var(--color-neutral-100); color: var(--color-neutral-600); }
  .badge--danger  { background: #FEE2E2; color: #991B1B; }
  
  /* --- Alerts --- */
  .alert {
	display: flex;
	gap: var(--space-3);
	padding: var(--space-4) var(--space-5);
	border-radius: var(--radius-md);
	border: 1px solid transparent;
	margin-bottom: var(--space-5);
	font-size: 0.9375rem;
  }
  .alert--info    { background: #EFF6FF; border-color: #BFDBFE; color: #1E40AF; }
  .alert--success { background: #ECFDF5; border-color: #A7F3D0; color: #065F46; }
  .alert--warning { background: #FFFBEB; border-color: #FDE68A; color: #92400E; }
  .alert--danger  { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }
  
  /* --- Error Pages --- */
  .error-page {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: var(--space-20) var(--space-6);
	min-height: 60vh;
	gap: var(--space-4);
  }
  .error-page__code {
	font-size: 6rem;
	font-weight: 800;
	color: var(--color-neutral-200);
	line-height: 1;
  }
  .error-page__title   { font-size: 1.5rem; color: var(--color-neutral-900); }
  .error-page__message { color: var(--color-neutral-500); max-width: 40ch; }
  
  /* --- Dividers --- */
  .divider {
	border: none;
	border-top: 1px solid var(--color-neutral-200);
	margin: var(--space-8) 0;
  }
  
  /* --- Skeleton loaders --- */
  .skeleton {
	background: linear-gradient(90deg, var(--color-neutral-100) 25%, var(--color-neutral-200) 50%, var(--color-neutral-100) 75%);
	background-size: 200% 100%;
	animation: shimmer 1.5s infinite;
	border-radius: var(--radius-md);
  }
  
  /* --- Progress bar --- */
  .progress {
	width: 100%;
	height: 8px;
	background: var(--color-neutral-200);
	border-radius: var(--radius-full);
	overflow: hidden;
  }
  .progress__bar {
	height: 100%;
	background: var(--color-primary);
	border-radius: var(--radius-full);
	transition: width var(--transition-slow);
  }
  
  /* --- Tags / Topics --- */
  .tag {
	display: inline-flex;
	align-items: center;
	padding: 0.25rem 0.75rem;
	font-size: 0.8125rem;
	font-weight: 500;
	border-radius: var(--radius-full);
	background: var(--color-neutral-100);
	color: var(--color-neutral-600);
	border: 1px solid var(--color-neutral-200);
	transition: all var(--transition-fast);
  }
  .tag:hover { background: var(--color-primary-light); color: var(--color-primary); border-color: var(--color-primary-light); }
  .tag.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
  
  /* --- Glossary term — visible affordance on highlighted words --- */
  .glossary-term {
	border-bottom: 2px dotted var(--color-primary);
	color: var(--color-primary-dark);
	cursor: help;
	border-radius: 2px;
	transition: background var(--transition-fast), color var(--transition-fast);
  }
  .glossary-term:hover,
  .glossary-term:focus-visible {
	background: var(--color-primary-light);
	outline: none;
  }
  /* Glossary terms inside code blocks sit next to Prism's own token
     colors — override color to `inherit` so the term keeps whatever
     syntax-highlight color Prism gave it; the code viewer itself now
     uses a light background, so the underline/hover just match the
     regular light-mode glossary-term styling. */
  .glossary-term--code {
	color: inherit;
	border-bottom-color: var(--color-primary);
  }
  .glossary-term--code:hover,
  .glossary-term--code:focus-visible {
	background: var(--color-primary-light);
  }

  /* --- Tables --- */
  .table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--color-neutral-200); }
  table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
  thead { background: var(--color-neutral-50); }
  th {
	text-align: left;
	padding: var(--space-3) var(--space-4);
	font-size: 0.8125rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--color-neutral-500);
	border-bottom: 1px solid var(--color-neutral-200);
  }
  td {
	padding: var(--space-3) var(--space-4);
	border-bottom: 1px solid var(--color-neutral-100);
	color: var(--color-neutral-700);
  }
  tbody tr:last-child td { border-bottom: none; }
  tbody tr:hover { background: var(--color-neutral-50); }
  
  /* --- Code blocks --- */
  .code-block {
	background: var(--color-neutral-900);
	border-radius: var(--radius-lg);
	overflow: hidden;
	margin: var(--space-5) 0;
  }
  .code-block__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--space-3) var(--space-4);
	background: var(--color-neutral-800);
	border-bottom: 1px solid var(--color-neutral-700);
  }
  .code-block__lang {
	font-size: 0.8125rem;
	font-weight: 500;
	color: var(--color-neutral-400);
	font-family: var(--font-mono);
  }
  .code-block__copy {
	font-size: 0.8125rem;
	color: var(--color-neutral-400);
	cursor: pointer;
	padding: var(--space-1) var(--space-2);
	border-radius: var(--radius-sm);
	transition: color var(--transition-fast), background var(--transition-fast);
  }
  .code-block__copy:hover { color: #fff; background: var(--color-neutral-700); }
  .code-block pre {
	padding: var(--space-5) var(--space-5);
	overflow-x: auto;
	margin: 0;
	font-size: 0.9rem;
	line-height: 1.7;
	color: #E2E8F0;
  }
  
  /* --- Animations --- */
  @keyframes spin    { to { transform: rotate(360deg); } }
  @keyframes fadeDown {
	from { opacity: 0; transform: translateY(-8px); }
	to   { opacity: 1; transform: translateY(0); }
  }
  @keyframes shimmer {
	from { background-position: 200% 0; }
	to   { background-position: -200% 0; }
  }
  
  /* --- Responsive --- */
  @media (max-width: 768px) {
	.footer-container {
	  grid-template-columns: 1fr;
	  gap: var(--space-10);
	}
	.footer-nav { grid-template-columns: repeat(2, 1fr); }
  }
  
  @media (max-width: 480px) {
	.footer-nav { grid-template-columns: 1fr; }
  }
  
  /* --- Accessibility --- */
  :focus-visible {
	outline: 2px solid var(--color-primary);
	outline-offset: 2px;
  }
  .sr-only {
	position: absolute;
	width: 1px; height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
  }
  @media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: 2s !important; transition-duration: 0.01ms !important; }
  }