:root {
  --base-font-size: 16px;
  --bg-page: #f3f5f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-hover: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  --border-color: #e2e8f0;

  /* OCSC Royal Navy & Gold Palette */
  --primary: #1e3a8a;
  --primary-hover: #172554;
  --primary-soft: #eff6ff;
  --gold: #b45309;
  --gold-soft: #fef3c7;

  /* Subject Colors */
  --eng-color: #0284c7;
  --eng-soft: #e0f2fe;
  --mt-color: #7c3aed;
  --mt-soft: #ede9fe;
  --law-color: #0f766e;
  --law-soft: #ccfbf1;

  /* Status Colors */
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.07);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="dark"] {
  --bg-page: #0b1120;
  --bg-surface: #131c31;
  --bg-subtle: #1a2642;
  --bg-hover: #223052;
  --text-main: #f1f5f9;
  --text-muted: #cbd5e1;
  --text-light: #94a3b8;
  --border-color: #29395b;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.16);

  --eng-color: #38bdf8;
  --eng-soft: rgba(56, 189, 248, 0.15);
  --mt-color: #a78bfa;
  --mt-soft: rgba(167, 139, 250, 0.15);
  --law-color: #2dd4bf;
  --law-soft: rgba(45, 212, 191, 0.15);

  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.16);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: var(--base-font-size);
  scroll-behavior: smooth;
}

body {
  font-family: "Sarabun", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.65;
  min-height: 100vh;
}

h1, h2, h3, h4, .brand-title, .btn, .badge, .q-num-pill {
  font-family: "Prompt", "Sarabun", sans-serif;
}

.hidden {
  display: none !important;
}

.w-full {
  width: 100%;
}

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.brand-emblem {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3a8a, #b45309);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
  box-shadow: 0 3px 10px rgba(30, 58, 138, 0.25);
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.25;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-light);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.font-controls {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ctrl-btn {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.font-controls .ctrl-btn {
  border: none;
  border-right: 1px solid var(--border-color);
}

.font-controls .ctrl-btn:last-child {
  border-right: none;
}

.ctrl-btn:hover {
  background: var(--bg-hover);
}

#btnThemeToggle {
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.timer-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(59, 130, 246, 0.35);
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  font-family: "Prompt", monospace;
  font-weight: 600;
  font-size: 0.95rem;
}

.timer-pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: var(--warning);
}

.timer-pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
  animation: pulseAlert 1s infinite alternate;
}

@keyframes pulseAlert {
  from { opacity: 1; }
  to { opacity: 0.65; }
}

.icon-mini-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: inherit;
  padding: 0 2px;
}

/* ==================== MAIN CONTAINER & VIEWS ==================== */
.main-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3.5rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

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

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.16s ease;
  text-decoration: none;
}

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

.btn-lg {
  padding: 0.75rem 1.4rem;
  font-size: 0.98rem;
  font-weight: 600;
}

.btn-sm {
  padding: 0.42rem 0.85rem;
  font-size: 0.84rem;
}

.btn-xs {
  padding: 0.25rem 0.55rem;
  font-size: 0.76rem;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--primary);
  border-color: rgba(30, 58, 138, 0.25);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--primary-soft);
}

.btn-outline {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-warning:hover:not(:disabled) {
  filter: brightness(0.93);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.btn-text-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

/* ==================== HERO & CARDS ==================== */
.hero-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 65%, #1d4ed8 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.75rem;
  align-items: center;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.8rem;
}

.hero-badge {
  display: inline-block;
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fde68a;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.22rem 0.7rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.hero-content h1 {
  font-size: 1.75rem;
  margin-bottom: 0.65rem;
  line-height: 1.3;
}

.hero-content p {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.98rem;
  margin-bottom: 1.3rem;
}

.hero-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.hero-quick-actions .btn-primary {
  background: #f59e0b;
  color: #0f172a;
}

.hero-quick-actions .btn-primary:hover {
  background: #fbbf24;
}

.hero-quick-actions .btn-outline {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.4);
}

.hero-quick-actions .btn-outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

.hero-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

.stat-box {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.stat-num {
  font-family: "Prompt", sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.15;
  color: #fde68a;
}

.stat-label {
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 0.2rem;
}

.stat-sub {
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.75);
}

.section-header {
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.28rem;
}

.section-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ==================== PRESET CARDS ==================== */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.8rem;
}

