:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1f2630;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #4493f8;
  --accent-hover: #2f81f7;
  --green: #3fb950;
  --green-bg: #103a1d;
  --red: #f85149;
  --red-bg: #4d1416;
  --yellow: #d29922;
  --radius: 8px;
  --max-width: 820px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 40px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 24px;
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

main {
  flex: 1;
}

footer {
  font-size: 12px;
  margin-top: 32px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.muted { color: var(--text-muted); }

kbd {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 11px;
  color: var(--text);
}

.loading {
  text-align: center;
  padding: 40px 0;
  color: var(--text-muted);
}

/* ===== Home screen ===== */

.home-cta {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 28px;
}

button.primary {
  background: var(--accent);
  color: white;
  font-size: 17px;
  font-weight: 600;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
}

button.primary:hover { background: var(--accent-hover); }
button.primary:disabled {
  background: var(--bg-elev-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

button.secondary {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}
button.secondary:hover { background: var(--bg-elev-2); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.12s;
}
.chip:hover { background: var(--bg-elev-2); }
.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bank-summary {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 14px;
}
.bank-summary table { width: 100%; border-collapse: collapse; }
.bank-summary td { padding: 4px 0; }
.bank-summary td:last-child { text-align: right; color: var(--text-muted); }

.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid;
}
.banner-warn { background: rgba(210, 153, 34, 0.1); border-color: var(--yellow); color: #f0b53e; }
.banner-error { background: var(--red-bg); border-color: var(--red); color: #ff8a85; }

/* ===== Cycle screen ===== */

.progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-elev-2);
  border-radius: 2px;
  margin: 0 14px;
  overflow: hidden;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.question-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.topic-tag {
  display: inline-block;
  background: var(--bg-elev-2);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 14px;
}

.question-text {
  font-size: 17px;
  line-height: 1.6;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  color: var(--text);
  transition: all 0.12s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.choice:hover:not(:disabled):not(.locked) {
  background: #28303a;
  border-color: var(--accent);
}
.choice:disabled, .choice.locked { cursor: default; }

.choice-letter {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 1px;
}

.choice.correct {
  background: var(--green-bg);
  border-color: var(--green);
}
.choice.correct .choice-letter {
  background: var(--green);
  color: white;
  border-color: var(--green);
}
.choice.wrong {
  background: var(--red-bg);
  border-color: var(--red);
}
.choice.wrong .choice-letter {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

.explain-panel {
  margin-top: 20px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  animation: slidein 0.18s ease-out;
}
@keyframes slidein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.explain-panel h4 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
}
.explain-panel h4.correct-h { color: var(--green); }
.explain-panel h4.wrong-h { color: var(--red); }
.explain-panel p { margin: 0 0 14px; font-size: 14px; line-height: 1.6; }
.explain-panel .source-link {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
.explain-panel .source-link:hover { text-decoration: underline; }

.next-row {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

/* ===== End-of-cycle screen ===== */

.cycle-summary {
  text-align: center;
  padding: 28px 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 22px;
}
.cycle-summary .score {
  font-size: 56px;
  font-weight: 700;
  margin: 8px 0 4px;
  color: var(--accent);
}
.cycle-summary .score-pct { color: var(--text-muted); font-size: 14px; }

.topic-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.topic-cell {
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 10px 12px;
  text-align: left;
}
.topic-cell .label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.topic-cell .value {
  font-size: 18px;
  font-weight: 600;
  margin-top: 2px;
}

.review-list { margin-top: 20px; }
.review-list h3 { font-size: 16px; margin: 0 0 12px; }
.review-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 14px;
}
.review-item .q { font-weight: 500; margin-bottom: 6px; }
.review-item .a { color: var(--text-muted); margin-bottom: 4px; }
.review-item .a strong { color: var(--green); }
.review-item .source-link { color: var(--accent); font-size: 12px; }

.end-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}
.end-actions button { flex: 1; }
