@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-dim: #1f6feb;
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --radius: 8px;
  --radius-lg: 12px;
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Keyframe Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes xpPop {
  0%   { opacity: 0; transform: translateY(0) scale(0.8); }
  30%  { opacity: 1; transform: translateY(-20px) scale(1.2); }
  70%  { opacity: 1; transform: translateY(-36px) scale(1); }
  100% { opacity: 0; transform: translateY(-48px) scale(0.9); }
}

@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
}
.btn-primary:hover { background: #79b8ff; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(88,166,255,0.3); }

.btn-success {
  background: var(--success);
  color: #0d1117;
}
.btn-success:hover { background: #56d364; transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
  border-radius: var(--radius-lg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-easy   { background: rgba(63,185,80,0.15);  color: var(--success); }
.badge-medium { background: rgba(210,153,34,0.15); color: var(--warning); }
.badge-hard   { background: rgba(248,81,73,0.15);  color: var(--error); }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.12);
}

/* ── Nav ── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.nav-logo span { color: var(--text); }

/* ── Progress Bar ── */
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* ── Stat chip ── */
.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

/* ── Feedback banners ── */
.feedback {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}

.feedback-pass {
  background: rgba(63,185,80,0.1);
  border: 1px solid rgba(63,185,80,0.3);
  color: var(--success);
}

.feedback-fail {
  background: rgba(248,81,73,0.1);
  border: 1px solid rgba(248,81,73,0.3);
  color: var(--error);
}

/* ── Output panel ── */
.output-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 60px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── XP Popup ── */
.xp-popup {
  position: fixed;
  top: 80px;
  right: 24px;
  background: var(--success);
  color: #0d1117;
  font-weight: 700;
  font-size: 18px;
  padding: 8px 16px;
  border-radius: 20px;
  pointer-events: none;
  animation: xpPop 1.2s ease forwards;
  z-index: 200;
}

/* ── Section headings ── */
.section-title {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.section-sub {
  color: var(--text-muted);
  font-size: 17px;
  max-width: 560px;
  margin: 0 auto;
}

/* ── Landing hero gradient ── */
.hero-gradient {
  background: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(88,166,255,0.15), transparent),
              radial-gradient(ellipse 60% 40% at 80% 60%, rgba(63,185,80,0.08), transparent);
}

/* ── Grid helpers ── */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

/* ── CodeMirror overrides ── */
.CodeMirror {
  font-family: var(--font-mono) !important;
  font-size: 14px !important;
  height: auto !important;
  min-height: 180px !important;
  border-radius: 0 0 var(--radius) var(--radius) !important;
  border: 1px solid var(--border) !important;
  border-top: none !important;
}

.CodeMirror-scroll { min-height: 180px; }

.editor-header {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 32px 0;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .section-title { font-size: 24px; }

  .app-layout {
    flex-direction: column !important;
  }

  .sidebar {
    width: 100% !important;
    height: auto !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
    max-height: 220px !important;
  }
}

/* ── App layout ── */
.app-layout {
  display: flex;
  height: calc(100vh - 60px);
  overflow: hidden;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-topic {
  padding: 6px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-top: 8px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.15s;
  user-select: none;
}

.sidebar-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-item.active {
  background: rgba(88,166,255,0.1);
  color: var(--accent);
  border-right: 2px solid var(--accent);
}

.sidebar-item.completed {
  color: var(--success);
}

.diff-dots {
  display: flex;
  gap: 3px;
  margin-left: auto;
}

.diff-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.diff-dot.filled { background: var(--warning); }
.diff-dot.hard   { background: var(--error); }

.main-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Hint box ── */
.hint-box {
  background: rgba(210,153,34,0.08);
  border: 1px solid rgba(210,153,34,0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--warning);
  animation: slideUp 0.3s ease;
}

/* ── Exercise header ── */
.exercise-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
