/* ============================================================
   NEC MCQ App — styles.css
   Mobile-first, theme-able via CSS custom properties.
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --surface-3: #e4e9f3;
  --text: #15203a;
  --text-muted: #586379;
  --text-faint: #5d6b82; /* AA: 5.40:1 on #fff, 5.03:1 on bg */
  --border: #e6eaf2;
  --border-strong: #d2dae8;

  --accent: #3056d3;
  --accent-hover: #2442b8;
  --accent-soft: #e9eefc;
  --accent-text: #ffffff;

  --correct: #15a34a; /* white-on-green fills / pills */
  --correct-text: #0f7a37; /* AA green for text: 5.44:1 on #fff, 4.95:1 on soft */
  --correct-soft: #dcfce7;
  --correct-border: #8ce0a8;

  --wrong: #b91c1c; /* AA: 5.30:1 on wrong-soft, 6.47:1 white-on-red */
  --wrong-soft: #fee2e2;
  --wrong-border: #f5a3a3;

  --tip-accent: #9a4d06; /* AA: 5.67:1 on tip-soft */
  --tip-soft: #fff5e9;
  --tip-border: #f6c089;

  --shadow-sm: 0 1px 2px rgba(20, 30, 55, 0.06), 0 1px 3px rgba(20, 30, 55, 0.07);
  --shadow-md: 0 6px 16px rgba(20, 30, 55, 0.09), 0 2px 5px rgba(20, 30, 55, 0.06);
  --shadow-lg: 0 16px 40px rgba(20, 30, 55, 0.16);

  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 22px;
  --radius-md: 12px; /* chrome: brand, icon-btn, tabs */
  --radius-xs: 8px; /* small controls, letter/segment chips */

  --maxw: 880px;
  --tap: 44px;
  --nav-h: 66px;
  --header-h: 0px; /* set by JS on desktop so the top nav can stack under header */

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
}

[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #151b26;
  --surface-2: #1b2230;
  --surface-3: #28313f;
  --text: #e9eef7;
  --text-muted: #a4b1c4;
  --text-faint: #7d8ba0; /* AA on dark surfaces: 4.6–5.5:1 */
  --border: #232c3a;
  --border-strong: #36414f;

  --accent: #5b8bff;
  --accent-hover: #7aa1ff;
  --accent-soft: #182740;
  --accent-text: #0b0f17;

  --correct: #3ddc77;
  --correct-text: #3ddc77; /* bright green already passes on dark */
  --correct-soft: #102a1b;
  --correct-border: #235f3b;

  --wrong: #fb7878;
  --wrong-soft: #2e1417;
  --wrong-border: #7c2f2f;

  --tip-accent: #fbbf24;
  --tip-soft: #2a2207;
  --tip-border: #6a5417;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.6);
}

/* ---------- Reset / base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute must always win, even over elements that set their own
   display (e.g. .modal-backdrop uses display:grid). */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

input,
select {
  font-family: inherit;
  font-size: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Icons ---------- */
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: inline-block;
  vertical-align: middle;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: 0;
  padding: 4px;
  color: var(--text);
  text-align: left;
  border-radius: var(--radius-md);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-text strong {
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-text small {
  color: var(--text-muted);
  font-size: 12px;
}

.icon-btn {
  display: grid;
  place-items: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s var(--ease), transform 0.12s var(--ease);
}
.icon-btn:hover {
  background: var(--surface-3);
}
.icon-btn:active {
  transform: scale(0.92);
}

.theme-toggle .theme-icon {
  width: 21px;
  height: 21px;
}
[data-theme="light"] .theme-icon-sun {
  display: none;
}
[data-theme="dark"] .theme-icon-moon {
  display: none;
}

/* ---------- Navigation (bottom bar on mobile) ---------- */
.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  gap: 2px;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-faint);
  font-weight: 600;
  font-size: 11.5px;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.tab .icon {
  width: 23px;
  height: 23px;
  transition: transform 0.18s var(--ease-spring);
}
.tab:hover {
  color: var(--text);
}
.tab[aria-current="page"] {
  color: var(--accent);
}
.tab[aria-current="page"] .icon {
  transform: translateY(-1px) scale(1.06);
}
.tab:active .icon {
  transform: scale(0.9);
}

/* ---------- Layout ---------- */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px 32px;
  min-height: 60vh;
}

/* Reserve space so the fixed bottom nav never covers content/footer
   (+12px buffer so the footer/last control never sits flush against the bar). */
body {
  padding-bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom));
}

