:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #e1e4ea;
  --accent: #3157d5;
  --accent-ink: #ffffff;
  --pass: #1f8a46;
  --pass-bg: #e8f6ee;
  --fail: #c9302c;
  --fail-bg: #fdecec;
  --warn: #a15c00;
  --warn-bg: #fff4e0;
  --code-bg: #1e1e1e;
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, "Liberation Mono", monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  display: flex;
  flex-direction: column;
}
button { font: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #151b2c;
  color: #fff;
  flex: none;
}
.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: #aab3c5; }
.timer {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  background: #232b40;
  color: #dfe5f2;
}
.timer.reading { background: #5a4100; color: #ffe08a; }
.timer.working { background: #17345e; color: #cfe0ff; }
.timer.low { background: #6b1d1a; color: #ffd2cf; }
.timer.over { background: #8f1d18; color: #fff; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: #b9c0cc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2648b8; }
.btn.ghost { background: transparent; }
.topbar .btn.ghost { color: #dfe5f2; border-color: #3a4560; }
.btn.danger { color: var(--fail); }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 230px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px 8px;
}
.sidebar h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 8px 6px; }
.qlink {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 6px;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  color: var(--ink);
}
.qlink:hover { background: #f1f3f7; }
.qlink.active { background: #e9eefc; border-color: #c9d5fa; }
.qnum { font-weight: 700; }
.qtitle { font-size: 12.5px; color: #3b4456; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qstatus { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.qstatus.pass { color: var(--pass); }
.qstatus.partial { color: var(--warn); }
.qstatus.fail { color: var(--fail); }
.hurdles { margin: 14px 8px 4px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; color: #3b4456; line-height: 1.5; }

.workspace { flex: 1; display: grid; grid-template-columns: minmax(320px, 40%) 1fr; min-width: 0; min-height: 0; }

/* ---------- question spec ---------- */
.spec { overflow-y: auto; padding: 18px 22px 40px; background: var(--panel); border-right: 1px solid var(--line); line-height: 1.55; }
.spec h2 { margin: 0 0 4px; font-size: 20px; }
.spec h4 { margin: 18px 0 6px; font-size: 14px; }
.spec code { font-family: var(--mono); font-size: 12.5px; background: #f0f2f6; padding: 1px 4px; border-radius: 4px; }
.spec pre { font-family: var(--mono); font-size: 12.5px; background: #f6f7f9; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; line-height: 1.45; }
.spec pre code { background: none; padding: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f6; color: #3b4456; }
.chip.marks { background: #e9eefc; color: #2240a8; font-weight: 600; }
.chip.hurdle { background: #fff1d6; color: #7a4a00; }
.chip.leak { background: #e8f6ee; color: #1b6e3a; }
.chip.forbid { background: #fdecec; color: #9b2420; }
.note { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 22px; padding-top: 10px; }

/* ---------- coding area ---------- */
.coding { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.editor-bar { display: flex; align-items: center; gap: 10px; padding: 7px 10px; background: #252526; color: #ccc; flex: none; }
.filename { font-family: var(--mono); font-size: 13px; color: #fff; background: #1e1e1e; padding: 4px 10px; border-radius: 4px 4px 0 0; border-top: 2px solid var(--accent); }
.save-state { font-size: 12px; color: #8a8f98; }
.editor-actions { margin-left: auto; display: flex; gap: 6px; }
.editor-bar .btn.ghost { color: #ddd; border-color: #444; }
.editor-bar .btn:not(.primary):not(.ghost) { background: #2f6e3b; border-color: #2f6e3b; color: #fff; }
.editor { flex: 1 1 55%; min-height: 160px; overflow: hidden; background: var(--code-bg); }
.editor .cm-editor { height: 100%; }
.editor .cm-editor.cm-focused { outline: none; }

.panel { flex: 1 1 45%; min-height: 180px; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); flex: none; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab .badge { margin-left: 6px; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #eef1f6; }
.tab .badge.pass { background: var(--pass-bg); color: var(--pass); }
.tab .badge.fail { background: var(--fail-bg); color: var(--fail); }
.tab-body { flex: 1; overflow: auto; padding: 10px 12px; min-height: 0; display: flex; flex-direction: column; gap: 8px; }

.run-inputs { display: flex; gap: 10px; flex: none; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 200px; }
.field.grow { flex: 1; }
.field input, .field textarea { font-family: var(--mono); font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid #c9d5fa; border-color: var(--accent); }

.console { flex: 1; margin: 0; min-height: 90px; background: #0f1320; color: #e6e9ef; font-family: var(--mono); font-size: 13px; line-height: 1.45; padding: 10px 12px; border-radius: 6px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.console .cmd { color: #8ab4ff; }
.console .err { color: #ff8f8a; }
.console .warn { color: #ffd479; }
.console .ok { color: #8ee6a8; }
.console .dim { color: #8a93a6; }

/* ---------- autotest results ---------- */
.test-results { display: flex; flex-direction: column; gap: 8px; }
.summary { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.summary .big { font-size: 15px; }
.test { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.test > summary { list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: center; padding: 7px 10px; font-family: var(--mono); font-size: 12.5px; }
.test > summary::-webkit-details-marker { display: none; }
.test.pass > summary { background: var(--pass-bg); }
.test.fail > summary { background: var(--fail-bg); }
.result-tag { font-family: system-ui, sans-serif; font-weight: 700; font-size: 12px; min-width: 52px; }
.test.pass .result-tag { color: var(--pass); }
.test.fail .result-tag { color: var(--fail); }
.test-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.test-body h5 { margin: 4px 0 2px; font-size: 12px; color: var(--muted); }
.test-body pre { margin: 0; font-family: var(--mono); font-size: 12.5px; background: #f6f7f9; border: 1px solid var(--line); border-radius: 5px; padding: 6px 8px; white-space: pre-wrap; word-break: break-word; }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diff .line-bad { background: #ffd9d6; }
.reason { color: var(--fail); font-weight: 600; font-size: 13px; }
.hint { color: var(--warn); font-size: 12.5px; }

.shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 16px; font-size: 13px; }
kbd { font-family: var(--mono); font-size: 11.5px; background: #f0f2f6; border: 1px solid #d3d8e1; border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; }
.muted { color: var(--muted); }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(14, 18, 30, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 12px; max-width: 760px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 24px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); line-height: 1.55; }
.modal h2 { margin-top: 0; }
.modal table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.modal th, .modal td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.modal td.num, .modal th.num { text-align: right; font-variant-numeric: tabular-nums; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal ul { padding-left: 20px; }
.pill { font-weight: 700; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.pill.pass { background: var(--pass-bg); color: var(--pass); }
.pill.fail { background: var(--fail-bg); color: var(--fail); }
.progress { height: 6px; background: #eef1f6; border-radius: 99px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.solution-box { margin-top: 18px; }
.solution-box pre { max-height: 420px; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .spec { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
  .sidebar { width: 170px; }
}
@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; display: flex; overflow-x: auto; padding: 6px; }
  .sidebar h3, .hurdles { display: none; }
  .qlink { width: auto; grid-template-columns: auto auto; }
  .qlink .qtitle { display: none; }
  .run-inputs { flex-direction: column; }
}
