/* ============================================================
   Raschy — participant-facing styles (stage one: Material 3)
   ============================================================
   Every colour, size and radius comes from css/tokens.css, a
   generated Material Design 3 token set (see docs/style.md). Each
   block names the Material component it implements; the comments
   also record where this deliberately departs from the spec. The
   trial screen is the one part outside the system: black on white,
   fixed, because it is the measurement.
   ============================================================ */

/* ── Reset & base ────────────────────────────────────────────── */

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

html, body {
  height: 100%;
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; align-items: center; }

/* ── Top app bar (center-aligned, small) ─────────────────────── */

.app-header {
  width: 100%;
  min-height: 64px;
  padding: 0 16px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  flex-shrink: 0;
}
.app-header-inner {
  max-width: 640px;
  min-height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 8px 0;
}
.app-header .app-title {
  font: var(--md-sys-typescale-title-large);
}

/* Assist chip, used for the "preview" marker */
.app-header .preview-badge {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-tertiary-container);
  background: var(--md-sys-color-tertiary-container);
  border-radius: var(--md-sys-shape-corner-small);
}

/* Text buttons, used for the preview screen links */
.app-header .preview-nav { margin-left: auto; display: flex; flex-wrap: wrap; gap: 4px; }
.app-header .preview-nav a {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-primary);
  text-decoration: none;
  border-radius: var(--md-sys-shape-corner-full);
}
.app-header .preview-nav a:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }
.app-header .preview-nav a.current { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }

#app {
  width: 100%;
  max-width: 640px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 32px;
}
@media (min-width: 480px) { #app { padding: 24px 24px 48px; } }

/* ── Screens: outlined card ──────────────────────────────────── */

/* Centred with auto margins rather than justify-content: a screen
   taller than the viewport (the results overview) then starts at the
   top and scrolls, instead of having its head clipped off-screen. */
.screen {
  width: 100%;
  margin: auto 0;
  padding: 24px 16px;
  text-align: center;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  animation: fadeIn 0.25s ease-out;
}
@media (min-width: 480px) { .screen { padding: 32px 40px; } }

.screen h1 { font: var(--md-sys-typescale-headline-medium); margin-bottom: 16px; }
.screen h2 { font: var(--md-sys-typescale-title-large); margin-bottom: 16px; }
.screen p  { font: var(--md-sys-typescale-body-large); letter-spacing: var(--md-sys-typescale-body-large-tracking); margin-bottom: 16px; color: var(--md-sys-color-on-surface); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Buttons ─────────────────────────────────────────────────── */

/* Filled button. Spec height is 40; 48 here so the whole container
   is the touch target on phones. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 24px;
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  color: var(--md-sys-color-on-primary);
  background: var(--md-sys-color-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  margin-top: 16px;
}
.btn:hover:not(:disabled)  { background: color-mix(in srgb, var(--md-sys-color-on-primary) 8%, var(--md-sys-color-primary)); box-shadow: var(--md-sys-elevation-1); }
.btn:active:not(:disabled) { background: color-mix(in srgb, var(--md-sys-color-on-primary) 10%, var(--md-sys-color-primary)); box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.btn:disabled {
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  cursor: not-allowed;
}

/* Filled tonal button */
.btn-tonal {
  color: var(--md-sys-color-on-secondary-container);
  background: var(--md-sys-color-secondary-container);
}
.btn-tonal:hover:not(:disabled)  { background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 8%, var(--md-sys-color-secondary-container)); }
.btn-tonal:active:not(:disabled) { background: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 10%, var(--md-sys-color-secondary-container)); }

/* Outlined button */
.btn-outlined {
  color: var(--md-sys-color-primary);
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
}
.btn-outlined:hover:not(:disabled)  { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); box-shadow: none; }
.btn-outlined:active:not(:disabled) { background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent); }

.btn-small { height: 40px; padding: 0 16px; margin-top: 8px; }

/* Text button */
.link-btn,
.word-list .lookup {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-primary);
  background: none;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  text-decoration: none;
  cursor: pointer;
}
.link-btn:hover, .word-list .lookup:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }

/* ── Questionnaire: outlined text fields ─────────────────────── */
/* Departure: the label sits above the field instead of floating
   into the outline — one less moving part, same affordance. */

.form-group {
  text-align: left;
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 4px;
}

.form-group select,
.form-group input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
}
.form-group select:hover,
.form-group input:hover { border-color: var(--md-sys-color-on-surface); }
.form-group select:focus,
.form-group input:focus {
  outline: none;
  border: 2px solid var(--md-sys-color-primary);
  padding: 0 15px;
}

/* ── Lexical decision trial area (outside the system) ────────── */
/* The measurement condition: black type on white, nothing else. */

.trial-area {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #000;
  font-family: var(--md-ref-typeface-plain);
  user-select: none;
  -webkit-user-select: none;
}

.stimulus {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  min-height: 1.2em;
  /* Stimuli must never wrap: a line-broken word is a different
     reading task. Long words are shrunk to fit by fitStimulus(). */
  white-space: nowrap;
  max-width: 96vw;
}

.key-hints {
  position: fixed;
  bottom: 40px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 96px;
  font: var(--md-sys-typescale-body-medium);
  color: var(--md-sys-color-on-surface-variant);
}

.key-hint {
  display: flex;
  align-items: center;
  gap: 8px;
}

