/* ===================================================================== */
/* Enhanced Modal Styles for Pandoc-WASM Mathematical Playground        */
/* Integrated with Playground's Sophisticated Design System             */
/* WCAG 2.2 AA Compliant with Warm Aesthetic                           */
/* Responsive & High-Zoom Optimized Structure                           */
/* ===================================================================== */

/* ===== STRUCTURE SECTION - PRIORITIZED USER PATTERNS ===== */

.universal-modal {
  padding: 0;
  border: none;
  background: transparent;
  max-width: none;
  max-height: none;
  color: var(--body-text);
  font-family: var(
    --font-family-sans,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif
  );
  line-height: 1.6;
}

.universal-modal::backdrop {
  background: rgba(0, 19, 29, 0.7); /* Playground dark blue with opacity */
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
}

.universal-modal-container {
  background: var(--sidebar-bg); /* Playground sidebar background */
  border: 2px solid var(--sidebar-border); /* Playground border system */
  border-radius: 4px;
  box-shadow: 0 10px 30px var(--sidebar-shadow),
    0 4px 12px rgba(0, 19, 29, 0.15); /* Enhanced shadow system */
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: all 0.3s ease;
}

/* Responsive modal: Remove sticky header at high zoom/small viewports */
@media (max-height: 500px), (max-width: 480px) {
  .universal-modal-container {
    overflow-y: auto;
    display: block;
  }

  .universal-modal-body {
    flex: none;
    overflow-y: visible;
    padding-bottom: 4rem;
  }

  .universal-modal-body.has-status {
    padding-bottom: 5rem;
  }
}

/* Even more aggressive for very constrained spaces */
@media (max-height: 400px) {
  .universal-modal-container {
    max-height: 95vh;
  }
}

/* ===== MODAL HEADER - PLAYGROUND SOPHISTICATED STYLING ===== */
.universal-modal-header {
  padding: 1.5rem 1.5rem 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface-color); /* Playground surface colour */
  border-bottom: 1px solid var(--sidebar-border);
  transition: background-color 0.3s ease;
}

.universal-modal-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;

  transition: all 0.3s ease;
}

/* Type-specific icon colours - Playground palette */
.universal-modal-icon .infoModalIcon {
  color: var(--link-color); /* Playground primary colour */
}

.universal-modal-icon .warningModalIcon {
  color: var(--warning-color); /* Playground warning colour */
}

.universal-modal-icon .errorModalIcon {
  color: var(--error-color); /* Playground error colour */
}

.universal-modal-icon .successModalIcon {
  color: var(--success-color); /* Playground success colour */
}

.universal-modal-icon .confirmModalIcon {
  color: var(--heading-color); /* Playground heading colour */
}

.universal-modal-heading {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--heading-color); /* Playground heading colour */
  flex: 1;
  line-height: 1.2; /* Ensures consistent text baseline */
  transition: color 0.3s ease;
}

.universal-modal-close {
  background: var(--surface-color);
  color: var(--body-text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  margin: -0.25rem -0.25rem 10px 0;
  border-radius: 8px; /* Playground border radius */
  flex-shrink: 0;
  outline: 0.2rem solid transparent;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.universal-modal-close::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.universal-modal-close:hover::before {
  transform: translateX(100%);
}

.universal-modal-close:hover {
  background: var(--body-bg);
  border-color: var(--link-color);
  color: var(--link-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--sidebar-shadow);
}

.universal-modal-close:focus-visible {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
  background-color: var(--focus-bg);
  border-color: var(--link-color);
}

.universal-modal-close:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--sidebar-shadow);
}

/* ===== MODAL BODY - PLAYGROUND CONTENT STYLING ===== */
.universal-modal-body {
  padding: 1.5rem;
  flex: 1;
  overflow-y: auto;
  padding-bottom: 4rem;
  background: var(--body-bg); /* Playground body background */
  transition: background-color 0.3s ease;
}

.universal-modal-body.has-status {
  padding-bottom: 5rem;
}

.universal-modal-body h1,
.universal-modal-body h2,
.universal-modal-body h3,
.universal-modal-body h4,
.universal-modal-body h5,
.universal-modal-body h6 {
  color: var(--heading-color); /* Playground heading colour */
  margin-top: 0;
  margin-bottom: 1rem;
  font-weight: 600;
  transition: color 0.3s ease;
}

.universal-modal-body p {
  margin-bottom: 1rem;
  color: var(--body-text); /* Playground body text */
  transition: color 0.3s ease;
}

.universal-modal-body ul,
.universal-modal-body ol {
  margin-bottom: 1rem;
  padding-left: 2rem;
}

