:root {
  --navy: #000000;
  --panel: #070707;
  --cream: #fff7df;
  --orange: #e52521;
  --yellow: #ff3b30;
  --blue: #c81018;
  --font-site: "Poppins", "Open Sans", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: white;
  font-family: var(--font-site);
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% -10%, #310608 0, transparent 40%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.018) 0 2px, transparent 2px 8px),
    #000;
}

button { font: inherit; }

.game-shell {
  width: min(100vw, 760px);
  height: 100dvh;
  min-height: 520px;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 34px;
  background: #000;
  border-inline: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 0 70px rgba(0,0,0,.65);
}

.topbar, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 16px;
  background: var(--navy);
  letter-spacing: .09em;
}

.topbar { justify-content: flex-end; }
.top-actions { display: flex; align-items: center; gap: 7px; }

.icon-button {
  color: white;
  background: transparent;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  padding: 8px 11px;
  font: 700 11px/1 var(--font-site);
  letter-spacing: .09em;
}
.top-actions .icon-button:first-child { border-color: var(--yellow); color: var(--yellow); }

.game-wrap { position: relative; overflow: hidden; min-height: 0; }
#game { display: block; width: 100%; height: 100%; background: #181818; }

.hud {
  position: absolute;
  inset: 12px 12px auto;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0,0,0,.65);
}

.hud > div:last-child { text-align: right; }
.hud-label { display: block; font: 700 10px/1 var(--font-site); letter-spacing: .18em; color: #c5d0dd; }
.hud strong { display: block; margin-top: 4px; font-size: 28px; line-height: 1; }
#statusPill {
  display: block;
  padding: 7px 10px 6px;
  border-radius: 6px;
  background: var(--yellow);
  border: 2px solid white;
  font: 800 11px/1 var(--font-site);
  letter-spacing: .08em;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}
.overlay.show { opacity: 1; visibility: visible; }

