:root {
  --bg: #0b1020;
  --card: #121a33;
  --sidebar: #0e1528;
  --muted: #9aa4c3;
  --text: #e8ecff;
  --border: #2a3561;
  --primary: #4f7cff;
  --warn: #ffb84f;
  --bad: #ff5f73;
  --good: #54e39a;
  --easy: #54e39a;
  --medium: #ffb84f;
  --hard: #ff5f73;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
* { box-sizing: border-box }
html, body { height: 100%; margin: 0 }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 600px at 10% 10%, #121a33, var(--bg));
  color: var(--text);
}

/* ── Header ─────────────────────────────────── */
.top {
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 18px }
.sub { color: var(--muted); font-size: 12px }
.top-center { flex: 1; min-width: 180px; max-width: 340px }
.stats-bar { display: flex; align-items: center; gap: 10px }
.stat { font-size: 13px; white-space: nowrap }
.progress-track {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,.08);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--good);
  border-radius: 3px;
  transition: width .4s ease;
}
.timer-controls { display: flex; align-items: center; gap: 6px }
.timer-display {
  font-family: var(--mono);
  font-size: 16px;
  min-width: 50px;
  text-align: center;
}
select {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* ── Buttons ────────────────────────────────── */
button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, transform .1s;
}
button:hover { background: rgba(255,255,255,.06) }
button:active { transform: translateY(1px) }
button.primary {
  background: color-mix(in oklab, var(--primary) 30%, transparent);
  border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
}
button.warn {
  background: color-mix(in oklab, var(--warn) 20%, transparent);
  border-color: color-mix(in oklab, var(--warn) 60%, var(--border));
}
button.sm { padding: 4px 8px; font-size: 12px }

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

/* ── Sidebar ────────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .25s ease, min-width .25s ease, opacity .25s ease;
  overflow: hidden;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}
.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head h2 { margin: 0; font-size: 15px }
.sidebar-toggle {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  padding: 2px 6px;
  cursor: pointer;
}
.sidebar-filters {
  padding: 10px 14px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  width: 100%;
  padding: 6px 8px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.filter-row { display: flex; gap: 6px }
.filter-row select { flex: 1; font-size: 12px }
.challenge-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.ch-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .12s;
  font-size: 13px;
}
.ch-item:hover { background: rgba(255,255,255,.04) }
.ch-item.active {
  background: rgba(79,124,255,.12);
  border-left-color: var(--primary);
}
.ch-item .ch-check {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  font-size: 11px;
  flex-shrink: 0;
}
.ch-item .ch-check.solved {
  background: var(--good);
  border-color: var(--good);
  color: #0b1020;
}
.ch-item .ch-info { flex: 1; min-width: 0 }
.ch-item .ch-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-item .ch-tags {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

/* ── Main content ───────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 18px;
  display: grid;
  grid-template-columns: 1.05fr 1.2fr;
  gap: 14px;
  align-content: start;
}
@media (max-width: 1100px) {
  .main-content { grid-template-columns: 1fr }
}

/* ── Cards ──────────────────────────────────── */
.card {
  background: color-mix(in oklab, var(--card) 92%, black);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.sandbox-card { grid-column: 1 / -1 }

.challenge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.challenge-header h2 { margin: 0 }
.badge-row { display: flex; gap: 6px }
.badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.diff-easy { background: rgba(84,227,154,.15); color: var(--easy) }
.diff-medium { background: rgba(255,184,79,.15); color: var(--medium) }
.diff-hard { background: rgba(255,95,115,.15); color: var(--hard) }
.cat-badge { background: rgba(79,124,255,.15); color: var(--primary) }

.meta { color: var(--muted); font-size: 12px; margin-bottom: 8px }
.prompt { white-space: pre-wrap; line-height: 1.4; font-size: 14px }

.hint { margin-top: 10px }
.hint summary { cursor: pointer; color: var(--muted); font-size: 13px }
.code {
  font-family: var(--mono);
  font-size: 12px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.06);
  padding: 10px;
  border-radius: 10px;
  overflow: auto;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap }

/* ── Editor ─────────────────────────────────── */
#editor {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.35);
  color: var(--text);
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
}
.small { color: var(--muted); font-size: 12px; margin-top: 6px }

/* ── Results ────────────────────────────────── */
.results {
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.25);
  min-height: 60px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
}
.results.ok { color: var(--good) }
.results.bad { color: var(--bad) }
.test-progress {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}
.next-wrap {
  margin-top: 10px;
  text-align: center;
}

/* ── Sandbox ────────────────────────────────── */
.sandbox {
  width: 100%;
  height: 300px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: white;
}

/* ── Footer ─────────────────────────────────── */
.foot {
  padding: 8px 18px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ── Responsive ─────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 240px; min-width: 240px }
  .top { flex-direction: column; align-items: flex-start }
  .top-center { max-width: 100% }
}
@media (max-width: 700px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; width: 280px; min-width: 280px }
  .sidebar.collapsed { width: 0; min-width: 0 }
  .app-layout { position: relative }
}

/* ── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 6px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 3px }
