/* ============================================================
   CPACC Practice Test — stylesheet
   ------------------------------------------------------------
   Organized into:
     1. Design tokens (CSS variables)
     2. Reset / base
     3. Accessibility primitives (focus, sr-only, skip link)
     4. Layout (wrap, panel, headings)
     5. Components (question, choices, nav, buttons, results grid)
     6. Chat
     7. Flashcards
     8. Disabilities reference
     9. Home button

   Accessibility notes:
   - --border (#708098) hits ≥3:1 non-text contrast against all panel backgrounds (WCAG 1.4.11).
   - --focus-ring is 3px solid amber on every focusable element (WCAG 2.4.7).
   - Cells, anchors, and pills all meet ≥24×24 CSS px target size (WCAG 2.5.8).
   - .dis-item uses scroll-margin-top so the sticky anchor bar doesn't obscure focused items (WCAG 2.4.11).
   ============================================================ */

/* 1. Design tokens
   ------------------------------------------------------------ */
:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f2330;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #7aa2ff;
  --accent-2: #5bd3a8;
  --wrong: #ff7a7a;
  --right: #5bd3a8;
  --border: #708098; /* hits 3:1+ non-text contrast against all panel backgrounds */
  --focus-ring: #ffd479;
}

/* 2. Reset / base
   ------------------------------------------------------------ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }

/* 3. Accessibility primitives
   ------------------------------------------------------------ */
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
.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; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 200; background: var(--focus-ring); color: #0b1020; padding: 10px 16px; border-radius: 6px; font-weight: 700; text-decoration: none; }
.skip-link:focus { left: 12px; }
button.linkish { background: none; border: none; color: inherit; font: inherit; padding: 0; cursor: pointer; text-align: left; }

/* Hint text shown only on devices whose primary pointer is fine (mouse/keyboard).
   Touch-primary devices (phones, most tablets) hide it via the media query below.
   Using display:none also removes it from the accessibility tree, so VoiceOver
   on iPhone won't read out keyboard-specific instructions. */
@media (pointer: coarse) {
  .kbd-only { display: none; }
}

/* 4. Layout
   ------------------------------------------------------------ */
.wrap { max-width: 820px; margin: 0 auto; padding: 16px 20px 80px; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin-bottom: 24px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; margin-bottom: 16px; }

/* 5. Components — questions, choices, results
   ------------------------------------------------------------ */