.universal-modal-body li {
  margin-bottom: 0.5rem;
  color: var(--body-text); /* Playground body text */
  transition: color 0.3s ease;
}

.universal-modal-body details {
  border: 1px solid var(--sidebar-border);
  border-radius: 8px; /* Playground border radius */
  padding: 1rem;
  margin: 1rem 0;
  background: var(--surface-color); /* Playground surface colour */
  transition: all 0.3s ease;
}

.universal-modal-body summary {
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem;
  margin: -0.5rem;
  border-radius: 4px;
  transition: all 0.3s ease;
  color: var(--heading-color); /* Playground heading colour */
}

.universal-modal-body summary:hover {
  background: var(--body-bg);
  color: var(--link-color);
}

.universal-modal-body summary:focus-visible {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
  background-color: var(--focus-bg);
}

/* ===== MODAL FOOTER - PLAYGROUND SURFACE STYLING ===== */
.universal-modal-footer {
  padding: 0 1.5rem 1.5rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  background: var(--surface-color); /* Playground surface colour */
  border-top: 1px solid var(--sidebar-border);
  transition: background-color 0.3s ease;
}

/* ===== MODAL BUTTONS - PLAYGROUND SOPHISTICATED STYLING ===== */
.universal-modal-button {
  border-radius: 8px;
  border: 2px solid var(--sidebar-border);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  min-width: 80px;
  display: inline-flex;
  padding: 15px;
  margin: 20px 20px 0 0;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Button Content Wrapper */
.universal-modal-button-content {
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  justify-content: center;
}

/* Primary Button - Export Button Style */
.universal-modal-button-primary {
  background: var(--link-hover);
  color: var(--body-bg);
  box-shadow: 0 4px 12px rgba(0, 46, 59, 0.25);
}

.universal-modal-button-primary:focus-visible {
  background: var(--link-hover);
}

.universal-modal-button-primary:hover::before {
  transform: translateX(100%);
}

.universal-modal-button-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 46, 59, 0.35);
}

.universal-modal-button-primary:active {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 46, 59, 0.25);
}

/* Secondary Button - Playground Secondary Style */
.universal-modal-button-secondary {
  background: var(--surface-color);
  color: var(--body-text);
  border: 2px solid var(--body-text);
  box-shadow: 0 2px 4px var(--sidebar-shadow);
}

.universal-modal-button-secondary:hover {
  background: var(--body-bg);
  border-color: var(--link-color);
  color: var(--link-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--sidebar-shadow);
}

/* Success Button - Playground Success Style */
.universal-modal-button-success {
  background: var(--success-color);
  color: var(--body-bg);
  box-shadow: 0 4px 12px rgba(10, 93, 58, 0.25);
}

.universal-modal-button-success::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.universal-modal-button-success:hover::before {
  transform: translateX(100%);
}

.universal-modal-button-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(10, 93, 58, 0.35);
}

/* Button Focus States - Playground Pattern */
.universal-modal-button:focus {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
}

.universal-modal-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.universal-modal-button:disabled::before {
  display: none;
}

/* ===== MODAL INPUT - PLAYGROUND FORM STYLING ===== */
.universal-modal-input {
  width: 100%;
  padding: 0.5rem;
  border: 2px solid var(--sidebar-border);
  border-radius: 8px; /* Playground border radius */
  font-size: 1rem;
  margin-top: 0.5rem;
  background: var(--body-bg);
  color: var(--body-text);
  font-family: var(--font-family-mono);
  transition: all 0.3s ease;
}

.universal-modal-input:hover {
  border-color: var(--link-color);
}

.universal-modal-input:focus {
  outline: 0;
  border-color: var(--link-color);
  box-shadow: 0 0 0 3px var(--focus-bg);
  outline-offset: 2px;
}

