:root {
  color-scheme: dark;
  font-family:
    Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #05080c;
  color: #f3f6f8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #05080c;
}

button {
  font: inherit;
}

/* 右上角小返回按钮（TOP 50 下方）：游戏进行中想退出的唯一入口，
   位置远离拇指收势区，避免误触。 */
.corner-back {
  position: fixed;
  z-index: 10;
  top: 152px;
  right: 18px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #c5ced5;
  background: rgba(8, 15, 22, 0.8);
  border: 1px solid rgba(255, 125, 82, 0.45);
  border-radius: 50%;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.corner-back:hover {
  transform: translateY(-2px);
  border-color: #ff7d52;
  color: #ff8b61;
}

.corner-back:focus-visible {
  outline: 2px solid #ff7d52;
  outline-offset: 3px;
}

.game-shell,
.game-frame {
  width: 100%;
  height: 100%;
}

.game-frame {
  display: block;
  border: 0;
  background: #05080c;
}

.leaderboard-open {
  position: fixed;
  z-index: 10;
  top: 92px;
  right: 18px;
  width: 82px;
  padding: 10px 9px 9px;
  color: #fff;
  background: rgba(8, 15, 22, 0.84);
  border: 1px solid rgba(255, 125, 82, 0.7);
  border-radius: 7px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

.leaderboard-open:hover {
  transform: translateY(-2px);
  background: rgba(20, 29, 38, 0.94);
  border-color: #ff7d52;
}

.leaderboard-open:focus-visible,
.icon-button:focus-visible {
  outline: 2px solid #ff7d52;
  outline-offset: 3px;
}

.leaderboard-open__label,
.leaderboard-open__sub {
  display: block;
}

.leaderboard-open__label {
  color: #ff8b61;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.leaderboard-open__sub {
  margin-top: 2px;
  color: #c5ced5;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.leaderboard-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgba(1, 4, 7, 0.58);
  backdrop-filter: blur(3px);
}

.leaderboard-panel {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100%;
  padding: 28px 24px 22px;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(255, 125, 82, 0.08), transparent 180px),
    rgba(7, 14, 21, 0.97);
  border-left: 1px solid rgba(185, 199, 209, 0.16);
  box-shadow: -28px 0 60px rgba(0, 0, 0, 0.42);
  transform: translateX(102%);
  visibility: hidden;
  transition:
    transform 220ms ease,
    visibility 220ms step-end;
}

.leaderboard-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  transition:
    transform 220ms ease,
    visibility 0s;
}

.leaderboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.leaderboard-kicker {
  margin: 0 0 5px;
  color: #ff8b61;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.leaderboard-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.player-id-line {
  margin: 8px 0 0;
  color: #8b96a3;
  font-size: 12px;
}

.player-id-line b {
  color: #e8edf2;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  color: #cbd4da;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  cursor: pointer;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.leaderboard-columns,
.leaderboard-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.leaderboard-columns {
  margin-top: 24px;
  padding: 0 10px 8px;
  color: #687782;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.leaderboard-columns span:last-child {
  text-align: right;
}

.leaderboard-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  min-height: 48px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid transparent;
  border-radius: 5px;
}

.leaderboard-row:nth-child(-n + 3) {
  background: rgba(255, 125, 82, 0.075);
  border-color: rgba(255, 125, 82, 0.17);
}

.leaderboard-row.is-current {
  background: rgba(255, 139, 97, 0.16);
  border-color: #ff8b61;
  box-shadow:
    inset 3px 0 0 #ff8b61,
    0 0 0 1px rgba(255, 139, 97, 0.12),
    0 8px 24px rgba(0, 0, 0, 0.22);
  animation: leaderboard-current-focus 720ms ease-out;
}

.leaderboard-row.is-current .leaderboard-rank {
  color: #ff8b61;
}

@keyframes leaderboard-current-focus {
  from {
    background: rgba(255, 139, 97, 0.32);
    box-shadow:
      inset 3px 0 0 #ff8b61,
      0 0 0 4px rgba(255, 139, 97, 0.2),
      0 8px 24px rgba(0, 0, 0, 0.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  .leaderboard-row.is-current {
    animation: none;
  }
}

.leaderboard-rank {
  color: #83919b;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.leaderboard-row:nth-child(-n + 3) .leaderboard-rank {
  color: #ff8b61;
}

.leaderboard-driver {
  overflow: hidden;
  color: #eaf0f3;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.leaderboard-score small {
  margin-left: 2px;
  color: #89969f;
  font-size: 10px;
  font-weight: 600;
}

.leaderboard-state {
  padding: 34px 12px;
  color: #84919a;
  font-size: 13px;
  text-align: center;
}

.leaderboard-state.is-error {
  color: #ff9c7b;
}

.score-toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 28px;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  color: #071017;
  background: #ff8b61;
  border-radius: 5px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.36);
  font-size: 13px;
  font-weight: 750;
  transform: translateX(-50%);
}

@media (max-width: 720px) {
  .leaderboard-open {
    top: max(18px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    width: 72px;
    padding: 8px 7px;
  }

  .corner-back {
    top: calc(max(18px, env(safe-area-inset-top)) + 84px);
    right: max(10px, env(safe-area-inset-right));
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  .leaderboard-open__label {
    font-size: 12px;
  }

  .leaderboard-panel {
    width: 100%;
    padding:
      max(22px, env(safe-area-inset-top))
      max(18px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(18px, env(safe-area-inset-left));
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .leaderboard-open {
    top: max(8px, env(safe-area-inset-top));
    right: auto;
    left: max(8px, env(safe-area-inset-left));
    width: 60px;
    padding: 6px 5px;
  }

  .leaderboard-open__label {
    font-size: 11px;
  }

  .leaderboard-open__sub {
    font-size: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .leaderboard-open,
  .leaderboard-panel {
    transition: none;
  }
}
