:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #182230;
  --muted: #4b5a6e;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --accent: #7c3aed;
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --border: #d7e0ec;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(24, 34, 48, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 800;
  font-size: 1.25rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #eef2ff;
  color: #1e3a8a;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.card, .hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.hero-card {
  margin-bottom: 20px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
}

h1 {
  margin: 0 0 6px;
  font-size: 1.65rem;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.25rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.profile-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 120px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.profile-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.profile-avatar {
  font-size: 2.2rem;
}

.profile-name {
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
}

.profile-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label, .form-row span {
  font-weight: 600;
}

input[type="text"], input[type="password"] {
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  min-height: 48px;
  width: 100%;
  color: var(--text);
  background: #fff;
}

input:focus {
  outline: none;
  border-color: var(--primary);
}

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-btn {
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.avatar-btn.selected {
  border-color: var(--primary);
  background: #dbeafe;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-sm {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

.btn-lg {
  min-height: 52px;
  font-size: 1.05rem;
}

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

.mission-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.mission-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.mission-icon {
  font-size: 2rem;
  line-height: 1;
}

.mission-num {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
}

.mission-title {
  margin: 2px 0 4px;
  font-size: 1.15rem;
}

.mission-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.mission-stats {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--success);
}

.mission-actions {
  display: flex;
  gap: 8px;
}

.mission-actions .btn {
  flex: 1;
}

.resume-banner {
  background: var(--warn-bg);
  border: 1px solid #f59e0b;
  color: var(--warn);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.exercise-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  background: #dbeafe;
  color: #1e3a8a;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}

.badge-secondary {
  background: #ede9fe;
  color: #5b21b6;
}

.autosave-pill {
  background: var(--success-bg);
  color: var(--success);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.progress-wrap {
  margin-bottom: 14px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 6px;
}

.progress-bar {
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.2s ease;
}

.question-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.q-dot {
  min-width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

.q-dot.answered {
  background: #dbeafe;
  border-color: #60a5fa;
}

.q-dot.current {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.exercise-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-prompt {
  font-size: 1.35rem;
  margin: 0;
}

.question-visual {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.choice-btn {
  min-width: 96px;
  min-height: 54px;
  font-size: 1.25rem;
  font-weight: 800;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  cursor: pointer;
  padding: 8px 18px;
}

.choice-btn.selected {
  border-color: var(--primary);
  background: #dbeafe;
  color: #1e3a8a;
}

.practice-feedback {
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 600;
}

.practice-feedback.ok {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #86efac;
}

.practice-feedback.err {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.exercise-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  margin-top: 8px;
}

.results-top {
  margin-bottom: 18px;
  text-align: center;
}

.score-big {
  font-size: 2.3rem;
  font-weight: 900;
  color: var(--primary);
  margin: 6px 0;
}

.results-errors {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.error-card {
  background: var(--surface);
  border: 2px solid #fca5a5;
  border-left: 8px solid var(--danger);
  border-radius: var(--radius);
  padding: 16px;
}

.ok-banner {
  background: var(--success-bg);
  border: 2px solid #86efac;
  color: var(--success);
  border-radius: var(--radius);
  padding: 18px;
  font-weight: 700;
  text-align: center;
}

.hint-box {
  margin-top: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
}

.results-all-details {
  margin-bottom: 18px;
}

.results-all-details summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 1.05rem;
}

.results-all-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.mini-item {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.mini-item.ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.mini-item.err {
  background: #fef2f2;
  border-color: #fecaca;
}

.results-footer {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-weight: 600;
}

.toast.error {
  background: var(--danger);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fca5a5;
  font-weight: 700;
  font-size: 0.95rem;
}

.question-visual svg {
  max-width: 100%;
  height: auto;
}

@media (max-width: 520px) {
  .topbar {
    padding: 10px 12px;
  }

  .brand {
    font-size: 1.1rem;
  }

  .container {
    padding: 14px 10px 36px;
  }

  .card,
  .hero-card {
    padding: 14px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .question-prompt {
    font-size: 1.15rem;
  }

  .profiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 10px;
  }

  .profile-card {
    padding: 12px 10px;
    min-height: 105px;
  }

  .missions-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .q-dot {
    min-width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .choice-btn {
    flex: 1 1 auto;
    min-width: 72px;
  }

  .exercise-actions {
    gap: 8px;
  }

  .exercise-actions .btn {
    flex: 1 1 calc(50% - 4px);
    padding: 10px 10px;
    font-size: 0.95rem;
  }

  .exercise-actions #btnFinish {
    flex: 1 1 100%;
  }

  .results-footer .btn {
    flex: 1 1 100%;
  }
}
