/* ============================================================
   DESIGN SYSTEM ? LOCKET UNIFIED DESIGN TOKENS
   Chu?n h?a to?n b? m?u s?c, spacing, typography, motion
   ============================================================ */
:root {
  /* ---- Background Colors ---- */
  --bg-primary: #0b1220;
  --bg-card: #0e1629;
  --bg-modal: #111d30;

  /* ---- Accent Colors ---- */
  --primary: #1f44c8;
  --primary-hover: #2750e0;
  --primary-border: rgba(99, 132, 255, 0.45);
  --accent-blue: #3b82f6;
  --accent-indigo: #6366f1;
  --success: #22c55e;
  --success-dark: #16a34a;
  --warning: #f97316;
  --warning-dark: #ea580c;
  --danger: #ef4444;

  /* ---- Text Colors ---- */
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-muted-dark: #9fb2db;

  /* ---- Border Colors ---- */
  --border: rgba(96, 165, 250, 0.15);
  --border-strong: rgba(96, 165, 250, 0.25);
  --border-input: rgba(148, 163, 184, 0.2);

  /* ---- Spacing Scale ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* ---- Border Radius Scale ---- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 22px;
  --radius-pill: 9999px;

  /* ---- Typography Scale ---- */
  --font-body: "Be Vietnam Pro", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --text-xs: 0.75rem;   /* 12px */
  --text-sm: 0.8125rem; /* 13px */
  --text-base: 0.875rem; /* 14px */
  --text-md: 1rem;       /* 16px */
  --text-lg: 1.15rem;    /* 18.4px */
  --text-xl: 1.4rem;     /* 22.4px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.75rem;   /* 28px */

  /* ---- Transitions ---- */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 150ms;
  --dur-normal: 250ms;
  --dur-slow: 400ms;

  /* ---- Box Shadows ---- */
  --shadow-xs: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 18px 42px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 30px 60px rgba(0, 0, 0, 0.5);
  --shadow-2xl: 0 36px 78px rgba(0, 0, 0, 0.52);

  /* ---- Breakpoints (max-width) ---- */
  --bp-sm: 420px;
  --bp-md: 520px;
  --bp-tab: 640px;
  --bp-lg: 768px;
}

/* ============================================================
   BASE RESET + TYPOGRAPHY
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text);
  font-family: var(--font-body);
}
/* ============================================================
   LAYOUT COMPONENTS
   ============================================================ */
.container { max-width: 980px; margin: 0 auto; padding: var(--sp-6); }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4); margin: 12px 0; }
.badge { display: inline-block; background: linear-gradient(135deg, var(--success), var(--success-dark)); border: 1px solid rgba(34,197,94,0.3); color: #fff; padding: 6px 12px; border-radius: var(--radius-sm); margin-right: 8px; font-weight: 600; box-shadow: 0 4px 12px rgba(34,197,94,.3); transition: all var(--dur-slow) var(--ease-out); }
.status { min-height: 22px; margin-top: var(--sp-2); }
.hidden { display: none; }
.muted { color: var(--text-muted-dark); }
.count { font: 600 2rem/1 var(--font-body); }
.countRow { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); }
.iframeWrap { height: 78vh; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
iframe { width: 100%; height: 100%; border: 0; }
.linkbtn { display: inline-block; border: 1px solid rgba(96,165,250,.25); padding: 10px 14px; border-radius: var(--radius-md); color: #cfe1ff; text-decoration: none; }
.header { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: 18px; }
.brand { width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover; }
.h1 { font-weight: 800; font-size: var(--text-3xl); letter-spacing: .2px; }
.subtitle { color: var(--text-muted-dark); font-size: var(--text-base); margin-top: 2px; }
.authed .header { display: none; }
.authed .container { padding-top: var(--sp-4); }

/* ============================================================
   GLASSMORPHISM ? COUNTDOWN CARD + STICKY HEADER
   ============================================================ */
#okBox {
  background: rgba(10,10,10,0.35);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-xl);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: 0 16px 40px rgba(5,4,8,0.45);
  transition: all var(--dur-slow) var(--ease-out);
}
#okBox .countRow h3 { color: rgba(255,255,255,0.9); font-size: var(--text-base); font-weight: 600; letter-spacing: .01em; text-shadow: 0 2px 8px rgba(0,0,0,0.2); margin: 0; }
#okBox .countRow .right { color: #fff; text-shadow: 0 0 20px rgba(248,250,252,.6), 0 0 40px rgba(59,130,246,.4), 0 0 60px rgba(147,51,234,.3); }

