/* =========================================================================
   Typing games: shell (HUD, stage, overlays), effects and the three game
   families (sprint, falling, sequence).
   ========================================================================= */

.game-app {
  max-width: 940px;
  margin-inline: auto;
  padding: 24px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.game-app:empty { min-height: 560px; }

/* ---------- HUD ---------- */
.game-hud {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.game-hud .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px;
  min-width: 0;
}
.game-hud .stat + .stat { border-left: 1px solid var(--border); }
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-label {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.game-hud .stat.is-pulse .stat-value,
.game-hud .stat.is-pulse .hearts { animation: hud-pulse 0.45s var(--ease-out); }
@keyframes hud-pulse {
  30% { transform: scale(1.22); color: var(--accent); }
}
.game-hud [data-stat="mult"] .stat-value { color: var(--accent); }

.hearts { display: flex; gap: 3px; height: 1.6rem; align-items: center; }
.hearts i { display: block; width: 18px; height: 18px; transition: transform 0.25s var(--ease-out), opacity 0.25s ease; }
.hearts svg { width: 100%; height: 100%; fill: var(--error); }
.hearts i.is-lost { opacity: 0.22; transform: scale(0.8); }
.hearts i.is-lost svg { fill: var(--text-faint); }

/* ---------- Stage ---------- */
.game-stage {
  position: relative;
  height: 460px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  background:
    radial-gradient(ellipse 70% 55% at 50% 0%, var(--accent-soft), transparent 70%),
    radial-gradient(var(--dot) 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--surface);
  isolation: isolate;
}
.game-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
}
.game-stage.is-flash-error::after { background: radial-gradient(ellipse at 50% 100%, var(--error-soft), transparent 70%); box-shadow: inset 0 0 0 2px var(--error); animation: stage-flash 0.45s ease; }
.game-stage.is-flash-success::after { box-shadow: inset 0 0 0 2px var(--success); background: var(--success-soft); animation: stage-flash 0.45s ease; }
@keyframes stage-flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.game-stage.is-shake { animation: stage-shake 0.32s ease; }
@keyframes stage-shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.game-layer { position: absolute; inset: 0; }

.game-hidden-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
  font-size: 16px; /* stops iOS zooming in on focus */
  color: transparent;
  background: transparent;
  caret-color: transparent;
  cursor: default;
  z-index: 5;
}

.game-timebar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--border);
  z-index: 4;
}
.game-timebar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  transition: transform 0.2s linear;
}
.game-timebar.is-warn .game-timebar-fill { background: var(--error); animation: warn-blink 0.8s steps(2) infinite; }
@keyframes warn-blink { 50% { opacity: 0.45; } }

.game-pause-btn {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 7;
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.game-pause-btn:hover { color: var(--text); border-color: var(--accent); }
.game-pause-btn svg { width: 16px; height: 16px; }

.game-keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  font-size: 0.8rem;
  color: var(--text-faint);
}
.game-keys span { display: inline-flex; align-items: center; gap: 4px; }
.game-app kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--elevated);
  color: var(--text-muted);
}

