/* FLATS Testing — mobile-first, ADA-compliant font resize */

dialog::backdrop { background: rgba(0,0,0,0.4); }

:root {
  /* Brand */
  --navy:         #262626;
  --navy-700:     #000000;
  --royal:        #DB9A4B;
  --royal-50:     #fbf3e8;
  --royal-100:    #f3e0c2;

  /* Surfaces */
  --bg:           #EBEEF2;
  --surface:      #ffffff;
  --surface-2:    #F7F5F4;
  --border:       #E2E4E8;
  --border-strong:#C2C5CC;

  /* Text */
  --ink:          #262626;
  --ink-2:        #383737;
  --muted:        #4D4D4D;
  --muted-2:      #9F9B9B;

  /* Status */
  --green:        #157C17;
  --green-50:     #e1f1e1;
  --orange:       #C85346;
  --orange-50:    #f9e6e3;
  --error:        #C91B1B;
  --error-50:     #fbe5e5;
  --amber:        #DB9A4B;
  --amber-50:     #fbf2dc;

  /* Typography */
  --font-sans:    "Source Sans 3", system-ui, sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-wordmark:"Archivo Black", serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, monospace;

  /* Geometry */
  --radius:       6px;
  --radius-lg:    10px;
  --shadow-sm:    0 1px 2px rgba(13,23,39,0.04);
  --shadow:       0 1px 2px rgba(13,23,39,0.04), 0 4px 12px rgba(13,23,39,0.04);

  /* ADA font size — adjusted by A-/A+ buttons, saved to localStorage */
  --base-font-size: 16px;
}

body.prefer-serif {
  --font-sans: "Source Serif 4", Georgia, serif;
}

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

html {
  font-size: var(--base-font-size);
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ===== Brand bar ===== */
.brand-bar {
  background: var(--navy);
  color: white;
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
  row-gap: 8px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand-bar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-bar .wm {
  font-family: var(--font-wordmark);
  font-size: 1.375rem;
  line-height: 1;
  color: white;
}
.brand-bar .product {
  padding-left: 12px;
  border-left: 1px solid rgba(255,255,255,0.2);
}
.brand-bar .product .name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.0625rem;
}
.brand-bar .spacer { flex: 1; min-width: 8px; }
.brand-bar .pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  font-size: 0.8125rem;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 999px;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
}
.brand-bar .pill .dot {
  width: 6px; height: 6px;
  border-radius: 999px;
  background: #6ee7b7;
  flex-shrink: 0;
}

/* ===== Font-resize bar (ADA) ===== */
.font-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.brand-bar .logout-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius);
  color: rgba(255,255,255,0.8);
  font-size: 0.8125rem;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms, color 120ms;
  touch-action: manipulation;
}
.brand-bar .logout-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.font-bar .font-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin-right: 4px;
}
.font-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: white;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms;
  touch-action: manipulation;
}
.font-btn:hover  { background: var(--surface-2); }
.font-btn:active { background: var(--royal-50); }
.font-btn.decrease { font-size: 0.75rem; }
.font-btn.increase { font-size: 1rem; }

/* ===== Progress bar ===== */
.progress-bar-wrap {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--royal);
  border-radius: 999px;
  transition: width 400ms ease;
}
.progress-label {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: right;
}

/* ===== Main content ===== */
main {
  flex: 1;
  padding: 16px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
}
.card .card-h {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card .card-h h2 {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.card .card-b { padding: 20px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  min-height: 48px;
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: white;
  color: var(--ink-2);
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover  { background: var(--surface-2); border-color: var(--muted-2); }
.btn:active { background: var(--royal-50); }
.btn.primary  { background: var(--navy);  color: white; border-color: var(--navy); }
.btn.primary:hover  { background: var(--navy-700); border-color: var(--navy-700); }
.btn.gold     { background: var(--royal); color: var(--navy); border-color: var(--royal); }
.btn.gold:hover     { background: #c48840; border-color: #c48840; }
.btn.danger   { background: var(--error); color: white; border-color: var(--error); }
.btn.ghost    { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover    { background: var(--surface-2); color: var(--ink); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }

.report-item-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 2px;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  border-radius: 4px;
  transition: color 120ms;
}
.report-item-btn svg { width: 22px; height: 22px; }
.report-item-btn:hover { color: var(--error); }
.report-item-btn:focus-visible { outline: 2px solid var(--royal); outline-offset: 2px; }
.btn.full { width: 100%; }

/* ===== Login / pre-auth layout ===== */
.pre-auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 48px;
  gap: 16px;
  flex: 1;
}
.pre-auth .page-head {
  text-align: center;
  max-width: 520px;
  width: 100%;
}
.pre-auth .page-head h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.75rem;
  margin: 0 0 8px 0;
  color: var(--ink);
}
.pre-auth .page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
}
.start-card {
  max-width: 520px;
  width: 100%;
}
.start-card .card-h h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}

