/* =========================================================================
   EXAM SECURITY SHIELD, ANTI-COPY, ANTI-PRINT & DYNAMIC WATERMARK SUBSYSTEM
   File: /home/clue/Documents/SAT/static/css/exam-security.css
   
   Hardened Anti-Cheat & Forensic Protection:
   - Fullscreen lockdown overlay & state monitoring
   - Window blur violation counter & incident telemetry
   - Clipboard copy/cut/paste blocking & forensic watermark injection
   - DevTools detection & dimension delta monitoring
   - Security shield modal (#exam-security-shield) with luxury glassmorphism
   - Dynamic canvas forensic watermark tile (#exam-watermark-layer)
   ========================================================================= */

/* --- 1. Dynamic Watermark Layer (Forensic Transparent Overlay) --- */
#exam-watermark-layer {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  z-index: 9999 !important;
  background-repeat: repeat !important;
  background-position: center center !important;
  opacity: 1 !important;
  display: block !important;
  visibility: visible !important;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- 2. Security Blur Shield Overlay (Focus Loss / Tab Switch / Snipping Tool) --- */
#exam-security-shield {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 1.25rem !important;
  box-sizing: border-box !important;
  background-color: rgba(2, 6, 23, 0.94) !important; /* Deep Slate 950 with 94% opacity */
  backdrop-filter: blur(32px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(32px) saturate(190%) !important;
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s linear;
  user-select: none !important;
  -webkit-user-select: none !important;
}

#exam-security-shield.security-shield-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* --- 3. Security Shield Modal Card (Luxury Glassmorphism & GPU Accelerated) --- */
.security-shield-card {
  max-width: 490px;
  width: 100%;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.97) 0%, rgba(9, 14, 28, 0.95) 100%) !important;
  border: 1.5px solid rgba(239, 68, 68, 0.55) !important;
  border-radius: 1.5rem !important;
  padding: 2.25rem 2rem !important;
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.9),
              0 0 45px rgba(239, 68, 68, 0.22),
              inset 0 1px 0 rgba(255, 255, 255, 0.12) !important;
  text-align: center;
  color: #f8fafc;
  position: relative;
  overflow: hidden;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  animation: shieldPulseIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.security-shield-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  pointer-events: none;
}

@keyframes shieldPulseIn {
  0% { transform: scale(0.92) translate3d(0, 8px, 0); opacity: 0; }
  100% { transform: scale(1) translate3d(0, 0, 0); opacity: 1; }
}

.security-shield-icon-wrap {
  width: 68px;
  height: 68px;
  margin: 0 auto 1.25rem;
  border-radius: 1.25rem;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.22) 0%, rgba(185, 28, 28, 0.15) 100%);
  border: 1.5px solid rgba(239, 68, 68, 0.45);
  box-shadow: 0 8px 20px -4px rgba(239, 68, 68, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f87171;
}

.security-shield-title {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: -0.025em;
  color: #ffffff;
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  line-height: 1.35;
}

.security-shield-desc {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #cbd5e1; /* Slate 300 - WCAG AAA contrast ratio > 11:1 on dark slate */
  margin-bottom: 1.35rem;
}

.security-shield-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 1rem;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fecaca;
  margin-bottom: 1.75rem;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.security-shield-btn {
  width: 100%;
  min-height: 48px; /* Touch target >= 44px */
  padding: 0.85rem 1.5rem;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.925rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.85rem;
  cursor: pointer;
  box-shadow: 0 6px 20px -2px rgba(37, 99, 235, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translate3d(0, 0, 0);
  will-change: transform, box-shadow;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.security-shield-btn:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  box-shadow: 0 8px 24px -2px rgba(37, 99, 235, 0.65), 0 0 20px rgba(59, 130, 246, 0.4);
  transform: translate3d(0, -1.5px, 0);
}

.security-shield-btn:active {
  transform: translate3d(0, 0, 0);
  filter: brightness(0.95);
}

/* --- 4. Light Mode Overrides for Shield (WCAG 2.1 AAA Compliant) --- */
html.light #exam-security-shield {
  background-color: rgba(248, 250, 252, 0.94) !important;
}

