/* ==========================================================================
 * HỌC CÙNG PHÚC K9 — EXAM CENTER & AUTOMATED GRADING SYSTEM STYLES
 * ========================================================================== */

.pk9-exam-hub {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
  max-width: 100%;
}

.pk9-exam-hero {
  position: relative;
  overflow: hidden;
  border-radius: 1.5rem;
  padding: 1.75rem 2rem;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(127, 192, 222, 0.16) 0%, transparent 55%),
    linear-gradient(135deg, #050b14 0%, #0f202e 52%, #16364d 100%);
  color: #f4f1e9;
  box-shadow: 0 22px 48px -16px rgba(5, 11, 20, 0.58);
  border: 1px solid rgba(212, 175, 55, 0.28);
}

.pk9-exam-hero::after {
  content: '';
  position: absolute;
  right: -60px;
  top: -60px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.28), transparent 70%);
  pointer-events: none;
}

.pk9-exam-hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: center;
}

.pk9-exam-hero-grid > *,
.pk9-exam-workspace > * {
  min-width: 0;
  max-width: 100%;
}

.pk9-exam-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.pk9-exam-kpi {
  background: rgba(15, 32, 46, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 1rem;
  padding: 0.9rem 1rem;
  min-width: 0;
}

.pk9-exam-kpi strong {
  display: block;
  font-family: var(--pk9-font-serif, Georgia, serif);
  font-size: 1.48rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff 0%, #7fc0de 50%, #fde68a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.pk9-exam-kpi span {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
}

/* Filter & Search Bar */
.pk9-exam-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
  justify-content: space-between;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.25rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 24px -12px rgba(15, 23, 42, 0.06);
}

.pk9-exam-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pk9-exam-chip {
  border: 1px solid var(--pk9-border, #e2e8f0);
  background: var(--pk9-surface-2, #f8fafc);
  color: var(--pk9-text-muted, #475569);
  border-radius: 999px;
  padding: 0.5rem 0.98rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--pk9-ease-snappy, cubic-bezier(0.22, 1, 0.36, 1)), border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.pk9-exam-chip:hover {
  border-color: #3b82f6;
  color: #2563eb;
  transform: translateY(-1px);
}

.pk9-exam-chip.active {
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 8px 18px -6px rgba(37, 99, 235, 0.45);
}

.pk9-exam-search {
  position: relative;
  min-width: min(100%, 200px);
  flex: 1 1 200px;
  max-width: 340px;
}

.pk9-exam-search input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  color: var(--pk9-text, #0f172a);
  padding: 0.55rem 1rem 0.55rem 2.35rem;
  font-size: 0.86rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.pk9-exam-search input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.pk9-exam-search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.6;
  pointer-events: none;
}

/* Exam Cards Grid */
.pk9-exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 1.15rem;
}

.pk9-exam-grid > .pk9-exam-card {
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
}

.pk9-exam-card {
  position: relative;
  isolation: isolate;
  contain: layout style;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.35rem;
  padding: 1.35rem;
  transition: transform 0.34s var(--pk9-ease-snappy, cubic-bezier(0.22, 1, 0.36, 1)), border-color 0.28s ease;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.pk9-exam-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 14%;
  right: 14%;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(127, 192, 222, 0.85), rgba(212, 175, 55, 0.95), transparent);
  opacity: 0;
  transform: scaleX(0.42) translateZ(0);
  transition: opacity 0.28s ease, transform 0.36s var(--pk9-ease-snappy, cubic-bezier(0.22, 1, 0.36, 1));
  pointer-events: none;
}

.pk9-exam-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 20px 42px -14px rgba(5, 11, 20, 0.24), 0 0 24px rgba(212, 175, 55, 0.14);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: -1;
}

@media (hover: hover) and (pointer: fine) {
  .pk9-exam-card:hover {
    transform: translate3d(0, -6px, 0);
    border-color: rgba(212, 175, 55, 0.52);
  }
  .pk9-exam-card:hover::before,
  .pk9-exam-card:hover::after {
    opacity: 1;
  }
  .pk9-exam-card:hover::before {
    transform: scaleX(1) translateZ(0);
  }
}

.pk9-exam-card:active {
  transform: scale(0.985) translateZ(0);
  transition-duration: 0.08s;
}

