:root {
  --bg: #1b1d22;
  --panel-bg: #24262d;
  --text: #e6e6e6;
  --muted: #7b7f8a;
  --correct: #4caf7d;
  --incorrect: #e05a5a;
  --missing: #b5453f;
  --accent: #6ea8fe;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --reflow-pulse-tint: var(--accent);
  --reflow-pulse-duration: 0.5s;
}

/* The reflow pulse is a color fall-off with no movement, so it is toned
 * down here rather than switched off: a muted wash over a longer, gentler
 * fade. It has to keep animating in some form — app.js retires the
 * .reflowed class on animationend, so a branch with no animation would
 * strand the class on the span permanently. Driving it through custom
 * properties keeps the keyframe name stable, which is what that listener
 * matches on. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --reflow-pulse-tint: var(--muted);
    --reflow-pulse-duration: 0.9s;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

main {
  width: 100%;
  max-width: 760px;
}

header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.subtitle {
  color: var(--muted);
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

#test-area {
  position: relative;
  margin-top: 2rem;
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 1.5rem;
  cursor: text;
}

#target-text {
  font-family: var(--mono);
  font-size: 1.25rem;
  line-height: 1.8;
  letter-spacing: 0.02em;
}

.char {
  transition: color 0.1s, background-color 0.1s;
}

.char.pending {
  color: var(--muted);
}

.char.correct {
  color: var(--correct);
}

.char.incorrect {
  color: var(--incorrect);
  text-decoration: underline;
}

.char.missing {
  color: var(--missing);
  text-decoration: line-through;
  opacity: 0.7;
}

/* Declared ahead of .char.caret deliberately: a pulse outlives the render
 * that started it, so a retreating caret can land on a span that is still
 * pulsing. Equal specificity means source order decides, and the caret
 * blink is the one that should win that overlap. */
.char.reflowed {
  animation: reflow-pulse var(--reflow-pulse-duration) ease-out;
}

.char.caret {
  background: var(--accent);
  color: var(--bg);
  border-radius: 2px;
  animation: blink 1s step-start infinite;
}

.char.revised {
  border-bottom: 2px dotted var(--accent);
  cursor: help;
}

@keyframes blink {
  50% {
    background: transparent;
    color: var(--accent);
  }
}

@keyframes reflow-pulse {
  0% {
    background: var(--reflow-pulse-tint);
    color: var(--bg);
    border-radius: 2px;
  }
  100% {
    background: transparent;
  }
}

#key-capture {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

#stats-row {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--panel-bg);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: fit-content;
}

/* Generic hover/focus tooltip, driven off data-tooltip — used by both the
 * top stat labels and the certification stat grid below. */
[data-tooltip] {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted var(--muted);
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 260px;
  max-width: 60vw;
  background: #0d0f12;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-size: 0.72rem;
  line-height: 1.45;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
  z-index: 20;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus-visible::before {
  opacity: 1;
  transform: translateY(0);
}

.stat-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

#certification-panel {
  margin-top: 1.5rem;
  background: #1e2b22;
  border: 1px solid var(--correct);
  border-radius: 8px;
  padding: 1.5rem;
}

.cert-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.eyebrow {
  color: var(--correct);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin: 0 0 0.25rem;
  text-transform: uppercase;
}

#certification-panel h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--correct);
}

.cert-hash-label {
  font-family: var(--mono);
  font-size: 0.8rem;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}

#cert-hash {
  color: var(--text);
}

.cert-stats {
  display: grid;
  gap: 1rem;
  margin: 1rem 0 0;
}

.cert-stat-group {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  padding: 0.9rem 1rem 1rem;
}

.cert-stat-group h3 {
  color: var(--correct);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  margin: 0 0 0.75rem;
  text-transform: uppercase;
}

.cert-stat-group dl {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.8rem 1.25rem;
  margin: 0;
}

.cert-stat-item {
  min-width: 0;
}

.cert-stat-group--featured {
  background: rgba(76, 175, 125, 0.12);
  border: 1px solid rgba(76, 175, 125, 0.25);
}

.cert-stat-group dt {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  width: fit-content;
}

.cert-stat-group dd {
  font-family: var(--mono);
  font-size: 1rem;
  margin: 0.1rem 0 0;
  color: var(--text);
}

.cert-stat-group--featured dd {
  font-size: 1.25rem;
  font-weight: 600;
}

.cert-note {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.5rem 0 0;
}

#restart-btn {
  margin-top: 1.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.25rem;
  font-size: 0.95rem;
  cursor: pointer;
}

#restart-btn:hover {
  filter: brightness(1.1);
}

#debug-panel {
  margin-top: 1.5rem;
}

#debug-panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.schema-info {
  margin-bottom: 0.75rem;
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
}

.schema-info summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--accent);
  user-select: none;
}

.schema-info-list {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.8rem;
  line-height: 1.5;
}

.schema-info-list dt {
  font-family: var(--mono);
  color: var(--accent);
  margin-top: 0.6rem;
}

.schema-info-list dt:first-child {
  margin-top: 0;
}

.schema-info-list dd {
  margin: 0.15rem 0 0;
  color: var(--muted);
}

.schema-info-list code {
  font-family: var(--mono);
  background: rgba(255, 255, 255, 0.06);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
}

#raw-state-panel {
  background: #0d0f12;
  color: #7dffa0;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 1rem;
  border-radius: 8px;
  max-height: 320px;
  overflow: auto;
  white-space: pre;
  margin: 0;
}

@media (max-width: 600px) {
  #stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cert-heading {
    align-items: start;
    flex-direction: column;
  }

  .cert-stat-group dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --panel-bg: #ffffff;
    --text: #1b1d22;
    --muted: #6b7280;
  }

  #test-area,
  .stat {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }

  #raw-state-panel {
    background: #12141a;
  }
}