.sign-card {
  width: min(100%, 470px);
  padding: 28px 25px 24px;
  text-align: center;
  background: rgba(0,0,0,.96);
  border: 3px solid white;
  border-radius: 12px;
  box-shadow: 0 0 0 7px var(--yellow), 0 16px 50px rgba(0,0,0,.5);
}
.game-logo { display: block; width: 100%; height: auto; margin: 0 auto 10px; border-radius: 6px; }
.sign-kicker {
  color: var(--yellow);
  font: 800 12px/1.2 var(--font-site);
  letter-spacing: .2em;
}
.sign-card h1 { margin: 12px 0 10px; font-size: clamp(64px, 14vw, 98px); font-weight: 900; line-height: .78; letter-spacing: -.045em; font-style: italic; }
.sign-card h1 span { color: var(--orange); font-size: 1.25em; }
.sign-card h2 { margin: 15px 0 10px; font-size: clamp(32px, 8vw, 52px); font-weight: 900; line-height: .95; }
.sign-card p { margin: 16px 0 20px; color: #d8e1ec; font: 700 16px/1.45 var(--font-site); }
.sign-card small { display: block; margin-top: 15px; color: #94a4b8; font: 700 11px/1.2 var(--font-site); letter-spacing: .08em; }

.level-track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 0 0 18px; }
.level-track > div { padding: 9px 4px; border: 1px solid rgba(255,255,255,.22); border-radius: 7px; background: rgba(255,255,255,.05); opacity: .58; }
.level-track > div.active { border-color: var(--yellow); background: rgba(255,59,48,.15); opacity: 1; }
.level-track span, .level-track small { display: block; font: 800 9px/1.15 var(--font-site); letter-spacing: .08em; color: #9cacc0; }
.level-track strong { display: block; margin: 4px 0; font-size: 22px; color: white; }
.level-track > div.active span, .level-track > div.active small { color: var(--yellow); }

.start-button {
  width: min(100%, 280px);
  min-height: 54px;
  padding: 13px 18px;
  border: 0;
  border-radius: 7px;
  background: var(--orange);
  color: white;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), 0 8px 20px rgba(229,37,33,.3);
  font-size: 22px;
  letter-spacing: .04em;
  cursor: pointer;
}
.start-button:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.start-button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.results { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.results div { padding: 12px; border-radius: 8px; background: rgba(255,255,255,.07); }
.results span { display: block; color: #9cacc0; font: 700 10px/1 var(--font-site); letter-spacing: .12em; }
.results strong { display: block; margin-top: 7px; font-size: 31px; }

.arrival-card {
  width: min(100%, 570px);
  overflow: hidden;
  text-align: center;
  background: rgba(0,0,0,.98);
  border: 3px solid white;
  border-radius: 14px;
  box-shadow: 0 0 0 7px var(--yellow), 0 16px 50px rgba(0,0,0,.55);
}
.arrival-card img { display: block; width: 100%; aspect-ratio: 16 / 8.4; object-fit: cover; }
.arrival-content { padding: 20px 24px 23px; }
.arrival-content h2 { margin: 8px 0; color: white; font-size: clamp(37px, 9vw, 60px); line-height: .95; }
.arrival-content p { margin: 10px 0 17px; color: #d8e1ec; font: 700 15px/1.4 var(--font-site); }
.arrival-score { margin: 8px auto 14px; }
.arrival-score span { display: block; color: #9cacc0; font: 800 10px/1 var(--font-site); letter-spacing: .14em; }
.arrival-score strong { display: block; margin-top: 3px; color: var(--yellow); font-size: 40px; }

.score-form { margin: 0 auto 13px; max-width: 360px; }
.score-form label { display: block; margin-bottom: 7px; color: #aebdce; font: 800 10px/1 var(--font-site); letter-spacing: .11em; text-align: left; }
.score-form > div { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.score-form input {
  min-width: 0;
  height: 45px;
  padding: 0 12px;
  border: 2px solid rgba(255,255,255,.4);
  border-radius: 7px;
  outline: none;
  background: white;
  color: var(--navy);
  font: 800 16px/1 var(--font-site);
}
.score-form input:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255,59,48,.22); }
.score-form button {
  min-width: 88px;
  border: 0;
  border-radius: 7px;
  background: var(--orange);
  color: white;
  font-size: 16px;
  cursor: pointer;
}
.score-form button:disabled { opacity: .55; cursor: wait; }
.score-status { min-height: 16px; margin: 6px 0 0; color: var(--yellow); font-size: 12px; text-align: left; }
.arrival-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 360px; margin: 0 auto; }
.secondary-button {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 7px;
  background: rgba(255,255,255,.08);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

.leaderboard-card {
  width: min(100%, 480px);
  max-height: calc(100dvh - 50px);
  overflow: auto;
  padding: 23px;
  background: rgba(0,0,0,.98);
  border: 3px solid white;
  border-radius: 14px;
  box-shadow: 0 0 0 7px var(--yellow), 0 16px 50px rgba(0,0,0,.55);
}
.leaderboard-head { display: flex; align-items: start; justify-content: space-between; }
.leaderboard-head h2 { margin: 5px 0 12px; font-size: 46px; line-height: .9; }
.leaderboard-head > button { width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.4); border-radius: 50%; background: transparent; color: white; font: 29px/30px var(--font-site); cursor: pointer; }
.leaderboard-list { min-height: 230px; margin-bottom: 17px; }
.leaderboard-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 9px; min-height: 42px; padding: 7px 9px; border-bottom: 1px solid rgba(255,255,255,.11); font-family: var(--font-site); }
.leaderboard-row:first-child { color: var(--yellow); background: rgba(255,59,48,.1); border-radius: 7px 7px 0 0; }
.leaderboard-rank { font-weight: 900; font-size: 18px; }
.leaderboard-name { min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-service { display: block; margin-top: 2px; color: #8fa1b6; font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.leaderboard-score { font-weight: 900; font-size: 21px; }
.leaderboard-state { padding: 60px 10px; color: #aebdce; font: 700 14px/1.4 var(--font-site); text-align: center; }
.leaderboard-card > .start-button { display: block; margin: 0 auto; }

.road-message {
  position: absolute;
  z-index: 4;
  top: 68px;
  left: 50%;
  transform: translate(-50%, -10px);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 9px 13px;
  border-radius: 6px;
  background: rgba(0,0,0,.94);
  border: 1px solid rgba(255,255,255,.45);
  color: var(--yellow);
  font: 800 13px/1.2 var(--font-site);
  letter-spacing: .045em;
  text-align: center;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.road-message.show { opacity: 1; transform: translate(-50%, 0); }

.mobile-controls {
  position: absolute;
  z-index: 4;
  inset: auto 16px 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.mobile-controls button {
  pointer-events: auto;
  width: 72px;
  height: 64px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.55);
  background: rgba(0,0,0,.62);
  color: white;
  font: 56px/44px var(--font-site);
  backdrop-filter: blur(3px);
}
.mobile-controls button:active { background: rgba(229,37,33,.88); }

footer { color: #7f90a4; font: 700 9px/1 var(--font-site); }
footer span:last-child { color: var(--yellow); }

@media (min-width: 800px) {
  .game-shell { height: min(94vh, 900px); border-radius: 18px; overflow: hidden; }
  .mobile-controls { opacity: .65; }
}

@media (max-height: 640px) {
  .game-shell { grid-template-rows: 48px minmax(0, 1fr) 26px; }
  .sign-card { padding-block: 18px; }
  .sign-card h1 { font-size: 62px; }
  .sign-card p { margin-block: 10px 14px; font-size: 14px; }
  .level-track { margin-bottom: 11px; }
  .level-track > div { padding-block: 6px; }
  .arrival-card img { aspect-ratio: 16 / 6; }
  .arrival-content { padding-block: 13px; }
  .arrival-content p { display: none; }
  .arrival-score { margin-block: 5px 8px; }
  .score-form { margin-bottom: 7px; }
  .mobile-controls button { width: 62px; height: 52px; }
}

@media (max-width: 480px) {
  #startScreen { place-items: start center; padding-top: 24px; }
  .sound-button { width: 41px; overflow: hidden; white-space: nowrap; color: transparent; position: relative; }
  .sound-button::after { content: '♪'; position: absolute; inset: 0; display: grid; place-items: center; color: white; font-size: 17px; }
  .leaderboard-card { padding: 19px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay, .road-message { transition: none; }
}
