/* ─── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 22px; border-radius: var(--radius-sm); font-size: 0.9rem;
  font-weight: 600; font-family: var(--font-system); cursor: pointer;
  border: none; transition: all var(--transition-normal); text-decoration: none;
  letter-spacing: 0.01em; white-space: nowrap;
}
.btn-lg { padding: 14px 32px; font-size: 1rem; border-radius: var(--radius-md); }
.btn-sm { padding: 7px 16px; font-size: 0.82rem; }

.btn-primary {
  background: var(--accent-gold); color: #0a0600;
  box-shadow: 0 4px 20px rgba(201, 168, 76, 0.35);
}
.btn-primary:hover {
  background: var(--accent-gold-hover); color: #0a0600;
  transform: translateY(-1px); box-shadow: 0 6px 28px rgba(201, 168, 76, 0.50);
}
.btn-jade {
  background: var(--accent-jade); color: #fff;
  box-shadow: 0 4px 20px rgba(45, 134, 83, 0.35);
}
.btn-jade:hover {
  background: var(--accent-jade-hover); color: #fff;
  transform: translateY(-1px);
}
.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}
.btn-ghost:hover { border-color: var(--accent-gold); color: var(--accent-gold); }
.btn-danger {
  background: var(--accent-vermillion-dim); color: #e87070;
  border: 1px solid rgba(192,57,43,0.3);
}
.btn-danger:hover { background: rgba(192,57,43,0.25); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* ─── Cards ───────────────────────────────────────── */
.card {
  background: var(--gradient-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: var(--space-xl);
  transition: all var(--transition-normal);
}
.card:hover {
  border-color: var(--glass-border-hover);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), var(--shadow-glow-gold);
}
.card-sm { padding: var(--space-lg); border-radius: var(--radius-md); }
.card-interactive { cursor: pointer; }

/* ─── Badge / Tag ─────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--radius-full);
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
.badge-gold  { background: var(--accent-gold-dim); color: var(--accent-gold); border: 1px solid rgba(201,168,76,0.25); }
.badge-jade  { background: var(--accent-jade-dim); color: var(--accent-jade-hover); border: 1px solid rgba(45,134,83,0.25); }
.badge-sky   { background: var(--accent-sky-dim); color: var(--accent-sky); border: 1px solid rgba(74,144,196,0.25); }
.badge-red   { background: var(--accent-vermillion-dim); color: #e07070; border: 1px solid rgba(192,57,43,0.25); }
.badge-ai    { background: rgba(201,168,76,0.10); color: var(--accent-gold); border: 1px solid rgba(201,168,76,0.20); }

/* ─── Forms ───────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }
.form-input {
  background: var(--bg-tertiary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 11px 14px;
  font-size: 0.95rem; color: var(--text-primary); font-family: var(--font-system);
  transition: border-color var(--transition-fast); outline: none; width: 100%;
}
.form-input:focus { border-color: var(--accent-gold); box-shadow: 0 0 0 3px var(--accent-gold-dim); }
.form-input::placeholder { color: var(--text-tertiary); }

/* ─── Stats ───────────────────────────────────────── */
.stat-card { text-align: center; }
.stat-number {
  font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -0.03em;
  background: var(--gradient-gold); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
}
.stat-label { font-size: 0.78rem; color: var(--text-tertiary); margin-top: 4px; letter-spacing: 0.05em; text-transform: uppercase; }

/* ─── Question Card ───────────────────────────────── */
.question-card {
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: var(--space-xl); margin-bottom: var(--space-lg);
}
.question-num {
  font-size: 0.78rem; font-weight: 600; color: var(--accent-gold);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: var(--space-md);
}
.question-text {
  font-size: 1.05rem; color: var(--text-primary); line-height: 1.75;
  margin-bottom: var(--space-lg); font-weight: 500;
}
.question-image { margin: calc(-1 * var(--space-sm)) 0 var(--space-lg); }
.question-image img {
  display: block; max-width: 100%; max-height: 420px; height: auto;
  border-radius: var(--radius-sm); background: #fff;
}
.options-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.option-item {
  display: flex; align-items: flex-start; gap: var(--space-md);
  padding: 12px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border); cursor: pointer;
  transition: all var(--transition-fast); font-size: 0.95rem;
  color: #ffffff; background: transparent;
  text-align: left; width: 100%; font-family: var(--font-system);
}
.option-item:hover:not(:disabled) {
  border-color: var(--accent-gold); color: var(--text-primary);
  background: var(--accent-gold-dim);
}
.option-item.selected {
  border-color: var(--accent-gold); background: var(--accent-gold-dim);
  color: var(--text-primary);
}
.option-item.correct {
  border-color: var(--accent-jade); background: var(--accent-jade-dim);
  color: var(--text-primary);
}
.option-item.incorrect {
  border-color: var(--accent-vermillion); background: var(--accent-vermillion-dim);
  color: var(--text-primary);
}
.option-label {
  width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; flex-shrink: 0; margin-top: 1px;
}

