:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-alt: #F1F5F9;
  --ink: #0F172A;
  --ink-muted: #475569;
  --brand: #0F2942;
  --brand-hover: #163A5C;
  --accent: #C81E1E;
  --accent-hover: #9B1C1C;
  --success: #059669;
  --success-bg: #ECFDF5;
  --warn: #D97706;
  --warn-bg: #FFFBEB;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --border: #E2E8F0;
  --radius-sm: 8px;
  --radius-md: 12px;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

[data-theme="dark"] {
  --bg: #0B1220;
  --surface: #111B2E;
  --surface-alt: #18253D;
  --ink: #F1F5F9;
  --ink-muted: #94A3B8;
  --brand: #E2E8F0;
  --brand-hover: #CBD5E1;
  --border: #24344F;
  --success-bg: #064E3B;
  --warn-bg: #451A03;
  --danger-bg: #450A0A;
}

[data-theme="dark"] .btn-brand {
  background: #1D4ED8;
  color: #FFFFFF;
}
[data-theme="dark"] .btn-brand:hover { background: #1E40AF; }
[data-theme="dark"] .hero-card { background: #162640; border: 1px solid var(--border); }
[data-theme="dark"] .cat-header { background: #0F1D35; border-bottom: 1px solid var(--border); }
[data-theme="dark"] .opt-btn.selected { background: #1E3A5F; border-color: #60A5FA; }
[data-theme="dark"] .opt-btn.selected .opt-key { background: #3B82F6; color: #FFFFFF; }
[data-theme="dark"] .num-cell { background: #DC2626; border-color: #B91C1C; color: #FFFFFF; }
[data-theme="dark"] .num-cell.answered { background: #16A34A; border-color: #15803D; color: #FFFFFF; }
[data-theme="dark"] .num-cell.flagged { background: #F59E0B; border-color: #D97706; color: #111827; }
[data-theme="dark"] .badge-brand { background: #1E3A5F; color: #93C5FD; }
[data-theme="dark"] .input { color: var(--ink); }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

.hidden { display: none !important; }

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 16px;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--brand);
  cursor: pointer;
  user-select: none;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-btn {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--surface-alt);
  color: var(--brand);
}
.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-brand {
  background: var(--brand);
  color: #fff;
}
.btn-brand:hover { background: var(--brand-hover); }
.btn-outline {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--surface-alt); border-color: #CBD5E1; }
.btn-success { background: var(--success); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 0.84rem; }
.btn-block { width: 100%; }

/* Hero */
.hero {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 52px 0 48px;
}
.hero-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.9fr;
  gap: 36px;
  align-items: center;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--danger-bg);
  padding: 5px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.hero h1 {
  font-size: clamp(1.9rem, 3.6vw, 2.75rem);
  line-height: 1.18;
  color: var(--brand);
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}
.hero p {
  color: var(--ink-muted);
  font-size: 1.02rem;
  max-width: 560px;
  margin-bottom: 24px;
}
.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.hero-card {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 24px;
}
.hero-card-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #CBD5E1;
  margin-bottom: 14px;
}
.pg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  font-size: 0.92rem;
}
.pg-row:last-of-type { border-bottom: none; }
.pg-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #FDE68A;
}

/* Sections */
.section { padding: 48px 0; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.section-head h2 {
  font-size: 1.55rem;
  color: var(--brand);
  letter-spacing: -0.015em;
}
.section-head p {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* Cards & Grids */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
}
.pkg-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}
.pkg-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  letter-spacing: 0.03em;
}
.badge-free { background: var(--success-bg); color: var(--success); }
.badge-hot { background: var(--danger-bg); color: var(--accent); }
.badge-brand { background: #EFF6FF; color: var(--brand); }
.pkg-price {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--brand);
  margin: 8px 0;
}
.pkg-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}
.pkg-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.pkg-list li::before {
  content: '✓';
  color: var(--success);
  font-weight: 800;
}

/* Subtest Quick Bar */
.subtest-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.subtest-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* CAT Exam Workspace */
.cat-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--brand);
  color: #fff;
  padding: 12px 0;
}
.cat-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.cat-timer {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  background: rgba(255,255,255,0.14);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
}
.cat-timer.warning { background: var(--accent); }
.cat-stat-pill {
  background: rgba(255,255,255,0.12);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cat-stat-pill strong { font-family: var(--font-mono); font-size: 0.9rem; }
.cat-stat-pill.pill-green { background: rgba(5,150,105,0.32); }
.cat-stat-pill.pill-red { background: rgba(220,38,38,0.35); }
.cat-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  padding: 24px 0 60px;
  align-items: start;
}
.q-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.q-text {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--ink);
  margin-bottom: 22px;
}
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.opt-btn {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}
.opt-btn:hover { background: var(--surface-alt); border-color: #94A3B8; }
.opt-btn.selected {
  border-color: var(--brand);
  background: #EFF6FF;
}
.opt-key {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--brand);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
}
.opt-btn.selected .opt-key {
  background: var(--brand);
  color: #fff;
}
.cat-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* Number Grid */
.num-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 14px 0;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}
.num-cell {
  height: 36px;
  border-radius: 6px;
  border: 1.5px solid #B91C1C;
  background: #DC2626;
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.num-cell.current {
  outline: 3px solid #1D4ED8;
  outline-offset: 2px;
  transform: scale(1.06);
  z-index: 2;
}
.num-cell.answered {
  background: #16A34A;
  color: #FFFFFF;
  border-color: #15803D;
}
.num-cell.flagged {
  background: #F59E0B;
  color: #111827;
  border-color: #D97706;
}

/* Result & Review */
.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 20px 0;
}
.score-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.score-num {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--brand);
}
.review-item {
  border-left: 4px solid var(--border);
  margin-bottom: 16px;
}
.review-item.correct { border-left-color: var(--success); }
.review-item.wrong { border-left-color: var(--danger); }
.explain-box {
  margin-top: 12px;
  background: var(--surface-alt);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* Table */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-alt);
  color: var(--ink-muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
}