.preset-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
}

.preset-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.preset-card.featured {
  border: 2px solid var(--primary);
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--bg-surface) 38%);
}

.preset-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  margin-bottom: 0.6rem;
}

.tag-eng { background: var(--eng-soft); color: var(--eng-color); }
.tag-mt { background: var(--mt-soft); color: var(--mt-color); }
.tag-law { background: var(--law-soft); color: var(--law-color); }

.preset-card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.45rem;
}

.preset-card p {
  font-size: 0.87rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  flex-grow: 1;
}

.preset-meta {
  list-style: none;
  font-size: 0.82rem;
  color: var(--text-light);
  margin-bottom: 1rem;
  border-top: 1px dashed var(--border-color);
  padding-top: 0.65rem;
}

.preset-meta li {
  margin-bottom: 0.22rem;
}

.preset-btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* ==================== CUSTOM BUILDER & SIDEBAR ==================== */
.builder-layout {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  margin-bottom: 1.1rem;
}

.card-header h3 {
  font-size: 1.1rem;
  margin-bottom: 0.2rem;
}

.card-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.86rem;
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.58rem 0.8rem;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text-main);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.form-control:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.form-control-sm {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
  width: auto;
}

.checkbox-row {
  margin: 0.75rem 0 1.15rem;
  padding: 0.7rem 0.9rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.builder-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.pool-info {
  font-size: 0.92rem;
  color: var(--text-muted);
}

.side-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Year Bars */
.year-bars {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.y-row {
  display: grid;
  grid-template-columns: 58px 1fr 78px;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
}

.y-label {
  font-weight: 600;
}

.y-track {
  height: 10px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.y-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #3b82f6);
}

.y-fill.hot {
  background: linear-gradient(90deg, #d97706, #f59e0b);
}

.y-count {
  text-align: right;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 220px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
}

.history-title {
  font-weight: 600;
}

.history-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

.history-score {
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.history-score.pass { background: var(--success-soft); color: var(--success); }
.history-score.fail { background: var(--danger-soft); color: var(--danger); }

.empty-note {
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: center;
  padding: 1rem 0;
}

.bank-explorer-card {
  margin-top: 0.5rem;
}

/* ==================== ACTIVE EXAM VIEW ==================== */
.exam-topbar-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.exam-info-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.exam-info-left h2 {
  font-size: 1.15rem;
}

.exam-info-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.badge {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
}

.badge-primary {
  background: var(--primary-soft);
  color: var(--primary);
}

.progress-stat {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.exam-progress-bar {
  height: 6px;
  background: var(--border-color);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.exam-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #10b981);
  transition: width 0.25s ease;
}

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

.question-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.6rem;
  box-shadow: var(--shadow-sm);
}

.q-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-bottom: 1rem;
  margin-bottom: 1.15rem;
  border-bottom: 1px solid var(--border-color);
}

.q-meta-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.q-num-pill {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.22rem 0.7rem;
  border-radius: 999px;
}

.q-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.q-tag-year {
  background: var(--gold-soft);
  color: var(--gold);
}

.flag-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.flag-btn.flagged {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning);
}

/* Passage / Table / Condition Box */
.passage-box {
  background: var(--bg-subtle);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 1.05rem 1.2rem;
  margin-bottom: 1.2rem;
  font-size: 0.96rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

.passage-box table,
.review-passage table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.9rem;
  white-space: normal;
}

.passage-box th,
.passage-box td,
.review-passage th,
.review-passage td {
  border: 1px solid var(--border-color);
  padding: 0.48rem 0.65rem;
  text-align: center;
}

.passage-box th,
.review-passage th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.q-stem {
  font-size: 1.08rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  white-space: pre-wrap;
}

/* Choices */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1.35rem;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  width: 100%;
  text-align: left;
  padding: 0.9rem 1.05rem;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  cursor: pointer;
  transition: all 0.14s ease;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--bg-subtle);
}