/* ===== ENHANCED STATUS NOTIFICATION SYSTEM - USER PRIORITY ===== */
.universal-modal-status {
  backdrop-filter: blur(8px);
  padding: 0.75rem 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  z-index: 10;
  transform: translateY(100%);
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;

  /* Default positioning for normal viewports */
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

/* Normal viewport: absolute positioning works fine */
.universal-modal-status.normal-viewport {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

/* High zoom viewport: dynamic positioning via JavaScript */
.universal-modal-status.scrollable-viewport {
  position: fixed;
  /* Left, right, bottom set dynamically by JavaScript */
}

.universal-modal-status.show {
  transform: translateY(0);
  opacity: 1;
}

/* Status States - Playground Gradient System */
.universal-modal-status.status-success {
  background: var(--success-color);
  color: var(--body-bg);
  box-shadow: 0 0 20px rgba(10, 93, 58, 0.3);
}

.universal-modal-status.status-error {
  background: var(--error-color);
  color: var(--body-bg);
  box-shadow: 0 0 20px rgba(139, 38, 53, 0.3);
}

.universal-modal-status.status-warning {
  background: var(--warning-color);
  color: var(--body-bg);
  box-shadow: 0 0 20px rgba(139, 69, 19, 0.3);
}

.universal-modal-status.status-info {
  background: var(--link-color);
  color: var(--body-bg);
  box-shadow: 0 0 20px rgba(0, 46, 59, 0.3);
}

.universal-modal-status-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.universal-modal-status-text {
  flex: 1;
  line-height: 1.4;
  font-weight: 500;
  font-size: 0.875rem;
}

.universal-modal-status-dismiss {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: 0.5rem;
  border-radius: 3px;
  font-size: 1.2rem;
  opacity: 0.8;
  flex-shrink: 0;
  transition: all 0.2s ease;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.universal-modal-status-dismiss:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.universal-modal-status-dismiss:focus {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
}

.universal-modal-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--sidebar-border);
  border-top: 2px solid var(--link-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.universal-modal-status.status-long {
  padding: 1rem 1.5rem;
  text-align: left;
  min-height: auto;
  max-height: 120px;
  overflow-y: auto;
}

.universal-modal-status.status-long .universal-modal-status-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== MODAL SIZE VARIANTS - USER PRIORITY ===== */
.universal-modal-small .universal-modal-container {
  width: 400px;
  max-height: 90vh;
}
.universal-modal-medium .universal-modal-container {
  width: 650px;
  max-height: 90vh;
}
.universal-modal-large .universal-modal-container {
  width: 800px;
}
.universal-modal-fullscreen .universal-modal-container {
  width: 90vw;
  height: 100vh;
  border-radius: 0;
  max-height: none;
}

/* ===== SCORM INSTRUCTIONS SPECIFIC STYLING ===== */
.scorm-instructions-modal {
  max-width: none;
}

.scorm-instructions-modal .instructions-quick {
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  background: var(--surface-color); /* Playground surface colour */
  border: 1px solid var(--sidebar-border);
  border-radius: 8px; /* Playground border radius */
  transition: background-color 0.3s ease;
}

.scorm-instructions-modal .instructions-quick h3 {
  color: var(--heading-color); /* Playground heading colour */
  margin-bottom: 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  transition: color 0.3s ease;
}

.scorm-instructions-modal .instructions-quick ol {
  font-size: 1.1rem;
  line-height: 1.6;
}

.scorm-instructions-modal .instructions-quick li {
  margin-bottom: 0.75rem;
  font-weight: 500;
  color: var(--body-text);
  transition: color 0.3s ease;
}

.scorm-instructions-modal .instructions-detailed {
  margin: 1.5rem 0;
}

.scorm-instructions-modal .instructions-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--sidebar-border);
}

/* Copy Instructions Button - Special Styling */
.copy-instructions-btn {
  background: var(--link-color);
  color: var(--body-bg);
  border: none;
  border-radius: 12px;
  padding: 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 46, 59, 0.25);
  transition: all 0.3s ease;
  min-width: 120px;
}

.copy-instructions-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    transparent,
    rgba(255, 255, 255, 0.15),
    transparent
  );
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.copy-instructions-btn:hover::before {
  transform: translateX(100%);
}

.copy-instructions-btn:hover {
  background: var(--link-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 46, 59, 0.35);
}

.copy-instructions-btn .universal-modal-button-content {
  padding: 0.75rem 1.5rem;
}

/* View README Button - Secondary Style */
.view-readme-btn {
  background: var(--surface-color);
  color: var(--body-text);
  border: 2px solid var(--sidebar-border);
  border-radius: 12px;
  padding: 0;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px var(--sidebar-shadow);
  min-width: 120px;
}

.view-readme-btn:hover {
  background: var(--body-bg);
  border-color: var(--link-color);
  color: var(--link-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--sidebar-shadow);
}

.view-readme-btn .universal-modal-button-content {
  padding: 0.75rem 1.5rem;
}