.key-hint kbd {
  display: inline-block;
  padding: 4px 10px;
  font: var(--md-sys-typescale-label-large);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-small);
}

/* ── Touch buttons (mobile): custom colours yes / no ─────────── */

.touch-buttons {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  display: flex;
  height: 30vh;
  min-height: 100px;
}

.touch-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font: var(--md-sys-typescale-headline-small);
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: filter 0.1s;
}
.touch-btn:active { filter: brightness(0.85); }
.touch-btn.no  { background: var(--md-custom-color-no);  color: var(--md-custom-color-on-no); }
.touch-btn.yes { background: var(--md-custom-color-yes); color: var(--md-custom-color-on-yes); }

/* ── Linear progress indicator ───────────────────────────────── */
/* Spec height is 4; 8 here so it reads from arm's length. No
   numbers: a count invites speeding up near the end. */

.trial-area::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: var(--md-sys-color-surface-container-highest);
}
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 8px;
  background: var(--md-custom-color-accent);
  transition: width 0.2s ease-out;
  z-index: 10;
}

/* ── Pre-instruction overlay ─────────────────────────────────── */

.pre-instruction {
  font: var(--md-sys-typescale-title-medium);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}

/* ── Results / debrief ───────────────────────────────────────── */

.result-number {
  font: var(--md-sys-typescale-display-large);
  font-weight: 500;
  color: var(--md-custom-color-accent);
  margin: 8px 0;
}

.result-detail {
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 8px;
}

/* Score bar (no Material equivalent): the non-word share is taken
   off the word share; the accent part that remains is the score. */
.score-bar {
  max-width: 440px;
  margin: 12px auto 20px;
  text-align: left;
}
.score-bar-track {
  position: relative;
  display: flex;
  height: 16px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  overflow: hidden;
}
.score-bar-fa    { background: var(--md-sys-color-error-container); }
.score-bar-score { background: var(--md-custom-color-accent); }
.score-bar-hit {
  position: absolute;
  top: 0; bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: var(--md-sys-color-on-surface);
}
.score-bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin-top: 8px;
  font: var(--md-sys-typescale-label-medium);
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
}
.score-bar-legend b { color: var(--md-sys-color-on-surface); font-weight: 600; }
.score-bar-legend .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}
.score-bar-legend .swatch.hit   { background: var(--md-sys-color-on-surface); width: 3px; }
.score-bar-legend .swatch.fa    { background: var(--md-sys-color-error-container); border: 1px solid var(--md-sys-color-on-error-container); }
.score-bar-legend .swatch.score { background: var(--md-custom-color-accent); }
.score-bar-formula {
  margin: 8px 0 4px;
  font: var(--md-sys-typescale-title-medium);
  letter-spacing: var(--md-sys-typescale-title-medium-tracking);
  text-align: center;
}
.score-bar-explain {
  font: var(--md-sys-typescale-body-small);
  letter-spacing: var(--md-sys-typescale-body-small-tracking);
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  margin-bottom: 0;
}

/* Item overview: list groups with subheaders */
.word-list {
  text-align: left;
  margin: 12px 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-lowest);
  overflow: hidden;
}

/* List subheader */
.word-list summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  font: var(--md-sys-typescale-title-small);
  letter-spacing: var(--md-sys-typescale-title-small-tracking);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.word-list summary::-webkit-details-marker { display: none; }
.word-list summary::before {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
  margin-right: 4px;
}
.word-list[open] summary::before { transform: rotate(45deg); }
.word-list summary:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.word-list summary .count {
  margin-left: auto;
  padding: 0 8px;
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: var(--md-sys-typescale-label-medium);
  color: var(--md-sys-color-on-secondary-container);
  background: var(--md-sys-color-secondary-container);
  border-radius: var(--md-sys-shape-corner-full);
}

.word-list ul {
  list-style: none;
  columns: 2;
  gap: 16px;
  padding: 4px 16px 12px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}
@media (max-width: 480px) { .word-list ul { columns: 1; } }

.word-list li {
  padding: 4px 0;
  font: var(--md-sys-typescale-body-large);
  letter-spacing: var(--md-sys-typescale-body-large-tracking);
  break-inside: avoid;
}

.word-list .actions { white-space: nowrap; }

/* Report form: outlined text area + tonal / text buttons */
.report-form { margin: 4px 0 12px; }
.report-form textarea {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  resize: vertical;
}
.report-form textarea:focus { outline: none; border: 2px solid var(--md-sys-color-primary); padding: 11px 15px; }
.report-form .muted {
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
}
.report-form .report-actions { display: flex; align-items: center; gap: 8px; }
.report-form .report-error { font: var(--md-sys-typescale-body-small); color: var(--md-sys-color-error); margin-top: 4px; }
.report-form .sent { font: var(--md-sys-typescale-body-medium); color: var(--md-custom-color-accent); }

/* ── Consent checkbox ────────────────────────────────────────── */

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  margin: 24px 0 8px;
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
}

.consent-check input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 1px;
  width: 18px;
  height: 18px;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
}

/* ── Utilities ───────────────────────────────────────────────── */

.muted  { font: var(--md-sys-typescale-body-small); letter-spacing: var(--md-sys-typescale-body-small-tracking); color: var(--md-sys-color-on-surface-variant); }
.mt-2   { margin-top: 16px; }
.mt-3   { margin-top: 24px; }