/* ===== Form fields ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field + .field { margin-top: 18px; }
.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-2);
}
.field .req { color: var(--error); }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
  min-height: 48px;
}
.field input:focus {
  border-color: var(--royal);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--royal) 15%, transparent);
}
.field .hint {
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ===== Callouts ===== */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.5;
  border: 1px solid transparent;
}
.callout.error  { background: var(--error-50);  border-color: #f0b8b8; color: #7a1010; }
.callout.info   { background: var(--amber-50);  border-color: var(--royal-100); color: #7a4a00; }
.callout.success { background: var(--green-50); border-color: #b0d9b0; color: #0d4d0e; }
.callout.warning { background: var(--amber-50); border-color: var(--royal-100); color: #7a4a00; }
.callout.paused {
  background: var(--orange-50);
  border-color: #f0b0a8;
  color: #7a1f18;
  text-align: center;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  font-size: 1rem;
}
.callout.paused .paused-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 8px;
}

/* ===== Test interface ===== */
#test-element {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Page heading (section/part labels) */
.page-heading {
  margin-bottom: 4px;
}
.page-heading .section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 4px;
}
.page-heading .part-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.25rem;
  color: var(--ink);
}

/* Instructional content */
.page-contents {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  line-height: 1.7;
}
.page-contents p:first-child { margin-top: 0; }
.page-contents p:last-child  { margin-bottom: 0; }

/* Audio button */
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  min-height: 48px;
  border: 1.5px solid var(--royal);
  border-radius: var(--radius);
  background: var(--royal-50);
  color: var(--navy);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms;
  touch-action: manipulation;
  margin: 8px 0;
}
.audio-btn:hover  { background: var(--royal-100); }
.audio-btn:active { background: var(--royal); color: white; }
.audio-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.audio-btn.playing {
  background: var(--royal);
  color: white;
}
.audio-wrap {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
}
.audio-wrap .audio-btn {
  margin: 0;
}
.audio-progress {
  height: 4px;
  background: var(--royal-100);
  border-radius: 2px;
  overflow: hidden;
}
.audio-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--royal);
  transition: width 200ms linear;
}

/* Test items */
.test-items {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.test-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.test-item.answered {
  border-color: var(--royal-100);
}
.item-stem {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  line-height: 1.7;
}
.item-number {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.item-options {
  padding: 8px 0;
}
.option-label {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 100ms;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.option-label:last-child { border-bottom: none; }
.option-label:hover { background: var(--surface-2); }
.option-label input[type="radio"] {
  width: 20px; height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--royal);
  cursor: pointer;
}
.option-label.selected {
  background: var(--royal-50);
}
[dir="rtl"] .option-letter { display: none; }
.option-letter {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  min-width: 18px;
  margin-top: 2px;
}
.option-content { flex: 1; line-height: 1.6; }

/* Nav buttons */
.test-nav {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 0 24px;
}
.test-nav .nav-left   { display: flex; gap: 12px; flex: 1; justify-content: flex-start; }
.test-nav .nav-center { display: flex; gap: 12px; flex: 1; justify-content: center; }
.test-nav .nav-right  { display: flex; gap: 12px; flex: 1; justify-content: flex-end; }

/* ===== Confirmation / completion screens ===== */
.confirm-screen,
.complete-screen {
  text-align: center;
  padding: 40px 24px;
  max-width: 560px;
  margin: 0 auto;
}
.confirm-screen h2,
.complete-screen h2 {
  font-family: var(--font-display);
  font-size: 1.625rem;
  font-weight: 500;
  margin: 0 0 12px 0;
  color: var(--ink);
}
.confirm-screen p,
.complete-screen p {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 28px 0;
}
.confirm-screen .btn-row,
.complete-screen .btn-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
@media (min-width: 420px) {
  .confirm-screen .btn-row,
  .complete-screen .btn-row {
    flex-direction: row;
    justify-content: center;
  }
}
.complete-screen .score-display {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 500;
  color: var(--royal);
  margin: 16px 0;
}

/* ===== Loading / status states ===== */
.loading-msg {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
  font-size: 1rem;
}
.loading-msg .spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--royal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Footer ===== */
.foot {
  padding: 14px 16px;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  margin-top: auto;
}
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--navy); }
.foot-links { display: flex; gap: 14px; flex-wrap: wrap; }

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .brand-bar { padding: 0 24px; }
  .font-bar  { padding: 6px 24px; }
  .progress-bar-wrap { padding: 8px 24px; }
  main { padding: 24px; }
}

@media (max-width: 420px) {
  .test-nav {
    flex-direction: column;
    align-items: stretch;
  }
  .test-nav .nav-left,
  .test-nav .nav-center,
  .test-nav .nav-right {
    width: 100%;
    justify-content: center;
  }
  .test-nav .btn { width: 100%; justify-content: center; }
}
