:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1c212a;
  --border: #272e3a;
  --text: #e3e7ee;
  --muted: #8b95a7;
  --accent: #00add8; /* Go blue */
  --accent-2: #5dc9e2;
  --ok: #3fb950;
  --fail: #f85149;
  --warn: #d29922;
  --easy: #3fb950;
  --medium: #d29922;
  --hard: #f85149;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; white-space: nowrap; }
.gopher { color: var(--accent); margin-right: 4px; }
.progress { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.progress .bar { width: 160px; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.icon-btn { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }

.layout { flex: 1; display: flex; min-height: 0; }

/* Sidebar */
aside {
  width: var(--sidebar-w, 280px);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filters { padding: 10px; display: flex; gap: 6px; border-bottom: 1px solid var(--border); }
.filters input, .filters select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font: inherit; min-width: 0;
}
.filters input { flex: 1; }
nav { overflow-y: auto; flex: 1; padding-bottom: 20px; }
.track-group h4 {
  margin: 0; padding: 12px 14px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between;
  position: sticky; top: 0; background: var(--panel);
}
nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; color: var(--text); text-decoration: none; font-size: 13px;
  border-left: 3px solid transparent;
}
nav a:hover { background: var(--panel-2); }
nav a.active { background: var(--panel-2); border-left-color: var(--accent); }
nav a .num { color: var(--muted); font-family: var(--mono); font-size: 11px; width: 22px; flex-shrink: 0; }
nav a .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav a .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
nav a .check { color: var(--ok); width: 14px; text-align: center; flex-shrink: 0; }
.dot.easy { background: var(--easy); } .dot.medium { background: var(--medium); } .dot.hard { background: var(--hard); }

/* Main */
main { flex: 1; display: grid; grid-template-columns: var(--problem-w, minmax(320px, 1fr)) 5px minmax(0, 1.25fr); min-width: 0; min-height: 0; }
.panel { min-height: 0; min-width: 0; }
#problem { overflow-y: auto; padding: 20px 24px 40px; min-width: 0; }
#problem-header h2 { margin: 6px 0 8px; font-size: 22px; }
.meta { display: flex; gap: 10px; align-items: center; }
.badge { font-size: 11px; font-weight: 600; text-transform: uppercase; padding: 2px 8px; border-radius: 10px; letter-spacing: .04em; }
.badge.easy { color: var(--easy); background: rgba(63,185,80,.12); }
.badge.medium { color: var(--medium); background: rgba(210,153,34,.12); }
.badge.hard { color: var(--hard); background: rgba(248,81,73,.12); }
.track { color: var(--muted); font-size: 12px; }
#topics { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.topic { font-size: 12px; font-family: var(--mono); color: var(--accent-2); background: rgba(0,173,216,.1); padding: 1px 8px; border-radius: 4px; }

.prose h3 { font-size: 15px; margin: 22px 0 6px; }
.prose p, .prose li { color: #cdd3dd; }
.prose ul { padding-left: 20px; }
.prose code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: #f0f3f6; }
.prose pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }

#hints { margin-top: 20px; }
.hint { background: rgba(210,153,34,.08); border: 1px solid rgba(210,153,34,.3); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; color: #e8d9b5; }
.hint b { color: var(--warn); }
.hint code { font-family: var(--mono); font-size: 12.5px; }

details { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
details summary { cursor: pointer; padding: 10px 12px; color: var(--muted); font-size: 13px; user-select: none; }
details summary:hover { color: var(--text); }
details pre.code { margin: 0; border-top: 1px solid var(--border); padding: 12px; overflow-x: auto; max-height: 500px; font: 12px/1.5 var(--mono); background: #212121; color: #eeffff; tab-size: 4; }

.nav-buttons { display: flex; justify-content: space-between; margin-top: 24px; }

/* Workspace */
#workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.file-name { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }
.btn { font: inherit; font-size: 13px; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; color: var(--text); background: var(--panel-2); }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #002733; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.primary:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; }
.btn.ai { background: linear-gradient(135deg, rgba(167,139,250,.18), rgba(0,173,216,.18)); border-color: rgba(167,139,250,.5); }
.btn.ai:hover { border-color: #a78bfa; }
.btn.ai:disabled { opacity: .6; cursor: wait; }
.btn.small { padding: 3px 10px; font-size: 12px; }

#editor-wrap { flex: 0 0 var(--editor-h, 55%); min-height: 80px; position: relative; }
#editor-wrap .CodeMirror, #editor-wrap textarea {
  position: absolute; inset: 0; height: 100%; width: 100%;
  font: 13px/1.55 var(--mono);
}
#editor-wrap textarea { background: #212121; color: #eee; border: 0; padding: 10px; resize: none; tab-size: 4; outline: none; }
.CodeMirror { background: #13161c !important; }
.CodeMirror-gutters { background: #13161c !important; border-right: 1px solid var(--border) !important; }

.results { flex: 1 1 0; overflow-y: auto; padding: 12px 14px; background: var(--bg); min-height: 60px; }
.results.empty { display: flex; align-items: center; justify-content: center; text-align: center; }
.muted { color: var(--muted); }
kbd { font-family: var(--mono); font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-weight: 600; }
.banner.pass { background: rgba(63,185,80,.12); color: var(--ok); border: 1px solid rgba(63,185,80,.35); }
.banner.fail { background: rgba(248,81,73,.1); color: var(--fail); border: 1px solid rgba(248,81,73,.35); }
.banner.running { background: var(--panel); color: var(--muted); border: 1px solid var(--border); font-weight: 400; }
.banner .time { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.race-badge { background: var(--fail); color: white; font-size: 11px; padding: 1px 8px; border-radius: 10px; font-weight: 700; }

.test { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; background: var(--panel); }
.test > summary { display: flex; gap: 8px; align-items: center; padding: 7px 10px; font-family: var(--mono); font-size: 12.5px; color: var(--text); }
.test.sub { margin-left: 18px; }
.test .icon { width: 16px; text-align: center; }
.test.pass .icon { color: var(--ok); }
.test.fail .icon { color: var(--fail); }
.test .elapsed { margin-left: auto; color: var(--muted); font-size: 11px; }
.test pre, pre.output {
  margin: 0; padding: 10px 12px; border-top: 1px solid var(--border);
  font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; color: #d7dbe2;
}
pre.output { border: 1px solid var(--border); border-radius: 6px; background: var(--panel); max-height: 400px; overflow: auto; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 6px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; overflow-y: auto; }
  #gutter-problem { display: none; }
  #problem { border-bottom: 1px solid var(--border); overflow: visible; }
  #workspace { min-height: 90vh; }
}
@media (max-width: 760px) {
  .icon-btn { display: block; }
  aside { position: fixed; top: 49px; bottom: 0; left: 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  aside.open { transform: none; }
  #gutter-sidebar { display: none; }
  .progress .bar { display: none; }
  header h1 { font-size: 14px; }
}

/* AI review */
.review { margin-top: 16px; border: 1px solid rgba(167,139,250,.4); border-radius: 8px; background: linear-gradient(180deg, rgba(167,139,250,.06), transparent 120px), var(--panel); }
.review-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border); color: #c4b5fd; font-weight: 600; font-size: 13px; }
.review-head .muted { font-weight: 400; font-size: 12px; margin-left: auto; }
.review-body { padding: 4px 16px 12px; }
.review-body pre { background: var(--bg); }
.review-body h1, .review-body h2, .review-body h3 { font-size: 14px; margin: 16px 0 6px; }
.review-body.streaming::after { content: "▍"; color: #a78bfa; animation: blink 1s steps(2) infinite; }
.review.error { border-color: rgba(248,81,73,.4); }
@keyframes blink { to { opacity: 0; } }

/* Autocomplete popup */
.CodeMirror-hints {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45); font: 12.5px/1.4 var(--mono); padding: 3px 0;
  max-height: 260px; min-width: 260px; z-index: 50;
}
.CodeMirror-hint { color: var(--text); padding: 3px 10px 3px 6px; display: flex; align-items: center; gap: 8px; border-radius: 0; }
li.CodeMirror-hint-active { background: rgba(0,173,216,.22); color: #fff; }
.hint-kind { width: 16px; height: 16px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 3px; font-size: 10px; font-weight: 700; background: #2a3140; color: var(--muted); }
.hint-kw .hint-kind { color: #c792ea; } .hint-fn .hint-kind { color: #82aaff; } .hint-method .hint-kind { color: #82aaff; }
.hint-type .hint-kind { color: #ffcb6b; } .hint-var .hint-kind { color: #89ddff; } .hint-snip .hint-kind { color: #c3e88d; }
.hint-pkg .hint-kind { color: #f78c6c; }
.hint-name { white-space: nowrap; }
.hint-detail { margin-left: auto; padding-left: 16px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }

/* Resizable panel splitters */
.gutter { flex-shrink: 0; background: var(--border); position: relative; z-index: 2; transition: background .15s; touch-action: none; }
.gutter::after { content: ""; position: absolute; inset: 0; }
.gutter-v { width: 5px; cursor: col-resize; }
.gutter-v::after { left: -3px; right: -3px; }
.gutter-h { height: 5px; cursor: row-resize; }
.gutter-h::after { top: -3px; bottom: -3px; }
.gutter:hover, .gutter.dragging { background: var(--accent); }
body.resizing { user-select: none; }
body.resizing iframe, body.resizing .CodeMirror { pointer-events: none; }
body.resizing.col { cursor: col-resize; }
body.resizing.row { cursor: row-resize; }

/* Show == != := <- as typed, not as ligature glyphs (JetBrains Mono / Fira Code).
   On every element, because the `font` shorthand resets font-variant-ligatures. */
*, *::before, *::after { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }

/* Lint markers */
.CodeMirror-lint-markers { width: 16px; }
.CodeMirror-lint-tooltip {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  font: 12px/1.5 var(--mono); padding: 6px 10px; max-width: 560px; box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 100;
}
.CodeMirror-lint-message { padding-left: 20px; }
