:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --pink: #ff3c8d;
  --cyan: #31e7ff;
  --amber: #ffd36a;
  --ink: #130816;
  --panel: rgba(13, 9, 32, 0.72);
  --panel-strong: rgba(10, 7, 24, 0.9);
  --white: #fffaf0;
}

* {
  box-sizing: border-box;
}

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

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  isolation: isolate;
}

.site-back {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 10px;
  color: var(--white);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04)),
    rgba(10, 7, 24, 0.76);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  font-size: 0.78rem;
  font-weight: 1000;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
}

.site-back:hover {
  border-color: rgba(49, 231, 255, 0.72);
  box-shadow: 0 0 22px rgba(49, 231, 255, 0.28);
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #0c1537;
  image-rendering: pixelated;
}

.hud {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: min(880px, calc(100vw - 260px));
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

body.is-playing .hud {
  opacity: 1;
}

.hud__meter--wide {
  grid-column: span 2;
}

.hud__meter {
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04)),
    var(--panel);
  box-shadow:
    0 10px 36px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.hud__meter span {
  display: block;
  color: var(--cyan);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hud__meter strong {
  display: block;
  overflow: hidden;
  color: var(--white);
  font-size: clamp(0.82rem, 2.05vh, 1.36rem);
  font-weight: 900;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* time pulse warning */
.hud__meter--warn strong {
  color: #ff5b7a;
  animation: warnPulse 0.7s ease-in-out infinite;
}

@keyframes warnPulse {
  50% {
    opacity: 0.45;
    text-shadow: 0 0 14px rgba(255, 60, 90, 0.9);
  }
}

.sys {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 8;
  display: flex;
  gap: 8px;
}

.sys__btn {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04)),
    var(--panel);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--white);
  font-weight: 900;
  font-size: 0.92rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.sys__btn.is-off {
  color: rgba(255, 250, 240, 0.4);
  border-color: rgba(255, 255, 255, 0.12);
}

.sys__btn:active {
  transform: scale(0.92);
}

.menu {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 24%, rgba(255, 211, 106, 0.26), transparent 36%),
    linear-gradient(180deg, rgba(6, 8, 35, 0.46), rgba(7, 2, 18, 0.9));
}

.menu.is-open {
  display: flex;
}

.menu__plate {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(20px, 4vw, 42px);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 60, 141, 0.2), rgba(49, 231, 255, 0.12)),
    var(--panel-strong);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 24px;
  color: var(--white);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(3.2rem, 11vw, 7.4rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 0.86;
  text-shadow:
    0 4px 0 #521c70,
    0 9px 0 #041b32,
    0 0 32px rgba(255, 60, 141, 0.65);
  text-transform: uppercase;
}

