/* =========================================================================
   PathPrep — Design Tokens (single source of truth)
   8px spacing grid · limited palette · one component per element
   ========================================================================= */
:root {
  /* ---- Color palette: 1 primary, 1 secondary accent, grays, semantic ---- */
  --c-primary:        #2563eb;   /* primary (indigo-blue)  */
  --c-primary-dark:   #1d4ed8;
  --c-primary-soft:   #eff4ff;   /* tinted primary surface */
  --c-secondary:      #0d9488;   /* teal accent (used sparingly) */

  --c-bg:             #f6f7f9;   /* calm app background */
  --c-surface:        #ffffff;
  --c-surface-2:      #fbfcfd;

  --c-ink:            #0f172a;   /* gray-900 text */
  --c-ink-2:          #475569;   /* gray-600 secondary text */
  --c-ink-3:          #94a3b8;   /* gray-400 muted */
  --c-line:           #e6e9ef;   /* hairline border */
  --c-line-strong:    #d4d9e2;

  --c-success:        #16a34a;
  --c-success-soft:   #ecfdf3;
  --c-error:          #dc2626;
  --c-error-soft:     #fef2f2;
  --c-warning:        #d97706;

  /* ---- Spacing scale: strict multiples of 8 (4 allowed as half-step) ---- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 16px;
  --s-4: 24px;
  --s-5: 32px;
  --s-6: 40px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 80px;

  /* ---- Radius scale ---- */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* ---- Typography scale ---- */
  --t-xs:   12px;
  --t-sm:   14px;
  --t-base: 16px;
  --t-md:   18px;
  --t-lg:   22px;
  --t-xl:   28px;
  --t-2xl:  36px;
  --lh-tight: 1.25;
  --lh-base:  1.6;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* ---- Shadow scale (very soft) ---- */
  --sh-1: 0 1px 2px rgba(15,23,42,.05);
  --sh-2: 0 2px 8px rgba(15,23,42,.06);
  --sh-3: 0 8px 28px rgba(15,23,42,.10);

  /* ---- Motion ---- */
  --ease: cubic-bezier(.22,.61,.36,1);
  --dur-1: .14s;
  --dur-2: .26s;

  --maxw: 920px;
}

/* ========================= Reset / base ========================= */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: var(--lh-base);
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--c-primary-soft); }

/* ========================= Layout shell ========================= */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.82);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--c-line);
}
.app-header__inner {
  max-width: var(--maxw); margin: 0 auto;
  padding: var(--s-3) var(--s-4);
  display: flex; align-items: center; gap: var(--s-3);
}
.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: 700; letter-spacing: -.01em; }
.brand__mark {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--c-primary), var(--c-secondary));
  display: grid; place-items: center; color: #fff; font-size: var(--t-md);
  box-shadow: var(--sh-2);
}
.brand__name { font-size: var(--t-md); }
.brand__name span { color: var(--c-primary); }
.header-spacer { flex: 1; }
.header-meta { font-size: var(--t-sm); color: var(--c-ink-2); }

.main {
  max-width: var(--maxw); margin: 0 auto;
  padding: var(--s-5) var(--s-4) var(--s-9);
}

/* ========================= Card (single component) ========================= */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card--pad { padding: var(--s-5); }

/* ========================= Buttons (one component, variants) ========================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-base); font-weight: 600;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--c-primary); color: #fff;
  box-shadow: var(--sh-1);
  transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
  text-decoration: none; line-height: 1;
}
.btn:hover { background: var(--c-primary-dark); box-shadow: var(--sh-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn--ghost { background: var(--c-surface); color: var(--c-ink); border-color: var(--c-line-strong); box-shadow: none; }
.btn--ghost:hover { background: var(--c-surface-2); border-color: var(--c-ink-3); }
.btn--block { width: 100%; }
.btn--lg { padding: var(--s-4) var(--s-5); font-size: var(--t-md); }
.btn--sm { padding: var(--s-2) var(--s-3); font-size: var(--t-sm); }

/* ========================= Typography helpers ========================= */
.h1 { font-size: var(--t-2xl); line-height: var(--lh-tight); letter-spacing: -.02em; font-weight: 800; }
.h2 { font-size: var(--t-xl); line-height: var(--lh-tight); letter-spacing: -.01em; font-weight: 700; }
.lead { font-size: var(--t-md); color: var(--c-ink-2); max-width: 56ch; }
.muted { color: var(--c-ink-2); }
.tiny { font-size: var(--t-xs); color: var(--c-ink-3); }

