/* style.css - ดีไซน์ระบบสอบออนไลน์ป้องกันการโกง */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&family=Sarabun:wght@400;500;600;700&display=swap');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-main: #f8fafc;
  --surface: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* 🛡️ บล็อกการคัดลอกและลากคลุมข้อความในระดับ CSS */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: 'Prompt', 'Sarabun', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 🪤 กับดัก AI (Honey-Prompt Trap) - ซ่อนจากสายตาคน แต่อยู่ใน DOM ให้อุปกรณ์ดูดข้อความเก็บไป */
.ai-honey-trap-text {
  font-size: 0px !important;
  line-height: 0px !important;
  width: 0px !important;
  height: 0px !important;
  opacity: 0 !important;
  overflow: hidden !important;
  display: inline-block !important;
  position: absolute !important;
  pointer-events: none !important;
  color: transparent !important;
  -webkit-user-select: text !important;
  user-select: text !important;
}

/* ลายน้ำ Canvas เคลื่อนที่ */
#watermarkCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 999;
}

/* เลย์เอาต์หลัก */
.app-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
}

/* แถบหัวข้อสอบ (Exam Header) */
.exam-navbar {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-left: 5px solid var(--primary);
  flex-wrap: wrap;
  gap: 1rem;
}

.student-badge-group {
  display: flex;
  flex-direction: column;
}

.student-name-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
}

.student-meta-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.header-status-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge-safe {
  background: #dcfce7;
  color: #166534;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.timer-box {
  background: #0f172a;
  color: #ffffff;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-family: 'Consolas', monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.timer-urgent {
  background: var(--danger);
  animation: pulseTimer 1s infinite;
}

@keyframes pulseTimer {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.03); }
}

/* พื้นที่ทำข้อสอบ (Exam Layout) */
.exam-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
}

@media (max-width: 860px) {
  .exam-grid {
    grid-template-columns: 1fr;
  }
}

.question-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.question-number-tag {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1.1rem;
}

.topic-tag {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
}

.badge-shuffle-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #ede9fe;
  color: #6366f1;
  border: 1px solid #c7d2fe;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(99, 102, 241, 0.08);
}

.flag-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.flag-btn.flagged {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--danger);
  font-weight: 600;
}

.question-text {
  font-size: 1.2rem;
  line-height: 1.8;
  color: var(--text-main);
  margin-bottom: 2rem;
}

/* รายการตัวเลือก */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.choice-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.choice-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.choice-item.selected {
  background: #eff6ff;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.choice-item input[type="radio"] {
  display: none;
}

.choice-prefix {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all 0.2s;
}

.choice-item.selected .choice-prefix {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.choice-text {
  font-size: 1.05rem;
  color: var(--text-main);
  flex: 1;
}

.choice-content-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

/* รูปภาพในข้อสอบ */
.question-exam-img-wrap {
  text-align: center;
  margin: 0.5rem 0 1.5rem 0;
}

.question-exam-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  object-fit: contain;
}

html.exam-gesture-locked {
  overscroll-behavior: none;
  touch-action: pan-y;
}

html.exam-gesture-locked body {
  overscroll-behavior: none;
}

.image-load-failed {
  min-height: 110px;
  display: grid;
  place-items: center;
  border: 2px dashed #f59e0b;
  border-radius: 12px;
  background: #fffbeb;
}

.image-retry-message {
  padding: 1rem;
  color: #92400e;
  font-weight: 700;
  text-align: center;
}