/* ============================================================
   FALLBACK PAGE
   ============================================================ */
.page-fallback .container { max-width: 980px; margin: 0 auto; padding: var(--sp-4); padding-left: max(var(--sp-4), env(safe-area-inset-left)); padding-right: max(var(--sp-4), env(safe-area-inset-right)); padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); box-sizing: border-box; }
.page-fallback .card { padding: var(--sp-4) var(--sp-5); border-radius: var(--radius-lg); }
.page-fallback .linkbtn { display: inline-flex; align-items: center; gap: .55rem; padding: .72rem 1.05rem; border-radius: var(--radius-pill); width: auto; max-width: 100%; margin: 12px auto 0; text-decoration: none; box-sizing: border-box; white-space: nowrap; }
@media (max-width: var(--bp-sm)){ .page-fallback .linkbtn { width: auto; } }

/* ============================================================
   PILL INPUT ? GATE KEY INPUT
   ============================================================ */
.inputRow { display: flex; align-items: center; gap: 10px; }
#keyInput { -webkit-appearance: none; appearance: none; flex: 1; height: 44px; padding: 0 var(--sp-4); border-radius: var(--radius-pill) !important; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.03); color: #e8eefc; outline: none; transition: box-shadow var(--dur-fast) ease, border-color var(--dur-fast) ease; }
#keyInput::placeholder { color: rgba(232,238,252,.45); }
#keyInput:focus { border-color: rgba(99,132,255,.55); box-shadow: 0 0 0 3px rgba(99,132,255,.18); }
#btnCheck, button.primary { -webkit-appearance: none; appearance: none; height: 44px; padding: 0 var(--sp-4); border-radius: var(--radius-pill) !important; border: 1px solid var(--primary-border); background: var(--primary); color: #fff; font-weight: 600; white-space: nowrap; transition: transform var(--dur-fast) ease, box-shadow var(--dur-fast) ease, background var(--dur-fast) ease; }
#btnCheck:hover { background: var(--primary-hover); }
#btnCheck:active { transform: translateY(1px); }
#btnCheck:focus { box-shadow: 0 0 0 3px rgba(99,132,255,.25); outline: none; }
@media (max-width: 420px){ .inputRow { gap: var(--sp-2); } #keyInput, #btnCheck { height: 42px; } }

/* ============================================================
   SCROLLBAR ? UNIFIED STYLE
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }

/* ===== LOADING EFFECTS - PREMIUM VERSION ===== */

/* Premium Loading Spinner - iOS Fixed */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  max-width: 20px;
  max-height: 20px;
  aspect-ratio: 1 / 1;
  -webkit-aspect-ratio: 1 / 1;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: #60a5fa;
  border-right-color: #3b82f6;
  animation: premium-spin 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
  margin-right: 8px;
  position: relative;
  box-sizing: border-box;
  flex-shrink: 0;
  vertical-align: middle;
  /* iOS Safari specific fixes */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
}

.loading-spinner::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, rgba(96, 165, 250, 0.3), transparent);
  animation: premium-spin 1.2s linear infinite reverse;
  z-index: -1;
}

@keyframes premium-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}

/* iOS Safari optimized animation */
@keyframes ios-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Premium Pulse Animation */
.loading-pulse {
  animation: premium-pulse 2s ease-in-out infinite;
}

@keyframes premium-pulse {
  0%, 100% { 
    opacity: 1; 
    transform: scale(1);
  }
  50% { 
    opacity: 0.7; 
    transform: scale(1.02);
  }
}

/* Premium Progress Bar */
.loading-progress {
  position: relative;
  width: 100%;
  height: 6px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 3px;
  overflow: hidden;
  margin: 16px 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.loading-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, 
    #60a5fa 0%, 
    #3b82f6 25%, 
    #2563eb 50%, 
    #1d4ed8 75%, 
    #1e40af 100%);
  border-radius: 3px;
  animation: premium-progress-flow 2.8s ease-in-out infinite;
  box-shadow: 0 0 10px rgba(96, 165, 250, 0.5);
}

