/* =========================
   Modal & Exam Results Styles
========================= */

/* =========================
   CSS Variables
========================= */
:root {
  --modal-blur-strength: 8px;

  /* Light Mode Exam Results Defaults */
  --bg-primary: var(--color-neutral-light-alt);
  --bg-card: #ffffff;
  --text-primary: #111827;
  --text-on-card: #111827;
  --text-on-pass: #ffffff;
  --text-on-fail: #ffffff;
  --border-card: #d1d5db;
  --progress-bg: #e5e7eb;
}

body.dark-mode {
  /* Dark Mode Exam Results */
  --bg-primary: var(--color-neutral-dark-alt);
  --bg-card: var(--color-neutral-dark);
  --text-primary: #f3f4f6;
  --text-on-card: #f3f4f6;
  --text-on-pass: #ffffff;
  --text-on-fail: #ffffff;
  --border-card: #374151;
  --progress-bg: #1f2937;
}

/* =========================
   Modal Base Styles
========================= */

/* Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-in-out, visibility 0s linear 0.3s;
  will-change: opacity, visibility;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s ease-in-out;
  backdrop-filter: blur(var(--modal-blur-strength));
  -webkit-backdrop-filter: blur(var(--modal-blur-strength));
}

/* Modal Window */
.modal {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-20px);
  transition: transform 0.3s ease-in-out;
  will-change: transform;
  pointer-events: auto;
}

.modal-overlay.show .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  transition: opacity 0.2s;
}

.modal-close:hover {
  opacity: 0.7;
}

.modal-close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.modal-body {
  padding: 1.5rem;
}

/* Status Modal */
.status-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1rem 2rem;
  border-radius: var(--border-radius);
  z-index: 10001; /* above overlay */
  /* animation removed — JS handles fade timing */
}

/* Prevent background scrolling when modal is open */
body.modal-open {
  overflow: hidden;
  padding-right: var(--scrollbar-width, 0px);
}

/* Fallback for browsers that don't support backdrop-filter */
@supports not (backdrop-filter: blur(4px)) {
  .modal-overlay.show {
    background: rgba(0, 0, 0, 0.75);
  }
}

/* =========================
   Exam Results Specific
========================= */
.exam-results {
  color: var(--text-primary);
  background-color: var(--bg-primary);
  padding: 1rem;
  border-radius: var(--border-radius);
}

.result-overview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
  color: var(--text-on-card);
  background-color: var(--bg-card);
  border: 1px solid var(--border-card);
}

.result-overview.pass {
  background-color: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  color: #000000; /* PASS text forced black */
}

.result-overview.fail {
  background-color: var(--color-accent-orange-light);
  border: 1px solid var(--color-accent-orange);
  color: #000000; /* FAIL text forced black */
}

.topic-progress {
  margin-bottom: 1rem;
}

/* Progress Bars */
.progress-bar-bg {
  width: 100%;
  height: 0.75rem;
  border-radius: var(--border-radius);
  overflow: hidden;
  background-color: var(--progress-bg);
}

.progress-bar-fg {
  height: 100%;
  border-radius: var(--border-radius);
  transition: width 0.5s ease-in-out;
}

.progress-bar-high { background: var(--color-primary); }
.progress-bar-medium { background: var(--color-accent-yellow); }
.progress-bar-low { background: var(--color-accent-orange); }

/* =========================
   Light Mode Overrides
========================= */
body.light-mode .modal {
  background: white;
  color: var(--color-neutral-dark);
  border: 1px solid #ccc;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

body.light-mode .modal-header {
  border-bottom: 1px solid var(--color-neutral-light);
}

body.light-mode .modal-overlay.show {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(calc(var(--modal-blur-strength) + 2px)) brightness(60%);
  -webkit-backdrop-filter: blur(calc(var(--modal-blur-strength) + 2px)) brightness(60%);
}

body.light-mode .modal-close {
  color: var(--color-neutral-dark);
}

body.light-mode .status-modal {
  background: var(--color-neutral-dark);
  color: white;
}

body.light-mode .progress-bar-bg {
  background: var(--color-neutral-light);
}

/* =========================
   Dark Mode Overrides
========================= */
body.dark-mode .modal {
  background: var(--color-neutral-dark-alt);
  color: var(--text-color-dark);
  border: 1px solid var(--border-color-dark);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

body.dark-mode .modal-header {
  border-bottom: 1px solid var(--border-color-dark);
}

body.dark-mode .modal-overlay.show {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(var(--modal-blur-strength)) brightness(90%);
  -webkit-backdrop-filter: blur(var(--modal-blur-strength)) brightness(90%);
}

body.dark-mode .modal-close {
  color: var(--text-color-dark);
}

body.dark-mode .status-modal {
  background: var(--color-neutral-dark-alt);
  color: var(--text-color-dark);
}

body.dark-mode .progress-bar-bg {
  background: var(--color-neutral-dark-alt);
}

/* =========================
   Reduced Motion
========================= */
@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal,
  .progress-bar-fg {
    transition: none !important;
  }
  .status-modal {
    animation: none !important;
  }
}