.image-retry-message button {
  margin-top: .65rem;
  border: 0;
  border-radius: 999px;
  padding: .55rem 1rem;
  background: #f59e0b;
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.choice-exam-img-wrap {
  margin-top: 0.25rem;
}

.choice-exam-img {
  max-width: 220px;
  max-height: 120px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
}

/* ปุ่มเลื่อนข้อ */
.nav-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.btn {
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
  background: #cbd5e1;
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}
.btn-success:hover {
  background: #059669;
}

/* แถบด้านข้าง (Question Palette Sidebar) */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.palette-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.palette-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.palette-btn {
  height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.palette-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.palette-btn.current {
  border: 2px solid var(--primary);
  color: var(--primary);
}

.palette-btn.answered {
  background: #dbeafe;
  color: var(--primary);
  border-color: #bfdbfe;
}

.palette-btn .flag-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.palette-legend {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

/* 🛑 จอดำป้องกันการแคป/Circle to Search/สลับแท็บ/Split-Screen (Shield Mask Modal) */
.shield-mask-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: #090d16;
  z-index: 999999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  padding: 2rem;
  text-align: center;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.shield-mask-modal.active {
  display: flex;
}

.shield-icon-big {
  font-size: 4rem;
  margin-bottom: 1.5rem;
  animation: pulseIcon 1.5s infinite;
}

@keyframes pulseIcon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.shield-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: #f87171;
  margin-bottom: 1rem;
}

.shield-reason-box {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  max-width: 600px;
  font-size: 1rem;
  color: #cbd5e1;
}

.shield-strike-pill {
  background: #ef4444;
  color: #ffffff;
  padding: 0.4rem 1.2rem;
  border-radius: 9999px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
}

.shield-instruction {
  font-size: 0.95rem;
  color: #94a3b8;
  max-width: 500px;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.shield-mask-modal.locked-modal {
  background: radial-gradient(circle at center, #1e090d 0%, #0c0204 100%);
  border: 4px solid #ef4444;
  box-shadow: inset 0 0 50px rgba(239, 68, 68, 0.4);
}

@keyframes bounceLock {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.15) rotate(-8deg); }
  75% { transform: scale(1.15) rotate(8deg); }
}

/* หน้าลงทะเบียนเริ่มสอบ (Welcome Screen) */
.welcome-card {
  max-width: 650px;
  margin: 3rem auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.welcome-header {
  text-align: center;
  margin-bottom: 2rem;
}

.welcome-header h1 {
  font-size: 1.75rem;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.security-rules-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 2rem;
}

.security-rules-box h4 {
  color: #b45309;
  font-size: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.security-rules-box ul {
  padding-left: 1.2rem;
  color: #78350f;
  font-size: 0.9rem;
  line-height: 1.7;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* หน้ารายงานสรุปผล (Result Screen) */
.result-card {
  max-width: 900px;
  margin: 2rem auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.status-banner {
  padding: 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
  text-align: center;
}

.banner-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.banner-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.banner-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.score-display-box {
  text-align: center;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
}

.score-number {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary);
}

/* ตาราง Audit Log */
.audit-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.audit-table th, .audit-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.audit-table th {
  background: #f1f5f9;
  color: var(--text-muted);
  font-weight: 600;
}

.badge-strike {
  background: #fee2e2;
  color: #dc2626;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.8rem;
}

/* กล่องเฉลย */
.review-item-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.review-item-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.review-q-text {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.review-answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  background: #ffffff;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.review-explanation {
  background: #eff6ff;
  border-left: 4px solid var(--primary);
  padding: 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #1e3a8a;
}

.trap-flag {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #be123c;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

/* ⏳ แอนิเมชันสำหรับห้องพักคอย (Lobby Waiting Screen) */
.lobby-radar-container {
  position: relative;
  width: 90px;
  height: 90px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lobby-radar-core {
  font-size: 2.8rem;
  z-index: 2;
  position: relative;
}

.lobby-pulse-ring {
  position: absolute;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.15);
  border: 2px solid rgba(37, 99, 235, 0.4);
  animation: lobbyPulse 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

.lobby-pulse-ring.delay-1 {
  animation-delay: 0.75s;
}

@keyframes lobbyPulse {
  0% {
    transform: scale(0.6);
    opacity: 1;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.lobby-status-alert {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

.lobby-dot-live {
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulseDotLive 1.5s infinite;
}

@keyframes pulseDotLive {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.hidden {
  display: none !important;
}
/* ม่านความเป็นส่วนตัว: แสดงทันทีเมื่อ browser/system overlay ทำให้หน้าสอบเสีย focus
   แยกจากการนับ Strike เพื่อซ่อนโจทย์ก่อน โดยไม่เพิ่ม false positive */
#securityPrivacyCurtain {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  display: none;
  place-items: center;
  background: #07111f;
  color: #f8fafc;
  text-align: center;
  padding: 2rem;
  opacity: 0;
}

#securityPrivacyCurtain.active {
  display: grid;
  opacity: 1;
}

.privacy-curtain-content {
  display: grid;
  gap: 0.65rem;
  justify-items: center;
  font-size: clamp(1rem, 3vw, 1.3rem);
}

.privacy-curtain-content strong { font-size: clamp(1.2rem, 4vw, 1.8rem); }
.privacy-curtain-content span { color: #93c5fd; }
.privacy-curtain-icon { font-size: clamp(3rem, 12vw, 5.5rem); }

html.exam-content-protected #examScreen {
  filter: blur(28px);
  visibility: hidden;
}
