:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #dde3ee;
  --text: #1b2333;
  --text-muted: #5a6478;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --radius: 10px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

a { color: var(--primary); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
}

label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin: 14px 0 6px;
  color: var(--text-muted);
}

input[type=text], input[type=password], input[type=number], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

textarea {
  font-family: var(--mono);
  min-height: 140px;
  resize: vertical;
}

textarea.statement {
  font-family: inherit;
  min-height: 220px;
}

.md-toolbar {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.md-toolbar button {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.md-toolbar button:hover { background: #eef2ff; border-color: var(--primary); }

.md-editor-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.md-editor-row textarea.statement { flex: 1; min-width: 0; margin-top: 0; }
.md-preview {
  flex: 1;
  min-width: 0;
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fbfcfe;
  font-size: 14px;
}
.md-preview h1, .md-preview h2, .md-preview h3 { margin-top: 0; }
.md-preview pre { background: #f4f6fb; padding: 10px; border-radius: 8px; overflow-x: auto; }
.md-preview code { font-family: var(--mono); }
.md-preview > *:first-child { margin-top: 0; }

@media (max-width: 720px) {
  .md-editor-row { flex-direction: column; }
}

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .btn:hover { background: var(--primary-dark); }

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--primary);
}
button.secondary:hover, .btn.secondary:hover { background: #eef2ff; }

button.danger, .btn.danger {
  background: var(--danger);
  border-color: var(--danger);
}
button.danger:hover { background: #b91c1c; }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.icon-btn:hover { background: #eef2ff; border-color: var(--primary); color: var(--primary); }
.icon-btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.icon-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.icon-btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.form-actions { margin-top: 16px; }

.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.draft { background: #eef2f7; color: var(--text-muted); }
.badge.running { background: var(--success-bg); color: var(--success); }
.badge.ended { background: #eef2f7; color: var(--text-muted); }
.badge.locked { background: var(--danger-bg); color: var(--danger); }
.badge.submitted { background: var(--success-bg); color: var(--success); }
.badge.waiting { background: var(--warn-bg); color: var(--warn); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
th { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

.exam-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.exam-list-item:last-child { border-bottom: none; }
.exam-list-item .meta { color: var(--text-muted); font-size: 13px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.join-link {
  font-family: var(--mono);
  background: #f4f6fb;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  word-break: break-all;
}

.timer {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
}

/* --- Eleve exam page --- */

.eleve-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.eleve-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.eleve-header .title { font-weight: 700; flex: 1; }

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

.statement-pane {
  width: 38%;
  min-width: 280px;
  max-width: 520px;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.statement-pane h1, .statement-pane h2, .statement-pane h3 { margin-top: 0; }
.statement-pane pre { background: #f4f6fb; padding: 10px; border-radius: 8px; overflow-x: auto; }
.statement-pane code { font-family: var(--mono); }

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--text-muted);
}

.code-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.CodeMirror {
  flex: 1;
  height: 100% !important;
  font-family: var(--mono);
  font-size: 14px;
}

.run-panel {
  height: 260px;
  min-height: 120px;
  max-height: 55vh;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.run-resize-handle {
  height: 6px;
  cursor: row-resize;
  background: var(--border);
  flex-shrink: 0;
}
.run-resize-handle:hover { background: var(--primary); }

.run-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.run-tab {
  padding: 9px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
}
.run-tab:hover { background: #f4f6fb; color: var(--text); }
.run-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.run-panel-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.console-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.console-log .entry { margin-bottom: 10px; }
.console-log .cmd { color: var(--primary); font-weight: 600; }
.console-log .out { color: var(--text); }
.console-log .err { color: var(--danger); }
.console-log .hint { color: var(--text-muted); font-style: italic; }

.console-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.console-input-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: 13px;
}
.console-input-row button { white-space: nowrap; }

.tests-pane {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-size: 13px;
}
.test-summary { font-weight: 700; margin-bottom: 10px; }
.test-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.test-row:last-child { border-bottom: none; }
.test-icon { font-weight: 700; }
.test-icon.pass { color: var(--success); }
.test-icon.fail { color: var(--danger); }
.test-detail { color: var(--text-muted); font-family: var(--mono); font-size: 11.5px; margin-top: 2px; }

.violations-banner {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--warn-bg);
  color: var(--warn);
  border-top: 1px solid #fde68a;
  font-size: 13px;
}
.violations-banner .item { padding: 1px 0; }

.pyodide-status {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 14px;
}

.centered-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.center-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.center-card h2 { margin-top: 0; }

.lock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 10, 0.92);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  text-align: center;
  padding: 20px;
}
.lock-overlay .box { max-width: 420px; }
.lock-overlay h2 { color: #fecaca; font-size: 26px; }
.lock-overlay p { color: #f1d5d5; line-height: 1.5; }

[hidden] { display: none !important; }

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.save-indicator {
  font-size: 12px;
  color: var(--text-muted);
}
.save-indicator.saving { color: var(--warn); }
.save-indicator.saved { color: var(--success); }
