.game-root,
.game-root * {
  box-sizing: border-box;
}

.game-root {
  --race-cursor-default: url("/static/img/cursors/cursor_cat.54234ab9b215.png") 0 0, auto;
  --race-cursor-action: url("/static/img/cursors/cursor_hand.7271d4ef0443.png") 12 4, pointer;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #e8e5dc;
  color: #26313f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: var(--race-cursor-default);
}

.race-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #e8e5dc;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.race-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  cursor: var(--race-cursor-default);
}

.race-collection {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  width: min(62vw, 650px);
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid rgba(255, 255, 255, 0.84);
  border-radius: 12px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 28px rgba(37, 48, 62, 0.17);
  backdrop-filter: blur(8px);
  transform: translateX(-50%);
  pointer-events: none;
}

.race-score {
  min-width: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #26313f;
  font-size: clamp(17px, 2.2vw, 25px);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.race-score-star {
  margin-right: 3px;
  color: #e4aa18;
  font-size: 1.15em;
  text-shadow: 0 1px 0 #fff5ad;
}

.race-collected {
  min-width: 0;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(10, minmax(20px, 1fr));
  gap: 4px;
}

.race-collected-slot {
  aspect-ratio: 1;
  min-width: 20px;
  max-width: 44px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid rgba(127, 138, 145, 0.3);
  border-radius: 8px;
  background: rgba(244, 239, 225, 0.82);
  color: #69528e;
  font-size: 14px;
  font-weight: 900;
}

.race-collected-slot.is-collected {
  border-color: rgba(237, 184, 45, 0.78);
  background: #fffdf6;
  box-shadow: 0 4px 10px rgba(50, 57, 63, 0.14);
}

.race-collected-slot img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  padding: 2px;
}

.race-status {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 4;
  max-width: min(54vw, 520px);
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 10px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.84);
  color: #45515d;
  box-shadow: 0 10px 24px rgba(37, 48, 62, 0.14);
  font-size: clamp(12px, 1.5vw, 16px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.race-sounds {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 12px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 28px rgba(37, 48, 62, 0.18);
  backdrop-filter: blur(8px);
}

.race-sounds-label {
  padding: 0 3px;
  color: #4e5c68;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.race-sound {
  min-width: 42px;
  min-height: 42px;
  border: 2px solid #ffffff;
  border-radius: 9px;
  padding: 0 10px;
  background: #d9e2ea;
  color: #334450;
  font-size: 19px;
  font-weight: 900;
  box-shadow: 0 5px 12px rgba(39, 59, 72, 0.14);
  cursor: var(--race-cursor-action);
}

.race-sound[aria-pressed="true"] {
  background: #f2b93d;
  color: #26313f;
  box-shadow: 0 6px 14px rgba(192, 132, 13, 0.25);
}

.race-sound:disabled {
  opacity: 0.65;
  cursor: var(--race-cursor-default);
}

.race-controls {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 5;
  display: grid;
  gap: 8px;
  pointer-events: auto;
}

.race-shell.is-portrait .race-controls {
  grid-template-columns: repeat(2, auto);
}

.race-shell.is-finale .race-controls {
  opacity: 0;
  pointer-events: none;
}

.race-control {
  width: clamp(54px, 7vw, 68px);
  height: clamp(54px, 7vw, 68px);
  border: 3px solid rgba(255, 255, 255, 0.94);
  border-radius: 12px;
  background: rgba(49, 104, 175, 0.94);
  color: #ffffff;
  box-shadow: 0 12px 25px rgba(31, 58, 89, 0.24);
  font-size: clamp(27px, 4.5vw, 37px);
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  cursor: var(--race-cursor-action);
}

.race-control:active {
  background: #28578f;
  transform: translateY(1px);
}

.race-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(38, 49, 63, 0.38);
  backdrop-filter: blur(5px);
}

.race-overlay[hidden] {
  display: none;
}

