/* ── Reset & variables ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --bg-card:   #161b22;
  --bg-card2:  #1c2129;
  --bg-input:  #0d1117;
  --border:    #30363d;
  --border-l:  #21262d;
  --text:      #e6edf3;
  --text-2:    #8b949e;
  --text-3:    #484f58;
  --accent:    #f78166;
  --accent2:   #d4a017;
  --green:     #3fb950;
  --red:       #f85149;
  --sidebar-w: 280px;
  --topbar-h:  52px;
  --radius:    6px;
  --font-ui:   -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "Fira Code", Consolas, monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.scroll::-webkit-scrollbar { width: 5px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.hidden { display: none !important; }
.muted  { color: var(--text-2); font-size: 13px; line-height: 1.65; margin-bottom: 4px; }

/* ── Shell ──────────────────────────────────────────────── */
#app  { display: flex; height: 100vh; overflow: hidden; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════ */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-top {
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}
.logo-bolt { font-size: 20px; line-height: 1; }

#sidebar-body { flex: 1; padding: 6px 0 20px; }

/* Checkpoint accordion */
.cp-block { margin-bottom: 1px; }

.cp-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.cp-header:hover { background: rgba(255,255,255,0.04); }

.cp-arrow {
  font-size: 9px;
  color: var(--text-3);
  width: 14px;
  flex-shrink: 0;
  transition: transform 0.18s;
}
.cp-block.open > .cp-header .cp-arrow { transform: rotate(90deg); }

.cp-name {
  flex: 1;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}
.cp-progress { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.cp-body { display: none; }
.cp-block.open > .cp-body { display: block; }

/* Level group */
.lv-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 28px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.lv-header:hover { background: rgba(255,255,255,0.03); }

.lv-badge {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #0d1117;
  flex-shrink: 0;
  line-height: 1;
}

.lv-info { flex: 1; min-width: 0; line-height: 1.25; }
.lv-name { font-size: 11.5px; font-weight: 600; color: var(--text); }
.lv-diff { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 1px; }

.lv-prog  { font-size: 11px; color: var(--text-3); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.lv-arrow { font-size: 9px; color: var(--text-3); width: 10px; flex-shrink: 0; transition: transform 0.18s; }
.lv-block.open > .lv-header .lv-arrow { transform: rotate(90deg); }

.lv-exercises { display: none; }
.lv-block.open > .lv-exercises { display: block; }

/* Exercise row */
.ex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 56px;
  cursor: pointer;
  user-select: none;
  border-left: 2px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  min-width: 0;
}
.ex-row:hover              { background: rgba(255,255,255,0.04); }
.ex-row.active             { background: rgba(88,166,255,0.08); border-left-color: #58a6ff; }
.ex-row.pass               { border-left-color: var(--green); }
.ex-row.fail               { border-left-color: var(--red); }
.ex-row.no-test            { opacity: 0.35; pointer-events: none; }

.ex-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--text-3);
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.ex-row.pass .ex-dot   { background: var(--green); border-color: var(--green); }
.ex-row.fail .ex-dot   { background: var(--red);   border-color: var(--red); }
.ex-row.active .ex-dot { border-color: #58a6ff; }

.ex-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.ex-row.no-test .ex-name { color: var(--text-3); }

/* ════════════════════════════════════════════════════════
   WELCOME
════════════════════════════════════════════════════════ */
#welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-inner { text-align: center; }
.welcome-bolt  { font-size: 56px; line-height: 1; margin-bottom: 16px; }
.welcome-inner h1 { font-size: 22px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.welcome-inner p  { font-size: 14px; color: var(--text-2); }

/* ════════════════════════════════════════════════════════
   EXERCISE VIEW
════════════════════════════════════════════════════════ */
#ex-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Top bar */
#ex-topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}
#ex-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#ex-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Scrollable content — IMPORTANT: display:block, not flex */
#ex-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px 36px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#ex-scroll::-webkit-scrollbar { width: 5px; }
#ex-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.card:last-child { margin-bottom: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-l);
  background: var(--bg-card2);
  border-radius: var(--radius) var(--radius) 0 0;
  min-height: 38px;
}

.card-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.card-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hint-text { font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* Buttons */
.btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-2);
  font-size: 12px;
  font-family: var(--font-ui);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s;
  line-height: 1.4;
}
.btn-ghost-sm:hover { border-color: var(--text-2); color: var(--text); }
.btn-ghost-sm.active { border-color: #58a6ff; color: #58a6ff; }

.btn-run {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #1a7f37;
  border: 1px solid #2ea043;
  border-radius: 5px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-ui);
  padding: 5px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
  line-height: 1.4;
}
.btn-run:hover:not(:disabled) { background: #238636; border-color: #3fb950; }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }
.run-icon { font-size: 9px; }

/* ── Description card ───────────────────────────────────── */
#desc-body { padding: 16px 18px 18px; }

.loading-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
}

#desc-content h1 {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
}
#desc-content h2, #desc-content h3 {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 14px 0 6px;
}
#desc-content p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 10px;
}
#desc-content strong { color: var(--text); font-weight: 600; }
#desc-content code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: #79c0ff;
}
#desc-content pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 6px 0 12px;
  overflow-x: auto;
}
#desc-content pre code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
  background: none;
  border: none;
  padding: 0;
}
#desc-content ul, #desc-content ol {
  padding-left: 22px;
  margin-bottom: 10px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
}
#desc-content li { margin-bottom: 3px; }
#desc-content hr { border: none; border-top: 1px solid var(--border-l); margin: 12px 0; }

/* ── Test chips card ────────────────────────────────────── */
#test-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px 12px;
  min-height: 44px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 9px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-2);
  line-height: 1.5;
}
.chip::before { content: '•'; color: var(--text-3); font-size: 10px; }

#test-code-wrap { border-top: 1px solid var(--border-l); }
#test-code-pre  {
  padding: 14px 16px;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Monaco Editor card ─────────────────────────────────── */
#monaco-container {
  width: 100%;
  height: 340px;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;  /* clip monaco chrome to card radius */
}

/* fallback textarea (shown while Monaco loads or on error) */
#code-fallback {
  width: 100%;
  height: 340px;
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 14px 16px;
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Results card ───────────────────────────────────────── */
.results-output {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px 16px;
  min-height: 52px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.results-output::-webkit-scrollbar { width: 5px; }
.results-output::-webkit-scrollbar-thumb { background: var(--border); }

.out-pass  { color: var(--green); }
.out-fail  { color: var(--red); }
.out-error { color: #f0883e; }
.out-dim   { color: var(--text-3); }

/* test code block */
.code-block {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Spinners ───────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-sm {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--text-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.spinner-run {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