.screen {
  animation: fade-in 0.28s var(--ease);
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.screen-title {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 28px 0 12px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 15px;
  transition: background 0.16s var(--ease), transform 0.1s var(--ease),
    border-color 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.btn .icon {
  width: 18px;
  height: 18px;
}
.btn:active {
  transform: scale(0.975);
}
.btn-block {
  width: 100%;
}
.btn-lg {
  min-height: 50px;
  font-size: 16px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--wrong);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(1.06);
}

.btn-danger-ghost {
  background: var(--surface);
  color: var(--wrong);
  border-color: var(--wrong-border);
}
.btn-danger-ghost:hover {
  background: var(--wrong-soft);
}

/* Disabled controls (scoped to .btn/.input so answered .opt buttons are unaffected) */
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
.btn-ghost:disabled,
.btn-ghost[disabled] {
  background: var(--surface-2);
  color: var(--text-faint);
  border-color: var(--border);
}
.btn:disabled:hover,
.btn[disabled]:hover {
  background: var(--surface-2);
}
.input:disabled,
.input[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  background: var(--surface-2);
  color: var(--text-faint);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 8px;
}
.action-row .btn {
  flex: 1 1 auto;
}

/* ---------- Cards / stats ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-value {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.stat.is-correct .stat-value {
  color: var(--correct-text);
}
.stat.is-wrong .stat-value {
  color: var(--wrong);
}
.stat.is-accent .stat-value {
  color: var(--accent);
}

/* ---------- Progress bar ---------- */
.overall-progress {
  margin: 14px 0 4px;
}
.progress-bar {
  height: 12px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar.slim {
  height: 8px;
  margin: 4px 0 14px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 999px;
  transition: width 0.6s var(--ease);
}
.progress-caption {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 7px;
}

/* ---------- Chapter grid ---------- */
.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.chapter-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 11px;
  transition: transform 0.16s var(--ease), box-shadow 0.18s var(--ease),
    border-color 0.16s var(--ease);
  color: var(--text);
  width: 100%;
}
.chapter-card:not(.is-empty):hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.chapter-card:not(.is-empty):active {
  transform: translateY(-1px) scale(0.99);
}
.chapter-card.is-empty {
  opacity: 0.7;
  cursor: default;
}
.chapter-card-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.chapter-num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.chapter-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.32;
  padding-top: 2px;
}
.chapter-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  background: var(--surface-3);
  color: var(--text-muted);
}
.badge.is-soon {
  background: var(--tip-soft);
  color: var(--tip-accent);
}
.chapter-accuracy .mini-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 7px;
}
.chapter-accuracy .mini-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--correct), color-mix(in srgb, var(--correct) 70%, #fff));
  border-radius: 999px;
  transition: width 0.6s var(--ease);
}

/* ---------- Toolbar / inputs ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.field {
  flex: 1 1 180px;
  min-width: 0;
}
.search-wrap {
  position: relative;
}
.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input.has-icon {
  padding-left: 42px;
}
.input::placeholder {
  color: var(--text-faint);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-sm {
  max-width: 110px;
  min-height: var(--tap);
}
.result-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ---------- Question cards ---------- */
.question-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* staggered entrance for list items */
.question-list > .q-card,
.chapter-grid > * ,
.history-list > * {
  animation: card-in 0.32s var(--ease) both;
}
.question-list > .q-card:nth-child(1),
.chapter-grid > *:nth-child(1),
.history-list > *:nth-child(1) { animation-delay: 0.02s; }
.question-list > .q-card:nth-child(2),
.chapter-grid > *:nth-child(2),
.history-list > *:nth-child(2) { animation-delay: 0.05s; }
.question-list > .q-card:nth-child(3),
.chapter-grid > *:nth-child(3),
.history-list > *:nth-child(3) { animation-delay: 0.08s; }
.question-list > .q-card:nth-child(4),
.chapter-grid > *:nth-child(4),
.history-list > *:nth-child(4) { animation-delay: 0.11s; }
.question-list > .q-card:nth-child(5),
.chapter-grid > *:nth-child(5),
.history-list > *:nth-child(5) { animation-delay: 0.14s; }
.question-list > .q-card:nth-child(n + 6),
.chapter-grid > *:nth-child(n + 6),
.history-list > *:nth-child(n + 6) { animation-delay: 0.16s; }
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.16s var(--ease), box-shadow 0.18s var(--ease);
}
.q-card.is-open {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.q-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 15px 15px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  color: var(--text);
}
.q-head[role="button"] {
  cursor: pointer;
}
.q-head-main {
  flex: 1;
  min-width: 0;
}
.q-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
  align-items: center;
}
.q-tag {
  font-size: 11px;
  font-weight: 650;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-muted);
}
.q-tag.q-tag-ch {
  background: var(--accent-soft);
  color: var(--accent);
}
.q-stem {
  font-weight: 600;
  font-size: 15.5px;
  line-height: 1.5;
}
.q-head-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: none;
}
.star-btn {
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  padding: 0;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: var(--radius-xs);
  color: var(--text-faint);
  transition: transform 0.16s var(--ease-spring), color 0.15s var(--ease),
    background 0.15s var(--ease);
}
.star-btn .icon {
  width: 21px;
  height: 21px;
  fill: none;
}
.star-btn:hover {
  background: var(--surface-2);
  color: var(--tip-accent);
}
.star-btn.is-on {
  color: var(--tip-accent);
}
.star-btn.is-on .icon {
  fill: currentColor;
}
.star-btn:active {
  transform: scale(1.25);
}
.chevron {
  color: var(--text-faint);
  transition: transform 0.28s var(--ease);
  display: grid;
  place-items: center;
}
.chevron .icon {
  width: 18px;
  height: 18px;
}
.q-card.is-open .chevron {
  transform: rotate(180deg);
}