/* ===== ANIMATIONS WITH REDUCED MOTION SUPPORT - USER PRIORITY ===== */
@media (prefers-reduced-motion: no-preference) {
  .universal-modal {
    animation: modal-scale-in 0.3s ease-out;
  }

  .universal-modal[closing] {
    animation: modal-scale-out 0.2s ease-in;
  }

  @keyframes modal-scale-in {
    from {
      opacity: 0;
      transform: scale(0.8);
    }
    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  @keyframes modal-scale-out {
    from {
      opacity: 1;
      transform: scale(1);
    }
    to {
      opacity: 0;
      transform: scale(0.8);
    }
  }
}

/* ===== RESPONSIVE ADJUSTMENTS - USER PRIORITY ===== */
@media (max-width: 768px) {
  .universal-modal-small .universal-modal-container,
  .universal-modal-medium .universal-modal-container,
  .universal-modal-large .universal-modal-container {
    width: 95vw;
    max-height: 90vh;
  }

  .universal-modal-header {
    padding: 1rem;
  }

  .universal-modal-body {
    padding: 1rem;
  }

  .universal-modal-footer {
    padding: 0 1rem 1rem 1rem;
    flex-direction: column;
  }

  .universal-modal-button {
    width: 100%;
    min-width: auto;
  }

  .scorm-instructions-modal .instructions-actions {
    flex-direction: column;
  }

  .universal-modal-heading {
    font-size: 1.125rem;
  }

  .universal-modal-close {
    width: 2rem;
    height: 2rem;
    font-size: 1.25rem;
  }
}

/* ===== STABILISE MODAL CONTAINER AT HIGH ZOOM - USER PRIORITY ===== */
@media (max-height: 500px), (max-width: 480px), (min-zoom: 2) {
  .universal-modal-container {
    /* Force consistent overflow behaviour */
    overflow-y: scroll; /* Changed from auto to always show scrollbar */
    overflow-x: hidden;

    /* Ensure smooth scrolling */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  .universal-modal-body {
    /* Prevent content from touching edges */
    margin-right: 0.5rem; /* Space for scrollbar */
  }
}

/* ===== HIGH CONTRAST MODE SUPPORT ===== */
@media (prefers-contrast: high) {
  .universal-modal-container {
    border-width: 3px;
    border-color: var(--body-text);
  }

  .universal-modal-button {
    border-width: 3px;
    font-weight: 700;
  }

  .universal-modal-close {
    border-width: 3px;
  }

  .universal-modal-close:focus-visible {
    outline-width: 4px;
  }

  .universal-modal-input {
    border-width: 3px;
  }
}

/* ===== REDUCED MOTION SUPPORT ===== */
@media (prefers-reduced-motion: reduce) {
  .universal-modal-button,
  .universal-modal-close,
  .universal-modal-container,
  .universal-modal-status {
    transition: none;
  }

  .universal-modal-button:hover,
  .universal-modal-close:hover {
    transform: none;
  }

  .universal-modal-spinner {
    animation: none;
  }

  .universal-modal-button::before,
  .universal-modal-close::before,
  .copy-instructions-btn::before {
    display: none;
  }

  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(0deg);
    }
  }
}

/* ===== SCREEN READER ONLY CONTENT ===== */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ===== DARK MODE SPECIFIC ENHANCEMENTS ===== */
[data-theme="dark"] .universal-modal-container {
  box-shadow: 0 10px 30px rgba(179, 219, 210, 0.1),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .universal-modal-status.status-success {
  background: var(--success-color);
}

[data-theme="dark"] .universal-modal-status.status-error {
  background: var(--error-color);
}

[data-theme="dark"] .universal-modal-status.status-warning {
  background: var(--warning-color);
}

[data-theme="dark"] .copy-instructions-btn,
[data-theme="dark"] .universal-modal-button-primary {
  box-shadow: 0 4px 12px rgba(60, 186, 198, 0.25);
}

[data-theme="dark"] .copy-instructions-btn:hover,
[data-theme="dark"] .universal-modal-button-primary:hover {
  box-shadow: 0 8px 20px rgba(60, 186, 198, 0.35);
}

/* ===== PLAYGROUND ANIMATION CONSISTENCY ===== */
@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 20px rgba(139, 69, 19, 0.3);
  }
  50% {
    box-shadow: 0 0 30px rgba(139, 69, 19, 0.5);
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* Status with pulse animation for loading states */
.universal-modal-status.status-info.loading {
  animation: pulse-glow 2s infinite;
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
.universal-modal[aria-hidden="true"] {
  display: none;
}

.universal-modal-button[aria-pressed="true"] {
  background: var(--link-hover);
  color: var(--body-bg);
}

/* Focus trap support */
.universal-modal-focusable {
  position: relative;
}

.universal-modal-focusable:focus-visible {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
  background-color: var(--focus-bg);
}

/* ===== MODAL ANIMATIONS ===== */
.universal-modal[open] {
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .universal-modal[open] {
    animation: none;
  }
}