/* ========================= Screen transitions ========================= */
.screen { animation: fade-up var(--dur-2) var(--ease) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.is-hidden { display: none !important; }

/* ========================= Home / setup ========================= */
.hero { text-align: center; padding: var(--s-6) 0 var(--s-5); }
.hero .h1 { margin-bottom: var(--s-3); }
.hero .lead { margin: 0 auto; }

.stat-row { display: flex; gap: var(--s-3); justify-content: center; flex-wrap: wrap; margin-top: var(--s-5); }
.stat {
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4); min-width: 132px; text-align: center; box-shadow: var(--sh-1);
}
.stat__num { font-size: var(--t-xl); font-weight: 800; color: var(--c-primary); line-height: 1.1; }
.stat__label { font-size: var(--t-sm); color: var(--c-ink-2); margin-top: var(--s-1); }

.setup { margin-top: var(--s-6); display: grid; gap: var(--s-5); }
.field__label { font-weight: 600; margin-bottom: var(--s-3); display: block; }
.field__hint { font-size: var(--t-sm); color: var(--c-ink-2); margin-top: var(--s-2); }

/* Option group (segmented choices) — single component */
.choices { display: grid; gap: var(--s-2); }
.choices--row { grid-auto-flow: column; grid-auto-columns: 1fr; }
@media (max-width: 560px){ .choices--row { grid-auto-flow: row; } }
.choice {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-line-strong); border-radius: var(--r-md);
  background: var(--c-surface); color: var(--c-ink);
  font-size: var(--t-base); font-weight: 500; text-align: left;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.choice:hover { border-color: var(--c-primary); background: var(--c-primary-soft); }
.choice[aria-pressed="true"] { border-color: var(--c-primary); background: var(--c-primary-soft); box-shadow: inset 0 0 0 1px var(--c-primary); }
.choice__radio {
  width: 20px; height: 20px; border-radius: var(--r-pill); border: 2px solid var(--c-line-strong);
  display: grid; place-items: center; flex: none; transition: border-color var(--dur-1) var(--ease);
}
.choice[aria-pressed="true"] .choice__radio { border-color: var(--c-primary); }
.choice[aria-pressed="true"] .choice__radio::after { content:""; width: 10px; height: 10px; border-radius: var(--r-pill); background: var(--c-primary); }
.choice__body { display: flex; flex-direction: column; gap: 2px; }
.choice__title { font-weight: 600; }
.choice__sub { font-size: var(--t-sm); color: var(--c-ink-2); font-weight: 400; }

/* ========================= Quiz ========================= */
.quizbar { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); }
.progress { flex: 1; height: 8px; border-radius: var(--r-pill); background: var(--c-line); overflow: hidden; }
.progress__fill { height: 100%; background: var(--c-primary); border-radius: var(--r-pill); width: 0; transition: width var(--dur-2) var(--ease); }
.quizbar__count { font-size: var(--t-sm); font-weight: 600; color: var(--c-ink-2); white-space: nowrap; }
.quizbar__score { font-size: var(--t-sm); font-weight: 600; color: var(--c-secondary); white-space: nowrap; }