@keyframes premium-progress-flow {
  0% { 
    width: 0%; 
    left: 0%; 
    opacity: 0.8;
  }
  50% { 
    width: 80%; 
    left: 0%; 
    opacity: 1;
  }
  100% { 
    width: 0%; 
    left: 100%; 
    opacity: 0.8;
  }
}

/* Premium Loading Dots */
.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  animation: premium-dots-bounce 1.6s ease-in-out infinite both;
  box-shadow: 0 2px 4px rgba(96, 165, 250, 0.3);
}

.loading-dots span:nth-child(1) { animation-delay: -0.4s; }
.loading-dots span:nth-child(2) { animation-delay: -0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes premium-dots-bounce {
  0%, 80%, 100% { 
    transform: scale(0.8) translateY(0);
    opacity: 0.6;
  }
  40% { 
    transform: scale(1.2) translateY(-4px);
    opacity: 1;
  }
}

/* Premium Button Loading State */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  cursor: wait;
  background: linear-gradient(135deg, #1d4ed8, #2563eb) !important;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.4) !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: -9px;
  margin-top: -9px;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  border-top-color: #fff;
  border-right-color: rgba(255, 255, 255, 0.8);
  animation: ios-spin 1s linear infinite;
  box-sizing: border-box;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: transform;
}

/* Premium Card Loading State */
.card-loading {
  position: relative;
  overflow: hidden;
}

.card-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(110deg, 
    transparent, 
    rgba(96, 165, 250, 0.1), 
    rgba(59, 130, 246, 0.15),
    rgba(96, 165, 250, 0.1),
    transparent);
  animation: premium-card-shimmer 3s ease-in-out infinite;
  z-index: 1;
}

@keyframes premium-card-shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Premium Status Loading */
.status-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  font-weight: 600;
  padding: 8px 0;
}

.status-loading .loading-spinner {
  width: 18px;
  height: 18px;
}

/* Premium Floating Loading Indicator */
.floating-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 20px;
  padding: 28px 36px;
  box-shadow: 
    0 25px 50px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(96, 165, 250, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: none;
  align-items: center;
  gap: 18px;
  color: #e2e8f0;
  font-weight: 700;
  min-width: 220px;
  text-align: center;
  font-size: 15px;
}

.floating-loading.show {
  display: flex;
  animation: premium-fadeInScale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes premium-fadeInScale {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) rotate(-5deg);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
}

.floating-loading .loading-spinner {
  width: 28px;
  height: 28px;
  border-width: 3px;
  margin-right: 0;
}

