/* ========== CSS Variables & Reset ========== */
:root {
  --bg: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent: #8b5cf6;

  --red: #DC2626;
  --blue: #2563EB;
  --green: #16A34A;
  --orange: #EA580C;
  --purple: #9333EA;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
  --transition: 150ms ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  font-size: 19px;  /* base text — bumped up from 16px browser default */
}

/* ========== Typography ========== */
h1 { font-size: 2.3rem; font-weight: 700; }
h2 { font-size: 1.75rem; font-weight: 600; }
h3 { font-size: 1.35rem; font-weight: 600; }
p, li { font-size: 1rem; }
.text-sm { font-size: .9rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== Layout ========== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 320px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.15rem;
}

.sidebar-header .logo .shield { font-size: 1.75rem; }
.sidebar-header .subtitle { font-size: .85rem; color: var(--text-muted); margin-top: 6px; }

.sidebar-nav {
  flex: 1;
  padding: 16px 14px;
}

.nav-section {
  margin-bottom: 20px;
}

/* Language toggle (teams only) */
.lang-toggle {
  display: flex;
  gap: 6px;
  padding: 0 12px;
}
.lang-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.lang-btn:hover { background: var(--bg-hover); color: var(--text); }
.lang-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.nav-section-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
  padding: 6px 12px 10px;
  font-weight: 700;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  font-size: 1rem;
  color: var(--text-muted);
  user-select: none;
  line-height: 1.4;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary); color: white; }
.nav-item .icon { width: 18px; text-align: center; }
.nav-item .badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: .65rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}
.nav-item.active .badge { background: rgba(255,255,255,.3); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
}

.team-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: .8rem;
}

.team-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.main-content {
  flex: 1;
  margin-left: 320px;
  padding: 32px 44px;
  max-width: 1320px;
}

/* ========== Cards ========== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: .75rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .8rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  font-family: inherit;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { cursor: pointer; }

/* ========== Login Screen ========== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-container {
  width: 100%;
  max-width: 480px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .shield { font-size: 3rem; display: block; margin-bottom: 12px; }
.login-logo h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-logo .subtitle { color: var(--text-muted); font-size: .9rem; }

.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.login-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 500;
  font-size: .9rem;
  border: none;
  transition: all var(--transition);
}
.login-tab.active { background: var(--primary); color: white; }
.login-tab:hover:not(.active) { background: var(--bg-hover); }

.login-panel { display: none; }
.login-panel.active { display: block; }

.team-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.team-select-btn {
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 500;
}
.team-select-btn:hover { border-color: var(--primary); }
.team-select-btn.selected { border-color: var(--primary); background: rgba(59,130,246,.1); }
.team-select-btn .team-icon { font-size: 1.5rem; display: block; margin-bottom: 4px; }

/* ========== Envelope Cards ========== */
.envelope-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  transition: all var(--transition);
}

.envelope-card:hover { border-color: var(--text-dim); }

.envelope-card.locked {
  opacity: .6;
}

.envelope-card.locked::after {
  content: '🔒';
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 1.2rem;
}

.envelope-card.released {
  border-color: var(--success);
}

.envelope-card.released::after {
  content: '📂';
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 1.2rem;
}

