/* ==========================================================================
   Civil Service Examination Reviewer - application styles
   Layered on top of Bootstrap 5.3. All colours are driven by CSS custom
   properties so light and dark mode share one set of rules.
   ========================================================================== */

:root {
  --csr-brand: #1d4ed8;
  --csr-brand-strong: #1e3a8a;
  --csr-brand-soft: rgba(29, 78, 216, 0.08);
  --csr-accent: #0ea5e9;
  --csr-surface: #ffffff;
  --csr-surface-muted: #f4f6fb;
  --csr-border: rgba(15, 23, 42, 0.09);
  --csr-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --csr-shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --csr-navbar-bg: rgba(255, 255, 255, 0.88);
  --csr-hero-from: #1e3a8a;
  --csr-hero-to: #0ea5e9;
  --csr-radius: 14px;
  --csr-transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-bs-theme="dark"] {
  --csr-brand: #60a5fa;
  --csr-brand-strong: #93c5fd;
  --csr-brand-soft: rgba(96, 165, 250, 0.14);
  --csr-accent: #38bdf8;
  --csr-surface: #161b26;
  --csr-surface-muted: #10141c;
  --csr-border: rgba(148, 163, 184, 0.18);
  --csr-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --csr-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --csr-navbar-bg: rgba(17, 22, 32, 0.9);
  --csr-hero-from: #0f172a;
  --csr-hero-to: #1e3a8a;

  --bs-body-bg: #0b0f17;
  --bs-body-color: #e2e8f0;
}

/* --------------------------------------------------------------- layout -- */
html,
body {
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bs-body-bg);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

[data-bs-theme="light"] body {
  background-color: var(--csr-surface-muted);
}

h1, h2, h3, h4, h5, h6 {
  letter-spacing: -0.02em;
}

.page-header {
  border-bottom: 1px solid var(--csr-border);
  padding-bottom: 1rem;
}

/* -------------------------------------------------------------- navbar --- */
.app-navbar {
  background-color: var(--csr-navbar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--csr-border);
  padding-block: 0.6rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--csr-hero-from), var(--csr-hero-to));
  color: #fff;
  font-size: 1.05rem;
  box-shadow: var(--csr-shadow);
}

.brand-text {
  font-weight: 700;
  letter-spacing: -0.03em;
}

.app-navbar .nav-link {
  font-weight: 500;
  border-radius: 8px;
  padding-inline: 0.75rem;
  transition: background-color var(--csr-transition), color var(--csr-transition);
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
  background-color: var(--csr-brand-soft);
  color: var(--csr-brand);
}

.btn-theme-toggle {
  border: 1px solid var(--csr-border);
  background: transparent;
  color: var(--bs-body-color);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--csr-transition), transform var(--csr-transition);
}

.btn-theme-toggle:hover {
  background-color: var(--csr-brand-soft);
  transform: rotate(-12deg);
}

[data-bs-theme="light"] .theme-icon-light,
[data-bs-theme="dark"] .theme-icon-dark {
  display: none;
}

.btn-outline-light-subtle {
  border: 1px solid var(--csr-border);
  color: var(--bs-body-color);
}

.btn-outline-light-subtle:hover {
  background-color: var(--csr-brand-soft);
  color: var(--csr-brand);
}

.avatar-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--csr-hero-from), var(--csr-hero-to));
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---------------------------------------------------------------- hero --- */
.hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--csr-hero-from) 0%, var(--csr-hero-to) 100%);
  color: #fff;
  padding-block: clamp(2.5rem, 8vw, 5rem);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.18), transparent 42%),
    radial-gradient(circle at 85% 75%, rgba(255, 255, 255, 0.12), transparent 45%);
  pointer-events: none;
}

.hero > * {
  position: relative;
  z-index: 1;
}

.hero .lead {
  color: rgba(255, 255, 255, 0.86);
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------------------- cards --- */
.card,
.surface {
  background-color: var(--csr-surface);
  border: 1px solid var(--csr-border);
  border-radius: var(--csr-radius);
  box-shadow: var(--csr-shadow);
}

.card {
  transition: transform var(--csr-transition), box-shadow var(--csr-transition);
}

.card-hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--csr-shadow-lg);
}

.stat-card {
  padding: 1.25rem;
  height: 100%;
}

.stat-card .stat-value {
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bs-secondary-color);
  font-weight: 600;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background-color: var(--csr-brand-soft);
  color: var(--csr-brand);
}

.category-tile {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 1.1rem;
  border-radius: var(--csr-radius);
  border: 1px solid var(--csr-border);
  background-color: var(--csr-surface);
  height: 100%;
  transition: transform var(--csr-transition), box-shadow var(--csr-transition),
    border-color var(--csr-transition);
}

.category-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--csr-shadow-lg);
  border-color: var(--csr-brand);
}

/* ------------------------------------------------------------ questions -- */
.question-card {
  border-radius: var(--csr-radius);
}

.question-stem {
  font-size: 1.05rem;
  line-height: 1.65;
  white-space: pre-line;
}

.question-passage {
  background-color: var(--csr-surface-muted);
  border-left: 3px solid var(--csr-brand);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  font-size: 0.94rem;
  line-height: 1.7;
  white-space: pre-line;
}

.choice-list {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 0.95rem;
  border: 1.5px solid var(--csr-border);
  border-radius: 11px;
  background-color: var(--csr-surface);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--csr-transition), background-color var(--csr-transition),
    transform var(--csr-transition);
}