/* Premium Success Animation */
.success-checkmark {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  position: relative;
  margin-right: 10px;
  animation: premium-success-pop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

@keyframes premium-success-pop {
  0% { transform: scale(0) rotate(-180deg); }
  50% { transform: scale(1.2) rotate(-90deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.success-checkmark::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 9px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

/* Premium Error Animation */
.error-cross {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--danger), #dc2626);
  position: relative;
  margin-right: 10px;
  animation: premium-error-shake 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

@keyframes premium-error-shake {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.1) rotate(-5deg); }
  75% { transform: scale(1.1) rotate(5deg); }
}

.error-cross::before,
.error-cross::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 2.5px;
  background: white;
  border-radius: 1px;
  transform: translate(-50%, -50%) rotate(45deg);
}

.error-cross::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* Premium Mobile Optimizations - iOS Fixed
   Note: box-sizing, flex-shrink, aspect-ratio inherited from base rules */
@media (max-width: var(--bp-lg)) {
  .floating-loading { padding: 24px 28px; min-width: 200px; font-size: 14px; border-radius: var(--radius-lg); }
  .floating-loading .loading-spinner { width: 24px; height: 24px; border-width: 2.5px; }
  .loading-spinner { width: 18px; height: 18px; border-width: 2px; }
  .btn-loading::after { width: 16px; height: 16px; margin-left: -8px; margin-top: -8px; border-width: 2px; }
  .status-loading .loading-spinner { width: 16px; height: 16px; border-width: 2px; }
  .loading-dots span { width: 7px; height: 7px; }
  .loading-progress { height: 5px; }
}

@media (max-width: var(--bp-sm)) {
  .floating-loading { padding: 20px 24px; min-width: 180px; font-size: 13px; }
  .floating-loading .loading-spinner { width: 22px; height: 22px; border-width: 2.5px; }
  .loading-spinner { width: 16px; height: 16px; border-width: 2px; }
  .btn-loading::after { width: 14px; height: 14px; margin-left: -7px; margin-top: -7px; border-width: 2px; }
  .status-loading .loading-spinner { width: 14px; height: 14px; border-width: 2px; }
}

/* iOS Safari: simpler spin animation (base rules already have translateZ/will-change) */
@supports (-webkit-touch-callout: none) {
  .loading-spinner,
  .status-loading .loading-spinner,
  .floating-loading .loading-spinner { animation: ios-spin 1.2s linear infinite; }
  .btn-loading::after { animation: ios-spin 1s linear infinite; }
}


/* ============================================================
   QUIZ MODAL ? S? d?ng design tokens
   ============================================================ */
.quiz-modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 2147483646; padding: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(max(16px, env(safe-area-inset-bottom, 0px)), 12px) max(16px, env(safe-area-inset-left, 0px)); overflow: hidden; box-sizing: border-box; }
.quiz-modal.show { display: flex; }
.quiz-modal-backdrop { position: absolute; inset: 0; background: rgba(8, 13, 26, 0.85); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.quiz-modal-panel { position: relative; min-height: 0; min-width: 0; width: 100%; max-width: 520px; box-sizing: border-box; max-height: min(90vh, calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px)); max-height: min(90dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px)); display: flex; flex-direction: column; overflow: hidden; background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius-2xl); padding: 28px 26px 24px; color: var(--text); box-shadow: var(--shadow-xl); font-family: var(--font-body); }
.quiz-modal-panel::before { content: ""; position: absolute; top: -120px; right: -120px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(circle at center, rgba(96, 165, 250, 0.2), transparent 65%); opacity: 0.7; pointer-events: none; }
.quiz-modal-title { font-size: var(--text-xl); font-weight: 800; margin: 0 0 8px; color: var(--text); letter-spacing: 0.04em; display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; overflow-wrap: break-word; }
.quiz-modal-title span { display: inline-flex; width: 44px; height: 44px; border-radius: var(--radius-md); background: linear-gradient(135deg, var(--accent-blue), var(--accent-indigo)); align-items: center; justify-content: center; color: #fff; font-size: 1.3rem; font-weight: 800; box-shadow: var(--shadow-sm); }
.quiz-subtitle { color: #fecaca; font-size: 0.95rem; margin-bottom: var(--sp-5); line-height: 1.5; overflow-wrap: break-word; }

.quiz-progress {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  min-width: 0;
  box-sizing: border-box;
}

.quiz-progress-bar {
  flex: 1 1 0;
  min-width: 0;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--success-dark));
  border-radius: 4px;
  transition: width var(--dur-slow) var(--ease-out);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}

.quiz-progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.quiz-question {
  position: relative;
  z-index: 2;
  margin-bottom: var(--sp-4);
}

.quiz-question-text {
  font-family: var(--font-body);
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.5;
  margin-bottom: var(--sp-4);
  letter-spacing: 0.01em;
  overflow-wrap: break-word;
  word-break: break-word;
  text-align: justify;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vw, 10px);
  min-width: 0;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 12px);
  padding: clamp(10px, 2vw, 14px) clamp(10px, 2.5vw, 16px);
  max-width: 100%;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-normal) ease, border-color var(--dur-normal) ease, box-shadow var(--dur-normal) ease;
  font-family: var(--font-body);
  font-size: clamp(0.9rem, 2.2vw, 1rem);
  font-weight: 600;
  color: #f1f5f9;
  text-align: left;
  letter-spacing: 0.01em;
}

.quiz-option:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(96, 165, 250, 0.5);
}

@media (hover: hover) and (pointer: fine) {
  .quiz-option:hover {
    transform: translateX(4px);
  }
}

.quiz-option.selected {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent-blue);
}

.quiz-option.correct {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--success);
  animation: quiz-correct-pulse 0.5s ease;
}

.quiz-option.wrong {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--danger);
  animation: quiz-wrong-shake 0.5s ease;
}

.quiz-option-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all var(--dur-normal) ease;
}

