*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f14;
  --surface: #161921;
  --surface2: #1e2230;
  --surface3: #252a3a;
  --border: #2a3045;
  --border2: #3a4260;
  --accent: #6c8fff;
  --accent2: #4d6fff;
  --green: #3dd68c;
  --red: #ff6b6b;
  --amber: #ffd166;
  --text: #e8eaf6;
  --muted: #7a82a0;
  --dim: #4a5270;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'DM Sans', sans-serif;
  --display: 'Syne', sans-serif;
  /* ── Syntax highlighting colours (dark mode) ── */
  --syn-keyword: #c792ea;
  --syn-builtin: #82aaff;
  --syn-string:  #c3e88d;
  --syn-number:  #f78c6c;
  --syn-comment: #546e7a;
  --syn-op:      #89ddff;
  --editor-bg:   #0a0c10;
}

/* ── LIGHT MODE ────────────────────────────────────────────────────────────── */
body.light-mode {
  --bg: #f0f2f8;
  --surface: #ffffff;
  --surface2: #e8ecf5;
  --surface3: #dde2ef;
  --border: #cdd3e6;
  --border2: #b0bbd4;
  --accent: #3a5fd9;
  --accent2: #2a4fc9;
  --green: #1a9e5e;
  --red: #d93535;
  --amber: #b07a00;
  --text: #1a1d2e;
  --muted: #555d7a;
  --dim: #8892aa;
  /* ── Syntax highlighting colours (light mode) ── */
  --syn-keyword: #7c3aed;
  --syn-builtin: #1d4ed8;
  --syn-string:  #15803d;
  --syn-number:  #c2410c;
  --syn-comment: #6b7280;
  --syn-op:      #0369a1;
  --editor-bg:   #f8f9fc;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: var(--sans); cursor: pointer; border: none; outline: none; }
input, textarea, select { font-family: var(--sans); outline: none; }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── LAYOUT ── */
#app { height: 100vh; display: flex; flex-direction: column; }
.shell { height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; display: flex; overflow: hidden; }
.content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── NAV ── */
.nav { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0; }
.nav-logo { font-family: var(--display); font-size: 15px; font-weight: 700; color: var(--accent); letter-spacing: -0.3px; }
.nav-logo span { color: var(--text); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: white; flex-shrink: 0; }
.user-name { font-size: 13px; color: var(--muted); }

/* ── SIDEBAR ── */
.sidebar { width: 220px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-section { padding: 14px 12px 8px; font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.8px; }
.sidebar-item { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; font-size: 13px; color: var(--muted); transition: all 0.15s; border-left: 3px solid transparent; border: none; background: none; width: 100%; text-align: left; }
.sidebar-item:hover { background: var(--surface2); color: var(--text); }
.sidebar-item.active { background: rgba(108,143,255,0.08); color: var(--accent); border-left: 3px solid var(--accent); }
.sidebar-item .icon { font-size: 17px; width: 20px; text-align: center; }
.sidebar-bottom { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }
.logout-btn { width: 100%; padding: 8px; background: transparent; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-size: 13px; cursor: pointer; transition: all 0.15s; }
.logout-btn:hover { background: var(--surface2); color: var(--text); }

/* ── BUTTONS ── */
.btn { padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s; border: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #7d9fff; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: rgba(255,107,107,0.15); color: var(--red); border: 1px solid rgba(255,107,107,0.3); }
.btn-danger:hover { background: rgba(255,107,107,0.25); }
.btn-success { background: rgba(61,214,140,0.15); color: var(--green); border: 1px solid rgba(61,214,140,0.3); }
.run-btn { padding: 7px 18px; background: var(--green); color: #0d0f14; border-radius: 6px; font-weight: 600; font-size: 13px; }
.run-btn:hover { background: #52e89e; }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-group-full { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.form-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; display: block; }
.form-input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 14px; transition: border-color 0.15s; }
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--dim); }
.form-textarea { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 13px; resize: vertical; min-height: 80px; }
.form-textarea:focus { border-color: var(--accent); }
.form-select { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 13px; }

/* ── BADGES / CHIPS ── */
.badge { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.badge-admin { background: rgba(108,143,255,0.15); color: var(--accent); }
.badge-student { background: rgba(61,214,140,0.15); color: var(--green); }
.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.task-type { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; }
.type-io { background: rgba(108,143,255,0.15); color: var(--accent); }
.type-unit { background: rgba(61,214,140,0.15); color: var(--green); }
.type-both { background: rgba(255,209,102,0.15); color: var(--amber); }
.type-none { background: rgba(122,130,160,0.15); color: var(--muted); }
.type-html_checklist { background: rgba(167,139,250,0.15); color: #a78bfa; }

/* ── LOGIN ── */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 380px; }
.login-title { font-family: var(--display); font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 28px; }
.btn-login { background: var(--accent); color: #fff; width: 100%; margin-top: 8px; justify-content: center; padding: 11px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.btn-login:hover { background: #7d9fff; }
.demo-accounts { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.demo-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.demo-btn { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.15s; width: 100%; margin-bottom: 6px; }
.demo-btn:hover { border-color: var(--border2); }
.demo-name { font-size: 13px; font-weight: 500; color: var(--text); text-align: left; }
.demo-role { font-size: 11px; color: var(--muted); text-align: left; }
.error-msg { background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.3); border-radius: 8px; padding: 10px 14px; color: var(--red); font-size: 13px; margin-bottom: 14px; }

/* ── SCROLL AREAS ── */
.scroll { overflow-y: auto; }

/* ── PAGE HEADER ── */
.page-header { margin-bottom: 20px; }
.page-title { font-family: var(--display); font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 13px; }

/* ── STAT CARDS ── */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-num { font-family: var(--display); font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── SECTION CARDS ── */
.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h3 { font-family: var(--display); font-size: 15px; font-weight: 600; }

/* ── DATA TABLE ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: rgba(255,255,255,0.02); }
.action-btns { display: flex; gap: 6px; }
.prog-bar-wrap { width: 80px; height: 6px; background: var(--surface2); border-radius: 3px; }
.prog-bar { height: 100%; border-radius: 3px; background: var(--green); transition: width 0.3s; }
.user-cell { display: flex; align-items: center; gap: 8px; }
.user-avatar-sm { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 600; flex-shrink: 0; }

/* ── TASK LIST ── */
.task-list-page { flex: 1; overflow-y: auto; padding: 24px; }
.mini-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 20px; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; }
.mini-stat .num { font-family: var(--display); font-size: 22px; font-weight: 700; }
.mini-stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.task-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 10px; cursor: pointer; transition: all 0.15s; display: flex; align-items: center; gap: 16px; }
.task-card:hover { border-color: var(--border2); background: var(--surface2); transform: translateX(2px); }
.task-section-header { cursor: pointer; user-select: none; transition: background 0.15s; }
.task-section-header:hover { background: rgba(108,143,255,0.05); }
.task-status-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.task-status-icon.done { background: rgba(61,214,140,0.15); color: var(--green); }
.task-status-icon.attempt { background: rgba(255,209,102,0.15); color: var(--amber); }
.task-status-icon.none { background: var(--surface2); color: var(--dim); }
.task-info { flex: 1; }
.task-name { font-weight: 500; font-size: 15px; margin-bottom: 4px; }
.task-meta { font-size: 12px; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.score-pill { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--surface2); color: var(--muted); }
.score-pill.pass { background: rgba(61,214,140,0.15); color: var(--green); }

/* ── CODING VIEW ── */
.coding-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.coding-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.coding-header h2 { font-family: var(--display); font-size: 15px; font-weight: 600; }
.coding-body { flex: 1; display: flex; overflow: hidden; }

.instruction-panel { width: 300px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; padding: 20px; flex-shrink: 0; font-size: var(--instr-font-size, 13px); }
.instr-title { font-family: var(--display); font-size: 1.23em; font-weight: 700; margin-bottom: 8px; }
.instr-desc { font-size: 1em; color: var(--muted); line-height: 1.7; margin-bottom: 16px; }
.instr-desc .instr-para { margin-bottom: 10px; }
.instr-desc .instr-para:last-child { margin-bottom: 0; }
.instr-desc .instr-list { margin: 4px 0 12px 20px; padding: 0; }
.instr-desc .instr-list li { margin-bottom: 5px; line-height: 1.6; }
.instr-desc .instr-list:last-child { margin-bottom: 0; }
.instr-code-block {
  background: var(--editor-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin: 4px 0 14px;
  font-family: var(--mono); font-size: 0.88em; line-height: 1.65;
  white-space: pre; overflow-x: auto; tab-size: 4;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}
.hint-text .instr-para { margin-bottom: 8px; }
.hint-text .instr-para:last-child { margin-bottom: 0; }
.hint-text .instr-list { margin: 4px 0 8px 20px; padding: 0; }
.hint-text .instr-list li { margin-bottom: 4px; }
.instr-section { font-size: 0.85em; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; margin-top: 14px; }
.instr-example { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; font-family: var(--mono); font-size: 0.92em; font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
.instr-example-row { display: flex; gap: 8px; margin-bottom: 3px; }
.ex-label { color: var(--dim); min-width: 55px; flex-shrink: 0; }
.ex-value { color: var(--text); word-break: normal; overflow-wrap: break-word; }
.hint-box { background: rgba(108,143,255,0.07); border: 1px solid rgba(108,143,255,0.2); border-radius: 8px; padding: 12px; margin-top: 14px; }
.hint-label { font-size: 0.85em; color: var(--accent); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.hint-text { font-size: 1em; color: var(--muted); line-height: 1.6; }

.editor-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.editor-toolbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.editor-toolbar .file-label { font-family: var(--mono); font-size: 11px; color: var(--dim); margin-right: auto; }
.editor-area { flex: 1; overflow: hidden; position: relative; display: flex; }
/* Line-number gutter: a plain, non-scrolling-by-mouse column kept in
   vertical sync with the textarea via JS (scrollTop), the same trick
   already used to keep the highlight layer in sync below. Font size,
   line-height and top padding all match the editor exactly so each
   number lines up with its source line. */
.code-gutter {
  flex-shrink: 0; overflow: hidden; box-sizing: border-box;
  background: var(--editor-bg); color: var(--dim);
  font-family: var(--mono); font-size: var(--code-font-size, 13px); line-height: 1.7;
  padding: 16px 10px 16px 14px; text-align: right; user-select: none;
  border-right: 1px solid var(--border);
  white-space: pre;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}
/* Houses the existing highlight+textarea overlay pair — they still
   position: absolute; inset: 0; exactly as before, just against this
   wrapper as their containing block instead of .editor-area directly. */
.code-editor-body { position: relative; flex: 1; min-width: 0; overflow: hidden; }

/* ── Shared font/size for both layers ── */
.code-highlight,
textarea.code-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  font-family: var(--mono);
  font-size: var(--code-font-size, 13px);
  line-height: 1.7;
  padding: 16px;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
  /* JetBrains Mono has built-in programming ligatures (e.g. >= and !=
     render as a single glyph). That's purely visual — the underlying
     characters typed/stored are unaffected — but it looks exactly like
     unwanted autocorrect to students, so switch it off in the editor. */
  font-variant-ligatures: none;
  -webkit-font-feature-settings: "liga" 0, "calt" 0;
  font-feature-settings: "liga" 0, "calt" 0;
  word-wrap: normal;
  box-sizing: border-box;
  border: none;
}

/* ── Highlight layer: behind the textarea ── */
.code-highlight {
  background: var(--editor-bg);
  color: var(--text);
  pointer-events: none;
  z-index: 0;
  margin: 0;
}

/* ── Textarea: transparent overlay ── */
textarea.code-editor {
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  resize: none;
  z-index: 1;
  outline: none;
  -webkit-text-fill-color: transparent;
  /* disable browser spellcheck red underlines interfering */
  spellcheck: false;
}
textarea.code-editor:focus { outline: none; }

/* Disabled prev/next buttons */
button:disabled { opacity: 0.35; cursor: not-allowed; }

.output-panel { height: 210px; background: var(--editor-bg); border-top: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.output-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.output-tab { padding: 8px 16px; font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; transition: all 0.15s; border: none; border-bottom: 2px solid transparent; background: none; }
.output-tab:hover { color: var(--text); }
.output-tab.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.output-content { flex: 1; overflow-y: auto; padding: 12px 16px; font-family: var(--mono); font-size: var(--output-font-size, 12px); line-height: 1.7; color: var(--text); font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
.out-line { margin-bottom: 1px; white-space: pre-wrap; word-break: break-all; }
.out-ok { color: var(--green); }
.out-err { color: var(--red); }
.out-info { color: var(--accent); }
.out-dim { color: var(--dim); }
.test-result { padding: 8px 12px; border-radius: 6px; margin-bottom: 6px; display: flex; align-items: flex-start; gap: 10px; }
.test-result.pass { background: rgba(61,214,140,0.08); border: 1px solid rgba(61,214,140,0.2); }
.test-result.fail { background: rgba(255,107,107,0.08); border: 1px solid rgba(255,107,107,0.2); }
.test-icon { font-size: 1em; flex-shrink: 0; margin-top: 1px; }
.test-info { flex: 1; }
.test-name { font-size: 1em; font-weight: 500; color: var(--text); }
.test-detail { font-size: 0.92em; color: var(--muted); margin-top: 2px; font-family: var(--mono); font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }

/* ── ADMIN AREAS ── */
.admin-page { flex: 1; overflow-y: auto; padding: 24px; }

/* ── QUESTION BUILDER ── */
.builder-layout { flex: 1; display: flex; overflow: hidden; }
.builder-list { width: 260px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column; }
.builder-list-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.builder-list-head span { font-size: 13px; font-weight: 600; }
.qlist-item { padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: all 0.15s; border-left: 3px solid transparent; }
.qlist-item:hover { background: rgba(108,143,255,0.05); }
.qlist-item.active { background: rgba(108,143,255,0.08); border-left-color: var(--accent); }
.qlist-item.move-picked { background: rgba(255,209,102,0.12); border-left-color: var(--amber); }
.qlist-name { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.qlist-meta { font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.builder-form { flex: 1; overflow-y: auto; padding: 24px; }
.test-case-row { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; display: grid; gap: 10px; align-items: start; }
.test-case-row.io { grid-template-columns: 1fr 1fr auto; }
.test-case-row.unit { grid-template-columns: 1fr 1fr 1fr auto; }
.add-test-btn { background: rgba(108,143,255,0.07); border: 1px dashed rgba(108,143,255,0.4); border-radius: 8px; padding: 10px; text-align: center; color: var(--accent); font-size: 13px; cursor: pointer; transition: all 0.15s; margin-bottom: 4px; }
.add-test-btn:hover { background: rgba(108,143,255,0.15); }
.save-bar { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.save-bar .spacer { flex: 1; }
.saved-msg { font-size: 13px; color: var(--green); }
.test-type-btns { display: flex; gap: 8px; }

/* ── MARKBOOK ── */
/* markbook-page: flex column, fills .content, clips nothing */
.markbook-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow: hidden;  /* let children control their own scroll */
  min-height: 0;
}
/* Student "My Progress" view: no sticky table so the page itself can scroll */
.markbook-page.markbook-student {
  overflow-y: auto;
}

/* markbook-scroll: the ONE element that scrolls both axes */
.markbook-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
}
/* markbook-outer just holds the table — no overflow */
.markbook-outer {
  display: inline-block;
  min-width: 100%;
}
.markbook-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
}

/* ── Header row: sticky to top of markbook-scroll ── */
.markbook-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border2);
  border-right: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

/* ── Body cells ── */
.markbook-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  background: var(--bg);
}
.markbook-table tr:last-child td { border-bottom: none; }
.markbook-table tbody tr:hover td { background: rgba(255,255,255,0.025); }

/* ── Frozen name column: sticky left ── */
.col-freeze {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left !important;
  min-width: 175px;
  white-space: nowrap;
  box-shadow: 3px 0 8px -2px rgba(0,0,0,0.4);
}
/* Top-left corner: sticky on both axes */
.col-freeze-header {
  z-index: 3 !important;
  background: var(--surface) !important;
}
.markbook-table tbody tr:hover .col-freeze { background: var(--surface2); }

/* ── Frozen Overall column: sticky right ── */
.col-freeze-last {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--surface);
  min-width: 100px;
  box-shadow: -3px 0 8px -2px rgba(0,0,0,0.4);
}
.markbook-table tbody tr:hover .col-freeze-last { background: var(--surface2); }
.mark-cell { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; padding: 2px 8px; height: 24px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.mark-pass { background: rgba(61,214,140,0.15); color: var(--green); }
.mark-fail { background: rgba(255,107,107,0.12); color: var(--red); }
.mark-none { background: var(--surface2); color: var(--dim); }
.mark-partial { background: rgba(255,209,102,0.15); color: var(--amber); }
.mark-pending { background: rgba(108,143,255,0.15); color: var(--accent); }
/* Overdue flag on markbook cells (assigned, not yet passed, past due date) —
   layered on top of whichever mark-* colour already applies via an inset
   ring, so "overdue and failed" still reads as failed first and foremost. */
.mark-cell.mark-overdue { box-shadow: 0 0 0 2px var(--red) inset; }

/* ── MODAL ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; width: 440px; max-height: 85vh; overflow-y: auto; }
.modal h3 { font-family: var(--display); font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── LOADING / EMPTY ── */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); font-size: 13px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }

/* ── PROGRESS MARKBOOK STUDENT ── */
.my-progress-table { width: 100%; border-collapse: collapse; }
.my-progress-table th { font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.my-progress-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.my-progress-table tr:last-child td { border-bottom: none; }
.my-progress-table tbody tr:hover td { background: rgba(255,255,255,0.03); }
/* ── SECTION GROUPS (Question Builder) ── */
.section-group { }
.section-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  user-select: none;
  position: relative;
}
.section-group-header:hover { background: rgba(108,143,255,0.05); }
.section-group-header.active { background: rgba(108,143,255,0.08); }
.sec-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sec-header-text { flex: 1; min-width: 0; }
.sec-title { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec-meta  { font-size: 11px; color: var(--muted); margin-top: 1px; }
.sec-chevron { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.sec-edit-btn {
  opacity: 0; font-size: 12px; padding: 2px 6px;
  background: var(--surface3); border: 1px solid var(--border2);
  border-radius: 4px; color: var(--muted); cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.section-group-header:hover .sec-edit-btn { opacity: 1; }
.section-q-list { background: rgba(0,0,0,0.15); border-bottom: 1px solid var(--border); }
.section-q-list .qlist-item { padding-left: 28px; }
.add-q-in-section {
  padding: 8px 28px; font-size: 12px; color: var(--accent);
  cursor: pointer; transition: background 0.15s;
  border-top: 1px dashed rgba(108,143,255,0.2);
}
.add-q-in-section:hover { background: rgba(108,143,255,0.05); }

/* ── ASSIGNMENTS PAGE ── */
.assign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── HOUSE STYLE: RED / BLACK / GOLD LOGIN ────────────────────────────────── */
.login-wrap {
  background: #0a0a0a;
  position: relative;
  overflow: hidden;
}

/* Diagonal gold accent stripe */
.login-wrap::before {
  content: '';
  position: absolute;
  top: -120px; right: -120px;
  width: 420px; height: 420px;
  background: linear-gradient(135deg, #c9a227 0%, #8b6914 100%);
  border-radius: 50%;
  opacity: 0.12;
  pointer-events: none;
}
.login-wrap::after {
  content: '';
  position: absolute;
  bottom: -80px; left: -80px;
  width: 300px; height: 300px;
  background: linear-gradient(135deg, #cc1111 0%, #7a0000 100%);
  border-radius: 50%;
  opacity: 0.15;
  pointer-events: none;
}

.login-card {
  background: #111111;
  border: 1px solid #2a2a2a;
  border-top: 3px solid #c9a227;
  border-radius: 4px;
  padding: 40px;
  width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(201,162,39,0.08);
}

.login-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.login-logo-wrap img {
  max-height: 72px;
  width: auto;
  display: block;
  margin-bottom: 14px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.login-school-name {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 700;
  color: #c9a227;
  letter-spacing: 0.5px;
  text-align: center;
}

.login-title {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 28px;
  margin-top: 2px;
}

.login-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, #2a2a2a 30%, #c9a227 50%, #2a2a2a 70%, transparent);
  margin-bottom: 28px;
}

/* Override form inputs for dark login */
.login-card .form-label {
  color: #888;
  font-size: 10px;
  letter-spacing: 1.5px;
}
.login-card .form-input {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: #e8e8e8;
  border-radius: 3px;
  padding: 12px 16px;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-card .form-input:focus {
  border-color: #c9a227;
  box-shadow: 0 0 0 3px rgba(201,162,39,0.08);
  outline: none;
}
.login-card .form-input::placeholder { color: #3a3a3a; }

.btn-login {
  background: linear-gradient(135deg, #cc1111 0%, #990000 100%) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 3px !important;
  font-weight: 600 !important;
  letter-spacing: 0.5px !important;
  padding: 13px !important;
  font-size: 14px !important;
  transition: all 0.2s !important;
  box-shadow: 0 4px 16px rgba(204,17,17,0.3) !important;
}
.btn-login:hover {
  background: linear-gradient(135deg, #e01a1a 0%, #aa0000 100%) !important;
  box-shadow: 0 6px 20px rgba(204,17,17,0.45) !important;
  transform: translateY(-1px);
}
.login-card .error-msg {
  background: rgba(204,17,17,0.1);
  border: 1px solid rgba(204,17,17,0.3);
  color: #ff6b6b;
  border-radius: 3px;
}

/* ── DRAG-RESIZE HANDLES ────────────────────────────────────────────────────── */
.drag-handle-v {
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
  z-index: 2;
  touch-action: none; /* let JS handle finger drags instead of the page scrolling/zooming */
}
.drag-handle-v:hover, .drag-handle-v.dragging { background: var(--accent); }
.drag-handle-v::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 40px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.4;
}

.drag-handle-h {
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
  z-index: 2;
  touch-action: none; /* let JS handle finger drags instead of the page scrolling/zooming */
}
.drag-handle-h:hover, .drag-handle-h.dragging { background: var(--accent); }
.drag-handle-h::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  height: 2px; width: 40px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.4;
}

/* Override coding-body to support flex with measured widths */
.coding-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.instruction-panel {
  /* width set by JS drag; override default */
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.editor-panel {
  flex: 1;
  min-width: 0;
}

/* Logo settings section in admin */
.logo-upload-box {
  border: 2px dashed var(--border2);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--surface2);
}
.logo-upload-box:hover { border-color: var(--accent); background: rgba(108,143,255,0.05); }
.logo-preview { max-height: 80px; margin: 10px auto 0; display: block; }

/* ── INFO ICONS / TOOLTIPS ──────────────────────────────────────────────────── */
/* Small "i" badge used to explain parts of the coding IDE to students on
   hover (e.g. the difference between Run and Run & Test).

   The tooltip content is a single shared element appended directly to
   <body> and positioned with `position: fixed`, computed in JS from the
   icon's on-screen location at the moment it's shown — NOT a normal
   absolutely-positioned child of the icon. Several of these icons live
   inside panels that scroll (.instruction-panel has overflow-y: auto), and
   a tooltip positioned as a child of a scrolling ancestor gets silently
   clipped the moment it pops outside that ancestor's bounds. Rendering to
   <body> with fixed coordinates avoids that regardless of which panel the
   icon sits in. */
.info-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--surface3);
  border: 1px solid var(--border2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
  font-family: var(--sans);
  cursor: help;
  flex-shrink: 0;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.info-icon-wrap:hover, .info-icon-wrap:focus {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  outline: none;
}
.info-tooltip-float {
  position: fixed;
  display: none;
  width: 230px;
  max-width: calc(100vw - 16px);
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  text-align: left;
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
  z-index: 9999;
  pointer-events: none;
  --arrow-left: 50%;
}
.info-tooltip-float::after {
  content: '';
  position: absolute;
  top: 100%;
  left: var(--arrow-left);
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--surface3);
}
/* Flipped below the icon — used automatically when there isn't enough room
   above it (e.g. an icon near the top of the screen). */
.info-tooltip-float.arrow-below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--surface3);
}

.type-pseudocode { background: rgba(244,114,182,0.15); color: #f472b6; }


/* ── ADMIN TABS (Dashboard / User Management / Assignments) ─────────────────── */
.tab-bar {
  display: flex; gap: 4px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; margin-bottom: -1px;
  background: none; color: var(--muted);
  font-size: 13px; font-weight: 600;
  border: none; border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); background: rgba(108,143,255,0.06); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: rgba(108,143,255,0.08); }
.tab-count {
  min-width: 20px; padding: 1px 7px; border-radius: 10px;
  background: var(--surface2); color: var(--muted);
  font-size: 11px; font-weight: 700; text-align: center;
}
.tab-btn.active .tab-count { background: rgba(108,143,255,0.18); color: var(--accent); }


/* ── DIGITAL BADGES ─────────────────────────────────────────────────────────── */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.badge-card {
  position: relative; text-align: center; padding: 18px 14px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.badge-card.badge-new { border-color: #c9a227; box-shadow: 0 0 0 1px rgba(201,162,39,0.35), 0 6px 22px rgba(201,162,39,0.15); }
.badge-new-chip {
  position: absolute; top: 10px; right: 10px; padding: 2px 8px; border-radius: 10px;
  background: #c9a227; color: #0d0f14; font-size: 10px; font-weight: 800; letter-spacing: 0.5px;
}
.badge-name { font-family: var(--display); font-size: 14px; font-weight: 700; margin-top: 10px; }
.badge-sec { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.badge-desc { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 8px; }
.badge-date { font-size: 11px; color: var(--dim); margin-top: 8px; }


/* Light/dark mode cross-fade (see toggleLightMode in app.js) */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.45s;
  animation-timing-function: ease-in-out;
} 

/* ── ADMIN TABLES ON SMALLER SCREENS ────────────────────────────────────────── */
.admin-page .section-card { overflow-x: auto; min-width: 0; }
.action-btns { flex-wrap: wrap; }
.user-table th, .user-table td { padding: 8px 8px; }
.user-table td .form-select { max-width: 130px; }
.user-table .action-btns { gap: 4px; min-width: 150px; }
@media (max-width: 1400px) {
  .admin-page { padding: 16px; }
  .data-table th, .data-table td { padding-left: 8px; padding-right: 8px; }
}


/* Locked (not yet earned) badges link to their section */
.badge-card.badge-locked { transition: border-color 0.15s, transform 0.15s; }
.badge-card.badge-locked:hover, .badge-card.badge-locked:focus { border-color: var(--accent); transform: translateY(-2px); outline: none; }