.choice-prefix {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.88rem;
  flex-shrink: 0;
}

.choice-btn.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

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

.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.choice-btn.correct .choice-prefix {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.choice-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.choice-btn.wrong .choice-prefix {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* Explanation Box */
.explain-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
  font-size: 0.95rem;
}

.explain-box.wrong-explain {
  border-left-color: var(--danger);
}

.explain-title {
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.q-nav-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.kbd-hint {
  font-size: 0.78rem;
  color: var(--text-light);
}

.kbd-hint code {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Scratchpad */
.scratchpad-card {
  margin-top: 1rem;
}

.scratch-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-dot.active {
  outline: 2px solid var(--text-main);
  outline-offset: 2px;
}

.scratchpad-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 0.85rem;
}

.canvas-wrap {
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  overflow: hidden;
}

#scratchCanvas {
  width: 100%;
  height: 240px;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.scratch-textarea {
  width: 100%;
  height: 240px;
  resize: vertical;
  padding: 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

/* Palette Sidebar */
.palette-sidebar {
  position: sticky;
  top: 76px;
}

.palette-header {
  margin-bottom: 0.75rem;
}

.palette-header h4 {
  margin-bottom: 0.5rem;
}

.palette-filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 6px;
}

.p-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.2rem;
  border-radius: 5px;
  cursor: pointer;
}

.p-tab.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.palette-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 3px;
}

.dot-answered { background: var(--primary); }
.dot-unanswered { background: var(--border-color); }
.dot-flagged { background: var(--warning); }

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  max-height: 390px;
  overflow-y: auto;
  padding-right: 2px;
  margin-bottom: 1rem;
}

.p-cell {
  position: relative;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}

.p-cell:hover {
  border-color: var(--primary);
}