/* ---------- Overlay screens ---------- */
.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
}
.game-overlay.is-countdown { background: color-mix(in srgb, var(--bg) 45%, transparent); backdrop-filter: blur(2px); }
.ov-card {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  animation: ov-in 0.35s var(--ease-out);
}
@keyframes ov-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.ov-eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.ov-card h2 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.1; }
.ov-card p { color: var(--text-muted); max-width: 380px; font-size: 0.95rem; }
.ov-card .btn-lg { margin-top: 6px; min-width: 180px; }
.ov-hint { font-size: 0.8rem; color: var(--text-faint); }
.ov-best { font-size: 0.85rem; color: var(--text-muted); }
.ov-best strong { font-family: var(--font-mono); color: var(--text); }
.ov-badge {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--accent-contrast);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  animation: badge-pop 0.5s var(--ease-out) 0.15s both;
}
@keyframes badge-pop { from { opacity: 0; transform: scale(0.6); } }
.ov-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.ov-score { display: flex; align-items: baseline; gap: 8px; }
.ov-score strong {
  font-family: var(--font-mono);
  font-size: clamp(2.6rem, 8vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
  background: linear-gradient(180deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.ov-score span { color: var(--text-faint); font-size: 0.9rem; }
.ov-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.ov-stats div { padding: 12px 6px; display: flex; flex-direction: column; gap: 2px; }
.ov-stats div + div { border-left: 1px solid var(--border); }
.ov-stats strong { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 600; letter-spacing: -0.02em; }
.ov-stats span { font-size: 0.66rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }

.ov-count {
  font-family: var(--font-mono);
  font-size: clamp(4rem, 14vw, 6.5rem);
  font-weight: 700;
  letter-spacing: -0.06em;
  color: var(--text);
  text-shadow: 0 0 40px var(--accent-soft);
  animation: count-pop 0.56s var(--ease-out);
}
.ov-count.is-go { color: var(--accent); }
@keyframes count-pop { from { opacity: 0; transform: scale(1.6); } 60% { opacity: 1; } }

/* ---------- Effects ---------- */
.game-fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }
.fx-float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent);
  white-space: nowrap;
  text-shadow: 0 2px 12px var(--bg);
  animation: fx-float 0.95s var(--ease-out) forwards;
}
.fx-float.is-time { color: var(--success); }
.fx-float.is-life { color: var(--error); }
.fx-float.is-error { color: var(--error); font-size: 0.9rem; font-family: var(--font-sans); }
@keyframes fx-float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}
.fx-particle {
  position: absolute;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--accent);
  animation: fx-particle 0.65s cubic-bezier(.15,.7,.3,1) forwards;
}
.fx-particle:nth-child(3n) { background: var(--accent-2); width: 4px; height: 4px; }
.fx-particle:nth-child(4n) { background: var(--success); }
.fx-particle.is-error { background: var(--error); }
.fx-particle.is-gold { background: var(--accent-2); }
@keyframes fx-particle {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}
.fx-banner {
  position: absolute;
  left: 50%; top: 22%;
  transform: translate(-50%, -50%);
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--accent-contrast);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: var(--shadow-pop);
  white-space: nowrap;
  animation: fx-banner 1.3s var(--ease-out) forwards;
}
@keyframes fx-banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%); }
}

/* Shared char colours */
.game-stage .char { transition: color 0.08s ease, background-color 0.08s ease; }
.game-stage .char.pending,
.game-stage .char.current { color: var(--text-faint); }
.game-stage .char.correct { color: var(--text); }
.game-stage .char.incorrect { color: var(--error); background: var(--error-soft); border-radius: 3px; }
.game-stage .char.space.incorrect { box-shadow: inset 0 -2px 0 var(--error); }

/* ---------- Sprint (Word Rush, Number Sprint) ---------- */
.sprint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 40px 20px 30px;
}
.sprint-meter { display: flex; align-items: center; gap: 12px; }
.sprint-mult {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  min-width: 2.6ch;
  text-align: right;
  color: var(--text-muted);
  transition: color 0.2s ease;
}
.sprint-mult[data-tier="2"] { color: var(--accent-2); }
.sprint-mult[data-tier="3"], .sprint-mult[data-tier="4"] { color: var(--accent); }
.sprint-mult[data-tier="5"] { color: var(--accent); text-shadow: 0 0 16px var(--accent); }
.sprint-streak { width: 160px; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.sprint-streak-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.25s var(--ease-out);
}
.sprint-streak-label { font-size: 0.75rem; color: var(--text-faint); font-family: var(--font-mono); min-width: 9ch; }

