/* ============================================
   CodeForge — Stylesheet
   Mobile-first, responsive, dark/light mode
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  /* Dark theme (default) */
  --bg: #0d1117;
  --bg-elevated: #161b22;
  --bg-hover: #1c2128;
  --bg-input: #0d1117;
  --border: #30363d;
  --border-subtle: #21262d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-subtle: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-bg: rgba(88, 166, 255, 0.1);
  --success: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.1);
  --warning: #d29922;
  --warning-bg: rgba(210, 153, 34, 0.1);
  --danger: #f85149;
  --danger-bg: rgba(248, 81, 73, 0.1);
  --purple: #bc8cff;
  --orange: #f78166;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --max-width: 1200px;
  --header-height: 56px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  --transition: 150ms ease;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f6f8fa;
  --bg-hover: #eaeef2;
  --bg-input: #ffffff;
  --border: #d0d7de;
  --border-subtle: #eaeef2;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-subtle: #848d97;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-bg: rgba(9, 105, 218, 0.08);
  --success: #1a7f37;
  --success-bg: rgba(26, 127, 55, 0.08);
  --warning: #9a6700;
  --warning-bg: rgba(154, 103, 0, 0.08);
  --danger: #cf222e;
  --danger-bg: rgba(207, 34, 46, 0.08);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img, svg { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
ul, ol { list-style: none; }

/* ---------- Layout ---------- */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 16px; }
.app { display: flex; flex-direction: column; min-height: 100vh; }
.main { flex: 1; padding-top: var(--header-height); }

/* ---------- Header ---------- */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  backdrop-filter: blur(12px);
}
.header__inner { display: flex; align-items: center; gap: 12px; width: 100%; }
.header__logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.header__logo svg { width: 28px; height: 28px; }
.header__search { flex: 1; max-width: 400px; position: relative; }
.header__search input {
  width: 100%; height: 36px; padding: 0 12px 0 36px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.875rem; outline: none; transition: border-color var(--transition);
}
.header__search input:focus { border-color: var(--accent); }
.header__search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.header__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.header__btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-muted); transition: background var(--transition), color var(--transition); }
.header__btn:hover { background: var(--bg-hover); color: var(--text); }
.header__btn svg { width: 20px; height: 20px; }

/* ---------- Bottom Nav (Mobile) ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: 56px; background: var(--bg-elevated); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav__item { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--text-muted); font-size: 0.6875rem; padding: 4px 12px; border-radius: var(--radius-sm); transition: color var(--transition); }
.bottom-nav__item.active { color: var(--accent); }
.bottom-nav__item svg { width: 22px; height: 22px; }
.bottom-nav__item:active { transform: scale(0.92); }

/* ---------- Pages ---------- */
.page { display: none; padding: 16px 0 72px; animation: fadeIn 200ms ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 32px 0 24px; }
.hero__title { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 8px; }
.hero__title .accent { background: linear-gradient(135deg, var(--accent), var(--purple)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.hero__subtitle { color: var(--text-muted); font-size: 0.9375rem; max-width: 500px; margin: 0 auto 24px; }

/* ---------- Cards ---------- */
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: border-color var(--transition), transform var(--transition); }
.card:hover { border-color: var(--text-subtle); }
.card:active { transform: scale(0.98); }

/* ---------- Language Grid ---------- */
.lang-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 16px; }
.lang-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 20px 12px; cursor: pointer; }
.lang-card__icon { font-size: 2rem; line-height: 1; }
.lang-card__name { font-weight: 600; font-size: 0.9375rem; }
.lang-card__desc { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }
.lang-card__badge { font-size: 0.6875rem; padding: 2px 8px; border-radius: 20px; background: var(--accent-bg); color: var(--accent); text-transform: capitalize; }
.lang-card__color-bar { width: 100%; height: 3px; border-radius: 2px; margin-top: auto; }

/* ---------- Section Headers ---------- */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h2 { font-size: 1.125rem; font-weight: 700; }
.section-header a { font-size: 0.8125rem; }

/* ---------- Course List ---------- */
.course-list { display: flex; flex-direction: column; gap: 12px; }
.course-card { display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; }
.course-card__icon { width: 44px; height: 44px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; }
.course-card__body { flex: 1; min-width: 0; }
.course-card__title { font-weight: 600; font-size: 0.9375rem; margin-bottom: 2px; }
.course-card__desc { font-size: 0.8125rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-card__meta { display: flex; gap: 8px; margin-top: 6px; }
.course-card__badge { font-size: 0.6875rem; padding: 2px 8px; border-radius: 20px; background: var(--bg-hover); color: var(--text-muted); }
.course-card__arrow { color: var(--text-subtle); flex-shrink: 0; }

/* ---------- Progress Bar ---------- */
.progress-bar { height: 6px; background: var(--border-subtle); border-radius: 3px; overflow: hidden; }
.progress-bar__fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 300ms ease; }