.qmeta { color: var(--muted); font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.qmeta-emoji { font-size: 18px; vertical-align: middle; margin-right: 6px; text-transform: none; }
.qtext { font-size: 17px; margin: 0 0 16px; }
.choice { display: block; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 8px 0; cursor: pointer; transition: border-color .15s, background .15s; }
.choice:hover { border-color: var(--accent); }
.choice input { margin-right: 10px; }
.choice.selected { border-color: var(--accent); background: #20263a; }
.choice.correct { border-color: var(--right); background: #163127; }
.choice.incorrect { border-color: var(--wrong); background: #3a1d1d; }
.nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
button { background: var(--accent); color: #0b1020; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.progress { color: var(--muted); font-size: 14px; }
.why { margin-top: 10px; padding: 10px 12px; background: #11151f; border-left: 3px solid var(--accent); border-radius: 4px; font-size: 14px; color: #cbd2e0; }
.why b { color: var(--text); }
.cite { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--muted); }
.flag { margin-top: 8px; padding: 8px 10px; border-left: 3px solid #d9a441; background: #2a210f; color: #e9d6a8; font-size: 13px; border-radius: 4px; }
.flag b { color: #ffd479; }
.score { font-size: 32px; font-weight: 700; }
.score small { font-size: 14px; font-weight: 400; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; margin: 12px 0 4px; }
.cell { aspect-ratio: 1/1; min-width: 24px; min-height: 24px; border-radius: 6px; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); border: 1px solid var(--border); font-family: inherit; cursor: pointer; padding: 0; }
.cell.answered { background: #20263a; color: var(--text); border-color: var(--accent); }
.cell.right { background: #163127; color: var(--right); border-color: var(--right); }
.cell.wrong { background: #3a1d1d; color: var(--wrong); border-color: var(--wrong); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); margin-right: 6px; }

/* 6. Chat
   ------------------------------------------------------------ */
.chat { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; background: #11151f; padding: 12px; }
.chat .log { max-height: 320px; overflow-y: auto; margin-bottom: 8px; }
.msg { padding: 8px 10px; border-radius: 6px; margin: 6px 0; font-size: 14px; white-space: pre-wrap; }
.msg.user { background: #1a2236; color: #cfd6e6; }
.msg.assistant { background: #14241d; color: #d3e8d9; }
.msg.error { background: #321; color: var(--wrong); }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 8px 10px; font: inherit; }
.toggle { font-size: 13px; color: var(--accent); cursor: pointer; user-select: none; background: none; border: 0; padding: 0; font-family: inherit; font-weight: 600; }

/* 7. Flashcards
   ------------------------------------------------------------ */
.flashcard { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; min-height: 240px; cursor: pointer; transition: border-color .15s; color: inherit; font: inherit; width: 100%; text-align: left; display: block; }
.flashcard:hover { border-color: var(--accent); }
.flashcard .front-text { font-size: 20px; font-weight: 600; line-height: 1.4; }
.flashcard .back-text { font-size: 15px; line-height: 1.6; white-space: pre-wrap; color: #cbd2e0; }
.flashcard .tag-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #11151f; border: 1px solid var(--border); color: var(--muted); margin-bottom: 12px; display: inline-block; text-transform: uppercase; letter-spacing: 0.05em; }
.flashcard .flip-hint { font-size: 12px; color: var(--muted); margin-top: 16px; font-style: italic; }

/* 8. Disabilities reference
   ------------------------------------------------------------ */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 8px; }
.cat-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; padding: 24px 14px; text-align: center; cursor: pointer; transition: border-color .15s, transform .1s; color: inherit; font: inherit; width: 100%; }
.cat-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.cat-card .cat-emoji { font-size: 64px; line-height: 1; margin-bottom: 10px; }
.cat-card .cat-label { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.cat-card .cat-count { font-size: 12px; color: var(--muted); }
.cat-overview { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.cat-overview .cat-hero { display: flex; gap: 16px; align-items: center; margin-bottom: 10px; }
.cat-overview .cat-hero-emoji { font-size: 56px; line-height: 1; }
.cat-overview h2 { margin: 0; font-size: 22px; }
.cat-overview .cat-summary { color: #cbd2e0; line-height: 1.55; margin: 0; }
.cat-overview .stat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.cat-overview .stat-pill { background: #11151f; border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--accent); }
.dis-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 12px; scroll-margin-top: 60px; /* keep heading clear of sticky anchor bar */ }
.dis-item .dis-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.dis-item .dis-emoji { font-size: 52px; line-height: 1; flex-shrink: 0; }
.dis-item .dis-name { font-weight: 700; font-size: 18px; margin: 0; }
.dis-item .dis-prev { font-size: 13px; color: var(--accent); margin-top: 4px; }
.dis-item .dis-desc { font-size: 15px; line-height: 1.6; color: #cbd2e0; margin: 8px 0 12px; }
.dis-item .section-h { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 14px 0 6px; font-weight: 600; }
.dis-item .dis-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .dis-item .dis-cols { grid-template-columns: 1fr; } }
.dis-item ul { margin: 0; padding-left: 18px; }
.dis-item li { margin: 4px 0; line-height: 1.5; font-size: 14px; color: #cbd2e0; }
.dis-anchor-bar { position: sticky; top: 0; background: var(--bg); padding: 8px 0; margin-bottom: 12px; border-bottom: 1px solid var(--border); z-index: 10; }
.dis-anchor-bar .anchor-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dis-anchor-bar .anchor { background: var(--panel-2); border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; font-size: 12px; color: var(--text); text-decoration: none; cursor: pointer; min-height: 24px; line-height: 1.2; font-family: inherit; }
.dis-anchor-bar .anchor:hover { border-color: var(--accent); }

/* 9. AI provenance badge + dialog (IBM-style transparency)
   ------------------------------------------------------------ */
.provenance { margin: 8px 0; }
.provenance > summary {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px;
  background: #11151f; border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--text);
  cursor: pointer; user-select: none;
  list-style: none;  /* hide default disclosure marker */
}
.provenance > summary::-webkit-details-marker { display: none; }
.provenance > summary::marker { display: none; }
.provenance > summary:hover { border-color: var(--accent); }
.provenance .pv-cat { font-weight: 600; }
.provenance .pv-conf {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px; font-weight: 500;
  border: 1px solid currentColor;
}
.provenance .pv-conf-glyph { font-size: 11px; line-height: 1; }
.provenance .pv-conf-high { color: #67e3a6; }
.provenance .pv-conf-med  { color: #e3c067; }
.provenance .pv-conf-low  { color: #ff9a9a; }
.provenance .pv-conf-var  { color: #b9c1cf; }
.provenance .pv-chev { font-size: 10px; transition: transform .15s; }
.provenance[open] .pv-chev { transform: rotate(90deg); }
.provenance-card {
  margin: 8px 0 0; padding: 12px 14px; background: #11151f;
  border: 1px solid var(--border); border-radius: 8px;
  display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px;
  font-size: 13px;
}
.provenance-card dt { font-weight: 600; color: var(--muted); }
.provenance-card dd { margin: 0; color: #cbd2e0; }
.provenance-card .pv-limits { margin: 4px 0 0; padding-left: 18px; }
.provenance-card .pv-limits li { line-height: 1.45; }

/* Neutral "scope" note — static descriptive label. NOT a warning or
   alert (no role). Uses the same neutral pill vocabulary as the
   provenance badges to avoid muddying the amber AI-warning channel. */
.scope-note {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 6px 0; padding: 5px 12px;
  background: #11151f; border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; color: var(--text);
}
.scope-note .scope-icon { font-size: 14px; line-height: 1; }
.scope-note b { font-weight: 600; }

.pv-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 10px; padding: 8px 12px;
  background: #2a210f; border-left: 3px solid #d9a441; border-radius: 4px;
  color: #e9d6a8; font-size: 13px;
}
.pv-banner .pv-icon { font-size: 16px; }
.pv-info-link { color: var(--accent); font-weight: 600; }

.ai-dialog {
  max-width: 640px; width: calc(100% - 32px);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 24px; box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.ai-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.ai-dialog h2 { font-size: 20px; }
.ai-dialog h3 { font-size: 15px; margin: 16px 0 4px; color: var(--accent); }
.ai-dialog p, .ai-dialog li { line-height: 1.55; font-size: 14px; }
.ai-dialog .secondary.small { padding: 4px 10px; }

/* Hint text shown only on devices whose primary pointer is fine (mouse/keyboard).
   (Defined below near other media queries.) */

/* 10. Home button
   ------------------------------------------------------------
   In normal document flow at the top of the page so it never overlaps
   the heading and scales correctly under reflow / zoom (WCAG 1.4.10).
   Visual order matches DOM/tab order (WCAG 1.3.2, 2.4.3). */
.home-btn { display: inline-block; margin: 12px 0 0 12px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.home-btn:hover { border-color: var(--accent); }