.sprint-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 40px;
  border-radius: var(--radius-lg);
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  max-width: 100%;
}
.sprint-card.is-in { animation: card-in 0.28s var(--ease-out); }
@keyframes card-in { from { opacity: 0.2; transform: translateY(12px) scale(0.96); } }
.sprint-card.is-wrong { animation: card-wrong 0.3s ease; border-color: var(--error); }
@keyframes card-wrong {
  25% { transform: translateX(-7px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}
.sprint-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
}
.sprint-word {
  font-family: var(--font-mono);
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: pre;
  display: flex;
  max-width: 100%;
}
.sprint-word.is-long { font-size: clamp(1.4rem, 5vw, 2.4rem); }
.sprint-word .char.current { box-shadow: inset 0 -3px 0 var(--caret); }
.game-stage:not(:focus-within) .sprint-word .char.current { box-shadow: none; }
.sprint-next { font-size: 0.85rem; color: var(--text-faint); display: flex; gap: 8px; align-items: baseline; }
.sprint-next span { font-family: var(--font-mono); color: var(--text-muted); font-size: 1rem; white-space: pre; }

.game-stage.is-urgent { box-shadow: var(--shadow), inset 0 0 0 1px var(--error); }
.game-app:has(.is-urgent) [data-hud="time"] { color: var(--error); }

/* ---------- Falling (Falling Words, Survival) ---------- */
.stage-falling { height: 500px; }
.fall-sky { position: absolute; inset: 0; }
.falling-word {
  position: absolute;
  top: 0; left: 0;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 20px -10px rgba(0, 0, 0, 0.6);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  white-space: nowrap;
  will-change: transform;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease;
}
.falling-word .char.pending,
.falling-word .char.current { color: var(--text-muted); }
.falling-word.is-spawning { animation: word-spawn 0.3s var(--ease-out); }
@keyframes word-spawn { from { opacity: 0; } }
.falling-word.is-danger { border-color: color-mix(in srgb, var(--error) 60%, transparent); background: color-mix(in srgb, var(--error) 10%, var(--elevated)); }
.falling-word.is-target {
  z-index: 2;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 10px 26px -10px var(--accent);
}
.falling-word.is-target::before {
  content: "";
  position: absolute;
  left: 50%; top: 100%;
  width: 2px; height: 600px;
  transform: translateX(-50%);
  background: linear-gradient(var(--accent), transparent 70%);
  opacity: 0.35;
  pointer-events: none;
}
.falling-word.is-wrong .char { animation: none; }
.falling-word.is-wrong { animation: word-wrong 0.28s ease; }
@keyframes word-wrong { 0%, 100% { margin-left: 0; } 25% { margin-left: -5px; } 75% { margin-left: 5px; } }
.falling-word.is-cleared { animation: word-cleared 0.3s ease forwards; border-color: var(--success); }
@keyframes word-cleared { to { opacity: 0; filter: blur(4px); scale: 1.25; } }
.falling-word.is-landed { animation: word-landed 0.38s ease forwards; border-color: var(--error); }
@keyframes word-landed { to { opacity: 0; scale: 0.8 0.4; } }

.fall-ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 54px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  background: linear-gradient(to top, var(--error-soft), transparent);
  border-top: 1px dashed color-mix(in srgb, var(--error) 55%, transparent);
  pointer-events: none;
}
.fall-ground span {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--error) 70%, transparent);
}

/* ---------- Sequence (Code Breaker, Data Dash) ---------- */
.stage-sequence { height: auto; min-height: 460px; }
.stage-sequence .game-layer { position: relative; padding: 26px; min-height: 460px; display: flex; flex-direction: column; justify-content: center; }

.seq { font-family: var(--font-mono); font-size: 1.02rem; line-height: 1.9; overflow-y: auto; overflow-x: auto; scrollbar-width: thin; }
.seq-line { display: flex; white-space: pre; border-radius: 6px; padding-right: 12px; transition: background-color 0.15s ease; }
.seq-line.is-current { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.seq-ln {
  flex: none;
  width: 3.2ch;
  padding-right: 1.4ch;
  text-align: right;
  color: var(--text-faint);
  opacity: 0.6;
  user-select: none;
}
.seq-line.is-current .seq-ln { color: var(--accent); opacity: 1; }
.seq-code { white-space: pre; }
.seq .char.current { box-shadow: inset 2px 0 0 var(--caret); animation: seq-caret 1s steps(1) infinite; }
.game-stage:not(:focus-within) .seq .char.current { animation: none; box-shadow: none; }
@keyframes seq-caret { 50% { box-shadow: none; } }
.seq .char.nl { color: var(--text-faint); opacity: 0.35; padding-left: 2px; font-size: 0.85em; }
.seq .char.nl.correct { opacity: 0; }
.seq .char.nl.current { opacity: 0.9; color: var(--accent); }
.seq .char.nl.incorrect { opacity: 1; }
.seq-progress { height: 3px; background: var(--border); overflow: hidden; }
.seq-progress div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transform-origin: left; transform: scaleX(0); transition: transform 0.15s ease; }