/* Modal & Forms */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 80;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--brand);
}
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  background: var(--surface);
}
.input:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

footer {
  background: #0F2942;
  color: #CBD5E1;
  padding: 44px 0 24px;
  margin-top: 48px;
  font-size: 0.88rem;
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.footer-title {
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 12px;
}
.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.footer-links a, .footer-links button {
  background: none;
  border: none;
  padding: 0;
  color: #CBD5E1;
  font-size: 0.86rem;
  cursor: pointer;
  text-align: left;
}
.footer-links a:hover, .footer-links button:hover { color: #FFFFFF; text-decoration: underline; }
.footer-bottom {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 20px;
  font-size: 0.82rem;
  color: #94A3B8;
}

@media (max-width: 900px) {
  .hero-grid, .grid-3, .subtest-bar, .cat-layout, .score-grid, .footer-grid {
    grid-template-columns: 1fr;
  }
  .grid-2 { grid-template-columns: 1fr; }
  .nav-links { display: none; }
}

/* ==================== MOBILE UX OPTIMIZATION (CAT BKN) ==================== */
.cat-header {
  position: sticky;
  top: 0;
  z-index: 40;
}
.mobile-only-grid-btn {
  display: none;
}
.options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.options-list .option-btn,
.options-list .opt-item,
.options-list button {
  min-height: 54px;
  padding: 14px 16px;
  line-height: 1.5;
  touch-action: manipulation;
}
@media (max-width: 768px) {
  .cat-header {
    padding: 8px 0;
  }
  .cat-header-inner {
    gap: 8px;
  }
  .cat-stat-pill,
  #exam-progress-text {
    display: none !important;
  }
  .mobile-only-grid-btn {
    display: inline-flex !important;
    align-items: center;
  }
  .cat-layout {
    grid-template-columns: 1fr !important;
  }
  .exam-num-drawer {
    display: none;
    position: fixed;
    left: 12px;
    right: 12px;
    top: 72px;
    bottom: 16px;
    z-index: 95;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.45);
    border: 2px solid var(--brand);
  }
  .exam-num-drawer.drawer-open {
    display: block;
  }
}