/* ─── Explanation Box ─────────────────────────────── */
.explanation-box {
  margin-top: var(--space-lg); padding: var(--space-lg);
  background: rgba(201,168,76,0.05); border: 1px solid rgba(201,168,76,0.15);
  border-radius: var(--radius-md); border-left: 3px solid var(--accent-gold);
}
.explanation-title {
  font-size: 0.82rem; font-weight: 700; color: var(--accent-gold);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: var(--space-sm);
}
.explanation-text { font-size: 0.92rem; color: #ffffff; line-height: 1.8; white-space: pre-wrap; }

/* ─── Progress Bar ────────────────────────────────── */
.progress-bar {
  height: 3px; background: var(--bg-tertiary); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--gradient-gold); border-radius: 2px;
  transition: width 0.4s ease;
}

/* ─── Score Display ───────────────────────────────── */
.score-display {
  text-align: center; padding: var(--space-2xl);
}
.score-ring {
  width: 140px; height: 140px; border-radius: 50%;
  border: 4px solid var(--glass-border); margin: 0 auto var(--space-xl);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
}
.score-ring.pass { border-color: var(--accent-jade); box-shadow: var(--shadow-glow-jade); }
.score-ring.fail { border-color: var(--accent-vermillion); }
.score-pct { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.04em; }
.score-pct.pass { color: var(--accent-jade-hover); }
.score-pct.fail { color: #e07070; }
.score-label { font-size: 0.72rem; color: var(--text-tertiary); letter-spacing: 0.06em; text-transform: uppercase; }

/* ─── Table ───────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th {
  text-align: left; padding: 10px 14px; color: var(--text-tertiary);
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--glass-border);
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.04); color: var(--text-secondary); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-card); }

/* ─── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000; padding: var(--space-md); backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: var(--space-2xl); max-width: 480px;
  width: 100%; box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: var(--space-md); }
.modal p  { margin-bottom: var(--space-xl); }
.modal-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; }

/* ─── Exam bar: question navigator + flagging ─────── */
.exam-bar {
  position: sticky; top: var(--nav-height); z-index: 100;
  background: rgba(8,8,8,0.95); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
  padding: 10px 0; margin-bottom: var(--space-xl);
}
.exam-bar-inner {
  max-width: 800px; margin: 0 auto; padding: 0 var(--space-lg);
  display: flex; align-items: center; gap: var(--space-md);
  flex-wrap: wrap;
}
.q-dots {
  display: flex; flex-wrap: wrap; gap: 4px;
  flex: 1 1 240px; min-width: 0;
}
.q-dot {
  position: relative;
  width: 20px; height: 20px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--glass-border); font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); transition: all 0.15s ease;
}
.q-dot.answered {
  background: var(--accent-gold-dim); border-color: rgba(201,168,76,0.4);
  color: var(--accent-gold);
}
.q-dot.active {
  border-color: var(--accent-gold); color: var(--accent-gold);
  box-shadow: 0 0 6px rgba(201,168,76,0.3);
}
/* Flag marker sits in the corner so it reads independently of answered state */
.q-dot.flagged::after {
  content: ''; position: absolute; top: -2px; right: -2px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-sky); border: 1px solid rgba(8,8,8,0.9);
}
.q-dot.flagged { border-color: rgba(74,144,196,0.55); }

/* Collapsed: hide the 題號 grid, keep counters + timer on one compact row */
.exam-bar.collapsed .q-dots { display: none; }
.exam-bar.collapsed .exam-bar-inner { justify-content: flex-end; }

.nav-collapse-btn {
  font-size: 0.75rem; font-weight: 600; padding: 3px 9px;
  border-radius: 12px; border: 1px solid var(--glass-border);
  background: transparent; color: var(--text-tertiary); cursor: pointer;
  white-space: nowrap; font-family: var(--font-system);
  transition: all var(--transition-fast);
}
.nav-collapse-btn:hover { border-color: var(--accent-gold); color: var(--accent-gold); }

