:root {
  --bg: #0d1016;
  --panel: #141821;
  --panel-2: #1a1f2a;
  --border: #262c38;
  --text: #e6e9f0;
  --muted: #8e97aa;
  --faint: #5b6375;
  --accent: #8aa4ff;
  --pos: #4f8cff;
  --neg: #ff7a45;
  --pass: #3fb950;
  --fail: #f85149;
  --warn: #e3b341;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
kbd {
  font: 11px var(--mono);
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  margin-left: 6px;
}

/* ---------- text selection ----------
 * Interface chrome and visualizations aren't text to copy, so a click-drag
 * over them shouldn't select anything. The description, the code, test
 * messages, output and error messages stay selectable. */
.topbar, .panel-head, .viz-root, .drawer, .modal {
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: 0.2px; color: var(--text); text-decoration: none; }
a.brand:hover { color: #fff; }
.logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent), #3b4fa8 70%);
  box-shadow: 0 0 0 3px rgba(138, 164, 255, 0.18);
}
.challenge-nav { display: flex; align-items: center; gap: 6px; margin-left: 12px; }
.drawer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  min-width: 240px;
  height: 32px;
  cursor: pointer;
  text-align: left;
}
.drawer-btn:hover { border-color: var(--accent); }
.drawer-btn .burger { color: var(--muted); }
.drawer-btn #current-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state="ready"] .dot { background: var(--pass); }
.status[data-state="running"] .dot { background: var(--accent); animation: pulse 0.8s ease-in-out infinite alternate; }
.status[data-state="loading"] .dot { animation: pulse 0.8s ease-in-out infinite alternate; }
.status[data-state="fatal"] .dot { background: var(--fail); }
@keyframes pulse { from { opacity: 0.35; } to { opacity: 1; } }

/* ---------- workspace: panels and gutters ---------- */
[hidden] { display: none !important; }
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 8px;
  background: #090b10;
}
.col { min-width: 320px; min-height: 0; }
.col-viz { order: 0; }
.gutter-col { order: 1; }
.col-work { order: 2; display: flex; flex-direction: column; }
.workspace.swapped .col-viz { order: 2; }
.workspace.swapped .col-work { order: 0; }

.panel {
  display: flex;
  flex-direction: column;
  min-height: var(--head-h);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
:root { --head-h: 38px; }
.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--head-h);
  padding: 0 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}
.panel-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.panel-head .pill:last-child { margin-left: auto; }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; }
/* the challenge window: one tab bar, one visible tab */
.work-head { padding: 0 8px 0 0; gap: 6px; }
.work-head .tabs { align-self: stretch; display: flex; }
.work-head .tabs [role=tab] {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--border);
}
.work-head .tabs [role=tab]:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.work-head .tabs [role=tab].active { background: var(--panel); color: var(--text); border-bottom-color: var(--accent); }
.work-head .btn { padding: 4px 10px; }
.tab-dot { font-size: 9px; color: var(--accent); }
.tab-dot.bad { color: var(--fail); }
.count.good { color: var(--pass); }
.tab-pane { flex: 1; min-height: 0; }
.code-pane { display: flex; flex-direction: column; }
.task-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px 0; }
.task-head h2 { margin: 0; font-size: 17px; }
.swap-btn { margin-left: auto; }
.swap-btn + .status { margin-left: 4px; }

.gutter { flex: none; position: relative; }
.gutter-col { width: 8px; cursor: col-resize; }
.gutter::after {
  content: "";
  position: absolute;
  border-radius: 2px;
  background: transparent;
  transition: background 0.15s;
}
.gutter-col::after { top: 50%; left: 3px; width: 2px; height: 36px; margin-top: -18px; }
.gutter:hover::after { background: var(--faint); }
.gutter.active::after { background: var(--accent); }
.gutter-col.active::after { top: 0; height: 100%; margin-top: 0; }
body.resizing { user-select: none; cursor: col-resize; }
body.resizing iframe, body.resizing .CodeMirror { pointer-events: none; }