.p-cell.current {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.p-cell.answered {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.p-cell.p-correct {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.p-cell.p-wrong {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.p-cell.flagged::after {
  content: "★";
  position: absolute;
  top: -4px;
  right: 1px;
  font-size: 0.68rem;
  color: #f59e0b;
}

/* ==================== RESULTS & ANALYTICS ==================== */
.result-banner {
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.result-banner.failed-banner {
  background: linear-gradient(135deg, #450a0a, #991b1b);
}

.pass-pill {
  display: inline-block;
  padding: 0.28rem 0.85rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.84rem;
  background: #22c55e;
  color: #052e16;
  margin-bottom: 0.65rem;
}

.pass-pill.fail {
  background: #fca5a5;
  color: #450a0a;
}

.result-status-wrap h1 {
  font-size: 1.65rem;
  margin-bottom: 0.4rem;
}

.result-status-wrap p {
  color: rgba(255, 255, 255, 0.88);
}

.result-score-circle {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-md);
  padding: 1.2rem 1.8rem;
  text-align: center;
  min-width: 210px;
}

.score-big {
  font-family: "Prompt", sans-serif;
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: #fde68a;
}

.score-sub {
  font-weight: 600;
  margin-top: 0.2rem;
}

.score-time {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.78);
  margin-top: 0.2rem;
}

.subject-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.subj-score-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.subj-score-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.subj-pass-tag {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
}

.subj-pass-tag.pass { background: var(--success-soft); color: var(--success); }
.subj-pass-tag.fail { background: var(--danger-soft); color: var(--danger); }

.subj-nums {
  font-size: 1.45rem;
  font-weight: 700;
  font-family: "Prompt", sans-serif;
  margin-bottom: 0.35rem;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bd-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.bd-label-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
  font-weight: 600;
}

.bd-bar {
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.bd-fill {
  height: 100%;
  border-radius: 999px;
}

.result-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}

/* Detailed Review Cards */
.review-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.review-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin-top: 1.1rem;
}

.review-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  background: var(--bg-subtle);
}

.review-item.is-correct {
  border-left: 4px solid var(--success);
}

.review-item.is-wrong {
  border-left: 4px solid var(--danger);
}

.review-passage {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin: 0.75rem 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

.review-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin: 0.85rem 0;
}

.rev-choice {
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.rev-choice.ans-correct {
  background: var(--success-soft);
  border-color: var(--success);
  font-weight: 600;
}

.rev-choice.ans-user-wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.review-explain {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  border: 1px dashed var(--border-color);
}

/* ==================== MODAL ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  max-width: 460px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.modal-card h3 {
  margin-bottom: 0.6rem;
}

.modal-card p {
  color: var(--text-muted);
  margin-bottom: 1.35rem;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1080px) {
  .preset-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hero-card,
  .builder-layout,
  .exam-workspace,
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  .palette-sidebar {
    position: static;
  }
  .palette-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}

@media (max-width: 680px) {
  .preset-grid,
  .form-grid,
  .scratchpad-grid,
  .review-choices {
    grid-template-columns: 1fr;
  }
  .palette-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .result-banner {
    flex-direction: column;
    text-align: center;
  }
  .kbd-hint {
    display: none;
  }
}


/* ==================== UPGRADE STYLES (6 NEW FEATURES) ==================== */
.ctrl-accent {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(59, 130, 246, 0.35);
}

.ctrl-accent:hover {
  background: var(--primary);
  color: #ffffff;
}

/* Resume Banner */
.resume-banner {
  background: linear-gradient(135deg, var(--warning-soft), var(--bg-surface));
  border: 2px solid var(--warning);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.4rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.resume-badge {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--warning);
  color: #fff;
  padding: 0.16rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
}

.resume-info h3 {
  font-size: 1.05rem;
  margin-bottom: 0.15rem;
}

.resume-info p {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Degree Bar */
.degree-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1.1rem;
  padding: 0.55rem 0.85rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: var(--radius-sm);
}

.degree-bar label {
  font-size: 0.88rem;
  font-weight: 600;
  color: #fde68a;
}

.degree-select {
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 23, 42, 0.75);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.checkbox-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* Passage Group Banner */
.passage-group-banner {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: 6px;
  padding: 0.42rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.86rem;
  white-space: normal;
}

/* Per-question Timer Pace Pill */
.q-pace-tag {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-family: "Prompt", monospace;
}

.q-pace-tag.pace-warn {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: var(--warning);
}

/* Choice Elimination Row */
.choice-row {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
}

.choice-row .choice-btn {
  flex: 1;
}

.choice-row.eliminated .choice-btn {
  opacity: 0.44;
  text-decoration: line-through;
  background: var(--bg-subtle);
}

.elim-btn {
  width: 38px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-light);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.14s;
}

.elim-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.choice-row.eliminated .elim-btn {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* Personal Note Per Question */
.personal-note-section {
  margin-bottom: 1.1rem;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--border-color);
}

.note-saved-badge {
  font-size: 0.78rem;
  color: var(--success);
  font-weight: 600;
}

.note-wrap {
  margin-top: 0.5rem;
}

.note-textarea {
  width: 100%;
  min-height: 70px;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.review-note-box {
  margin-top: 0.6rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border-left: 3px solid var(--gold);
  font-size: 0.88rem;
}

/* Time Management Coach */
.time-coach-card {
  margin-bottom: 1.5rem;
}

.time-coach-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1.25rem;
}

.mini-heading {
  font-size: 0.95rem;
  margin-bottom: 0.7rem;
  color: var(--text-main);
}

.slow-q-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.slow-q-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.58rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.14s;
}

.slow-q-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.slow-q-time {
  font-family: "Prompt", monospace;
  font-weight: 700;
  color: var(--warning);
  flex-shrink: 0;
}

/* ==================== STUDY HUB (CHEAT SHEETS & FLASHCARDS) ==================== */
.study-header-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.study-header-bar p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.study-tabs {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.study-tab {
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: "Prompt", sans-serif;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.study-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.cs-selector-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.cs-pill-btn {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

.cs-pill-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.cs-content-card h3 {
  font-size: 1.2rem;
  margin-bottom: 0.25rem;
}

.cs-section {
  margin-top: 1.35rem;
}

.cs-section h4 {
  font-size: 1.02rem;
  margin-bottom: 0.7rem;
  color: var(--primary);
}

.cs-table-wrap {
  overflow-x: auto;
}

.cs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.cs-table th,
.cs-table td {
  border: 1px solid var(--border-color);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.cs-table th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.cs-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.cs-mini-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem 1.15rem;
  font-size: 0.9rem;
}

.cs-mini-card h5 {
  font-size: 0.96rem;
  margin-bottom: 0.5rem;
}

.cs-mini-card ul {
  padding-left: 1.2rem;
}

.cs-mini-card li {
  margin-bottom: 0.35rem;
}

.cs-mini-card code,
.cs-table code {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.86em;
}

/* Flashcards */
.fc-toolbar-card {
  margin-bottom: 1.25rem;
}

.fc-progress-wrap {
  min-width: 240px;
}

.fc-progress-track {
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}

.fc-progress-fill {
  height: 100%;
  background: var(--success);
  transition: width 0.25s ease;
}

.fc-stage {
  max-width: 680px;
  margin: 0 auto;
}

.flashcard-3d {
  perspective: 1100px;
  height: 310px;
  cursor: pointer;
  margin-bottom: 1.15rem;
}

.fc-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}

.flashcard-3d.flipped .fc-inner {
  transform: rotateY(180deg);
}

.fc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.fc-back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--bg-surface) 45%);
  border-color: var(--primary);
}

