/* ==========================================================================
   Civics Streak — design system
   Every screen in the app loads this one file. If you need a color, a size,
   or a button, take it from here rather than inventing a new one. That is
   what keeps the screens looking like one app.

   Sections:
     1. Tokens          the raw values (color, type, spacing)
     2. Reset + base    sensible defaults
     3. Layout          the phone-width column every screen sits in
     4. Buttons
     5. Forms
     6. Cards + panels
     7. Game pieces     answer options, hearts, progress bar, stat tiles
     8. Logo + brand
     9. Utilities
   ========================================================================== */


/* 1. TOKENS
   ========================================================================== */

:root {
  /* --- Color ------------------------------------------------------------ */
  --ink:        #111318;   /* near-black: body text, headings */
  --ink-soft:   #4A4F5A;   /* secondary text, captions */
  --ink-faint:  #8A909C;   /* placeholder text, disabled states */

  --blue:       #1B4DB1;   /* primary: buttons, links, CORRECT answers */
  --blue-dark:  #143A87;   /* button underside + pressed state */
  --blue-tint:  #E8EEFB;   /* selected option background, info panels */

  --red:        #D7263D;   /* accent: hearts, WRONG answers, destructive */
  --red-dark:   #A81B2E;   /* pressed state */
  --red-tint:   #FCEAEC;   /* wrong-answer background */

  --paper:      #FFFFFF;   /* page background */
  --surface:    #F5F6F8;   /* cards, unselected options */
  --line:       #E2E5EA;   /* borders, dividers */

  /* --- Type ------------------------------------------------------------- */
  --font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --t-display: 32px;  /* score numbers, big screen titles */
  --t-h1:      24px;
  --t-h2:      20px;  /* question text */
  --t-body:    17px;  /* answer options, paragraphs */
  --t-label:   15px;  /* buttons, form labels */
  --t-small:   13px;  /* captions, helper text, errors */

  /* --- Spacing ---------------------------------------------------------- */
  /* Use only these. Mixing in stray values is what makes layouts feel sloppy. */
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  24px;
  --s-6:  32px;
  --s-7:  48px;

  /* --- Shape ------------------------------------------------------------ */
  --radius:      14px;   /* buttons, cards, inputs */
  --radius-pill: 999px;  /* pills, progress bars */
  --tap:         44px;   /* minimum tap target. Never go smaller. */

  --column: 480px;       /* max content width; phone-shaped even on desktop */
}


/* 2. RESET + BASE
   ========================================================================== */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);
  font-weight: 500;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }

h1 { font-size: var(--t-h1); font-weight: 700; line-height: 1.2; }
h2 { font-size: var(--t-h2); font-weight: 700; line-height: 1.3; }

a {
  color: var(--blue);
  font-weight: 600;
  text-underline-offset: 3px;
}
a:hover { color: var(--blue-dark); }

/* One visible focus style for the whole app. Keyboard users need this;
   removing it without a replacement makes the app unusable for them. */
:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: var(--s-1);
}

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


/* 3. LAYOUT
   ==========================================================================
   .app     centers a phone-width column on any screen size
   .screen  vertical rhythm for a full page of content
   .stack   generic "space these children evenly" helper
   ========================================================================== */

.app {
  width: 100%;
  max-width: var(--column);
  margin: 0 auto;
  padding: 0 20px;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;      /* dvh dodges the mobile browser address bar */
  padding-top: var(--s-6);
  padding-bottom: var(--s-5);
}

/* Pushes whatever follows it to the bottom of the screen. */
.screen__spacer { flex: 1 1 auto; }

/* Top row on inner pages: the small logo, acting as a way back out.
   Every screen has to be leavable. */