.quiz-option.selected .quiz-option-marker {
  background: var(--accent-blue);
  color: #fff;
}

.quiz-option.correct .quiz-option-marker {
  background: var(--success);
  color: #fff;
}

.quiz-option.wrong .quiz-option-marker {
  background: var(--danger);
  color: #fff;
}

.quiz-option-text {
  flex: 1 1 0;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

@keyframes quiz-correct-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes quiz-wrong-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.quiz-feedback {
  display: none;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  margin-top: var(--sp-4);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
  box-sizing: border-box;
  max-width: 100%;
}

.quiz-feedback.show {
  display: block;
  animation: quiz-feedback-in var(--dur-normal) ease;
}

.quiz-feedback.correct {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #86efac;
}

.quiz-feedback.wrong {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

@keyframes quiz-feedback-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.quiz-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* B??c intro: header + v?ng cu?n gi?a + footer c? ??nh (? tick + ?? hi?u lu?n th?y tr?n mobile) */
/* display do JS ??t none | flex ? m?c ??nh flex ?? c?u tr?c c?t ??ng khi hi?n */
#quizIntro {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  /* Kh?ng d?ng overflow:hidden: tr?n iOS d? c?t m?t ??y footer/n?t khi flex l?m tr?n chi?u cao */
  overflow: visible;
  box-sizing: border-box;
  /* ??m d??i c?ng trong c?t flex ? tr?nh n?t d?nh s?t m?p v?ng clip c?a panel bo g?c */
  padding-bottom: 8px;
}

#quizMain {
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.quiz-main-scroll {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 16px;
  padding-bottom: 4px;
}

#quizComplete {
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  justify-content: center;
  align-items: center;
}

.quiz-intro-header {
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.quiz-intro-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 12px;
  padding-bottom: 2px;
  position: relative;
}

/* Gradient mo dan o day de goi y nguoi dung con noi dung ben duoi */
.quiz-intro-scroll::after {
  content: "";
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: block;
  background: linear-gradient(to bottom, transparent, rgba(15, 23, 42, 0.9));
  pointer-events: none;
  border-radius: 0 0 8px 8px;
  flex-shrink: 0;
}

.quiz-intro-scroll .quiz-notes-body {
  max-height: none;
  overflow: visible;
  margin-bottom: 0;
}

/* Thanh ti?n ?? + gate + footnote: c? ??nh d??i khung cu?n, lu?n nh?n th?y kh?ng c?n cu?n c? panel */
.quiz-intro-meta {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.quiz-intro-meta .scroll-progress-bar {
  margin-top: 4px;
  margin-bottom: 10px;
}

.quiz-intro-meta .quiz-intro-gate-status {
  margin-top: 0;
}

.quiz-intro-meta .quiz-intro-footnote {
  margin-top: 8px;
  margin-bottom: 0;
}

.quiz-intro-meta .quiz-fail-warning {
  margin-top: 10px;
  margin-bottom: 0;
}

.quiz-intro-footer {
  flex-shrink: 0;
  position: relative;
  z-index: 3;
  margin-top: 4px;
  padding-top: 14px;
  /* ?? ch? cho n?t + shadow, tr?nh b? panel overflow:hidden c?t m?p d??i */
  padding-bottom: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  /* C?ng t?ng v?i panel #111d30 ? bo g?c d??i kh?p th? modal */
  border-radius: 0 0 16px 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(11, 18, 32, 0.35) 0%, rgba(17, 29, 48, 0.88) 55%, rgba(15, 23, 42, 0.95) 100%);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.22);
  /* Tr?nh l?i compositing Safari c?t m?p n?t */
  isolation: isolate;
}

.quiz-intro-footer .quiz-intro-ack {
  margin-top: 0;
  margin-bottom: 10px;
}

.quiz-intro-footer .quiz-intro-actions {
  margin-top: 0;
}

.quiz-btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--dur-normal) ease;
  -webkit-appearance: none;
  appearance: none;
  vertical-align: middle;
}

.quiz-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.quiz-btn-primary {
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.quiz-btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.quiz-btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: linear-gradient(135deg, #374151, #1f2937);
  box-shadow: var(--shadow-xs);
  transform: none;
}

/* Scroll progress bar ? xu?t hi?n khi user ph?i scroll tru?c khi b?m n?t */
.scroll-progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  margin-bottom: var(--sp-3);
  overflow: hidden;
}