.qmeta { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); }
.tag {
  display: inline-flex; align-items: center; gap: var(--s-1);
  font-size: var(--t-xs); font-weight: 600; letter-spacing: .02em;
  padding: var(--s-1) var(--s-2); border-radius: var(--r-pill);
  background: var(--c-primary-soft); color: var(--c-primary-dark);
}
.tag--neutral { background: #eef1f6; color: var(--c-ink-2); }
.tag--teal { background: #e6f6f4; color: var(--c-secondary); }

.qstem { font-size: var(--t-lg); font-weight: 700; line-height: var(--lh-tight); margin-bottom: var(--s-4); letter-spacing: -.01em; }

.figure {
  background: #0f172a; border-radius: var(--r-md); overflow: hidden;
  margin-bottom: var(--s-4); border: 1px solid var(--c-line);
  display: grid; place-items: center; min-height: 200px; position: relative;
}
.figure img { width: 100%; height: auto; max-height: 460px; object-fit: contain; }
.figure__skeleton { position: absolute; inset: 0; background: linear-gradient(100deg,#1e293b 30%,#334155 50%,#1e293b 70%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.options { display: grid; gap: var(--s-2); }
.option {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; text-align: left;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-line-strong); border-radius: var(--r-md);
  background: var(--c-surface); color: var(--c-ink);
  font-size: var(--t-base); line-height: var(--lh-tight);
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.option:hover:not(:disabled) { border-color: var(--c-primary); background: var(--c-primary-soft); }
.option:active:not(:disabled) { transform: translateY(1px); }
.option:disabled { cursor: default; }
.option__key {
  width: 28px; height: 28px; flex: none; border-radius: var(--r-sm);
  display: grid; place-items: center; font-weight: 700; font-size: var(--t-sm);
  background: #eef1f6; color: var(--c-ink-2); transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.option__text { flex: 1; }
.option__icon { flex: none; font-size: var(--t-md); opacity: 0; transition: opacity var(--dur-1) var(--ease); }
.option.is-correct { border-color: var(--c-success); background: var(--c-success-soft); }
.option.is-correct .option__key { background: var(--c-success); color: #fff; }
.option.is-correct .option__icon { opacity: 1; color: var(--c-success); }
.option.is-wrong { border-color: var(--c-error); background: var(--c-error-soft); }
.option.is-wrong .option__key { background: var(--c-error); color: #fff; }
.option.is-wrong .option__icon { opacity: 1; color: var(--c-error); }

.quiz-actions { margin-top: var(--s-4); display: flex; gap: var(--s-3); justify-content: space-between; align-items: center; }
.feedback { font-weight: 600; font-size: var(--t-sm); display: flex; align-items: center; gap: var(--s-2); }
.feedback--correct { color: var(--c-success); }
.feedback--wrong { color: var(--c-error); }

/* ========================= Results ========================= */
.result-hero { text-align: center; padding: var(--s-5) 0 var(--s-4); }
.score-ring { width: 160px; height: 160px; margin: 0 auto var(--s-4); position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring__track { fill: none; stroke: var(--c-line); stroke-width: 12; }
.score-ring__bar { fill: none; stroke: var(--c-primary); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset 1s var(--ease); }
.score-ring__label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.score-ring__pct { font-size: var(--t-2xl); font-weight: 800; line-height: 1; }
.score-ring__sub { font-size: var(--t-sm); color: var(--c-ink-2); margin-top: var(--s-1); }
.result-msg { font-size: var(--t-md); font-weight: 600; margin-bottom: var(--s-2); }

.review-list { display: grid; gap: var(--s-3); margin-top: var(--s-5); }
.review-item { display: grid; grid-template-columns: 96px 1fr; gap: var(--s-3); padding: var(--s-3); }
@media (max-width: 560px){ .review-item { grid-template-columns: 72px 1fr; } }
.review-item__thumb { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: var(--r-sm); background: #0b1220; border: 1px solid var(--c-line); }
.review-item__body { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.review-item__q { font-size: var(--t-sm); color: var(--c-ink-2); }
.review-item__row { font-size: var(--t-sm); display: flex; gap: var(--s-2); align-items: baseline; flex-wrap: wrap; }
.review-item__row b { font-weight: 700; }
.ans-correct { color: var(--c-success); font-weight: 600; }
.ans-wrong { color: var(--c-error); font-weight: 600; text-decoration: line-through; }
.review-badge { font-size: var(--t-xs); font-weight: 700; padding: 2px var(--s-2); border-radius: var(--r-pill); flex: none; }
.review-badge--ok { background: var(--c-success-soft); color: var(--c-success); }
.review-badge--no { background: var(--c-error-soft); color: var(--c-error); }

.results-actions { display: flex; gap: var(--s-3); flex-wrap: wrap; justify-content: center; margin-top: var(--s-6); }
.filter-row { display:flex; gap: var(--s-2); margin-top: var(--s-5); flex-wrap: wrap; }
.chip {
  font-size: var(--t-sm); font-weight: 600; padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill); border: 1px solid var(--c-line-strong);
  background: var(--c-surface); color: var(--c-ink-2);
  transition: all var(--dur-1) var(--ease);
}
.chip[aria-pressed="true"] { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* ========================= States: empty / error ========================= */
.state { text-align: center; padding: var(--s-8) var(--s-4); }
.state__icon { font-size: 40px; margin-bottom: var(--s-3); }
.state__title { font-size: var(--t-md); font-weight: 700; margin-bottom: var(--s-2); }

/* ========================= Footer ========================= */
.app-footer { max-width: var(--maxw); margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-7); text-align: center; }

/* loading spinner */
.spinner { width: 28px; height: 28px; border: 3px solid var(--c-line); border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto var(--s-3); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