.page-top {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.page-top__home {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  text-decoration: none;
  color: inherit;
}

.stack       { display: flex; flex-direction: column; gap: var(--s-4); }
.stack--tight{ gap: var(--s-2); }
.stack--loose{ gap: var(--s-5); }

.center { text-align: center; }


/* 4. BUTTONS
   ==========================================================================
   Chunky, with a solid 4px underside that compresses when pressed. That
   press feedback matters a lot on a phone, where there is no hover.
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 56px;
  padding: 0 var(--s-5);
  border: 0;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: var(--t-label);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active     { transform: translateY(4px); }
.btn[disabled],
.btn--disabled  {
  opacity: .5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Primary — the one thing we want tapped on a screen. Only ever one. */
.btn--primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 0 var(--blue-dark);
}
.btn--primary:hover  { background: #1F58C7; color: #fff; }
.btn--primary:active { box-shadow: 0 0 0 var(--blue-dark); }

/* Secondary — the alternative path. */
.btn--secondary {
  background: var(--paper);
  color: var(--blue);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
}
.btn--secondary:hover  { background: var(--blue-tint); color: var(--blue-dark); }
.btn--secondary:active { box-shadow: 0 0 0 var(--line); }

/* Danger — log out, delete. Never the default on a screen. */
.btn--danger {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 0 var(--red-dark);
}
.btn--danger:hover  { background: #E13B50; color: #fff; }
.btn--danger:active { box-shadow: 0 0 0 var(--red-dark); }

/* Quiet — a text link that still meets the 44px tap target. */
.btn--quiet {
  min-height: var(--tap);
  background: none;
  color: var(--ink-soft);
  box-shadow: none;
  font-weight: 600;
}
.btn--quiet:hover   { color: var(--ink); }
.btn--quiet:active  { transform: none; }

.btn--auto { width: auto; }


/* 5. FORMS
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: var(--s-2); }

.field__label {
  font-size: var(--t-label);
  font-weight: 600;
  color: var(--ink);
}

.field__hint {
  font-size: var(--t-small);
  font-weight: 500;
  color: var(--ink-soft);
}

.input,
.select {
  width: 100%;
  min-height: 56px;
  padding: 0 var(--s-4);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);   /* 16px+ stops iOS zooming on focus */
  font-weight: 500;
}
.input::placeholder { color: var(--ink-faint); }
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-tint);
}

.select {
  appearance: none;
  padding-right: var(--s-6);
  /* Chevron drawn inline so there is no extra image request. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%234A4F5A' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
}

/* Invalid state */
.field--error .input,
.field--error .select { border-color: var(--red); }
.field__error {
  font-size: var(--t-small);
  font-weight: 600;
  color: var(--red);
}


/* 6. CARDS + PANELS
   ========================================================================== */

.card {
  padding: var(--s-5);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}

.panel {
  padding: var(--s-4);
  border-radius: var(--radius);
  font-size: var(--t-small);
  font-weight: 500;
}
.panel--info  { background: var(--blue-tint); color: var(--blue-dark); }
.panel--error { background: var(--red-tint);  color: var(--red-dark); }

.divider {
  height: 2px;
  background: var(--line);
  border: 0;
  margin: var(--s-5) 0;
}


/* 7. GAME PIECES
   ==========================================================================
   Used by the Lesson and Results screens. Defined here so the game screen
   is markup only, no new CSS.
   ========================================================================== */

/* --- Answer options --- */
.option {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 60px;
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 3px 0 var(--line);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease,
              background-color .12s ease, border-color .12s ease;
}
.option:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }

/* Three states that must never be confused with each other:
     --selected  you tapped this, but haven't submitted yet  (outline only)
     --correct   this is the right answer                    (blue + check)
     --wrong     you picked this and it was wrong            (red + cross)
   Selected is outline-only so that once the answer is graded, the filled
   states clearly outrank it. */
.option--selected {
  background: var(--paper);
  border-color: var(--blue);
  box-shadow: 0 3px 0 var(--blue);
  color: var(--blue-dark);
}

.option--correct {
  background: var(--blue-tint);
  border-color: var(--blue);
  box-shadow: 0 3px 0 var(--blue);
  color: var(--blue-dark);
}
.option--wrong {
  background: var(--red-tint);
  border-color: var(--red);
  box-shadow: 0 3px 0 var(--red);
  color: var(--red-dark);
}

/* A check or cross badge on the right. This is what makes right-vs-wrong
   readable for the roughly 1 in 12 men who can't reliably separate the two
   colors. Never rely on color alone to carry meaning. */