.race-card {
  width: min(100%, 540px);
  max-height: calc(100% - 12px);
  overflow: auto;
  border: 3px solid #ffffff;
  border-radius: 18px;
  padding: clamp(24px, 4vw, 42px);
  background: #fffdf7;
  text-align: center;
  box-shadow: 0 24px 60px rgba(28, 38, 49, 0.28);
  cursor: var(--race-cursor-default);
}

.race-kicker {
  margin: 0 0 7px;
  color: #28715f;
  font-size: clamp(11px, 1.4vw, 13px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.race-card h2 {
  margin: 0;
  color: #26313f;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.03;
}

.race-card p:not(.race-kicker) {
  margin: 14px auto 0;
  max-width: 440px;
  color: #56646f;
  font-size: clamp(15px, 1.9vw, 18px);
  font-weight: 700;
  line-height: 1.45;
}

.race-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.race-button,
.race-link {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 0 20px;
  background: #3168af;
  color: #ffffff;
  text-decoration: none;
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(49, 104, 175, 0.25);
  cursor: var(--race-cursor-action);
}

.race-link {
  background: #e57e58;
  box-shadow: 0 12px 24px rgba(192, 94, 58, 0.2);
}

.race-error {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #e8e5dc;
  color: #9f2e24;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

@media (max-width: 900px) and (orientation: portrait) {
  .race-collection {
    top: max(62px, calc(env(safe-area-inset-top) + 58px));
    width: calc(100% - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right)));
  }

  .race-status {
    bottom: max(82px, calc(env(safe-area-inset-bottom) + 76px));
    max-width: calc(100% - 32px);
  }

  .race-sounds {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .race-controls {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 520px) {
  .race-shell.is-portrait .race-status {
    display: none;
  }

  .race-collection {
    min-height: 42px;
    gap: 4px;
    border-radius: 10px;
    padding: 5px;
  }

  .race-score {
    min-width: 52px;
    font-size: 16px;
  }

  .race-collected {
    gap: 2px;
  }

  .race-collected-slot {
    min-width: 18px;
    border-width: 1px;
    border-radius: 5px;
  }

  .race-sounds-label {
    display: none;
  }

  .race-sound {
    min-width: 40px;
    min-height: 44px;
  }

  .race-control {
    width: 52px;
    height: 52px;
  }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 620px) {
  .race-collection {
    top: max(7px, env(safe-area-inset-top));
    width: min(58vw, 570px);
    min-height: 40px;
    padding: 4px 7px;
  }

  .race-score {
    min-width: 58px;
    font-size: 16px;
  }

  .race-collected {
    gap: 3px;
  }

  .race-collected-slot {
    min-width: 20px;
    max-width: 34px;
    border-radius: 6px;
  }

  .race-status {
    bottom: max(9px, env(safe-area-inset-bottom));
    max-width: 42vw;
    padding: 5px 9px;
    font-size: 12px;
  }

  .race-sounds {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 4px;
  }

  .race-sound {
    min-width: 38px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 17px;
  }

  .race-controls {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 5px;
  }

  .race-control {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    font-size: 25px;
  }

  .race-overlay {
    padding: 10px max(70px, calc(env(safe-area-inset-left) + 58px));
  }

  .race-card {
    width: min(100%, 590px);
    padding: 14px 22px;
  }

  .race-card h2 {
    font-size: clamp(25px, 7vh, 36px);
  }

  .race-card p:not(.race-kicker) {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.32;
  }

  .race-actions {
    margin-top: 12px;
  }

  .race-button,
  .race-link {
    min-height: 42px;
  }
}

@media (orientation: landscape) and (max-width: 950px) and (max-height: 500px) {
  .race-collection {
    width: min(55vw, 500px);
  }

  .race-collected-slot {
    max-width: 30px;
  }

  .race-status {
    max-width: 38vw;
  }
}

@media (prefers-reduced-motion: reduce) {
  .race-control:active {
    transform: none;
  }
}