/* Editor chrome */
.editor {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--elevated);
}
.editor-bar i { width: 11px; height: 11px; border-radius: 50%; background: var(--border-strong); }
.editor-bar i:nth-child(1) { background: #ff5f57; }
.editor-bar i:nth-child(2) { background: #febc2e; }
.editor-bar i:nth-child(3) { background: #28c840; }
.editor-file { margin-left: 10px; font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-muted); }
.editor-lang {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
}
.editor-body { padding: 14px 6px; max-height: 300px; }
.editor-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 14px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  background: var(--elevated);
}

/* Data entry records */
.records { display: flex; flex-direction: column; gap: 16px; }
.record-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--elevated);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.record-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.record-head strong { color: var(--text); font-family: var(--font-mono); }
.record-tag {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
}
.record-tag.is-done { color: var(--success); background: var(--success-soft); }
.record-body { padding: 34px 18px 18px; font-size: 1.12rem; }
.record-body .seq-code { display: flex; flex-wrap: wrap; row-gap: 26px; white-space: normal; }
.record-body .char { white-space: pre; }
.seq-field {
  position: relative;
  white-space: pre;
  padding: 2px 4px;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.seq-field::before {
  content: attr(data-label);
  position: absolute;
  left: 4px; bottom: calc(100% + 2px);
  font-family: var(--font-sans);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  line-height: 1.4;
}
.seq-field:has(.char.current) { box-shadow: inset 0 0 0 1px var(--accent); }
.seq-field:has(.char.current)::before { color: var(--accent); }
.seq-field:not(:has(.pending, .current, .incorrect)) { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--success) 50%, transparent); }

