/* styles.css — CSR MCQ quiz: clean, readable, light + dark (prefers-color-scheme).
 * Green/red feedback states are driven by .is-correct / .is-wrong on options.
 */

/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b2430;
  --text-dim: #5a6572;
  --border: #d7dde4;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --focus-ring: rgba(47, 111, 237, 0.45);

  /* feedback states */
  --correct-bg: #e7f6ee;
  --correct-border: #2fa35e;
  --correct-ink: #1d6b40;
  --wrong-bg: #fdefed;
  --wrong-border: #d6504a;
  --wrong-ink: #a02f2a;

  --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 4px 16px rgba(20, 30, 45, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --surface: #1a212b;
    --surface-2: #232c38;
    --text: #e6ebf1;
    --text-dim: #98a3b1;
    --border: #2e3946;
    --accent: #5b8def;
    --accent-ink: #0e1520;
    --focus-ring: rgba(91, 141, 239, 0.55);

    --correct-bg: #122f20;
    --correct-border: #35b46a;
    --correct-ink: #7ee0a6;
    --wrong-bg: #35181a;
    --wrong-border: #d45852;
    --wrong-ink: #f0a09c;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- base ---------- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}

code {
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

button {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- header ---------- */
.app-header {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 8px;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

h1 {
  margin: 0 0 2px;
  font-size: 1.45rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.score-block {
  text-align: right;
  min-width: 200px;
}

.score {
  display: block;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-label {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ---------- mode switch ---------- */
.mode-switch {
  display: inline-flex;
  gap: 4px;
  margin-top: 16px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 6px 18px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- filter chips ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* ---------- main ---------- */
main {
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 20px 40px;
}

.quiz-topline {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 10px;
}

.counter {
  color: var(--text-dim);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.browse-count {
  color: var(--text-dim);
  margin: 8px 0 14px;
  font-size: 0.9rem;
}

.browse-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- question card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 26px;
  box-shadow: var(--shadow);
}

.q-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-bottom: 10px;
}

.q-text {
  margin: 0 0 16px;
  font-size: 1.1rem;
  line-height: 1.45;
  font-weight: 650;
}

.options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--surface-2);
}

.option:disabled {
  cursor: default;
}

.key {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

.opt-text {
  flex: 1;
}

.mark {
  flex: none;
  font-weight: 700;
  font-size: 1rem;
}

/* feedback states */
.option.is-correct {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}

.option.is-correct .key {
  background: var(--correct-border);
  border-color: var(--correct-border);
  color: #ffffff;
}

.option.is-correct .mark {
  color: var(--correct-ink);
}

.option.is-wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong-border);
}

.option.is-wrong .key {
  background: var(--wrong-border);
  border-color: var(--wrong-border);
  color: #ffffff;
}

.option.is-wrong .mark {
  color: var(--wrong-ink);
}

.option.is-muted {
  opacity: 0.55;
}

/* explanation panel */
.explanation {
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: 10px;
  border-left: 4px solid var(--border);
  background: var(--surface-2);
  font-size: 0.95rem;
}

.explanation.is-ok {
  background: var(--correct-bg);
  border-left-color: var(--correct-border);
  color: var(--correct-ink);
}

.explanation.is-no {
  background: var(--wrong-bg);
  border-left-color: var(--wrong-border);
  color: var(--wrong-ink);
}

/* ---------- buttons ---------- */
.next-slot {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

.btn-primary,
.btn-secondary {
  padding: 10px 20px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  border: 1.5px solid var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.done-card {
  text-align: center;
}

.done-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ---------- notice (empty bank) ---------- */
.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.notice h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.notice p {
  margin: 0;
  color: var(--text-dim);
}

/* ---------- footer ---------- */
.app-footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.reset-btn {
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.reset-btn:hover {
  border-color: var(--wrong-border);
  color: var(--wrong-ink);
}

.toast {
  color: var(--text-dim);
  font-size: 0.88rem;
}

/* ---------- responsive ---------- */
@media (max-width: 620px) {
  .header-inner {
    flex-direction: column;
  }

  .score-block {
    text-align: left;
    min-width: 0;
    width: 100%;
  }

  .card {
    padding: 16px 14px;
  }

  .q-text {
    font-size: 1rem;
  }

  .option {
    padding: 10px 12px;
  }
}