.exam-bar-meta {
  display: flex; align-items: center; gap: var(--space-sm);
  flex-shrink: 0; flex-wrap: wrap;
}
.flag-count {
  font-size: 0.78rem; font-weight: 700; padding: 3px 9px; border-radius: 12px;
  border: 1px solid var(--glass-border); color: var(--text-tertiary);
  background: transparent; cursor: pointer; white-space: nowrap;
  font-family: var(--font-system); transition: all var(--transition-fast);
}
.flag-count.has-flags {
  color: var(--accent-sky); border-color: rgba(74,144,196,0.45);
  background: var(--accent-sky-dim);
}
.flag-count:hover { border-color: var(--accent-sky); color: var(--accent-sky); }
.only-flagged-btn {
  font-size: 0.75rem; padding: 3px 9px; border-radius: 12px;
  border: 1px solid var(--glass-border); background: transparent;
  color: var(--text-tertiary); cursor: pointer; white-space: nowrap;
  font-family: var(--font-system); transition: all var(--transition-fast);
}
.only-flagged-btn:hover,
.only-flagged-btn.active {
  border-color: var(--accent-sky); color: var(--accent-sky);
  background: var(--accent-sky-dim);
}

/* Per-question flag toggle */
.flag-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.75rem; font-weight: 600; padding: 4px 10px;
  border-radius: 12px; border: 1px solid var(--glass-border);
  background: transparent; color: var(--text-tertiary); cursor: pointer;
  font-family: var(--font-system); transition: all var(--transition-fast);
  text-transform: none; letter-spacing: normal;
}
.flag-btn:hover { border-color: var(--accent-sky); color: var(--accent-sky); }
.flag-btn.active {
  border-color: rgba(74,144,196,0.5); background: var(--accent-sky-dim);
  color: var(--accent-sky);
}
.question-card.flagged { border-color: rgba(74,144,196,0.45); }
.question-card.flagged .question-num::before {
  content: '⚑ '; color: var(--accent-sky);
}

/* Mobile: controls take their own full-width row so they can never be pushed
   off-screen, and the 題號 grid gets the whole width below them. */
@media (max-width: 700px) {
  .exam-bar-inner {
    padding: 0 var(--space-md);
    align-items: stretch;
    gap: 8px;
  }
  .exam-bar-meta {
    order: -1;                 /* controls above the grid */
    width: 100%; flex: 0 0 100%;
    justify-content: space-between;
    gap: 6px;
  }
  .q-dots {
    width: 100%; flex: 0 0 100%;
    max-height: 34vh; overflow-y: auto;   /* 100 題不會吃掉整個畫面 */
    gap: 5px;
  }
  .q-dot {
    width: 28px; height: 28px;            /* 可點擊的觸控目標 */
    font-size: 0.7rem; border-radius: 5px;
  }
  .q-dot.flagged::after { width: 8px; height: 8px; }
  #answered-count { display: inline; }
  .nav-collapse-btn, .flag-count, .only-flagged-btn {
    padding: 6px 10px;                    /* 更好按 */
  }
}

/* ─── Timer ───────────────────────────────────────── */
.timer-display {
  font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
  font-variant-numeric: tabular-nums; letter-spacing: 0.05em;
}
.timer-display.warning { color: var(--accent-gold); }
.timer-display.danger  { color: #e07070; animation: pulse 1s ease infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

/* ─── Divider ─────────────────────────────────────── */
.divider-line {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--glass-border), transparent);
}

/* ─── Gradient text ───────────────────────────────── */
.gradient-text {
  background: linear-gradient(135deg, #e8d5a0, var(--accent-gold), #8B6914);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* ─── Breadcrumb nav ──────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.82rem; color: var(--text-tertiary); margin-bottom: var(--space-lg);
}
.breadcrumb a { color: var(--text-tertiary); }
.breadcrumb a:hover { color: var(--accent-gold); }
.breadcrumb-sep { opacity: 0.4; }

/* ─── Empty state ─────────────────────────────────── */
.empty-state {
  text-align: center; padding: var(--space-3xl) var(--space-xl);
  color: var(--text-tertiary);
}
.empty-state p { margin-top: var(--space-md); }