.q-body {
  display: none;
  padding: 0 15px 15px;
}
.q-card.is-open .q-body {
  display: block;
  animation: fade-in 0.22s var(--ease);
}

/* Options */
.opt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 0;
}
.opt {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease),
    transform 0.08s var(--ease);
}
.opt:not(:disabled):hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.opt:not(:disabled):active {
  transform: scale(0.99);
}
.opt-letter {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  font-weight: 800;
  font-size: 13px;
  flex: none;
  color: var(--text-muted);
}
.opt-text {
  flex: 1;
}
.opt.is-correct {
  border-color: var(--correct-border);
  background: var(--correct-soft);
  color: var(--text);
}
.opt.is-correct .opt-letter {
  background: var(--correct);
  color: #fff;
}
.opt.is-wrong {
  border-color: var(--wrong-border);
  background: var(--wrong-soft);
}
.opt.is-wrong .opt-letter {
  background: var(--wrong);
  color: #fff;
}
.opt.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.opt.is-selected .opt-letter {
  background: var(--accent);
  color: var(--accent-text);
}
.opt-mark {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  font-size: 12.5px;
  flex: none;
}
.opt-mark .icon {
  width: 16px;
  height: 16px;
}
.opt.is-correct .opt-mark {
  color: var(--correct-text);
}
.opt.is-wrong .opt-mark {
  color: var(--wrong);
}

/* Reasoning + tip */
.reveal-toggle {
  margin-top: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
  min-height: var(--tap);
  transition: background 0.15s var(--ease);
}
.reveal-toggle:hover {
  background: var(--surface-3);
}
.explain {
  margin-top: 12px;
  display: none;
}
.explain.is-open {
  display: block;
  animation: fade-in 0.22s var(--ease);
}
.explain-block {
  font-size: 14.5px;
  line-height: 1.6;
}
.explain-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.tip-callout {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--tip-soft);
  border: 1px solid var(--tip-border);
  border-left: 4px solid var(--tip-accent);
  border-radius: var(--radius-sm);
}
.tip-callout .explain-label {
  color: var(--tip-accent);
}
.tip-callout .explain-block {
  color: var(--text);
}

/* ---------- Empty / load-more ---------- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 44px;
  height: 44px;
  color: var(--text-faint);
  margin-bottom: 12px;
  stroke-width: 1.6;
}
.empty-state p {
  max-width: 320px;
  margin: 0 auto;
  font-size: 14.5px;
}
.load-more-wrap {
  text-align: center;
  margin-top: 16px;
}

/* ---------- Test setup ---------- */
.setup-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.setup-group {
  border: 0;
  padding: 0;
  margin: 0;
}
.setup-group legend {
  font-weight: 700;
  font-size: 15px;
  padding: 0;
  margin-bottom: 10px;
}
.setup-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  min-height: 40px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.chip:hover {
  background: var(--surface-2);
  color: var(--text);
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  min-height: var(--tap);
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.check-row:hover {
  background: var(--surface-2);
}
.check-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}
.check-row.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.check-row .check-name {
  flex: 1;
  font-size: 14.5px;
  font-weight: 600;
}
.check-row .check-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Segmented control */
.seg {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  flex-wrap: wrap;
}
.seg-btn {
  min-width: 54px;
  min-height: var(--tap);
  padding: 6px 16px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.seg-btn:hover {
  color: var(--text);
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  min-height: var(--tap);
  cursor: pointer;
}
.switch-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.inline-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.inline-field label {
  font-size: 14px;
  color: var(--text-muted);
}
.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 8px;
}

