.timetrial-page--booting {
  overflow: hidden;
  background: #000000;
}

.timetrial-boot {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #000000;
}

.timetrial-boot[hidden] {
  display: none !important;
}

.timetrial-boot-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.timetrial-page {
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  user-select: none;
  -webkit-user-select: none;
}

/* Retro landing uses ropers-heaven.css; legacy rules kept for non-rh fallback */
.timetrial-landing:not(.rh-page) .timetrial-landing-main {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.25rem;
  max-width: min(100%, 720px);
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 2.5rem) 1rem 2rem;
}

.rh-timetrial.timetrial-landing {
  overflow-x: hidden;
  overflow-y: auto;
}

.timetrial-landing-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  text-align: center;
  margin-bottom: 0;
  padding: 0;
}

.timetrial-landing-title {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  font-weight: 700;
  color: #d8ecff;
  line-height: 1.25;
}

.timetrial-landing-start {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  color: #f0f6fc;
}

.timetrial-landing-board {
  margin-top: 0;
  width: 100%;
}

.timetrial-back-btn {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  z-index: 12;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border: 1px solid #5a8ab8;
  border-radius: 6px;
  background: rgba(8, 12, 18, 0.88);
  color: #e8f4ff;
  cursor: pointer;
  pointer-events: auto;
}

.timetrial-back-btn:hover {
  border-color: #7eb0e0;
  background: rgba(26, 48, 72, 0.95);
}

.timetrial-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

.timetrial-replay-done-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem;
  background: #121820;
  border: 1px solid #3a5068;
  border-radius: 10px;
  pointer-events: auto;
}

.timetrial-replay-done-label {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #9fd4ff;
  text-align: center;
}

.timetrial-page main.timetrial-main {
  display: block;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: none;
}

/* Play + replay: fill the window, keep aspect ratio (cover — no stretch). */
.timetrial-page.timetrial-game-shell {
  height: 100dvh;
  overflow: hidden;
  background: #000000;
}

.timetrial-page.timetrial-game-shell main.timetrial-main,
.timetrial-page.timetrial-game-shell .timetrial-game,
.timetrial-page.timetrial-game-shell .timetrial-viewport {
  height: 100%;
  width: 100%;
}

.timetrial-page.timetrial-game-shell .timetrial-stage {
  width: 100%;
  height: 100%;
  aspect-ratio: unset;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000000;
}

.timetrial-page.timetrial-game-shell #game {
  aspect-ratio: var(--tt-aspect, 16 / 9);
  width: max(100vw, calc(100dvh * var(--tt-aspect-num, 1.777)));
  height: auto;
  max-width: none;
  flex-shrink: 0;
  image-rendering: pixelated;
  background: #0a0c10;
}

.timetrial-page .wa-panel-overlay {
  z-index: 12;
}

.timetrial-game {
  width: 100%;
  max-width: none;
}

.timetrial-landing-board .timetrial-ladder {
  max-height: none;
  width: 100%;
}

.timetrial-leaderboard {
  width: 100%;
  max-width: min(100%, 720px);
  margin: 0.85rem auto 0;
  padding: 0.85rem 1rem 1rem;
  background: #121820;
  border: 1px solid #2a3544;
  border-radius: 8px;
}

.timetrial-leaderboard h3 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
  font-weight: 600;
  color: #c5d4e3;
}

.timetrial-leaderboard .timetrial-ladder {
  max-height: none;
  width: 100%;
}

.timetrial-viewport {
  width: 100%;
  max-width: none;
}

.timetrial-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 2304 / 816;
  overflow: hidden;
}

.timetrial-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.timetrial-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.timetrial-layer[hidden] {
  display: none !important;
}

.timetrial-layer--dim {
  background: rgba(8, 12, 18, 0.55);
}