.viz-body { padding: 14px 16px 20px; background: #10131a; container-type: inline-size; }
.viz-root { display: flex; flex-direction: column; gap: 14px; transition: opacity 0.2s, filter 0.2s; }
.viz-root.stale { opacity: 0.45; filter: grayscale(0.6); }
@container (min-width: 900px) {
  .viz-root { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.pill:empty { display: none; }
.pill.good { color: var(--pass); border-color: rgba(63, 185, 80, 0.4); }
.pill.bad { color: var(--fail); border-color: rgba(248, 81, 73, 0.4); }
.pill.warn { color: var(--warn); border-color: rgba(227, 179, 65, 0.4); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px 14px;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}
.card-head strong { color: var(--text); font-weight: 600; }
.card-head .pill { margin-left: auto; }
.card svg, .card canvas { display: block; width: 100%; height: auto; }
.plot { position: relative; width: 100%; max-width: 420px; margin: 0 auto; }
.plot canvas, .plot svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.plot::before { content: ""; display: block; padding-top: 100%; }
.plot.clickable { cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.readout {
  font: 12px/1.7 var(--mono);
  color: var(--muted);
  margin-top: 8px;
  white-space: pre-wrap;
  overflow-x: auto;
}
.readout b { color: var(--text); font-weight: 500; }

.error-box {
  border: 1px solid rgba(248, 81, 73, 0.45);
  background: rgba(248, 81, 73, 0.08);
  color: #ffb3ae;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap;
}
.error-box .where { color: var(--muted); }

/* timeline */
.timeline { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.timeline input[type="range"] { flex: 1; accent-color: var(--accent); }
.timeline select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
}
.timeline .label { font: 12px var(--mono); color: var(--muted); min-width: 150px; text-align: right; }

/* ---------- code pane ---------- */
.task-body {
  padding: 12px 18px 14px;
  color: #c9cfdb;
}
.task-body p { margin: 0 0 10px; }
.task-body ul, .task-body ol { margin: 0 0 10px; padding-left: 20px; }
.task-body li { margin-bottom: 4px; }
.task-body code {
  font: 12.5px var(--mono);
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
  color: #d6dcff;
}
.task-body .math {
  font: 13px var(--mono);
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  padding: 6px 10px;
  border-radius: 4px;
  margin: 0 0 10px;
}
.task-body .try {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
}
.task-body .try strong { color: var(--warn); }

.spacer { flex: 1; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; font-size: 13px; }
.toggle input { accent-color: var(--accent); }
.btn {
  border-radius: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: #3d5bd9; border-color: #3d5bd9; color: #fff; font-weight: 600; }
.btn.primary:hover { background: #4a68e8; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; } /* events reach the wrapper's tooltip */
.btn.primary:disabled { background: #3d5bd9; }
.run-wrap { display: inline-flex; cursor: not-allowed; }
.run-wrap:has(.btn:not(:disabled)) { cursor: auto; }

.editor { flex: 1; min-height: 0; position: relative; }
.editor .CodeMirror {
  position: absolute;
  inset: 0;
  height: auto;
  font: 13.5px/1.6 var(--mono);
  background: var(--panel);
}
.editor .cm-s-material-darker .CodeMirror-gutters { background: var(--panel); border-right: 1px solid var(--border); }
.editor .cm-s-material-darker .CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.035); }
.CodeMirror .error-line { background: rgba(248, 81, 73, 0.16); }

.tabs { gap: 2px; }
.tabs [role=tab] {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.tabs [role=tab].active { color: var(--text); border-bottom-color: var(--accent); }
.count { font-size: 11px; color: var(--muted); }
.tab-body { padding: 8px 12px; margin: 0; }
.tab-body.output { font: 12.5px/1.5 var(--mono); white-space: pre-wrap; color: #c9cfdb; }

.test {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 2px 8px;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 13px;
}
.test .mark { font-weight: 700; }
.test.pass .mark { color: var(--pass); }
.test.fail .mark { color: var(--fail); }
.test .msg { grid-column: 2; font: 12px/1.5 var(--mono); color: #ffb3ae; white-space: pre-wrap; }
.banner {
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 13px;
}
.banner.solved { background: rgba(63, 185, 80, 0.12); color: var(--pass); border: 1px solid rgba(63, 185, 80, 0.35); }
.banner.muted { color: var(--muted); background: var(--panel-2); font-weight: 400; }

@media (max-width: 899px) {
  body { overflow: auto; height: auto; }
  .workspace { flex-direction: column; gap: 8px; }
  .gutter, .swap-btn { display: none !important; }
  .col { min-width: 0; }
  .col-viz, .workspace.swapped .col-viz { order: 0; }
  .col-work, .workspace.swapped .col-work { order: 2; height: 85vh; flex: none; }
  .viz-body { overflow: visible; }
  .work-head { overflow-x: auto; }
  .drawer-btn { min-width: 0; max-width: 46vw; }
  .status .label { display: none; }
}

/* ---------- challenge list (landing page + drawer) ---------- */
.muted { color: var(--muted); }
.ch-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ch-card {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.ch-card:hover { border-color: var(--accent); background: #171c27; }
.ch-card.current { border-color: rgba(138, 164, 255, 0.6); box-shadow: inset 3px 0 0 var(--accent); }
.ch-top { display: flex; align-items: center; gap: 8px; }
.ch-title { font-weight: 600; }
.ch-implement { font-size: 13px; color: #c9cfdb; }
.ch-implement code { font: 12px var(--mono); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: #d6dcff; }
.ch-blurb { font-size: 13px; color: var(--muted); }
.ch-status { margin-left: auto; font-size: 12px; white-space: nowrap; color: var(--faint); }
.ch-status.solved { color: var(--pass); }
.ch-status.in-progress { color: var(--warn); }
.ch-status.in-progress::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); margin-right: 6px; vertical-align: 1px;
}
.drawer-btn .ch-status { margin-left: 0; font-weight: 700; }
.drawer-btn .ch-status.in-progress::before { margin-right: 0; }

/* ---------- drawer ---------- */
.drawer {
  margin: 0;
  height: 100%;
  max-height: none;
  width: min(420px, 92vw);
  padding: 16px;
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}
.drawer[open] { animation: slide-in 0.18s ease-out; }
.drawer::backdrop { background: rgba(5, 7, 12, 0.6); }
@keyframes slide-in { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-head .muted { font-size: 13px; }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-foot { margin: 18px 0 0; font-size: 13px; color: var(--faint); }
.drawer-foot a { color: var(--muted); }

/* ---------- modal ---------- */
.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 24px 22px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal::backdrop { background: rgba(5, 7, 12, 0.7); }
.modal-icon { font-size: 34px; margin-bottom: 6px; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 18px; color: #c9cfdb; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn { padding: 8px 16px; }

/* ---------- loading Python ---------- */
.py-loading .card-head span { color: var(--muted); }
.py-steps { list-style: none; margin: 6px 0 12px; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--faint); }
.py-steps li::before { content: "○"; margin-right: 6px; }
.py-steps li.active { color: var(--text); }
.py-steps li.active::before { content: "◐"; color: var(--accent); }
.py-steps li.done { color: var(--muted); }
.py-steps li.done::before { content: "●"; color: var(--pass); }
.py-bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.py-bar i {
  display: block; height: 100%; width: 0;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 10px, #6f8cf0 10px 20px);
  background-size: 28px 28px;
  animation: py-stripes 0.8s linear infinite;
  transition: width 0.6s ease;
}
@keyframes py-stripes { to { background-position: 28px 0; } }
.py-slow { margin: 10px 0 0; font-size: 13px; color: var(--warn); }
.py-failed p { margin: 10px 0 0; color: #c9cfdb; }
.py-failed .py-why { font: 12px var(--mono); color: var(--muted); }
.py-failed .py-retry { margin-top: 12px; }
.py-loading.failed .py-steps, .py-loading.failed .py-bar { display: none; }

/* ---------- tooltips (src/tooltip.js) ---------- */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 280px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1f2533;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  animation: tooltip-in 0.12s ease-out;
}
.tooltip[data-side="above"] { animation-name: tooltip-in-above; }
@keyframes tooltip-in { from { opacity: 0; transform: translateY(-3px); } }
@keyframes tooltip-in-above { from { opacity: 0; transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) { .tooltip { animation: none; } }

/* ---------- feedback (src/feedback.js) ---------- */
.feedback-btn { margin-left: auto; }
.feedback-btn + .swap-btn { margin-left: 8px; }
.fb-dialog { width: min(520px, calc(100vw - 32px)); text-align: left; padding: 18px 20px 14px; }
.fb-head { display: flex; align-items: center; margin-bottom: 10px; }
.fb-head h2 { margin: 0; }
.fb-head .icon-btn { margin-left: auto; }
.fb-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.fb-tabs [role=tab] {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 8px 10px; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px;
}
.fb-tabs [role=tab]:hover { color: var(--text); }
.fb-tabs [role=tab][aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.fb-tabs [role=tab][hidden] { display: none; }
.fb-form { display: flex; flex-direction: column; gap: 12px; }
.fb-form[hidden] { display: none; }
.fb-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.fb-field textarea, .fb-field input {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); outline: none; resize: vertical; font: inherit; font-size: 14px;
}
.fb-field textarea:focus, .fb-field input:focus { border-color: var(--accent); }
.fb-count { align-self: flex-end; color: var(--warn); font-size: 12px; }
.fb-votes { display: flex; gap: 8px; }
.fb-vote {
  font-size: 20px; line-height: 1; padding: 6px 12px; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2);
}
.fb-vote:hover { border-color: var(--accent); }
.fb-vote[aria-pressed=true] { border-color: var(--accent); background: rgba(138, 164, 255, 0.16); }
.fb-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fb-chips button {
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: none; color: var(--muted); cursor: pointer; font-size: 12px;
}
.fb-chips button:hover { color: var(--text); }
.fb-chips button[aria-pressed=true] { color: var(--text); border-color: var(--accent); background: rgba(138, 164, 255, 0.12); }
.fb-name[hidden] { display: none; }
.fb-tick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.fb-sent-with { margin: 0; font-size: 12px; color: var(--faint); }
.fb-details { font-size: 12px; color: var(--faint); background: var(--panel-2); border-radius: 8px; padding: 8px 12px; }
.fb-details strong { color: var(--muted); font-weight: 600; }
.fb-details ul { margin: 6px 0 0; padding-left: 18px; }
.fb-details li { overflow-wrap: anywhere; }
.fb-actions { display: flex; align-items: center; gap: 12px; }
.fb-actions .btn { margin-left: auto; padding: 7px 18px; }
.fb-msg { font-size: 13px; color: var(--muted); }
.fb-msg.error { color: var(--fail); }
.fb-check:empty { display: none; }
.fb-thanks { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--pass); font-size: 14px; padding: 6px 0; }
.fb-thanks .btn { margin-left: auto; }
.fb-foot { margin: 14px 0 0; font-size: 12px; color: var(--faint); text-align: left; }
.fb-foot a { color: var(--muted); }

/* the offer under the Solved banner */
.fb-offer { margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.fb-offer[hidden] { display: none; }
.fb-offer-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.fb-offer-row span { margin-right: 4px; }
.fb-offer-row .fb-vote { font-size: 16px; padding: 3px 9px; }
.fb-offer-x { margin-left: auto; border: 0; background: none; color: var(--faint); font-size: 18px; cursor: pointer; padding: 0 4px; }
.fb-offer-x:hover { color: var(--text); }
.fb-offer .fb-form { margin-top: 10px; }
