/* ==========================================================================
   CertifPrep – Stylesheet
   ========================================================================== */

:root {
  --bg-primary: #0b1220;
  --bg-secondary: #131c30;
  --bg-elevated: #1a2540;
  --bg-hover: #22304f;
  --border: #2a3654;
  --border-strong: #3b4a70;
  --text-primary: #f1f5fb;
  --text-secondary: #a5b2cc;
  --text-muted: #6f7d99;
  --accent: #4d8cff;
  --accent-hover: #3a75e0;
  --accent-soft: rgba(77, 140, 255, 0.15);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.18);
  --success-border: rgba(34, 197, 94, 0.55);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.18);
  --danger-border: rgba(239, 68, 68, 0.55);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.18);
  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --transition: 150ms ease;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

/* ---------- Reset / base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  line-height: 1.25;
  font-weight: 600;
}

p { margin: 0 0 1em; }

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

img { max-width: 100%; height: auto; display: block; }

/* ---------- App shell ---------- */
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    transform var(--transition);
  text-align: center;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); }

.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Form controls ---------- */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input,
.form-select {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-primary);
  color: var(--text-primary);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a5b2cc' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 20px; }

.card-title {
  font-size: 18px;
  margin: 0 0 16px;
  color: var(--text-primary);
}

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert-error {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: #fecaca;
}
.alert-info {
  background: var(--accent-soft);
  border-color: rgba(77, 140, 255, 0.4);
  color: #cfe0ff;
}

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

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.login-title {
  font-size: 24px;
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
  font-size: 14px;
}

.captcha-question {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* ==========================================================================
   Dashboard
   ========================================================================== */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header .brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.app-header .actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.dashboard-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 640px) {
  .dashboard-controls { grid-template-columns: 1fr; }
}

.mode-toggle {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-toggle button {
  flex: 1;
  padding: 11px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  font: inherit;
  transition: background var(--transition), color var(--transition);
}

.mode-toggle button.active {
  background: var(--accent);
  color: white;
}

.mode-toggle button:hover:not(.active) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.session-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.session-item .session-info {
  flex: 1;
  min-width: 200px;
}

.session-item .session-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

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

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  font-style: italic;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.badge-timed { background: var(--warn-soft); color: var(--warn); }
.badge-practice { background: var(--accent-soft); color: var(--accent); }

/* ==========================================================================
   Exam view
   ========================================================================== */
.exam-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.exam-header .left,
.exam-header .right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.exam-header .right { justify-content: flex-end; }

.exam-header .q-count {
  font-weight: 600;
}

.exam-header .exam-name {
  color: var(--text-secondary);
  font-size: 13px;
}

.timer {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  min-width: 100px;
  text-align: center;
}

.timer.warn {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-soft);
  animation: pulse 1.5s ease-in-out infinite;
}

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

.progress-bar {
  height: 4px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.progress-bar > .fill {
  height: 100%;
  background: var(--accent);
  transition: width 300ms ease;
}

/* Question card */
.question-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-top: 24px;
  box-shadow: var(--shadow);
}

.question-type-hint {
  display: inline-block;
  margin-bottom: 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 600;
}

.question-text {
  font-size: 16px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 20px;
}

.question-images,
.answer-images {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.question-images img,
.answer-images img {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  padding: 4px;
  max-width: 100%;
}

.choices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.choice {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
    transform var(--transition);
  user-select: none;
}

.choice:hover:not(.disabled) {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.choice.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice.disabled {
  cursor: default;
}

.choice.correct {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.choice.wrong {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.choice .key {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  min-width: 24px;
  color: var(--text-secondary);
}

.choice.selected .key,
.choice.correct .key,
.choice.wrong .key { color: var(--text-primary); }

.choice .text {
  flex: 1;
  line-height: 1.55;
  white-space: pre-wrap;
}

.choice .mark {
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  padding-top: 2px;
}

.choice.correct .mark { color: var(--success); }
.choice.wrong .mark { color: var(--danger); }

.exam-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* Justification */
.justification {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.justification-toggle {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  font: inherit;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
}

.justification-toggle:hover { background: var(--bg-hover); }

.justification-toggle .arrow {
  transition: transform var(--transition);
  color: var(--text-secondary);
}

.justification.open .justification-toggle .arrow {
  transform: rotate(180deg);
}

.justification-body {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  display: none;
}

.justification.open .justification-body { display: block; }

.justification-body h4 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-top: 16px;
}
.justification-body h4:first-child { margin-top: 0; }

.justification-body .correct-explanation {
  padding: 12px;
  background: var(--success-soft);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
}

.choice-explanations {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-explanation {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border-strong);
  background: var(--bg-elevated);
  font-size: 14px;
}

.choice-explanation.correct { border-color: var(--success); }
.choice-explanation.wrong { border-color: var(--danger); }

.choice-explanation .k {
  font-family: var(--font-mono);
  font-weight: 700;
  margin-right: 6px;
}

/* ==========================================================================
   Results view
   ========================================================================== */
.result-summary {
  text-align: center;
  padding: 40px 24px;
}

.result-score {
  font-size: 48px;
  font-weight: 700;
  margin: 12px 0;
}

.result-percent {
  font-size: 20px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.result-badge {
  display: inline-block;
  padding: 8px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 32px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.result-badge.pass {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.result-badge.fail {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Review list */
.review-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.review-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.review-header {
  padding: 14px 18px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: background var(--transition);
}

.review-header:hover { background: var(--bg-elevated); }

.review-header .num {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 40px;
}

.review-header .preview {
  flex: 1;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-header .status {
  font-size: 18px;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
}

.review-header .status.correct { color: var(--success); }
.review-header .status.wrong { color: var(--danger); }
.review-header .status.na { color: var(--text-muted); }

.review-body {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  display: none;
}

.review-item.open .review-body { display: block; }

.review-body .question-text {
  font-size: 15px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Utility
   ========================================================================== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  vertical-align: middle;
}

.loading-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  color: var(--text-secondary);
}

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

.hidden { display: none !important; }

.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
  .container, .container-narrow { padding: 16px; }
  .exam-header {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .exam-header .left, .exam-header .right { justify-content: center; }
  .card, .question-card { padding: 18px; }
  .result-score { font-size: 36px; }
}