.fc-hint-pill {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-light);
  margin-bottom: 0.9rem;
}

.fc-pos {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.2rem;
}

.fc-word {
  font-family: "Prompt", sans-serif;
  font-size: 2.3rem;
  font-weight: 700;
}

.fc-meaning {
  font-family: "Prompt", sans-serif;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.fc-synonyms {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.fc-example-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  width: 100%;
  font-size: 0.92rem;
}

.fc-ex-en {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.fc-ex-th {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.fc-nav-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.fc-counter {
  font-weight: 700;
  padding: 0 0.45rem;
}

/* ==================== PRINT / PDF MODE ==================== */
.print-only {
  display: none;
}

@media (max-width: 900px) {
  .time-coach-grid,
  .cs-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11.5pt !important;
    line-height: 1.45 !important;
  }
  header.topbar,
  main.main-container,
  .app-footer,
  .modal-backdrop {
    display: none !important;
  }
  .print-only {
    display: block !important;
    padding: 0;
  }
  .print-header {
    border-bottom: 2px solid #000;
    padding-bottom: 8px;
    margin-bottom: 14px;
  }
  .print-header h1 {
    font-size: 15pt;
    margin-bottom: 3px;
  }
  .print-passage-box {
    border: 1px solid #444;
    background: #f8f8f8;
    padding: 8px 10px;
    margin: 10px 0 8px;
    white-space: pre-wrap;
    break-inside: avoid;
  }
  .print-passage-box table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
  }
  .print-passage-box th,
  .print-passage-box td {
    border: 1px solid #333;
    padding: 4px 6px;
    text-align: center;
  }
  .print-q-block {
    margin-bottom: 12px;
    break-inside: avoid;
  }
  .print-q-stem {
    font-weight: 700;
    margin-bottom: 4px;
    white-space: pre-wrap;
  }
  .print-choices {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 3px 14px;
    padding-left: 12px;
  }
  .print-answer-page {
    break-before: page;
    page-break-before: always;
  }
  .print-ans-item {
    border-bottom: 1px solid #ccc;
    padding: 6px 0;
    break-inside: avoid;
    font-size: 10.5pt;
  }
}

/* ==================== SIGNATURE / PEN NAME ==================== */
.sig-pill {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.3px;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.12), rgba(180, 83, 9, 0.15));
  color: var(--gold);
  border: 1px solid rgba(180, 83, 9, 0.32);
  vertical-align: middle;
}

.app-footer {
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  padding: 1.1rem 1.25rem;
  margin-top: 1.5rem;
}

.footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.signature-mark {
  font-family: "Prompt", "Georgia", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.8px;
  background: linear-gradient(135deg, var(--primary), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.footer-text {
  font-size: 0.84rem;
  color: var(--text-light);
}