.timetrial-start-btn,
.timetrial-ok-btn,
.timetrial-again-btn {
  font: inherit;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 700;
  padding: 0.85rem 2.75rem;
  border: 3px solid #7eb0e0;
  border-radius: 10px;
  background: linear-gradient(180deg, #2a4a68 0%, #1a3048 100%);
  color: #f0f6fc;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.timetrial-start-btn:hover,
.timetrial-ok-btn:hover,
.timetrial-again-btn:hover {
  border-color: #7eb0e0;
  background: linear-gradient(180deg, #355a7d 0%, #243d58 100%);
}

.timetrial-name-form,
.timetrial-ready-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: min(90vw, 280px);
  padding: 1.25rem 1.5rem;
  background: #121820;
  border: 1px solid #3a5068;
  border-radius: 10px;
  pointer-events: auto;
}

.timetrial-player-label {
  margin: 0;
  font-size: 1.05rem;
  color: #e8edf2;
  text-align: center;
}

.timetrial-name-form label,
.timetrial-ready-form label {
  font-size: 0.95rem;
  color: #a8bccf;
}

.timetrial-name-form input {
  font: inherit;
  font-size: 1.1rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid #3a5068;
  border-radius: 6px;
  background: #0a0e14;
  color: #e8edf2;
}

.timetrial-resolution-select {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid #3a5068;
  border-radius: 6px;
  background: #0a0e14;
  color: #e8edf2;
  cursor: pointer;
}

.timetrial-replay-layer .timetrial-resolution-select {
  font-size: 0.82rem;
  padding: 0.3rem 0.45rem;
  max-width: 9.5rem;
}

.timetrial-countdown {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(3rem, 12vw, 6rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  z-index: 11;
}

.timetrial-countdown[hidden] {
  display: none !important;
}

.timetrial-timer {
  position: absolute;
  top: 0.65rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.35rem 0.85rem;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 700;
  color: #f4fbff;
  background: rgba(8, 12, 18, 0.72);
  border: 1px solid #3a5068;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 11;
}

.timetrial-timer[hidden] {
  display: none !important;
}

.timetrial-replay-layer {
  position: absolute;
  top: 0.65rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.85rem;
  background: rgba(8, 12, 18, 0.88);
  border: 1px solid #3a5068;
  border-radius: 8px;
  pointer-events: auto;
  z-index: 11;
}

.timetrial-replay-layer[hidden] {
  display: none !important;
}

.timetrial-replay-loading {
  position: absolute;
  inset: 0;
  z-index: 14;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 18, 0.82);
  pointer-events: none;
}

.timetrial-replay-loading[hidden] {
  display: none !important;
}

.timetrial-replay-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.35rem 1.75rem;
  background: #121820;
  border: 2px solid #5a8ab8;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  max-width: min(92vw, 22rem);
  text-align: center;
}

.timetrial-replay-loading-spinner {
  width: 2.75rem;
  height: 2.75rem;
  border: 4px solid #2a3544;
  border-top-color: #9fd4ff;
  border-radius: 50%;
  animation: timetrial-replay-spin 0.85s linear infinite;
}

.timetrial-replay-loading-label {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #d8ecff;
  line-height: 1.4;
}

@keyframes timetrial-replay-spin {
  to { transform: rotate(360deg); }
}

.timetrial-replay-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #d8ecff;
  white-space: nowrap;
}

.timetrial-replay-stop {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border: 1px solid #5a8ab8;
  border-radius: 6px;
  background: #1a3048;
  color: #f0f6fc;
  cursor: pointer;
}

.timetrial-replay-stop:hover {
  border-color: #7eb0e0;
  background: #243d58;
}

.timetrial-results {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1.5rem;
  background: rgba(8, 12, 18, 0.88);
  pointer-events: auto;
  overflow-y: auto;
}

.timetrial-results[hidden] {
  display: none !important;
}

.timetrial-results h2,
.timetrial-results h3 {
  margin: 0;
}

.timetrial-run-time {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #9fd4ff;
}

.timetrial-ladder {
  margin: 0;
  padding: 0;
  list-style: none;
  width: min(100%, 360px);
  max-height: 40vh;
  overflow-y: auto;
}

.timetrial-ladder li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid #2a3544;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 0.95rem;
}

.timetrial-ladder-rank {
  flex: 0 0 auto;
  color: #8fa3b8;
}

.timetrial-ladder-label {
  flex: 1 1 auto;
  min-width: 0;
}

.timetrial-watch-btn {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border: 1px solid #5a8ab8;
  border-radius: 5px;
  background: #1a3048;
  color: #e8f4ff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.35;
}

.timetrial-watch-btn:hover {
  border-color: #7eb0e0;
  background: #243d58;
}

.timetrial-ladder-you {
  background: rgba(61, 90, 128, 0.35);
  color: #d8ecff;
  font-weight: 700;
}

.timetrial-ladder-empty {
  color: #8fa3b8;
  font-style: italic;
}

.timetrial-ladder-error {
  color: #f0a8a0;
  font-style: normal;
}

.timetrial-page #game {
  border: none;
  border-radius: 0;
  outline: none;
  display: block;
  cursor: crosshair;
}

.timetrial-page #game:focus {
  outline: none;
}

.timetrial-page #game:focus-visible {
  outline: 2px solid #3d5a80;
  outline-offset: -2px;
}