.pk9-exam-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.pk9-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.68rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.pk9-badge-subj {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.pk9-badge-verified {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.pk9-badge-code {
  background: rgba(245, 158, 11, 0.15);
  color: #b45309;
}

.pk9-exam-card h4 {
  font-size: 1.07rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--pk9-text, #0f172a);
  margin: 0 0 0.5rem;
}

.pk9-exam-origin {
  font-size: 0.84rem;
  color: var(--pk9-text-muted, #475569);
  margin-bottom: 0.85rem;
  line-height: 1.5;
}

.pk9-exam-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.75rem 0;
  border-top: 1px dashed var(--pk9-border, #e2e8f0);
  border-bottom: 1px dashed var(--pk9-border, #e2e8f0);
  margin-bottom: 1rem;
  font-size: 0.83rem;
  color: var(--pk9-text-muted, #475569);
  font-weight: 600;
}

.pk9-exam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.pk9-btn-exam-primary {
  position: relative;
  overflow: hidden;
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1rem;
  border-radius: 0.9rem;
  border: none;
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.24s ease;
  box-shadow: 0 10px 20px -8px rgba(37, 99, 235, 0.45);
}

.pk9-btn-exam-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 22%, rgba(255, 255, 255, 0.32) 50%, transparent 78%);
  transform: translateX(-125%);
  transition: transform 0.58s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.pk9-btn-exam-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px -8px rgba(37, 99, 235, 0.58), 0 0 16px rgba(212, 175, 55, 0.2);
}

.pk9-btn-exam-primary:hover::after {
  transform: translateX(125%);
}

.pk9-btn-exam-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.68rem 0.95rem;
  border-radius: 0.9rem;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  color: var(--pk9-text, #0f172a);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.18s var(--pk9-ease-snappy, cubic-bezier(0.22, 1, 0.36, 1)), border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.pk9-btn-exam-ghost:hover {
  border-color: #2563eb;
  color: #2563eb;
}

/* Interactive Exam Room */
.pk9-exam-room {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.pk9-exam-sticky-bar {
  position: sticky;
  top: 4.25rem;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #cbd5e1);
  border-radius: 1.25rem;
  padding: 0.9rem 1.25rem;
  box-shadow: 0 14px 32px -12px rgba(15, 23, 42, 0.14);
}

.pk9-exam-sticky-head {
  min-width: 0;
  flex: 1 1 220px;
}

.pk9-exam-sticky-org {
  font-size: 0.76rem;
  font-weight: 800;
  color: #2563eb;
  text-transform: uppercase;
}

.pk9-exam-sticky-title {
  font-size: 1.02rem;
  font-weight: 900;
  color: var(--pk9-text, #0f172a);
}

.pk9-exam-sticky-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pk9-exam-progress-pill {
  font-size: 0.84rem;
  font-weight: 800;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--pk9-surface-2, #f1f5f9);
  white-space: nowrap;
}

.pk9-timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.05rem;
  font-weight: 800;
}

.pk9-timer-pill.warning {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  animation: pk9Pulse 1s infinite;
}

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

.pk9-exam-workspace {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 1.25rem;
  align-items: start;
}

.pk9-exam-workspace.with-pdf {
  grid-template-columns: 1fr 1.15fr;
}

.pk9-exam-pdf-pane {
  position: sticky;
  top: 9.5rem;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.25rem;
  overflow: hidden;
  height: calc(100vh - 11rem);
  display: flex;
  flex-direction: column;
}

.pk9-exam-pdf-pane iframe {
  width: 100%;
  flex: 1;
  border: 0;
  background: #0f172a;
}

.pk9-exam-palette {
  position: sticky;
  top: 9.5rem;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.25rem;
  padding: 1.15rem;
}

.pk9-palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.pk9-palette-btn {
  height: 2.25rem;
  border-radius: 0.65rem;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  color: var(--pk9-text, #0f172a);
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.pk9-palette-btn.answered {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

.pk9-palette-btn.flagged {
  box-shadow: 0 0 0 2px #f59e0b;
}

/* Question Cards */
.pk9-section-banner {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.09), rgba(13, 148, 136, 0.09));
  border-left: 4px solid #2563eb;
  border-radius: 0.9rem;
  padding: 0.9rem 1.15rem;
  margin: 1.25rem 0 0.85rem;
}

.pk9-section-banner h4 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 800;
  color: var(--pk9-text, #0f172a);
}

.pk9-section-banner p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--pk9-text-muted, #475569);
}

.pk9-q-card {
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.2rem;
  padding: 1.2rem 1.35rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pk9-q-card.answered {
  border-color: rgba(37, 99, 235, 0.45);
}

.pk9-q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.pk9-q-num {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 800;
  font-size: 0.95rem;
  color: #2563eb;
}

.pk9-q-topic-tag {
  font-size: 0.77rem;
  font-weight: 600;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  background: var(--pk9-surface-2, #f1f5f9);
  color: var(--pk9-text-muted, #475569);
}

.pk9-q-prompt {
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.72;
  color: var(--pk9-text, #0f172a);
  margin-bottom: 1rem;
  white-space: pre-line;
}

.pk9-mcq-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

.pk9-mcq-opt {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  border-radius: 0.9rem;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
  font-size: 0.94rem;
  line-height: 1.55;
  color: var(--pk9-text, #0f172a);
}

.pk9-mcq-opt:hover {
  border-color: #3b82f6;
}

.pk9-mcq-opt.selected {
  background: rgba(37, 99, 235, 0.1);
  border-color: #2563eb;
  font-weight: 700;
}

.pk9-mcq-letter {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #cbd5e1);
  flex-shrink: 0;
}

.pk9-mcq-opt.selected .pk9-mcq-letter {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

/* True/False 4-Statement Table */
.pk9-tf-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.pk9-tf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.95rem;
  border-radius: 0.85rem;
  min-width: 0;
  max-width: 100%;
  background: var(--pk9-surface-2, #f8fafc);
  border: 1px solid var(--pk9-border, #e2e8f0);
}

.pk9-tf-text {
  font-size: 0.94rem;
  line-height: 1.58;
  color: var(--pk9-text, #0f172a);
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.pk9-tf-toggle {
  display: inline-flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.pk9-tf-btn {
  padding: 0.4rem 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface, #ffffff);
  color: var(--pk9-text, #0f172a);
  font-weight: 800;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.pk9-tf-btn.active-true {
  background: #10b981;
  color: #ffffff;
  border-color: #10b981;
}

.pk9-tf-btn.active-false {
  background: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
}

/* Short Answer Input */
.pk9-short-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.pk9-short-input {
  min-width: 220px;
  padding: 0.7rem 1rem;
  border-radius: 0.85rem;
  border: 2px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  color: var(--pk9-text, #0f172a);
  font-size: 1rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
}

.pk9-short-input:focus {
  border-color: #2563eb;
  background: var(--pk9-surface, #ffffff);
}

/* Result & Grading Report */
.pk9-result-banner {
  border-radius: 1.5rem;
  padding: 1.75rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #0f766e 100%);
  color: #ffffff;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.pk9-score-circle {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 4px solid #38bdf8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.35);
}

.pk9-score-circle strong {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  color: #38bdf8;
}

.pk9-score-circle span {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 0.2rem;
}

.pk9-topic-breakdown {
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.25rem;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.pk9-topic-bar-row {
  display: grid;
  grid-template-columns: 180px 1fr 90px;
  gap: 0.85rem;
  align-items: center;
  padding: 0.45rem 0;
  font-size: 0.85rem;
}

.pk9-topic-track {
  height: 0.6rem;
  border-radius: 999px;
  background: var(--pk9-surface-2, #e2e8f0);
  overflow: hidden;
}

.pk9-topic-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #10b981);
}

.pk9-review-card {
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-left: 5px solid #94a3b8;
  border-radius: 1.15rem;
  padding: 1.15rem 1.35rem;
  margin-bottom: 0.9rem;
}

.pk9-review-card.correct {
  border-left-color: #10b981;
}

.pk9-review-card.partial {
  border-left-color: #f59e0b;
}

.pk9-review-card.wrong {
  border-left-color: #ef4444;
}

.pk9-exp-box {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.16);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--pk9-text, #0f172a);
}

@media (max-width: 960px) {
  .pk9-exam-hero-grid,
  .pk9-exam-workspace,
  .pk9-exam-workspace.with-pdf {
    grid-template-columns: 1fr;
  }
  .pk9-exam-pdf-pane {
    position: static;
    height: 55vh;
    min-height: 320px;
  }
  .pk9-exam-palette {
    position: static;
  }
  .pk9-mcq-list {
    grid-template-columns: 1fr;
  }
  .pk9-result-banner {
    grid-template-columns: 1fr;
    text-align: center;
    justify-items: center;
  }
  .pk9-topic-bar-row {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }
  .pk9-exam-sticky-bar {
    top: calc(var(--pk9-topbar-h, 66px) - 2px);
    padding: 0.58rem 0.78rem;
    gap: 0.45rem;
  }
}

/* Status Filter Strip & Exam Paper Themes */
.pk9-exam-status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.pk9-paper-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  padding: 0.22rem;
  border-radius: 999px;
  background: var(--pk9-surface-2, #f1f5f9);
  border: 1px solid var(--pk9-border, #e2e8f0);
}

.pk9-paper-btn {
  border: none;
  background: transparent;
  color: var(--pk9-text-muted, #475569);
  border-radius: 999px;
  padding: 0.26rem 0.56rem;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.pk9-paper-btn.active {
  background: #2563eb;
  color: #ffffff;
}

.pk9-exam-room.paper-white .pk9-q-card {
  background: #ffffff;
}

.pk9-exam-room.paper-ivory .pk9-q-card {
  background: #faf6eb;
  border-color: #e7dec6;
}

.pk9-exam-room.paper-softgray .pk9-q-card {
  background: #eef2f6;
  border-color: #cbd5e1;
}

html.dark .pk9-exam-room.paper-ivory .pk9-q-card {
  background: #1c1b18;
  border-color: #38342b;
}

html.dark .pk9-exam-room.paper-softgray .pk9-q-card {
  background: #171e2b;
  border-color: #2d384b;
}

@media (max-width: 640px) {
  .pk9-exam-hub {
    gap: 0.78rem;
  }
  .pk9-exam-hero {
    padding: 0.88rem 0.85rem;
    border-radius: 1rem;
  }
  .pk9-exam-hero h2 {
    font-size: 1.12rem !important;
    line-height: 1.28 !important;
  }
  .pk9-exam-hero p {
    font-size: 0.8rem !important;
    line-height: 1.45 !important;
  }
  .pk9-exam-kpis {
    gap: 0.42rem;
  }
  .pk9-exam-kpi {
    padding: 0.52rem 0.62rem;
    border-radius: 0.76rem;
  }
  .pk9-exam-kpi strong {
    font-size: 1.08rem;
  }
  .pk9-exam-kpi span {
    font-size: 0.68rem;
  }
  .pk9-exam-toolbar {
    padding: 0.62rem 0.68rem;
    gap: 0.48rem;
    border-radius: 0.92rem;
  }
  .pk9-exam-tabs,
  .pk9-exam-status-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.18rem;
    max-width: 100%;
  }
  .pk9-exam-tabs::-webkit-scrollbar,
  .pk9-exam-status-bar::-webkit-scrollbar {
    display: none;
  }
  .pk9-exam-chip {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.34rem 0.62rem;
    font-size: 0.76rem;
  }
  .pk9-exam-search {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }
  .pk9-exam-card {
    padding: 0.82rem;
    border-radius: 0.95rem;
  }
  .pk9-exam-card:hover {
    transform: none;
  }
  .pk9-exam-sticky-bar {
    top: calc(var(--pk9-topbar-h, 50px) - 1px);
    padding: 0.44rem 0.6rem;
    border-radius: 0.88rem;
    gap: 0.34rem;
    flex-direction: column;
    align-items: stretch;
  }
  .pk9-exam-sticky-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
  }
  .pk9-exam-sticky-org {
    display: none;
  }
  .pk9-exam-sticky-title {
    font-size: 0.83rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pk9-exam-sticky-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .pk9-exam-sticky-controls::-webkit-scrollbar {
    display: none;
  }
  .pk9-timer-pill {
    padding: 0.28rem 0.56rem;
    font-size: 0.78rem;
    flex-shrink: 0;
  }
  .pk9-exam-progress-pill {
    padding: 0.28rem 0.52rem;
    font-size: 0.74rem;
    flex-shrink: 0;
  }
  .pk9-paper-switch {
    padding: 0.14rem;
    flex-shrink: 0;
  }
  .pk9-paper-btn {
    padding: 0.22rem 0.42rem;
    font-size: 0.67rem;
    white-space: nowrap;
  }
  .pk9-btn-exam-primary,
  .pk9-btn-exam-ghost,
  .pk9-mcq-opt,
  .pk9-tf-btn {
    min-height: 40px;
  }
  .pk9-btn-exam-primary,
  .pk9-btn-exam-ghost {
    padding: 0.46rem 0.7rem;
    font-size: 0.79rem;
  }
  .pk9-exam-submit-btn,
  .pk9-exam-pdf-btn,
  .pk9-exam-mode-btn,
  .pk9-exam-palette-btn,
  .pk9-exam-exit-btn {
    min-height: 34px !important;
    padding: 0.28rem 0.56rem !important;
    font-size: 0.74rem !important;
    border-radius: 0.65rem;
    flex-shrink: 0;
    white-space: nowrap;
  }
  .pk9-q-card {
    padding: 0.82rem 0.85rem;
    border-radius: 0.95rem;
    margin-bottom: 0.72rem;
  }
  .pk9-q-prompt {
    font-size: 0.93rem;
    line-height: 1.58;
    margin-bottom: 0.75rem;
  }
  .pk9-mcq-opt {
    padding: 0.58rem 0.72rem;
    font-size: 0.88rem;
    border-radius: 0.78rem;
  }
  .pk9-tf-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.52rem;
    padding: 0.68rem 0.75rem;
  }
  .pk9-tf-text {
    font-size: 0.86rem;
  }
  .pk9-tf-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .pk9-short-input {
    font-size: 16px !important;
  }
}

/* v49: Draft Badge, Single-Question Focus Mode & Mobile Palette Drawer */
.pk9-badge-draft {
  background: rgba(245, 158, 11, 0.16);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.pk9-palette-btn.current {
  outline: 2.5px solid #2563eb;
  outline-offset: 1px;
  font-weight: 900;
}

.pk9-single-q-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  border-radius: 0.95rem;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.pk9-palette-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0.75rem;
}

.pk9-palette-drawer-backdrop.open {
  display: flex;
}

.pk9-palette-drawer {
  width: 100%;
  max-width: 520px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.25rem;
  padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
  animation: pk9SlideUpSheet 0.2s ease-out;
}

.pk9-palette-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--pk9-border, #e2e8f0);
}

@keyframes pk9SlideUpSheet {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================================
 * GROUP 2 UPGRADES: ARENA 1v1, CONTEST BANNER, DIAGNOSTICS, TOOLS & DGNL LOCK
 * ============================================================================ */
.pk9-contest-banner {
  border-radius: 1.25rem;
  padding: 1.1rem 1.35rem;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 55%, #0c4a6e 100%);
  border: 1.5px solid rgba(250, 204, 21, 0.45);
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.22);
}

.pk9-contest-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.68rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: rgba(239, 68, 68, 0.22);
  border: 1px solid rgba(248, 113, 113, 0.55);
  color: #fecaca;
}

.pk9-contest-badge.upcoming {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.5);
  color: #bae6fd;
}

.pk9-contest-badge.ended {
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.45);
  color: #e2e8f0;
}

.pk9-diag-card {
  background: var(--pk9-surface, #ffffff);
  border: 1px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.15rem;
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
}

.pk9-diag-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(120px, 2fr) auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px dashed var(--pk9-border, #e2e8f0);
}

.pk9-diag-row:last-child {
  border-bottom: none;
}

.pk9-arena-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.pk9-arena-box {
  background: var(--pk9-surface, #ffffff);
  border: 1.5px solid var(--pk9-border, #e2e8f0);
  border-radius: 1.2rem;
  padding: 1.15rem 1.25rem;
  min-width: 0;
  max-width: 100%;
}

.pk9-arena-vs-card {
  border-radius: 1.25rem;
  padding: 1.2rem 1.35rem;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #f8fafc;
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  margin-bottom: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.pk9-section-lock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  margin-bottom: 0.85rem;
  border-radius: 0.95rem;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.14), rgba(212, 175, 55, 0.12));
  border: 1.5px solid rgba(56, 189, 248, 0.45);
}

/* Floating Casio Calculator & Canvas Scratchpad */
.pk9-tool-float-card {
  position: fixed;
  z-index: 1250;
  background: var(--pk9-surface, #ffffff);
  color: var(--pk9-text, #0f172a);
  border: 1.5px solid var(--pk9-border, #cbd5e1);
  border-radius: 1.15rem;
  box-shadow: 0 22px 55px rgba(2, 6, 23, 0.38);
  overflow: hidden;
  animation: pk9SlideUpSheet 0.18s ease-out;
}

.pk9-calc-card {
  right: 1rem;
  bottom: 1rem;
  width: min(350px, calc(100vw - 1.5rem));
  background: #0f172a;
  color: #f8fafc;
  border-color: rgba(56, 189, 248, 0.45);
}

.pk9-pad-card {
  left: 1rem;
  bottom: 1rem;
  width: min(480px, calc(100vw - 1.5rem));
}

.pk9-tool-float-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  font-size: 0.84rem;
  font-weight: 800;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.06);
}

.pk9-calc-card .pk9-tool-float-head {
  background: rgba(255, 255, 255, 0.05);
}

.pk9-tool-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-weight: 800;
}

.pk9-calc-screen {
  padding: 0.65rem 0.85rem;
  background: #061322;
  border-bottom: 1px solid rgba(56, 189, 248, 0.22);
}

.pk9-calc-hist {
  min-height: 28px;
  font-size: 0.72rem;
  color: #94a3b8;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
}

.pk9-calc-expr-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: #e2e8f0;
  font-size: 0.95rem;
  font-family: 'JetBrains Mono', monospace;
  text-align: right;
  margin-top: 0.2rem;
}

.pk9-calc-res {
  font-size: 1.45rem;
  font-weight: 900;
  color: #38bdf8;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  margin-top: 0.15rem;
  word-break: break-all;
}

.pk9-calc-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
  padding: 0.65rem;
}

.pk9-calc-key {
  min-height: 38px;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: #1e293b;
  color: #f8fafc;
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
}

.pk9-calc-key.fn { background: #16243b; color: #93c5fd; font-size: 0.75rem; }
.pk9-calc-key.op { background: #1d4ed8; color: #ffffff; }
.pk9-calc-key.warn { background: #92400e; color: #fef3c7; }
.pk9-calc-key.danger { background: #991b1b; color: #fee2e2; }
.pk9-calc-key.eq { background: #059669; color: #ffffff; border-color: #10b981; }
.pk9-calc-key:active { transform: scale(0.96); }

.pk9-pad-colors {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.48rem 0.85rem;
  border-bottom: 1px solid var(--pk9-border, #e2e8f0);
}

.pk9-pad-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  cursor: pointer;
}

.pk9-pad-swatch.active {
  transform: scale(1.16);
  box-shadow: 0 0 0 2px #2563eb;
}

.pk9-pad-mini-btn {
  padding: 0.22rem 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid var(--pk9-border, #cbd5e1);
  background: var(--pk9-surface-2, #f8fafc);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.pk9-pad-mini-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.pk9-pad-canvas-wrap {
  width: 100%;
  height: 280px;
  background-color: #fffef7;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 18px 18px;
  touch-action: none;
}

.pk9-pad-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.pk9-ts-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.85rem;
  margin-top: 0.55rem;
  border-radius: 0.85rem;
  background: var(--pk9-surface-2, #f8fafc);
  border: 1px solid var(--pk9-border, #e2e8f0);
}

.pk9-ts-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.08);
  color: var(--pk9-primary, #2563eb);
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 760px) {
  .pk9-diag-row {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .pk9-arena-vs-card {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .pk9-pad-card {
    left: 0.5rem;
    right: 0.5rem;
    width: auto;
    bottom: calc(var(--pk9-mob-nav-h, 58px) + 0.5rem);
  }
  .pk9-calc-card {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    bottom: calc(var(--pk9-mob-nav-h, 58px) + 0.5rem);
  }
}
