.tr-game { max-width: 680px; margin: 1rem auto 3rem; padding: 0 1rem; position: relative; z-index: 1; }

.panel {
  background: var(--card); border: 3px solid var(--card-border); border-radius: var(--radius);
  padding: clamp(1.25rem, 4vw, 2rem); box-shadow: var(--shadow); text-align: center;
  backdrop-filter: blur(10px);
}
.panel.hidden { display: none; }
.panel h1, .panel h2 {
  font-family: var(--font-display); font-weight: 600;
  margin: 0.25rem 0 0.5rem; font-size: clamp(1.8rem, 5vw, 2.8rem);
  background: linear-gradient(95deg, var(--primary), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent; padding-bottom: 0.1em;
}
.tr-icon { font-size: 4rem; filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.tagline { margin: 0 0 1.25rem; color: var(--text-soft); font-weight: 600; }

/* ===== Level picker ===== */
.levels { border: none; margin: 0 0 1.25rem; padding: 0; }
.levels legend {
  font-weight: 800; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-soft); margin-bottom: 0.6rem; padding: 0;
}
/* Fixed 2x2 rather than auto-fit: four levels auto-fitted wrap 3+1 and leave
   an orphan, which reads as a mistake. */
.level-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
@media (max-width: 330px) { .level-grid { grid-template-columns: 1fr; } }

.level-btn {
  font: inherit; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  padding: 0.85rem 0.6rem; border-radius: var(--radius-sm);
  border: 3px solid transparent; background: rgba(127, 127, 127, 0.14); color: var(--text);
  transition: transform 0.15s var(--ease-pop), border-color 0.15s ease, background 0.15s ease;
}
.level-btn:hover { transform: translateY(-3px); }
.level-btn[aria-pressed="true"] {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, transparent);
}
.level-emoji { font-size: 1.7rem; line-height: 1; }
.level-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.level-sub { font-size: 0.72rem; color: var(--text-soft); font-weight: 600; line-height: 1.25; }

.setup-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; align-items: center; }
.btn-primary {
  font-family: var(--font-display); font-weight: 600; padding: 0.7rem 1.6rem; border-radius: var(--radius-pill);
  border: none; background: linear-gradient(95deg, var(--primary), var(--accent)); color: #fff; cursor: pointer;
  box-shadow: var(--shadow); transition: transform 0.15s var(--ease-pop); font-size: 1.1rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.btn-primary:hover { transform: translateY(-3px) scale(1.03); }
.btn-secondary {
  display: inline-block; margin-left: 0.75rem; padding: 0.7rem 1.4rem; border-radius: var(--radius-pill);
  text-decoration: none; color: var(--text); background: var(--card);
  border: 2px solid var(--card-border); font-weight: 700;
}
.best-line { margin: 1rem 0 0; color: var(--text-soft); font-weight: 700; font-size: 0.9rem; min-height: 1.2em; }

/* ===== HUD ===== */
.tr-header { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 0.9rem; }
.hud { display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,0.15); border-radius: 12px; padding: 0.5rem; }
.hud-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-soft); font-weight: 700; }
.hud-value { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.hud-value.low { color: #ff5c5c; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ===== Race track ===== */
.track {
  background: rgba(0, 0, 0, 0.14); border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem; margin-bottom: 0.4rem;
}
.lane {
  display: grid; grid-template-columns: 2.9rem 1fr; align-items: center;
  height: 2.3rem;
  border-bottom: 3px dashed rgba(127, 127, 127, 0.35);
}
.lane:last-child { border-bottom: none; }

.lane-tag {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--accent); text-align: left;
}
.lane-tag.robo { color: var(--text-soft); }

.lane-track { position: relative; height: 100%; display: block; }

.racer {
  position: absolute;
  /* left is driven by --pos (0-1); the emoji's own width is held back at the
     far end so it never overlaps the flag. */
  left: calc(var(--pos, 0) * (100% - 2.4rem));
  font-size: 1.5rem; line-height: 1;
  transition: left 0.35s var(--ease-pop);
}
.racer.you { filter: drop-shadow(0 0 6px var(--accent)); }
.flag { position: absolute; right: 0; font-size: 1.35rem; opacity: 0.9; }

.progress-line { margin: 0 0 0.9rem; font-weight: 700; font-size: 0.85rem; color: var(--text-soft); }

/* ===== Target text ===== */
.target {
  background: rgba(255,255,255,0.93); color: #3a3450;
  border-radius: 14px; padding: 1rem 1.25rem; margin-bottom: 0.9rem;
  min-height: 3.4rem; display: flex; align-items: center; justify-content: center;
  font-family: 'Consolas', 'Courier New', monospace; font-weight: 700;
  font-size: 1.45rem; line-height: 1.55;
}

.target-text {
  white-space: pre-wrap;      /* keep the spaces, still break lines at them */
  overflow-wrap: break-word;  /* only splits a word with nowhere else to go */
  display: block; text-align: center; max-width: 100%;
}
/* One giant letter for the youngest level — it has to be readable across a room. */
.target.huge { font-size: clamp(3.5rem, 18vw, 6rem); letter-spacing: 0.05em; }
/* At that size the letter is its own emphasis; the cursor highlight behind it
   just reads as a solid slab. */
.target.huge .cur { background: none; box-shadow: none; }

.target .ok { color: #227a2e; }
.target .bad { color: #fff; background: #d94a41; border-radius: 3px; }
.target .cur { background: var(--accent-2); border-radius: 3px; box-shadow: 0 0 0 2px var(--accent-2); }

.target.shake { animation: shake 0.3s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}
.target.pop { animation: pop 0.25s var(--ease-pop); }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.07); } 100% { transform: scale(1); } }