html.light .security-shield-card {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.96) 100%) !important;
  border: 1.5px solid rgba(239, 68, 68, 0.5) !important;
  color: #0f172a !important;
  box-shadow: 0 25px 50px -10px rgba(0, 0, 0, 0.16),
              0 0 35px rgba(239, 68, 68, 0.12),
              inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
}

html.light .security-shield-card::before {
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.2), transparent);
}

html.light .security-shield-icon-wrap {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.15);
}

html.light .security-shield-title {
  color: #0f172a !important; /* Slate 900 - WCAG AAA > 19:1 */
}

html.light .security-shield-desc {
  color: #334155 !important; /* Slate 700 - WCAG AAA > 8.5:1 */
}

html.light .security-shield-badge {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b; /* Red 800 - WCAG AAA > 7:1 */
}

html.light .security-shield-btn {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 6px 18px rgba(29, 78, 216, 0.35) !important;
}

html.light .security-shield-btn:hover {
  background: linear-gradient(135deg, #1e40af 0%, #172554 100%) !important;
  box-shadow: 0 8px 24px rgba(29, 78, 216, 0.5) !important;
}

/* --- 5. Selection & Bluebook Annotation Rules --- */
/* Enable smooth text selection for Bluebook Highlighting and Notes in Reading & Questions */
.passage-body,
.question-prompt,
#question-prompt-box,
#left-pane,
#right-pane,
.reading-passage,
.sat-passage-text,
#grid-in-input,
#profile-name-input,
#scratchpad-textarea,
#solver-note-input,
#ai-chat-input,
#math-formula-search-input,
#taxonomy-search-input,
#challenge-search-input,
#filter-search,
input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]),
textarea,
[contenteditable="true"] {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}

/* Prevent image and card drag exploits */
img,
.option-card,
.option-item {
  -webkit-user-drag: none !important;
  user-drag: none !important;
}

/* --- 6. Instant Anti-Screenshot & Screen Capture Framebuffer Blankout --- */
body.exam-screenshot-active #view-question-solver,
body.exam-screenshot-active #rush-gameplay-arena,
body.exam-window-blurred #view-question-solver,
body.exam-window-blurred #rush-gameplay-arena {
  filter: blur(60px) brightness(0.02) contrast(0) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  transition: none !important;
}

body.exam-screenshot-active::after,
body.exam-window-blurred::after {
  content: "🔒 NỘI DUNG ĐỀ THI DIGITAL SAT ĐÃ ĐƯỢC BẢO VỆ CHỐNG SAO CHÉP & CHỤP MÀN HÌNH" !important;
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background-color: rgba(2, 6, 23, 0.98) !important;
  color: #ef4444 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  font-size: 1.35rem !important;
  font-weight: 900 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
  padding: 2rem !important;
  z-index: 2147483647 !important;
  letter-spacing: 0.05em !important;
  text-transform: uppercase !important;
}

/* --- 7. Hardened Anti-Print Shield (@media print) --- */
@media print {
  body:not(.allow-print) * {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  body:not(.allow-print)::before {
    content: "TÀI LIỆU BẢO MẬT: Nghiêm cấm in ấn, sao chép hoặc trích xuất đề thi Digital SAT dưới mọi hình thức!" !important;
    display: block !important;
    visibility: visible !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    box-sizing: border-box !important;
    padding: 160pt 30pt !important;
    font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 22pt !important;
    font-weight: 900 !important;
    line-height: 1.6 !important;
    text-align: center !important;
    text-transform: uppercase !important;
    color: #dc2626 !important;
    background-color: #ffffff !important;
    border: 6pt solid #dc2626 !important;
    z-index: 2147483647 !important;
  }

  /* When print is authorized (e.g. Mistake Cheat Sheet), conceal security shields, duplicate tab overlays & forensic watermark layer */
  body.allow-print #exam-watermark-layer,
  body.allow-print #exam-security-shield,
  body.allow-print #exam-duplicate-tab-overlay,
  body.allow-print .exam-duplicate-tab-overlay {
    display: none !important;
    visibility: hidden !important;
  }

  body.allow-print::before,
  body.allow-print::after {
    display: none !important;
    content: none !important;
  }
}

/* --- 8. Duplicate Tab Lockdown Overlay (#exam-duplicate-tab-overlay) --- */
#exam-duplicate-tab-overlay,
.exam-duplicate-tab-overlay {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 1000000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 1.25rem !important;
  box-sizing: border-box !important;
  background-color: rgba(2, 6, 23, 0.96) !important;
  backdrop-filter: blur(36px) saturate(200%) !important;
  -webkit-backdrop-filter: blur(36px) saturate(200%) !important;
  opacity: 1;
  visibility: visible;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s linear;
  user-select: none !important;
  -webkit-user-select: none !important;
}

#exam-duplicate-tab-overlay.duplicate-tab-hidden,
.exam-duplicate-tab-overlay.duplicate-tab-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  display: none !important;
}

