:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #dcdde1;
  --text: #1c1e21;
  --text-muted: #5b5f66;
  --accent: #6e44ff;
  --accent-contrast: #ffffff;
  --correct: #1a7f37;
  --incorrect: #cf222e;
  --warning-bg: #fff4e5;
  --warning-border: #f2a950;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2023;
    --border: #34363b;
    --text: #eaeaea;
    --text-muted: #a3a7ad;
    --accent: #9b7bff;
    --accent-contrast: #14141a;
    --correct: #3fb950;
    --incorrect: #ff7b72;
    --warning-bg: #3a2e12;
    --warning-border: #8a6a1e;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

code {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

h1 { font-size: 1.6rem; margin-bottom: 0.25rem; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
.subtitle { color: var(--text-muted); margin-top: 0; }

.resource-links {
  display: flex;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}
.resource-links span { color: var(--text-muted); }

.btn {
  font: inherit;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-ghost { background: transparent; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar[hidden] {
  display: none;
}
.topbar-progress { font-weight: 600; }
.topbar-timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}
.topbar-timer.timer-low { color: var(--warning-border); }
.topbar-timer.timer-critical { color: var(--incorrect); }
.topbar > :last-child { margin-left: auto; }
.topbar > .btn-primary { margin-left: 0.5rem; }

/* Start screen */
.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1.5rem;
}
.exam-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text);
}
.exam-card:hover { border-color: var(--accent); }
.exam-card-title { font-weight: 700; font-size: 1.05rem; }
.exam-card-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.badge-medium { background: #fff4e5; color: #9a6700; }
.badge-hard { background: #ffe3e3; color: #a40e26; }
@media (prefers-color-scheme: dark) {
  .badge-medium { background: #3a2e12; color: #e2b04a; }
  .badge-hard { background: #3a1418; color: #ff9c9c; }
}
.exam-card-coverage { color: var(--text-muted); font-size: 0.85rem; }

.load-status { color: var(--text-muted); margin-top: 1rem; }

.file-picker {
  margin-top: 1.5rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.file-picker-filenames {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.file-picker-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.75rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Ready screen */
.resume-box {
  margin: 1.25rem 0;
  padding: 1rem;
  border-radius: 10px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
}
.resume-actions { display: flex; gap: 0.6rem; margin-top: 0.6rem; }
.duration-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.5rem 0;
}
.duration-row input {
  width: 5rem;
  font: inherit;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.ready-actions { display: flex; gap: 0.6rem; }

/* Exam view */
.exam-layout {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.exam-main {
  flex: 1 1 65%;
  min-width: 0;
}
.exam-sidebar {
  flex: 0 0 35%;
  max-width: 35%;
}

.question-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.scenario-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.scenario-tag {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.select-hint {
  font-size: 0.8rem;
  color: var(--warning-border);
  font-weight: 600;
}
.question-stem { font-size: 1.1rem; margin: 0 0 1.25rem; }

.choices-list { display: flex; flex-direction: column; gap: 0.6rem; }
.choice-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.choice-row:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.choice-row:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.choice-letter { font-weight: 700; }
.choice-text { flex: 1; }

.exam-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 1.25rem;
}

/* Question map sidebar */
.palette-panel {
  position: sticky;
  top: 5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 600;
}
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 0.4rem;
}
.palette-btn {
  font: inherit;
  padding: 0.5rem 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.palette-btn.palette-answered { background: color-mix(in srgb, var(--correct) 18%, transparent); border-color: var(--correct); }
.palette-btn.palette-current { outline: 2px solid var(--accent); outline-offset: 1px; }
.palette-legend {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.legend-swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  margin-right: 0.3rem;
}
.legend-answered { background: color-mix(in srgb, var(--correct) 18%, transparent); border-color: var(--correct); }
.legend-current { outline: 2px solid var(--accent); }

/* Results */
.score-summary {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 1rem 0;
}
.score-big { font-size: 2.5rem; font-weight: 800; }
.score-pct { font-size: 1.2rem; color: var(--text-muted); }

.warning-banner {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
}

.results-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
}
.stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.stat-table th, .stat-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.stat-table th { color: var(--text-muted); font-weight: 600; }

.results-actions { display: flex; gap: 0.6rem; margin-bottom: 1rem; }

.review-scenario-heading {
  margin-top: 1.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.review-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin: 0.75rem 0;
  background: var(--surface);
}
.review-item.review-correct { border-left-color: var(--correct); }
.review-item.review-incorrect { border-left-color: var(--incorrect); }
.review-item-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}
.review-q-number { font-weight: 700; }
.review-badge {
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}
.review-correct .review-badge { background: color-mix(in srgb, var(--correct) 20%, transparent); color: var(--correct); }
.review-incorrect .review-badge { background: color-mix(in srgb, var(--incorrect) 20%, transparent); color: var(--incorrect); }
.review-domain { color: var(--text-muted); margin-left: auto; }
.review-stem { margin-bottom: 0.5rem; }
.review-answers { display: flex; gap: 1.5rem; font-size: 0.9rem; margin-bottom: 0.5rem; }
.review-rationale { color: var(--text-muted); font-size: 0.9rem; }

@media (max-width: 760px) {
  .exam-layout { flex-direction: column; }
  .exam-sidebar { max-width: none; flex-basis: auto; width: 100%; }
  .palette-panel { position: static; }
}

@media (max-width: 600px) {
  .results-tables { grid-template-columns: 1fr; }
  .review-answers { flex-direction: column; gap: 0.25rem; }
}