.radio {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.radio__station,
.start-button,
.fork button,
.touch button {
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 10px 24px rgba(0, 0, 0, 0.28);
  transition: transform 90ms ease;
}

.radio__station {
  padding: 12px 10px;
  text-align: left;
}

.radio__station span,
.radio__station small {
  display: block;
}

.radio__station span {
  color: var(--white);
  font-weight: 900;
}

.radio__station small {
  color: rgba(255, 250, 240, 0.72);
  font-size: 0.78rem;
}

.radio__station.is-active {
  border-color: rgba(49, 231, 255, 0.75);
  background:
    linear-gradient(135deg, rgba(49, 231, 255, 0.28), rgba(255, 60, 141, 0.18)),
    rgba(255, 255, 255, 0.09);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 0 22px rgba(49, 231, 255, 0.35);
}

.radio__station:active {
  transform: scale(0.97);
}

.start-button {
  width: min(340px, 100%);
  margin-top: 4px;
  background:
    linear-gradient(180deg, #ffef8f, #ff9138 54%, #db245a),
    var(--amber);
  color: #260612;
  font-weight: 1000;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.start-button--ghost {
  margin-left: auto;
  margin-right: auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05)),
    rgba(10, 7, 24, 0.72);
  color: var(--white);
  border-color: rgba(49, 231, 255, 0.42);
}

.start-button:active {
  transform: scale(0.97);
}

.result-plate,
.rankings-plate {
  width: min(720px, calc(100vw - 32px));
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}

.result-stats div,
.score-entry,
.ranking-table {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
}

.result-stats div {
  padding: 12px 10px;
}

.result-stats span,
.score-entry label {
  display: block;
  color: var(--cyan);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-stats strong {
  display: block;
  overflow: hidden;
  margin-top: 5px;
  color: var(--white);
  font-size: clamp(1rem, 2.8vw, 1.55rem);
  font-weight: 1000;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-entry {
  padding: 14px;
  margin-bottom: 16px;
}

.score-entry > div,
.result-actions,
.ranking-tabs {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.score-entry input {
  flex: 1 1 180px;
  min-height: 46px;
  min-width: 0;
  border: 1px solid rgba(49, 231, 255, 0.38);
  border-radius: 10px;
  background: rgba(6, 8, 35, 0.55);
  color: var(--white);
  padding: 0 14px;
  font: 1000 1rem Inter, system-ui, sans-serif;
  text-transform: uppercase;
}

.score-entry .start-button,
.result-actions .start-button,
.ranking-tabs button,
#rankings-back {
  width: auto;
  min-width: 132px;
}

#score-status {
  min-height: 18px;
  margin: 9px 0 0;
  color: rgba(255, 250, 240, 0.66);
  font-size: 0.8rem;
  font-weight: 800;
}

.ranking-tabs {
  margin: 0 0 14px;
}

.ranking-tabs button {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--white);
  font-weight: 1000;
  text-transform: uppercase;
}

.ranking-tabs button.is-active {
  border-color: rgba(49, 231, 255, 0.75);
  color: #fff8d6;
  box-shadow: 0 0 22px rgba(49, 231, 255, 0.24);
}

.ranking-table {
  width: 100%;
  margin-bottom: 16px;
  border-collapse: collapse;
  overflow: hidden;
  color: var(--white);
  text-align: left;
}

.ranking-table th,
.ranking-table td {
  padding: 10px 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.ranking-table th {
  color: var(--amber);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ranking-table td:nth-child(3) {
  color: var(--white);
  font-weight: 1000;
}

.hint {
  margin: 16px 0 0;
  color: rgba(255, 250, 240, 0.55);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.fork {
  position: absolute;
  left: 50%;
  bottom: 26%;
  z-index: 6;
  display: none;
  grid-template-columns: 110px minmax(120px, 280px) 110px;
  gap: 10px;
  align-items: center;
  transform: translateX(-50%);
  color: var(--white);
  text-align: center;
  pointer-events: auto;
}

.fork.is-open {
  display: grid;
}

.fork button {
  min-height: 64px;
  font-weight: 900;
  font-size: 1.05rem;
}

.fork button:active {
  transform: scale(0.96);
}

.fork div {
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: var(--panel-strong);
}

.fork p {
  margin: 0;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fork strong {
  display: block;
  overflow-wrap: anywhere;
}

.toast {
  position: absolute;
  left: 50%;
  top: 16%;
  z-index: 6;
  min-width: min(360px, calc(100vw - 36px));
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(10, 7, 24, 0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--white);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
  opacity: 0;
  transform: translate(-50%, -12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
}

.toast.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Touch controls ===== */
.touch {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: none;
  pointer-events: none;
}

.touch__cluster {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
  pointer-events: auto;
}

.touch__cluster--steer {
  left: max(16px, env(safe-area-inset-left));
}

.touch__cluster--drive {
  right: max(16px, env(safe-area-inset-right));
}

.touch button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(64px, 17vw, 92px);
  height: clamp(64px, 17vw, 92px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.04) 60%),
    rgba(10, 7, 24, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: var(--white);
  font-weight: 1000;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  letter-spacing: 0.02em;
}

.touch button:active,
.touch button.is-down {
  transform: scale(0.92);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 0 26px rgba(49, 231, 255, 0.55);
}

.touch--gas {
  border-color: rgba(85, 239, 143, 0.6) !important;
  background:
    radial-gradient(circle at 50% 32%, rgba(85, 239, 143, 0.4), rgba(85, 239, 143, 0.05) 62%),
    rgba(10, 7, 24, 0.62) !important;
}

.touch--brake {
  border-color: rgba(255, 91, 122, 0.6) !important;
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 91, 122, 0.4), rgba(255, 91, 122, 0.05) 62%),
    rgba(10, 7, 24, 0.62) !important;
  font-size: clamp(0.9rem, 3.2vw, 1.2rem);
}

.touch--gas {
  font-size: clamp(0.95rem, 3.4vw, 1.25rem);
}

.touch--boost {
  border-color: rgba(255, 211, 106, 0.72) !important;
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 211, 106, 0.42), rgba(255, 60, 141, 0.12) 62%),
    rgba(10, 7, 24, 0.62) !important;
  color: #fff8d6;
  font-size: clamp(0.82rem, 2.8vw, 1rem);
}

/* show touch controls on coarse pointers / touch screens */
body.is-touch .touch {
  display: block;
}

@media (max-width: 720px) {
  .touch {
    display: block;
  }
}

.crt {
  position: absolute;
  inset: 0;
  z-index: 12;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 50%, rgba(0, 0, 0, 0.09) 50%),
    radial-gradient(circle at center, transparent 50%, rgba(0, 0, 0, 0.42) 100%);
  background-size:
    100% 4px,
    100% 100%;
  mix-blend-mode: soft-light;
  pointer-events: none;
}

@media (max-width: 720px) {
  .site-back {
    min-height: 36px;
    padding: 8px 11px;
    font-size: 0.7rem;
  }

  .menu {
    align-items: flex-start;
    padding-top: max(72px, calc(62px + env(safe-area-inset-top)));
  }

  .menu__plate {
    max-height: calc(100dvh - 88px);
  }

  h1 {
    font-size: clamp(2.55rem, 14vw, 4rem);
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: calc(100vw - 20px);
    top: max(60px, calc(50px + env(safe-area-inset-top)));
    gap: 6px;
  }

  .hud__meter {
    padding: 5px 7px;
  }

  .hud__meter span {
    font-size: 0.54rem;
  }

  .hud__meter strong {
    font-size: 0.84rem;
  }

  .hud__meter--wide {
    grid-column: span 3;
  }

  .radio {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ranking-table {
    font-size: 0.8rem;
  }

  .ranking-table th:nth-child(5),
  .ranking-table td:nth-child(5) {
    display: none;
  }

  .radio__station {
    min-height: 58px;
    padding: 9px 10px;
  }

  .radio__station span {
    font-size: 0.88rem;
  }

  .radio__station small {
    font-size: 0.68rem;
  }

  .fork {
    grid-template-columns: 84px minmax(120px, 1fr) 84px;
    width: calc(100vw - 22px);
    bottom: 30%;
  }

  .touch__cluster {
    gap: 8px;
  }

  .touch__cluster--drive {
    flex-direction: column-reverse;
  }
}

/* short landscape phones: keep HUD on one row, clear of clusters */
@media (max-height: 480px) and (orientation: landscape) {
  .hud {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: min(780px, calc(100vw - 220px));
  }

  .hud__meter--wide { display: none; }

  .hud__meter {
    padding: 5px 8px;
  }

  .touch button {
    width: clamp(58px, 13vh, 80px);
    height: clamp(58px, 13vh, 80px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
  .hud__meter--warn strong {
    animation: none;
  }
}