/* ---------- Test running ---------- */
.run-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.run-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}
.run-progress {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.run-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 15px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.run-timer .icon {
  width: 16px;
  height: 16px;
}
.run-timer.is-warning {
  background: var(--wrong-soft);
  color: var(--wrong);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}

.question-stage {
  padding: 18px;
  margin-top: 4px;
}
.stage-stem {
  font-weight: 650;
  font-size: 17px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.stage-tags {
  margin-bottom: 12px;
}

.run-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.run-nav #runSubmit {
  grid-column: 1 / -1;
}

.palette-wrap {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4px 14px;
}
.palette-wrap summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 11px 0;
  color: var(--text-muted);
}
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  padding: 6px 0 14px;
}
.pal-btn {
  aspect-ratio: 1;
  min-height: var(--tap);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.1s var(--ease), background 0.15s var(--ease);
}
.pal-btn:active {
  transform: scale(0.92);
}
.pal-btn.is-answered {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.pal-btn.is-current {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Results ---------- */
.result-hero {
  text-align: center;
  padding: 28px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  margin-bottom: 8px;
}
.result-hero.is-pass {
  background: var(--correct-soft);
  border-color: var(--correct-border);
}
.result-hero.is-fail {
  background: var(--wrong-soft);
  border-color: var(--wrong-border);
}
.result-medal {
  width: 46px;
  height: 46px;
  margin-bottom: 8px;
}
.result-hero.is-pass .result-medal {
  color: var(--correct);
}
.result-hero.is-fail .result-medal {
  color: var(--wrong);
}
.result-score {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.result-pct {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 7px;
}
.result-verdict {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 15px;
  padding: 7px 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.result-verdict .icon {
  width: 18px;
  height: 18px;
}
.result-hero.is-pass .result-verdict {
  background: var(--correct);
  color: #fff;
}
.result-hero.is-fail .result-verdict {
  background: var(--wrong);
  color: #fff;
}
.result-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-top: 13px;
}

/* History / breakdown rows */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.history-main {
  flex: 1;
  min-width: 0;
}
.history-title {
  font-weight: 650;
  font-size: 14.5px;
}
.history-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.history-score {
  font-weight: 800;
  font-size: 17px;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.history-score.is-pass {
  color: var(--correct-text);
}
.history-score.is-fail {
  color: var(--wrong);
}
.breakdown-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 7px;
}
.breakdown-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.6s var(--ease);
}

/* Review card states */
.q-card.review-wrong {
  border-color: var(--wrong-border);
}
.q-card.review-correct {
  border-color: var(--correct-border);
}
.review-flag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.review-flag.is-wrong {
  background: var(--wrong-soft);
  color: var(--wrong);
}
.review-flag.is-correct {
  background: var(--correct-soft);
  color: var(--correct-text);
}
.review-flag.is-skipped {
  background: var(--surface-3);
  color: var(--text-muted);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 12, 22, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade-in 0.16s var(--ease);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 100%;
  padding: 22px;
  animation: pop 0.2s var(--ease-spring);
}
@keyframes pop {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.modal-title {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 8px;
}
.modal-body {
  color: var(--text-muted);
  font-size: 14.5px;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 120;
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease-spring);
  max-width: 90vw;
  text-align: center;
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Footer ---------- */
.app-footer {
  border-top: 1px solid var(--border);
  padding: 20px 16px 24px;
  text-align: center;
  margin-top: 8px;
}
.app-footer p {
  max-width: var(--maxw);
  margin: 0 auto;
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ---------- Responsive (tablet/desktop) ---------- */
@media (min-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .chapter-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .check-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .action-row .btn {
    flex: 0 1 auto;
  }
  .run-nav {
    grid-template-columns: 1fr 1fr 1.4fr;
  }
  .run-nav #runSubmit {
    grid-column: auto;
  }
  .screen-title {
    font-size: 29px;
  }
}

/* Desktop: move nav to a sticky top pill bar under the header. */
@media (min-width: 760px) {
  body {
    padding-bottom: 0;
  }
  .tabs {
    position: sticky;
    top: var(--header-h);
    bottom: auto;
    z-index: 45;
    max-width: var(--maxw);
    margin: 0 auto;
    gap: 4px;
    padding: 8px 16px;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 90%, transparent);
  }
  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 8px;
    min-height: 40px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
  }
  .tab .icon {
    width: 18px;
    height: 18px;
  }
  .tab:hover {
    background: var(--surface-2);
  }
  .tab[aria-current="page"] {
    background: var(--accent-soft);
  }
  .tab[aria-current="page"] .icon {
    transform: none;
  }
  .toast {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