.record-log { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 124px; overflow: hidden; }
.record-log li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  animation: log-in 0.35s var(--ease-out);
}
.record-log li:nth-child(n+3) { opacity: 0.55; }
@keyframes log-in { from { opacity: 0; transform: translateY(-8px); } }
.record-check { color: var(--success); font-weight: 700; }
.record-text { flex: 1; min-width: 0; font-family: var(--font-mono); color: var(--text-muted); white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.record-meta { flex: none; font-family: var(--font-mono); color: var(--text-faint); }

/* ---------- Start-screen choices (Ghost Race pace) ---------- */
.ov-choice { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.ov-choice-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.ov-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.ov-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.ov-chip:hover { color: var(--text); border-color: var(--accent); }
.ov-chip.is-active { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }
.fx-banner.is-bad { background: var(--error); color: #fff; }

/* ---------- Ghost Race ---------- */
.stage-race { height: auto; min-height: 460px; }
.stage-race .game-layer { position: relative; padding: 30px 26px 26px; min-height: 460px; }
.race { display: flex; flex-direction: column; gap: 22px; }
.race-track {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border-strong);
}
.race-lane { display: flex; align-items: center; gap: 12px; }
.race-name { width: 44px; flex: none; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.race-road {
  position: relative;
  flex: 1;
  height: 34px;
  border-radius: 8px;
  background: repeating-linear-gradient(90deg, var(--border-strong) 0 14px, transparent 14px 28px) center / 100% 2px no-repeat, var(--surface);
}
.race-car {
  --p: 0;
  position: absolute;
  top: 50%;
  left: calc(var(--p) * (100% - 44px));
  width: 44px;
  height: 22px;
  transform: translateY(-50%);
  transition: left 0.18s linear;
}
.race-car svg { width: 100%; height: 100%; }
.race-car.is-you svg { fill: var(--accent); filter: drop-shadow(0 0 8px var(--accent-soft)); }
.race-car.is-ghost svg { fill: var(--text-faint); opacity: 0.7; }
.race-finish {
  position: absolute;
  top: 8px; bottom: 8px; right: 14px;
  width: 6px;
  background: repeating-linear-gradient(0deg, var(--text) 0 6px, var(--bg) 6px 12px);
  opacity: 0.5;
  border-radius: 2px;
}
.race-text {
  font-family: var(--font-mono);
  font-size: 1.22rem;
  line-height: 1.9;
  max-height: calc(1.9em * 4);
  overflow: hidden;
  padding: 4px 2px;
}
.race-text .char.current { box-shadow: inset 2px 0 0 var(--caret); }
.game-stage:not(:focus-within) .race-text .char.current { box-shadow: none; }
.game-hud .stat.is-behind .stat-value { color: var(--error); }
.game-hud [data-stat="lead"]:not(.is-behind) .stat-value { color: var(--success); }

/* ---------- Key Hunt ---------- */
.keyhunt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 30px 16px;
}
.keyhunt-prompt { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.keyhunt-stage { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); }
.keyhunt-target {
  display: grid;
  place-items: center;
  width: 92px; height: 92px;
  border-radius: 22px;
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 600;
  color: var(--accent-contrast);
  background: linear-gradient(160deg, var(--accent-2), var(--accent));
  box-shadow: 0 16px 40px -14px var(--accent), inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}
.keyhunt-target.is-in { animation: kh-pop 0.22s var(--ease-out); }
@keyframes kh-pop { from { transform: scale(0.7); opacity: 0.4; } }
.keyhunt-finger { font-size: 0.82rem; color: var(--text-muted); text-transform: capitalize; min-height: 1.2em; }
.kh-board { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.kh-row { display: flex; gap: 6px; }
.kh-row-2 { margin-left: 18px; }
.kh-row-3 { margin-left: 42px; }
.kh-key {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-muted);
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  border-bottom-width: 3px;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.2s ease, transform 0.1s ease;
}
.kh-key.is-bump::after { content: ""; position: absolute; bottom: 7px; width: 10px; height: 2px; border-radius: 2px; background: currentColor; opacity: 0.6; }
.kh-key.is-locked { opacity: 0.28; }
.kh-key.is-target { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); opacity: 1; }
.kh-key.is-hit { animation: kh-hit 0.3s ease; }
@keyframes kh-hit { 40% { transform: translateY(2px) scale(0.92); background: var(--success); color: var(--bg); } }
.kh-key.is-miss { animation: kh-miss 0.3s ease; }
@keyframes kh-miss { 40% { background: var(--error); color: #fff; transform: translateX(-3px); } 70% { transform: translateX(3px); } }

/* ---------- Flash Recall ---------- */
.recall {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 40px 20px 30px;
}
.recall-meter { width: min(360px, 80%); height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.recall-meter-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transform-origin: left; transform: scaleX(0); }
.recall-card {
  width: min(620px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 24px;
  border-radius: var(--radius-lg);
  background: var(--elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  text-align: center;
  transition: border-color 0.2s ease;
}
.recall-phase { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-faint); }
.recall-phrase {
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 4.4vw, 2.2rem);
  font-weight: 500;
  line-height: 1.35;
  min-height: 1.35em;
  word-break: break-word;
}
.recall-card.is-flash .recall-phrase { color: var(--text); animation: kh-pop 0.2s var(--ease-out); }
.recall-card.is-flash .recall-phase { color: var(--accent); }
.recall-card.is-recall .recall-phrase { color: var(--text-faint); letter-spacing: 0.08em; }
.recall-card.is-correct { border-color: var(--success); }
.recall-card.is-correct .recall-phase { color: var(--success); }
.recall-card.is-wrong { border-color: var(--error); }
.recall-card.is-wrong .recall-phase { color: var(--error); }
.recall-answer {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  min-height: 1.6em;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 60%;
  white-space: pre-wrap;
}
.recall-card.is-flash .recall-answer { visibility: hidden; }
.recall-card.is-recall .recall-answer { border-color: var(--accent); }
.recall-card.is-recall .recall-answer::after { content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 1px; vertical-align: -0.15em; background: var(--caret); animation: warn-blink 1s steps(2) infinite; }
.recall-hint { font-size: 0.82rem; color: var(--text-faint); min-height: 1.3em; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .kh-key { width: 29px; height: 38px; font-size: 0.8rem; border-radius: 7px; }
  .kh-row, .kh-board { gap: 4px; }
  .kh-row-2 { margin-left: 10px; }
  .kh-row-3 { margin-left: 24px; }
  .keyhunt-target { width: 76px; height: 76px; font-size: 2.4rem; }
  .race-text { font-size: 1rem; }
  .stage-race .game-layer { padding: 16px 14px; }
  .game-app { padding: 16px 16px 48px; }
  .game-hud { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
  .game-hud .stat { padding: 10px 6px; }
  .game-hud .stat + .stat { border-left: 0; }
  .game-hud .stat:not(:nth-child(3n + 1)) { border-left: 1px solid var(--border); }
  .game-hud .stat:nth-child(n + 4) { border-top: 1px solid var(--border); }
  .stat-value { font-size: 1.15rem; }
  .game-stage { height: 400px; }
  .stage-falling { height: 440px; }
  .stage-sequence .game-layer { padding: 14px; }
  .seq { font-size: 0.88rem; }
  .editor-status span:last-child { display: none; }
  .ov-stats { grid-template-columns: repeat(2, 1fr); }
  .ov-stats div:nth-child(3) { border-left: 0; }
  .ov-stats div:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .sprint-card { padding: 20px 22px; }
  .game-keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .falling-word.is-target::before { display: none; }
}
