:root {
  --bg: #0f1115;
  --bg-elev: #161922;
  --bg-elev-2: #1c2030;
  --border: #262b3a;
  --border-strong: #353b50;
  --text: #e6e9ef;
  --text-dim: #a4abbd;
  --muted: #7a8298;
  --accent: #7c5cff;
  --accent-2: #5b8dff;
  --success: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --info: #60a5fa;
  --radius: 10px;
  --radius-sm: 6px;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Monaco, Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* Top bar */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #141826, #0f1115);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-family: var(--font-mono);
  font-weight: 700;
  color: #0f1115;
  font-size: 14px;
}
.title { font-weight: 600; letter-spacing: 0.2px; }
.subtitle { color: var(--muted); font-size: 12px; margin-left: 8px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  background: var(--bg-elev);
}
.pill-demo { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); }
.pill-live { color: var(--success); border-color: rgba(52, 211, 153, 0.4); }
.pill-error { color: var(--error); border-color: rgba(248, 113, 113, 0.4); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100vh - 52px);
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 16px 8px;
}
.sidebar-header h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.problem-list { list-style: none; margin: 0; padding: 4px 8px 16px; }
.problem-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid transparent;
}
.problem-item:hover { background: var(--bg-elev-2); }
.problem-item.active {
  background: rgba(124, 92, 255, 0.12);
  border-color: rgba(124, 92, 255, 0.35);
}
.problem-item .pname { font-weight: 500; }
.diff-easy { color: var(--success); }
.diff-medium { color: var(--warn); }
.diff-hard { color: var(--error); }

/* Content area: problem + editor side by side */
.content {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(420px, 1.4fr);
  overflow: hidden;
}

/* Problem pane */
.problem-pane {
  border-right: 1px solid var(--border);
  padding: 20px 24px;
  overflow-y: auto;
  background: var(--bg);
}
.problem-header h1 { margin: 0 0 8px; font-size: 20px; }
.problem-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.badge {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-elev);
}
.tags { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--bg-elev-2); color: var(--text-dim); }

.problem-body { color: var(--text-dim); }
.problem-body p { margin: 0 0 12px; }
.problem-body code, .examples code {
  font-family: var(--font-mono);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text);
}
.problem-body ul { padding-left: 20px; margin: 0 0 12px; }
.examples-details {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.examples-details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  margin-bottom: 8px;
}
.examples-details > summary::-webkit-details-marker { display: none; }
.examples-details > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 0.15s;
}
.examples-details[open] > summary::before { transform: rotate(90deg); }
.example {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre-wrap;
}
.example .label { color: var(--muted); margin-right: 6px; }

/* Editor pane */
.editor-pane {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 0;
  background: var(--bg-elev);
}
.editor-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.select { display: flex; align-items: center; gap: 8px; }
.select .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.select select {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font: inherit;
  min-width: 200px;
}
.grow { flex: 1; }
button { font: inherit; }
.primary-btn, .accent-btn, .ghost-btn {
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  transition: filter 0.12s, background 0.12s, border-color 0.12s;
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.primary-btn:hover { filter: brightness(1.07); }
.accent-btn { background: var(--success); border-color: var(--success); color: #0a1a13; font-weight: 600; }
.accent-btn:hover { filter: brightness(1.05); }
.ghost-btn:hover { background: #232838; }
button:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.4); }

.editor { min-height: 200px; height: 100%; border-bottom: 1px solid var(--border); }

/* IO tabs */
.io-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); background: var(--bg); }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 14px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab-active { color: var(--text); border-bottom-color: var(--accent); }

.io-panels {
  height: 220px;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}
.panel { display: none; height: 100%; overflow-y: auto; padding: 12px 14px; }
.panel-active { display: block; }

/* Test cases panel */
.testcase-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tc-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 6px;
}
.tc-chip.active { color: var(--text); border-color: var(--accent); }
.tc-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.tc-dot.pass { background: var(--success); }
.tc-dot.fail { background: var(--error); }
.tc-dot.run { background: var(--info); }

.testcase-detail { font-family: var(--font-mono); font-size: 12.5px; }
.tc-row { margin-bottom: 8px; }
.tc-row .k { color: var(--muted); display: block; margin-bottom: 3px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.tc-row .v {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  white-space: pre-wrap;
  display: block;
  min-height: 22px;
}
.tc-row .v.pass { border-color: rgba(52, 211, 153, 0.4); }
.tc-row .v.fail { border-color: rgba(248, 113, 113, 0.4); }

/* Output panel */
.output-summary { padding: 6px 0; font-family: var(--font-mono); font-size: 12.5px; }
.output-summary.pass { color: var(--success); }
.output-summary.fail { color: var(--error); }
.output-summary.warn { color: var(--warn); }
.output-block {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 6px 0;
  white-space: pre-wrap;
  max-height: 100%;
  overflow: auto;
}
.output-block:empty { display: none; }
.output-block.error { border-color: rgba(248, 113, 113, 0.4); color: #ffd1d1; }
.output-block.warn { border-color: rgba(251, 191, 36, 0.4); color: #ffe6a8; }

/* Stdin panel */
.stdin {
  width: 100%; height: calc(100% - 24px);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  resize: none;
}

/* Dialog */
.dialog {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px 22px;
  width: min(520px, 92vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.dialog::backdrop { background: rgba(5, 7, 12, 0.6); backdrop-filter: blur(2px); }
.dialog h3 { margin: 0 0 6px; }
.dialog .field { display: grid; grid-template-columns: 140px 1fr; gap: 10px; align-items: center; margin: 10px 0; }
.dialog .field span { color: var(--text-dim); font-size: 13px; }
.dialog input, .dialog select {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
}
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; }

/* Utilities */
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Scrollbars (subtle) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3145; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #364063; }
::-webkit-scrollbar-track { background: transparent; }

/* Responsive */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 220px 1fr; }
  .content { grid-template-columns: 1fr; grid-template-rows: minmax(240px, 0.55fr) 1.45fr; }
  .problem-pane { border-right: none; border-bottom: 1px solid var(--border); }
}
