@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&family=Inter:wght@400;500;600&display=swap');

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

:root {
  --bg: #0A0A10;
  --bg-elevated: #0F0F18;
  --surface: #161620;
  --surface-hover: #1C1C2A;
  --border: #252535;
  --border-hover: #35354A;
  --accent: #8B23E5;
  --accent-dim: #6B18B5;
  --accent-glow: rgba(139, 35, 229, 0.25);
  --accent-subtle: rgba(139, 35, 229, 0.08);
  --success: #22C55E;
  --success-dim: rgba(34, 197, 94, 0.12);
  --warning: #EAB308;
  --warning-dim: rgba(234, 179, 8, 0.12);
  --error: #EF4444;
  --error-dim: rgba(239, 68, 68, 0.12);
  --text: #EEEEF2;
  --text-secondary: #A0A0B8;
  --text-muted: #6B6B85;
  --font-display: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* — Background grid texture — */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(139, 35, 229, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 35, 229, 0.02) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* — Noise grain overlay — */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #A855F7; }

/* ═══════════════════════════════════════
   TYPOGRAPHY
   ═══════════════════════════════════════ */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h1 { font-size: 2.5rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; font-weight: 600; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-mono { font-family: var(--font-mono); }

/* ═══════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════ */
.page-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.container-narrow {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ═══════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════ */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 24px;
}

.landing-card {
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.landing-header {
  text-align: center;
  margin-bottom: 40px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

.landing-title {
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--text-secondary);
  margin-top: 20px;
  letter-spacing: 0.04em;
}

.landing-subtitle {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
  padding: 8px 16px;
  background: var(--accent-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(139, 35, 229, 0.15);
  display: inline-block;
}

.landing-divider {
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 32px auto;
}

/* ═══════════════════════════════════════
   CARDS
   ═══════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.card-glow:hover {
  box-shadow: 0 0 30px var(--accent-glow), 0 4px 20px rgba(0,0,0,0.3);
  border-color: rgba(139, 35, 229, 0.3);
}

/* ═══════════════════════════════════════
   FORMS
   ═══════════════════════════════════════ */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder { color: var(--text-muted); }

textarea.form-input {
  min-height: 160px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  resize: vertical;
}

/* ═══════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-primary:hover {
  background: #9D3FF3;
  box-shadow: 0 4px 24px rgba(139, 35, 229, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-primary:disabled {
  background: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

.btn-sm { padding: 8px 16px; font-size: 0.8rem; }
.btn-lg { padding: 16px 36px; font-size: 1.05rem; }
.btn-full { width: 100%; }

/* Button loading state */
.btn.loading { pointer-events: none; }
.btn.loading .btn-text { opacity: 0; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ═══════════════════════════════════════
   TIMER
   ═══════════════════════════════════════ */
.timer-bar {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.timer-display {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  text-shadow: 0 0 20px var(--accent-glow);
}

.timer-display.warning { color: var(--warning); text-shadow: 0 0 20px rgba(234, 179, 8, 0.3); }
.timer-display.critical { color: var(--error); text-shadow: 0 0 20px rgba(239, 68, 68, 0.3); animation: pulse 1s ease-in-out infinite; }

.timer-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.timer-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.timer-user {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.timer-user strong {
  color: var(--text);
  font-weight: 600;
}

/* ═══════════════════════════════════════
   MISSION CARDS
   ═══════════════════════════════════════ */
.missions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 32px 0;
}

@media (max-width: 768px) {
  .missions-grid { grid-template-columns: 1fr; }
}

.mission-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
}

.mission-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

.mission-card.active {
  grid-column: 1 / -1;
  border-color: rgba(139, 35, 229, 0.3);
  box-shadow: 0 0 30px var(--accent-glow);
}

.mission-card-header {
  padding: 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.mission-number {
  width: 44px;
  height: 44px;
  min-width: 44px;
  background: var(--accent-subtle);
  border: 1px solid rgba(139, 35, 229, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.mission-card.submitted .mission-number {
  background: var(--success-dim);
  border-color: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.mission-info { flex: 1; }
.mission-info h3 { margin-bottom: 4px; }
.mission-info p { font-size: 0.85rem; color: var(--text-muted); }

.mission-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.mission-weight {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.mission-score {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.mission-score.has-score {
  background: var(--success-dim);
  color: var(--success);
}

.mission-score.no-score {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.mission-attempts {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Badge */
.badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-open { background: var(--accent-subtle); color: var(--accent); border: 1px solid rgba(139, 35, 229, 0.2); }
.badge-submitted { background: var(--success-dim); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.2); }
.badge-locked { background: var(--surface-hover); color: var(--text-muted); border: 1px solid var(--border); }

/* Mission expanded content */
.mission-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.mission-card.active .mission-body {
  max-height: 8000px;
}

.mission-content {
  padding: 0 24px 24px;
  border-top: 1px solid var(--border);
}

.mission-instructions {
  padding: 20px 0;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-secondary);
}

.mission-instructions h1,
.mission-instructions h2 {
  color: var(--text);
  margin: 24px 0 12px;
  font-size: 1.15rem;
}

.mission-instructions h1:first-child { margin-top: 0; }

.mission-instructions p { margin-bottom: 12px; }

.mission-instructions ul,
.mission-instructions ol {
  margin: 12px 0;
  padding-left: 24px;
}

.mission-instructions li { margin-bottom: 6px; }

.mission-instructions code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: #C084FC;
}

.mission-instructions pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 16px 0;
}

.mission-instructions pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.mission-instructions strong { color: var(--text); font-weight: 600; }

/* Submission area */
.submission-area {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.submission-area h4 { margin-bottom: 12px; }

/* Score result */
.score-result {
  padding: 16px;
  border-radius: var(--radius);
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.score-result.good { background: var(--success-dim); border: 1px solid rgba(34, 197, 94, 0.2); }
.score-result.partial { background: var(--warning-dim); border: 1px solid rgba(234, 179, 8, 0.2); }
.score-result.bad { background: var(--error-dim); border: 1px solid rgba(239, 68, 68, 0.2); }

.score-value {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
}

.score-result.good .score-value { color: var(--success); }
.score-result.partial .score-value { color: var(--warning); }
.score-result.bad .score-value { color: var(--error); }

.score-detail { font-size: 0.85rem; color: var(--text-secondary); }
.score-detail strong { color: var(--text); }

/* ═══════════════════════════════════════
   ADMIN DASHBOARD
   ═══════════════════════════════════════ */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

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

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}

.stat-value .accent { color: var(--accent); }

/* Table */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

th {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th:hover { color: var(--text-secondary); }
th.sorted { color: var(--accent); }
th.sorted::after { content: ' \u25BC'; font-size: 0.6rem; }
th.sorted.asc::after { content: ' \u25B2'; }

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:hover td { background: var(--surface-hover); }
tr:last-child td { border-bottom: none; }

td.score-cell {
  font-family: var(--font-mono);
  font-weight: 600;
}

.score-high { color: var(--success); }
.score-mid { color: var(--warning); }
.score-low { color: var(--error); }

/* Expandable row */
.candidate-detail {
  display: none;
  background: var(--bg-elevated);
}

.candidate-detail.open { display: table-row; }

.candidate-detail td {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

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

.detail-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  border: 1px solid var(--border);
}

.detail-item .label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-item .value {
  font-size: 0.9rem;
  color: var(--text);
  word-break: break-all;
}

/* ═══════════════════════════════════════
   TOOLBAR
   ═══════════════════════════════════════ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  gap: 16px;
}

.toolbar h2 { margin: 0; }

/* ═══════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
  min-width: 280px;
  max-width: 420px;
}

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

.toast.exiting { animation: slideOut 0.3s ease-in forwards; }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; }

/* ═══════════════════════════════════════
   MODAL / OVERLAY
   ═══════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 440px;
  width: 100%;
  animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.modal h3 { margin-bottom: 16px; }

/* ═══════════════════════════════════════
   PROGRESS BAR
   ═══════════════════════════════════════ */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #A855F7);
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ═══════════════════════════════════════
   FINALIZE SECTION
   ═══════════════════════════════════════ */
.finalize-section {
  padding: 32px 0;
  text-align: center;
}

.total-score-display {
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  margin: 16px 0;
}

/* ═══════════════════════════════════════
   ADMIN AUTH
   ═══════════════════════════════════════ */
.admin-auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ═══════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════ */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.pt-16 { padding-top: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ═══════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════ */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-in { animation: fadeIn 0.4s ease both; }
.fade-in-delay-1 { animation-delay: 0.1s; }
.fade-in-delay-2 { animation-delay: 0.2s; }
.fade-in-delay-3 { animation-delay: 0.3s; }
.fade-in-delay-4 { animation-delay: 0.4s; }

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */
@media (max-width: 640px) {
  h1 { font-size: 1.8rem; }
  .timer-display { font-size: 1.5rem; }
  .card { padding: 20px; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
}