.choice:hover {
  border-color: var(--csr-brand);
  background-color: var(--csr-brand-soft);
}

.choice:active {
  transform: scale(0.995);
}

.choice input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-letter {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background-color: var(--csr-surface-muted);
  border: 1px solid var(--csr-border);
  font-weight: 700;
  font-size: 0.85rem;
}

.choice-text {
  flex: 1 1 auto;
  line-height: 1.5;
}

.choice.is-selected {
  border-color: var(--csr-brand);
  background-color: var(--csr-brand-soft);
}

.choice.is-selected .choice-letter {
  background-color: var(--csr-brand);
  border-color: var(--csr-brand);
  color: #fff;
}

.choice.is-correct {
  border-color: var(--bs-success);
  background-color: rgba(25, 135, 84, 0.1);
}

.choice.is-correct .choice-letter {
  background-color: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}

.choice.is-wrong {
  border-color: var(--bs-danger);
  background-color: rgba(220, 53, 69, 0.1);
}

.choice.is-wrong .choice-letter {
  background-color: var(--bs-danger);
  border-color: var(--bs-danger);
  color: #fff;
}

.answer-reveal {
  border-top: 1px dashed var(--csr-border);
  margin-top: 1rem;
  padding-top: 1rem;
  animation: csr-fade-in 220ms ease-out;
}

.explanation-box {
  background-color: var(--csr-surface-muted);
  border-radius: 10px;
  padding: 0.9rem 1.05rem;
  font-size: 0.94rem;
  line-height: 1.65;
  white-space: pre-line;
}

/* --------------------------------------------------------------- timer --- */
.exam-shell {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}

@media (min-width: 992px) {
  .exam-shell {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }
}

.exam-sidebar {
  position: sticky;
  top: 5rem;
}

.timer-box {
  text-align: center;
  padding: 1rem;
  border-radius: var(--csr-radius);
  background-color: var(--csr-surface);
  border: 1px solid var(--csr-border);
}

.timer-value {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.timer-box.is-warning {
  border-color: var(--bs-warning);
}

.timer-box.is-warning .timer-value {
  color: var(--bs-warning);
}

.timer-box.is-critical {
  border-color: var(--bs-danger);
  animation: csr-pulse 1.4s ease-in-out infinite;
}

.timer-box.is-critical .timer-value {
  color: var(--bs-danger);
}

.navigator-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 0.4rem;
}

.nav-dot {
  aspect-ratio: 1 / 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1.5px solid var(--csr-border);
  background-color: var(--csr-surface);
  color: var(--bs-body-color);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  position: relative;
  transition: transform var(--csr-transition), border-color var(--csr-transition);
}

.nav-dot:hover {
  transform: translateY(-2px);
  border-color: var(--csr-brand);
  color: var(--csr-brand);
}

.nav-dot.is-answered {
  background-color: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}

.nav-dot.is-current {
  outline: 2px solid var(--csr-brand);
  outline-offset: 2px;
}

.nav-dot.is-flagged::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: var(--bs-warning);
  border: 1.5px solid var(--csr-surface);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: middle;
}

/* -------------------------------------------------------------- charts --- */
.donut {
  --donut-size: 170px;
  width: var(--donut-size);
  height: var(--donut-size);
  transform: rotate(-90deg);
}

.donut-track {
  stroke: var(--csr-border);
}

.donut-label {
  transform: rotate(90deg);
  transform-origin: center;
}

.bar-row + .bar-row {
  margin-top: 0.9rem;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background-color: var(--csr-surface-muted);
  overflow: hidden;
  border: 1px solid var(--csr-border);
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--csr-brand), var(--csr-accent));
  transition: width 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

.histogram {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  height: 150px;
}

.histogram-bar {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  height: 100%;
}

.histogram-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--csr-accent), var(--csr-brand));
  transition: height 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* -------------------------------------------------------------- result --- */
.result-banner {
  border-radius: var(--csr-radius);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.result-banner.is-passed {
  background: linear-gradient(135deg, #047857, #10b981);
}

.result-banner.is-failed {
  background: linear-gradient(135deg, #9f1239, #ef4444);
}

.result-score {
  font-size: clamp(2.6rem, 9vw, 4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
}

/* --------------------------------------------------------------- misc ---- */
.app-footer {
  background-color: var(--csr-surface);
  border-top: 1px solid var(--csr-border);
}

.footer-link {
  color: var(--bs-body-color);
  text-decoration: none;
}

.footer-link:hover {
  color: var(--csr-brand);
}

.badge-soft {
  background-color: var(--csr-brand-soft);
  color: var(--csr-brand);
  font-weight: 600;
}

.bookmark-btn.is-active {
  color: var(--bs-warning);
}

.empty-state {
  text-align: center;
  padding: clamp(2rem, 8vw, 4rem) 1rem;
  color: var(--bs-secondary-color);
}

.empty-state i {
  font-size: 2.75rem;
  opacity: 0.45;
  display: block;
  margin-bottom: 0.75rem;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background-color: var(--csr-surface);
  border-top: 1px solid var(--csr-border);
  padding: 0.75rem 0;
  z-index: 5;
}

/* ------------------------------------------------------------ animation -- */
@keyframes csr-fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes csr-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
}

.fade-in-up {
  animation: csr-fade-in-up 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes csr-fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------- printing -- */
@media print {
  .app-navbar,
  .app-footer,
  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