.scroll-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--success-dark));
  border-radius: 2px;
  transition: width var(--dur-fast) ease;
}

/* C?nh b?o fail nhi?u l?n */
.quiz-fail-warning {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fca5a5;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-4);
  font-size: 0.9rem;
  font-weight: 600;
  animation: quiz-feedback-in var(--dur-normal) ease;
}

.quiz-btn-retry {
  background: linear-gradient(135deg, var(--warning), var(--warning-dark));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.quiz-btn-retry:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.quiz-btn-retry:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: linear-gradient(135deg, #374151, #1f2937);
  box-shadow: none;
  transform: none;
}

/* Dialog x?c nh?n: overlay ph? l?n intro, card nh? gi?a m?n h?nh */

.quiz-confirm-overlay[hidden] {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
}

.quiz-confirm-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 13, 26, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: inherit;
  padding: var(--sp-5);
  box-sizing: border-box;
  animation: quiz-feedback-in var(--dur-fast) ease;
}

.quiz-confirm-card {
  background: var(--bg-modal);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: var(--sp-6) 22px var(--sp-5);
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-xl);
  box-sizing: border-box;
}

.quiz-confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-indigo));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  margin: 0 auto var(--sp-3);
  box-shadow: var(--shadow-sm);
}

.quiz-confirm-title {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text);
  margin: 0 0 12px;
  letter-spacing: 0.02em;
}

.quiz-confirm-body {
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.6;
  margin: 0 0 var(--sp-5);
}

.quiz-confirm-body strong {
  color: #93c5fd;
}

.quiz-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* Quiz Complete State */
.quiz-complete {
  text-align: center;
  padding: var(--sp-5) 0;
}

.quiz-complete-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--sp-5);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--success), var(--success-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  animation: quiz-complete-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: var(--shadow-lg);
}

@keyframes quiz-complete-bounce {
  0% { transform: scale(0) rotate(-180deg); }
  50% { transform: scale(1.2) rotate(-10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.quiz-complete-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: #86efac;
  margin-bottom: var(--sp-2);
}

.quiz-complete-text {
  color: var(--text-muted);
  font-size: var(--text-md);
  margin-bottom: var(--sp-6);
}

/* Mobile quiz: intro panel/footer = backup; #quizMain keeps compact answer fonts + overflow:visible */
@media (max-width: 520px) {
  .quiz-modal.show {
    align-items: center;
  }

  .quiz-modal {
    justify-content: center;
    --quiz-bottom-reserve: max(10px, calc(env(safe-area-inset-bottom, 0px) + 10px));
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-bottom: var(--quiz-bottom-reserve);
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .quiz-modal-panel {
    flex: 0 1 auto;
    align-self: center;
    width: 100%;
    max-width: 520px;
    min-height: 0;
    max-height: min(
      92dvh,
      calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px)
    );
    padding: 14px 12px;
    padding-bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    border-radius: 16px;
  }

  #quizIntro {
    /* Less bottom padding when panel is full-height (footer sticks to bottom) */
    padding-bottom: 4px;
  }

  .quiz-intro-scroll {
    padding-bottom: 4px;
  }

  .quiz-actions {
    margin-top: 0;
    padding-top: 12px;
    padding-bottom: 2px;
    justify-content: stretch;
    align-items: stretch;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    background: linear-gradient(180deg, rgba(11, 18, 32, 0.2) 0%, rgba(17, 29, 48, 0.78) 100%);
  }

  #quizMain .quiz-actions .quiz-btn {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .quiz-main-scroll {
    padding-bottom: 10px;
    scroll-padding-bottom: 20px;
  }

  .quiz-intro-footer .quiz-intro-actions {
    margin-top: 0;
    padding-bottom: 4px;
    justify-content: center;
    width: 100%;
  }

  .quiz-intro-footer .quiz-intro-actions .quiz-btn {
    width: 100%;
    max-width: 300px;
  }

  .quiz-intro-footer {
    padding-top: 12px;
    margin-left: 0;
    margin-right: 0;
    padding-left: 12px;
    padding-right: 12px;
    margin-bottom: 0;
    /* safe-area already in .quiz-modal-panel padding-bottom */
    padding-bottom: 8px;
    /* match panel bottom radius on mobile */
    border-radius: 0 0 12px 12px;
  }

  .quiz-modal-title {
    font-size: 1.2rem;
  }

  .quiz-modal-title span {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  /* Answer step only: slightly smaller than backup to reduce scroll */
  .quiz-question-text {
    font-size: 0.95rem;
    line-height: 1.45;
    margin-bottom: var(--sp-3);
  }

  .quiz-option {
    padding: 10px 12px;
    font-size: 0.88rem;
    gap: 8px;
  }

  .quiz-option-marker {
    width: 24px;
    height: 24px;
    min-width: 24px;
    font-size: 0.8rem;
  }

  .quiz-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
  }



}