/* ---------- Lesson View ---------- */
.lesson { max-width: 760px; margin: 0 auto; }
.lesson__header { margin-bottom: 20px; }
.lesson__breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 8px; flex-wrap: wrap; }
.lesson__breadcrumb a { color: var(--text-muted); }
.lesson__breadcrumb a:hover { color: var(--accent); }
.lesson__breadcrumb span { color: var(--text-subtle); }
.lesson__title { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.lesson__desc { color: var(--text-muted); font-size: 0.9375rem; }

.lesson__content { font-size: 0.9375rem; line-height: 1.7; }
.lesson__content h2 { font-size: 1.125rem; font-weight: 700; margin: 20px 0 8px; }
.lesson__content h3 { font-size: 1rem; font-weight: 600; margin: 16px 0 6px; }
.lesson__content p { margin-bottom: 12px; }
.lesson__content ul { padding-left: 20px; margin-bottom: 12px; list-style: disc; }
.lesson__content li { margin-bottom: 4px; }
.lesson__content code { font-family: var(--font-mono); font-size: 0.85em; background: var(--bg-hover); padding: 2px 6px; border-radius: 4px; }
.lesson__content pre { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; overflow-x: auto; margin: 12px 0; }
.lesson__content pre code { background: none; padding: 0; font-size: 0.8125rem; line-height: 1.5; }

/* ---------- Code Editor ---------- */
.editor { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 16px 0; }
.editor__toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--bg-elevated); border-bottom: 1px solid var(--border); }
.editor__lang { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); display: flex; align-items: center; gap: 6px; }
.editor__actions { display: flex; gap: 8px; }
.editor__btn { padding: 4px 12px; font-size: 0.8125rem; border-radius: var(--radius-sm); background: var(--bg-hover); color: var(--text); display: flex; align-items: center; gap: 4px; transition: background var(--transition); }
.editor__btn:hover { background: var(--border); }
.editor__btn--run { background: var(--accent); color: #fff; }
.editor__btn--run:hover { background: var(--accent-hover); }
.editor__btn--hint { background: var(--warning-bg); color: var(--warning); }
.editor__btn--hint:hover { background: var(--warning); color: #fff; }
.editor__textarea { width: 100%; min-height: 200px; padding: 14px; background: var(--bg-input); color: var(--text); border: none; outline: none; resize: vertical; font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.6; tab-size: 2; }
.editor__output { padding: 12px; background: var(--bg-input); border-top: 1px solid var(--border); font-family: var(--font-mono); font-size: 0.8125rem; white-space: pre-wrap; word-break: break-word; min-height: 48px; }
.editor__output:empty::before { content: 'Output will appear here...'; color: var(--text-subtle); }
.editor__output--error { color: var(--danger); }
.editor__output--success { color: var(--success); }

/* ---------- Quiz ---------- */
.quiz { margin: 20px 0; }
.quiz__question { font-weight: 600; margin-bottom: 12px; font-size: 0.9375rem; }
.quiz__options { display: flex; flex-direction: column; gap: 8px; }
.quiz__option { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition); font-size: 0.875rem; }
.quiz__option:hover { border-color: var(--accent); background: var(--accent-bg); }
.quiz__option.selected { border-color: var(--accent); background: var(--accent-bg); }
.quiz__option.correct { border-color: var(--success); background: var(--success-bg); }
.quiz__option.incorrect { border-color: var(--danger); background: var(--danger-bg); }
.quiz__option-letter { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; flex-shrink: 0; }
.quiz__option.correct .quiz__option-letter { background: var(--success); color: #fff; border-color: var(--success); }
.quiz__option.incorrect .quiz__option-letter { background: var(--danger); color: #fff; border-color: var(--danger); }
.quiz__feedback { margin-top: 12px; padding: 12px; border-radius: var(--radius-sm); font-size: 0.8125rem; display: none; }
.quiz__feedback.show { display: block; }
.quiz__feedback--correct { background: var(--success-bg); color: var(--success); }
.quiz__feedback--incorrect { background: var(--danger-bg); color: var(--danger); }
.quiz__nav { display: flex; justify-content: space-between; margin-top: 16px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 20px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.875rem; transition: all var(--transition); white-space: nowrap; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn--secondary:hover { background: var(--border); }
.btn--ghost { color: var(--text-muted); }
.btn--ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn--sm { padding: 6px 12px; font-size: 0.8125rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Dashboard ---------- */
.dashboard__stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { text-align: center; padding: 20px 12px; }
.stat-card__value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-card__label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card--streak .stat-card__value { color: var(--orange); }
.stat-card--xp .stat-card__value { color: var(--accent); }
.stat-card--lessons .stat-card__value { color: var(--success); }
.stat-card--achievements .stat-card__value { color: var(--purple); }

/* ---------- Achievements ---------- */
.achievement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.achievement { text-align: center; padding: 16px 8px; }
.achievement__icon { font-size: 2rem; margin-bottom: 6px; }
.achievement__title { font-size: 0.8125rem; font-weight: 600; margin-bottom: 2px; }
.achievement__desc { font-size: 0.6875rem; color: var(--text-muted); line-height: 1.3; }
.achievement--locked { opacity: 0.4; filter: grayscale(1); }
.achievement--unlocked { border-color: var(--accent); background: var(--accent-bg); }

/* ---------- Search Results ---------- */
.search-results { display: flex; flex-direction: column; gap: 8px; }
.search-result { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition); }
.search-result:hover { border-color: var(--accent); background: var(--accent-bg); }
.search-result__icon { font-size: 1.25rem; flex-shrink: 0; }
.search-result__body { flex: 1; min-width: 0; }
.search-result__title { font-weight: 600; font-size: 0.875rem; }
.search-result__desc { font-size: 0.75rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result__type { font-size: 0.6875rem; padding: 2px 8px; border-radius: 20px; background: var(--bg-hover); color: var(--text-muted); text-transform: uppercase; flex-shrink: 0; }

/* ---------- Challenge View ---------- */
.challenge__header { margin-bottom: 16px; }
.challenge__title { font-size: 1.25rem; font-weight: 700; }
.challenge__desc { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }
.challenge__meta { display: flex; gap: 8px; margin-top: 8px; }
.challenge__tests { margin-top: 16px; }
.challenge__test { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; font-family: var(--font-mono); font-size: 0.75rem; display: flex; align-items: center; gap: 8px; }
.challenge__test--pass { border-color: var(--success); background: var(--success-bg); }
.challenge__test--fail { border-color: var(--danger); background: var(--danger-bg); }
.challenge__test-icon { font-size: 1rem; }

/* ---------- Hint Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.modal-overlay.show { display: flex; animation: fadeIn 150ms ease; }
.modal { background: var(--bg-elevated); border-radius: var(--radius-lg) var(--radius-lg) 0 0; width: 100%; max-width: 500px; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0)); max-height: 80vh; overflow-y: auto; animation: slideUp 200ms ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal__title { font-weight: 700; font-size: 1.125rem; }
.modal__close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-muted); }
.modal__close:hover { background: var(--bg-hover); color: var(--text); }
.modal__body { font-size: 0.875rem; line-height: 1.6; color: var(--text-muted); }
.modal__body strong { color: var(--text); }
.modal__body code { font-family: var(--font-mono); background: var(--bg-hover); padding: 2px 6px; border-radius: 4px; font-size: 0.85em; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 20px; font-size: 0.8125rem; font-weight: 500; z-index: 300; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity 200ms ease, transform 200ms ease; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }
.toast--success { border-color: var(--success); }
.toast--error { border-color: var(--danger); }

/* ---------- Skeleton Loading ---------- */
.skeleton { background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border-subtle) 50%, var(--bg-hover) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-card { height: 80px; margin-bottom: 12px; }

/* ---------- Empty State ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state__icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state__title { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.empty-state__desc { font-size: 0.875rem; }

/* ---------- Breadcrumbs ---------- */
.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 12px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb__sep { color: var(--text-subtle); }

/* ---------- Responsive ---------- */
@media (min-width: 768px) {
  .header__search { max-width: 500px; }
  .hero__title { font-size: 2.25rem; }
  .hero__subtitle { font-size: 1rem; }
  .lang-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .dashboard__stats { grid-template-columns: repeat(4, 1fr); }
  .bottom-nav { display: none; }
  .page { padding-bottom: 32px; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}

@media (min-width: 1024px) {
  .lang-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* ---------- Accessibility ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