.duplicate-tab-card {
  max-width: 520px;
  width: 100%;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.98) 0%, rgba(10, 15, 30, 0.96) 100%) !important;
  border: 1.5px solid rgba(239, 68, 68, 0.65) !important;
  border-radius: 1.5rem !important;
  padding: 2.25rem 2rem !important;
  box-shadow: 0 32px 64px -12px rgba(0, 0, 0, 0.95),
              0 0 50px rgba(239, 68, 68, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.12) !important;
  text-align: center;
  color: #f8fafc;
  position: relative;
  overflow: hidden;
  transform: translate3d(0, 0, 0);
  will-change: transform, opacity;
  animation: shieldPulseIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.duplicate-tab-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.6), transparent);
  pointer-events: none;
}

.duplicate-tab-icon-wrap {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
  border-radius: 1.25rem;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.25) 0%, rgba(185, 28, 28, 0.18) 100%);
  border: 1.5px solid rgba(239, 68, 68, 0.5);
  box-shadow: 0 8px 24px -4px rgba(239, 68, 68, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ef4444;
}

.duplicate-tab-title {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: -0.025em;
  color: #ffffff;
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  line-height: 1.35;
}

.duplicate-tab-desc {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.6;
  color: #fca5a5;
  margin-bottom: 1rem;
}

.duplicate-tab-notice-banner {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #fee2e2;
  margin-bottom: 1rem;
  text-align: center;
}

.duplicate-tab-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 1rem;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fecaca;
  margin-bottom: 1.25rem;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.duplicate-tab-instruction {
  font-size: 0.85rem;
  line-height: 1.6;
  color: #94a3b8;
  margin-bottom: 1.5rem;
}

.duplicate-tab-btn {
  width: 100%;
  min-height: 48px;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.85rem;
  cursor: pointer;
  box-shadow: 0 6px 20px -2px rgba(220, 38, 38, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.duplicate-tab-btn:hover {
  background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
  box-shadow: 0 8px 24px -2px rgba(220, 38, 38, 0.65), 0 0 20px rgba(239, 68, 68, 0.4);
  transform: translate3d(0, -1.5px, 0);
}

.duplicate-tab-btn:active {
  transform: translate3d(0, 0, 0);
  filter: brightness(0.95);
}

/* Light mode overrides for duplicate tab overlay */
html.light #exam-duplicate-tab-overlay,
html.light .exam-duplicate-tab-overlay {
  background-color: rgba(248, 250, 252, 0.96) !important;
}

html.light .duplicate-tab-card {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.96) 100%) !important;
  border: 1.5px solid rgba(239, 68, 68, 0.5) !important;
  color: #0f172a !important;
  box-shadow: 0 25px 50px -10px rgba(0, 0, 0, 0.16),
              0 0 35px rgba(239, 68, 68, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
}

html.light .duplicate-tab-title {
  color: #0f172a !important;
}

html.light .duplicate-tab-desc {
  color: #b91c1c !important;
}

html.light .duplicate-tab-notice-banner {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

html.light .duplicate-tab-instruction {
  color: #475569 !important;
}

/* Touch Target Minimum Size & Typography Scaling (Phase 2 Task 8) */
@media (pointer: coarse), (max-width: 768px) {
  .security-shield-btn,
  .duplicate-tab-btn,
  #exam-security-shield button,
  #exam-duplicate-tab-overlay button {
    min-height: 44px !important;
    min-width: 44px !important;
  }
}

.security-shield-desc,
.duplicate-tab-instruction,
.duplicate-tab-notice-banner {
  font-size: 0.875rem; /* 14px text-sm minimum for legibility */
}

