:root {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
}

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

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

header {
  background: linear-gradient(135deg, #1e3a5f, #0f172a);
  border-bottom: 3px solid var(--primary);
  padding: 1.5rem 1rem;
  text-align: center;
}

header h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 0.3rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.info-list {
  margin: 1rem 0 1.5rem 1.2rem;
  color: var(--muted);
}

.info-list li { margin-bottom: 0.5rem; }
.info-list strong { color: var(--text); }

.btn {
  display: inline-block;
  padding: 0.7rem 1.4rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn.secondary { background: var(--border); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: #475569; }

.btn.success { background: var(--success); color: #052e16; }
.btn.success:hover { background: #16a34a; }

.hidden { display: none !important; }

/* Progress */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.25s;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.2rem;
}

/* Question */
.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.4rem;
  margin-bottom: 1.2rem;
}

.topic-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.8rem;
}

.question-text {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.2rem;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.option:hover { border-color: var(--primary); }
.option.selected {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
}

.option input { margin-top: 0.2rem; accent-color: var(--primary); }

.nav-buttons {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  justify-content: space-between;
}

/* Results */
.result-card { text-align: center; }

.score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 8px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1.2rem auto;
  font-size: 2rem;
  font-weight: 700;
}

.score-circle.pass { border-color: var(--success); color: var(--success); }
.score-circle.fail { border-color: var(--danger); color: var(--danger); }

.score-detail { color: var(--muted); margin-bottom: 0.5rem; }

.pass-fail {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}
.pass-fail.pass { color: var(--success); }
.pass-fail.fail { color: var(--danger); }

/* Review */
.review-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
  margin-bottom: 1rem;
}

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

.review-item h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.review-item .your-answer { margin: 0.4rem 0; }
.review-item .correct-answer { color: var(--success); font-weight: 600; }
.review-item .wrong-answer { color: var(--danger); }
.review-item .explain {
  margin-top: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.reference-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.question-references {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

.question-references p { margin: 0.25rem 0; }
.question-references a { color: var(--link, #93c5fd); }

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.muted { color: var(--muted); margin: 0.4rem 0; }
.muted.small { font-size: 0.85rem; }

.level-grid {
  display: grid;
  gap: 0.9rem;
  margin: 1.4rem 0;
}

.level-card {
  text-align: left;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.level-card:hover:not(.locked) {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.level-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.level-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  width: fit-content;
}

.level-meta { font-size: 0.85rem; color: var(--muted); }
.level-status { font-size: 0.9rem; font-weight: 600; color: var(--success); }
.level-card.locked .level-status { color: var(--muted); }

.stats-bar {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  min-height: 1.2em;
}

.disclaimer {
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.exam-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.incentive {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.incentive strong { color: var(--success); }

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: center;
  margin-top: 0.9rem;
}
.top-nav a {
  color: #93c5fd;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.top-nav a:hover { color: #fff; text-decoration: underline; }

.study-card h3 {
  margin: 1.4rem 0 0.6rem;
  font-size: 1.05rem;
  color: #93c5fd;
}
.study-list {
  margin: 0.4rem 0 0.8rem 1.2rem;
  color: var(--muted);
}
.study-list li { margin-bottom: 0.35rem; }
.study-list strong { color: var(--text); }
.study-list.links-list a { color: #93c5fd; }
.study-list.links-list a:hover { color: #fff; }

.table-wrap { overflow-x: auto; margin: 0.6rem 0 1rem; }
.study-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.study-table th,
.study-table td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  text-align: left;
}
.study-table th {
  background: var(--bg);
  color: #93c5fd;
}
.study-table td { color: var(--muted); }
.study-table strong { color: var(--success); }

.links-card .links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin-top: 1rem;
}
.link-block h3 {
  font-size: 1rem;
  color: #93c5fd;
  margin-bottom: 0.5rem;
}
.link-block ul { list-style: none; }
.link-block li { margin-bottom: 0.35rem; }
.link-block a {
  color: #e2e8f0;
  text-decoration: none;
  font-size: 0.9rem;
}
.link-block a:hover { color: #93c5fd; text-decoration: underline; }

footer a { color: #93c5fd; text-decoration: none; }
footer a:hover { text-decoration: underline; }

.share-card .share-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 0.5rem;
}
.share-btn {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  color: #fff;
}
.share-btn.fb { background: #1877f2; }
.share-btn.fb:hover { background: #0d65d9; }
.share-btn.tw { background: #000; }
.share-btn.tw:hover { background: #333; }
.share-btn.copy { background: var(--border); color: var(--text); }
.share-btn.copy:hover { background: #475569; }
.share-msg {
  font-size: 0.85rem;
  color: var(--success);
  margin-top: 0.4rem;
}

.operator-panel {
  display: grid;
  gap: 0.45rem;
  max-width: 430px;
  margin: 1.2rem 0;
}
.operator-panel label { font-weight: 650; }
#operatorName {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#operatorName:focus { outline: 2px solid #60a5fa; outline-offset: 1px; }
.operator-panel p { margin: 0; }
.history-panel { margin-top: 1.5rem; }
.history-panel h3 { margin-bottom: 0.35rem; }
.history-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.55rem;
  margin: 0.85rem 0 0.35rem;
}
.history-controls label { font-size: 0.85rem; color: var(--muted); }
.history-controls select {
  min-width: 125px;
  padding: 0.58rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.history-controls .btn { padding: 0.58rem 0.8rem; font-size: 0.85rem; }
.history-controls button:disabled { opacity: 0.5; cursor: not-allowed; }
.history-message { min-height: 1.3em; margin: 0.2rem 0; }
.timer-choice { display: flex; align-items: center; gap: 0.55rem; margin-top: 0.5rem; cursor: pointer; }
.timer-choice input { width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.timer-panel {
  margin-left: auto;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.15);
  font-variant-numeric: tabular-nums;
}
.timer-panel strong { font-size: 1.1rem; }
.timer-panel.timer-warning { color: #fbbf24; background: rgba(245, 158, 11, 0.14); }
.timer-panel.timer-expired { color: #fca5a5; background: rgba(239, 68, 68, 0.18); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.history-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.history-table th, .history-table td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.7rem;
  text-align: left;
  white-space: nowrap;
}
.history-table th { background: var(--bg); color: #93c5fd; }
.history-table td { color: var(--muted); }
.history-table .history-pass { color: var(--success); font-weight: 700; }
.history-table .history-practice { color: var(--warning); font-weight: 700; }
#exam { scroll-margin-top: 1rem; }