/* ===== QUIZ INTRO (important notes) ? dark tone, minimal accents ===== */
.quiz-intro-lead {
  margin: 0 0 14px;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  color: #cbd5e1;
}

.quiz-notes-body {
  margin-bottom: 12px;
  max-height: min(48vh, 320px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 14px 12px;
  scrollbar-gutter: stable;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
}

.quiz-notes-body::-webkit-scrollbar {
  width: 6px;
}

.quiz-notes-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-sm);
}

.quiz-notes-body::-webkit-scrollbar-track {
  background: transparent;
}

.quiz-intro-gate-status {
  margin: 10px 0 0;
  padding: 11px 14px 11px 16px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: var(--radius-sm);
  border-left: 3px solid rgba(96, 165, 250, 0.7);
  color: #93c5fd;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.45;
  min-height: 2.6em;
}

.quiz-intro-gate-status:empty {
  display: none;
}

.quiz-intro-footnote {
  margin: 8px 0 0;
  padding: 0;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.45;
  color: #94a3b8;
}

.quiz-intro-ack {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 16px;
  padding: 12px 14px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.15);
  border-radius: 12px;
  color: #e2e8f0;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.45;
  cursor: pointer;
  user-select: none;
}

.quiz-intro-ack input[type="checkbox"] {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin-top: 0;
  padding: 0;
  border: 2px solid rgba(96, 165, 250, 0.5);
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}

.quiz-intro-ack input[type="checkbox"]:checked {
  background: var(--success);
  border-color: var(--success);
}

.quiz-intro-ack input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: translate(-50%, -60%) rotate(45deg);
}

.quiz-intro-ack span {
  flex: 1 1 0;
  min-width: 0;
}

.quiz-notes-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quiz-notes-list li {
  position: relative;
  padding-left: 28px;
  color: #f1f5f9;
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.55;
}

.quiz-notes-list li::before {
  /* U+2022 bullet ? tr?nh nh?m v?i ch?m h?i n?u file b? l?i encoding */
  content: "\2022";
  position: absolute;
  left: 8px;
  top: 0;
  color: #fb923c;
  font-size: 1.1rem;
}

.quiz-notes-list li strong {
  color: #fff;
  font-weight: 700;
}

.quiz-intro-hint {
  margin-top: 14px;
  margin-bottom: 0;
  padding: 12px 14px 12px 16px;
  background: rgba(59, 130, 246, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  border-left: 3px solid rgba(59, 130, 246, 0.65);
  color: #bfdbfe;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
}

@media (max-width: 520px) {
  .quiz-notes-list li {
    font-size: 0.95rem;
    padding-left: 24px;
  }

  .quiz-intro-lead {
    font-size: 0.82rem;
    margin-bottom: 12px;
  }

  .quiz-intro-gate-status {
    font-size: 0.8rem;
    padding: 10px 12px 10px 14px;
  }

  .quiz-intro-footnote {
    font-size: 0.74rem;
  }

  .quiz-intro-ack {
    font-size: 0.8rem;
    padding: 10px 12px;
  }
  
  .quiz-intro-hint {
    font-size: 0.86rem;
    padding: 10px 12px 10px 14px;
  }
}

/* ============================================================
   FOCUS-VISIBLE ? unified accessibility styles
   ============================================================ */
:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.7);
  outline-offset: 2px;
}

button:focus-visible,
.quiz-option:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.7);
  outline-offset: 3px;
}

a:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.7);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Suppress focus outline on mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