.envelope-number {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.envelope-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.envelope-module {
  font-size: .8rem;
  color: var(--text-muted);
}

/* ========== Evidence Viewer ========== */
.evidence-viewer {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.evidence-header {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.evidence-classification {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(234,179,8,.15);
  color: var(--warning);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.evidence-body {
  padding: 0;
  font-size: 1.05rem;
  line-height: 1.75;
}

/* The universal `* { margin: 0 }` reset zeros markdown paragraph margins;
   restore readable spacing between paragraphs, lists, and headings. */
.evidence-body > * { margin-bottom: 1em; }
.evidence-body p, .evidence-body ul, .evidence-body ol, .evidence-body blockquote {
  margin-bottom: 1em;
}
.evidence-body ul, .evidence-body ol {
  padding-left: 1.4em;
}
.evidence-body li { margin-bottom: 0.4em; }
.evidence-body li:last-child { margin-bottom: 0; }
.evidence-body > *:last-child { margin-bottom: 0; }

.evidence-body pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  font-size: .8rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  line-height: 1.5;
  margin: 12px 0;
}

.evidence-body code {
  background: rgba(59,130,246,.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: .85em;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.evidence-body h1, .evidence-body h2, .evidence-body h3 {
  margin-top: 1.4em;
  margin-bottom: 0.6em;
}
.evidence-body > h1:first-child,
.evidence-body > h2:first-child,
.evidence-body > h3:first-child { margin-top: 0; }

.evidence-body hr { border-color: var(--border); margin: 16px 0; }

.evidence-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: .85rem;
}

.evidence-body th, .evidence-body td {
  padding: 8px 12px;
  text-align: left;
  border: 1px solid var(--border);
}

.evidence-body th { background: var(--bg-surface); font-weight: 600; }

.evidence-body strong { color: var(--warning); }

/* ========== Quiz ========== */
.quiz-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.quiz-question {
  font-weight: 600;
  margin-bottom: 14px;
  font-size: .95rem;
}

.quiz-question .q-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: .7rem;
  margin-right: 8px;
  font-weight: 700;
}

.quiz-options { display: flex; flex-direction: column; gap: 8px; }

.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  font-size: .875rem;
}

.quiz-option:hover { border-color: var(--primary); background: rgba(59,130,246,.05); }
.quiz-option.selected { border-color: var(--primary); background: rgba(59,130,246,.1); }
.quiz-option.correct { border-color: var(--success); background: rgba(34,197,94,.1); }
.quiz-option.incorrect { border-color: var(--danger); background: rgba(239,68,68,.1); }

.quiz-option .radio {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-option.selected .radio { border-color: var(--primary); }
.quiz-option.selected .radio::after {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
}

.quiz-option.correct .radio { border-color: var(--success); }
.quiz-option.correct .radio::after { content: '✓'; background: none; color: var(--success); font-weight: bold; font-size: .8rem; }
.quiz-option.incorrect .radio { border-color: var(--danger); }
.quiz-option.incorrect .radio::after { content: '✗'; background: none; color: var(--danger); font-weight: bold; font-size: .8rem; }

.quiz-explanation {
  margin-top: 12px;
  padding: 12px;
  background: rgba(59,130,246,.08);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .85rem;
  color: var(--text-muted);
  display: none;
}

.quiz-explanation.show { display: block; }

.quiz-result {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
  margin-top: 8px;
}

/* ========== Countdown Timer ========== */
.timer-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 20px 24px;
  margin-bottom: 24px;
  text-align: center;
}
.timer-label {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.timer-display {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 3.25rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
  line-height: 1.1;
}
.timer-display.expired { color: var(--danger); }
.timer-status {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 4px;
  min-height: 1.2em;
}
.timer-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

/* ========== Scoreboard ========== */
.scoreboard-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--bg);
}

.scoreboard-rank {
  font-size: 1.3rem;
  font-weight: 700;
  width: 36px;
  text-align: center;
  color: var(--text-dim);
}

.scoreboard-rank.gold { color: #fbbf24; }
.scoreboard-rank.silver { color: #94a3b8; }
.scoreboard-rank.bronze { color: #b45309; }

.scoreboard-team {
  flex: 1;
}

.scoreboard-team .name { font-weight: 600; }

.scoreboard-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.scoreboard-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.scoreboard-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 500ms ease;
}

/* ========== Progress indicators ========== */
.progress-ring {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-ring .label {
  font-size: .8rem;
  color: var(--text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ========== Instructor Release Grid ========== */
.release-grid {
  display: grid;
  grid-template-columns: auto repeat(5, 1fr);
  gap: 2px;
  font-size: .8rem;
}

.release-grid .header {
  background: var(--bg-surface);
  padding: 8px 12px;
  font-weight: 600;
  text-align: center;
  border-radius: 4px;
}

.release-grid .row-label {
  background: var(--bg-surface);
  padding: 8px 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  border-radius: 4px;
}

.release-cell {
  padding: 6px;
  text-align: center;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.release-cell.released {
  background: rgba(34,197,94,.15);
  color: var(--success);
}

.release-cell.locked {
  background: var(--bg);
  color: var(--text-dim);
}

.release-cell:hover { opacity: .8; }

/* ========== Module Content ========== */
.module-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.module-header { margin-bottom: 1rem; }
.module-header h2 { margin: 0; }

/* Flag-type question: single masked input that shows underscores + dashes
   inline. The student types straight through; each character overwrites the
   underscore at the cursor, dashes are skipped automatically. */
.flag-pattern {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.3rem;
  flex-wrap: wrap;
}

.flag-brace {
  color: var(--text-muted);
  user-select: none;
  font-weight: 600;
}

.flag-masked-input {
  font: inherit;
  letter-spacing: 0.18em;  /* keeps underscores visually separated */
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  caret-color: var(--primary);
  /* Width computed from `--mask-len` (set inline per question) so every
     character + its letter-spacing fits without clipping. 1ch is the width
     of `0` in monospace; letter-spacing adds ~0.18em between chars, plus a
     bit of caret+safety buffer. box-sizing: content-box means padding/border
     are added on top, so the content area fits exactly. */
  box-sizing: content-box;
  width: calc(var(--mask-len, 15) * 1ch + var(--mask-len, 15) * 0.18em + 0.6ch);
}
.flag-masked-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.flag-masked-input:disabled { cursor: default; opacity: .95; }

/* Green when a team has submitted the correct answer */
.flag-masked-input.correct {
  background: rgba(22, 163, 74, 0.18);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}
/* Subtle red for a previous wrong submission that can still be retried */
.flag-masked-input.incorrect {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--danger);
}

.flag-submit {
  margin-left: 12px;
}

/* ========== Toast / Notifications ========== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .875rem;
  animation: slideIn 300ms ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar { width: 100%; position: relative; }
  .main-content { margin-left: 0; padding: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .release-grid { font-size: .7rem; }
  .team-select-grid { grid-template-columns: 1fr; }
}

/* ========== Utility ========== */
.hidden { display: none !important; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-sm { font-size: .85rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