.option--correct::after,
.option--wrong::after {
  flex: 0 0 auto;
  margin-left: auto;
  padding-left: var(--s-3);
  font-size: var(--t-h2);
  font-weight: 800;
  line-height: 1;
}
.option--correct::after { content: '\2713'; color: var(--blue); }  /* check */
.option--wrong::after   { content: '\2715'; color: var(--red); }   /* cross */

.option[disabled] { cursor: default; transform: none; }

/* --- Hearts (lives) --- */
.hearts { display: flex; gap: var(--s-1); align-items: center; }
.heart  { width: 22px; height: 22px; color: var(--red); }
.heart--spent { color: var(--line); }

/* --- Progress bar --- */
.progress {
  flex: 1 1 auto;
  height: 14px;
  background: var(--line);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0;
  background: var(--blue);
  border-radius: var(--radius-pill);
  transition: width .3s ease;
}

/* Top bar of the lesson screen: quit, progress, hearts */
.gamebar { display: flex; align-items: center; gap: var(--s-3); }

/* --- Stat tiles (home + results) --- */
.stats { display: flex; gap: var(--s-3); }
.stat {
  flex: 1 1 0;
  padding: var(--s-4) var(--s-3);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.stat__value {
  font-size: var(--t-display);
  font-weight: 800;
  line-height: 1.1;
  color: var(--ink);
}
.stat__value--blue { color: var(--blue); }
.stat__value--red  { color: var(--red); }
.stat__label {
  margin-top: var(--s-1);
  font-size: var(--t-small);
  font-weight: 600;
  color: var(--ink-soft);
}


/* --- Avatar picker (Sign Up, later Account Settings) ---
   A radio group that does not look like radio buttons. The native input is
   still there, still keyboard-reachable, still what the form submits; it is
   just moved off screen and the tile next to it does the talking. */
.avatar { width: 100%; height: auto; aspect-ratio: 1 / 1; }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-3);
}
/* At 360px that is four ~71px tiles. Comfortably past the 44px minimum. */

.avatar-choice { position: relative; display: block; cursor: pointer; }

.avatar-choice input {
  position: absolute;
  width: 1px; height: 1px;
  margin: 0;
  opacity: 0;
}

.avatar-choice__box {
  display: block;
  padding: var(--s-2);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  transition: background-color .12s ease, border-color .12s ease, transform .06s ease;
}

.avatar-choice input:checked + .avatar-choice__box {
  background: var(--blue-tint);
  border-color: var(--blue);
}

/* The keyboard focus ring has to land on the tile, since the input itself is
   a 1px speck nobody can see. */
.avatar-choice input:focus-visible + .avatar-choice__box {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.avatar-choice:active .avatar-choice__box { transform: translateY(2px); }

/* Same rule as the answer options: never let color alone carry the meaning.
   A check badge says "this one" even if the blue tint reads as grey. */
.avatar-choice input:checked + .avatar-choice__box::after {
  content: '\2713';
  position: absolute;
  top: -7px; right: -7px;
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  background: var(--blue);
  color: #fff;
  border: 2px solid var(--paper);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

/* fieldset carries browser default chrome we never want. */
.fieldset {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.fieldset > legend { padding: 0; margin-bottom: var(--s-2); }


/* 8. LOGO + BRAND
   ========================================================================== */

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
}

.logo__mark { width: 88px; height: 88px; }

.logo__word {
  font-size: var(--t-display);
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
  color: var(--ink);
}
.logo__word em {
  font-style: normal;
  color: var(--blue);
}

/* Small horizontal version for the header on logged-in screens. */
.logo--inline { flex-direction: row; gap: var(--s-2); }
.logo--inline .logo__mark { width: 32px; height: 32px; }
.logo--inline .logo__word { font-size: var(--t-h2); }

.tagline {
  font-size: var(--t-body);
  font-weight: 500;
  color: var(--ink-soft);
  max-width: 22em;
  margin: 0 auto;
}


/* 9. UTILITIES
   ========================================================================== */

.muted   { color: var(--ink-soft); }
.small   { font-size: var(--t-small); }
.strong  { font-weight: 700; }

/* Visible to screen readers, invisible on screen. For labels that would be
   redundant to sighted users but that a blind user still needs. */
.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;
}