.typed {
  font: inherit; font-size: 1.25rem; width: 100%; padding: 0.6rem 1rem; border-radius: 12px;
  border: 2px solid var(--primary); background: #fff; color: #1f1b2e;
  font-family: 'Consolas', 'Courier New', monospace;
}
.typed[hidden] { display: none; }

/* ===== On-screen keyboard =====
   The point of this is a six-year-old on a tablet: in Letters mode there is no
   text input at all, so these keys are the only way to play. */
.keyboard { margin-top: 0.9rem; display: flex; flex-direction: column; gap: 0.35rem; }
.keyboard[hidden] { display: none; }
.kb-row { display: flex; gap: 0.3rem; justify-content: center; }

.kb-key {
  font: inherit; font-weight: 800; cursor: pointer;
  flex: 1 1 0; min-width: 0; max-width: 2.9rem;
  /* A fixed height, not aspect-ratio: rows hold different numbers of keys,
     so a ratio makes the short bottom row visibly taller. */
  height: 2.7rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 2px solid rgba(127,127,127,0.3);
  background: rgba(255,255,255,0.85); color: #2b2640;
  font-size: clamp(0.75rem, 2.7vw, 1rem); text-transform: uppercase;
  transition: transform 0.12s var(--ease-pop), background 0.15s ease, box-shadow 0.15s ease;
}
.kb-key:active { transform: scale(0.92); }

/* Deliberately NOT .target: that class is the big "type this" box, and a key
   carrying it inherits that box's padding, font-size and min-height. */
.kb-key.is-next {
  background: linear-gradient(95deg, var(--primary), var(--accent));
  color: #fff; border-color: transparent;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent);
  animation: key-glow 1.2s ease-in-out infinite;
}
@keyframes key-glow { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }

.hint-line { color: var(--text-soft); font-size: 0.88rem; margin: 0.8rem 0 0; font-weight: 600; }

#end-title { font-size: clamp(1.6rem, 4.5vw, 2.3rem); }
#final-items { color: var(--text-soft); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .racer { transition: none; }
}

@media (max-width: 420px) {
  .kb-key { max-width: none; border-radius: 7px; }
  .target { font-size: 1.2rem; padding: 0.8rem 0.9rem; }
}
