:root {
  color-scheme: dark;
  --bg: #070912;
  --panel: #111725;
  --panel-2: #151827;
  --line: #31415c;
  --line-soft: rgba(255, 255, 255, 0.11);
  --text: #edf4ff;
  --muted: #96a6bd;
  --cyan: #25d9ff;
  --gold: #ffd24a;
  --pink: #ff4fb6;
  --green: #57f287;
  --red: #ff6b5f;
  --violet: #9c88ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(37, 217, 255, 0.1), transparent 38%),
    radial-gradient(circle at 18% 74%, rgba(255, 79, 182, 0.08), transparent 30%),
    linear-gradient(180deg, #080912 0%, #0d0b17 44%, #06070c 100%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(238px, 24vw, 300px);
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100svh;
  min-width: 320px;
  background:
    linear-gradient(135deg, rgba(37, 217, 255, 0.045), transparent 38%),
    linear-gradient(315deg, rgba(255, 79, 182, 0.04), transparent 42%);
}

.hud {
  z-index: 2;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(148px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px clamp(10px, 2.6vw, 26px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(9, 10, 18, 0.88);
  backdrop-filter: blur(16px);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.18);
}

.brand,
.stats,
.actions {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand {
  gap: 10px;
  color: var(--text);
  font-size: clamp(0.88rem, 1.5vw, 1rem);
  font-weight: 850;
  text-shadow: 0 0 14px rgba(37, 217, 255, 0.2);
  white-space: nowrap;
}

.brand strong {
  color: var(--gold);
  font-size: 0.78em;
  letter-spacing: 0;
  text-transform: uppercase;
}

.mark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--gold);
  background: linear-gradient(135deg, #ffe66d, #ff9e44 54%, #ff4fb6);
  border-radius: 2px;
  box-shadow: 0 0 18px rgba(255, 210, 74, 0.46);
}

.stats {
  justify-content: end;
  gap: 7px;
  color: var(--muted);
  font-size: clamp(0.68rem, 1.3vw, 0.9rem);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}

.stats span,
.speed-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  max-width: 100%;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(17, 21, 32, 0.78);
  box-shadow: inset 0 0 16px rgba(37, 217, 255, 0.035);
  white-space: nowrap;
}

#score,
#best-score,
#level-record {
  color: var(--gold);
}

#level-record {
  color: var(--cyan);
}

.lives {
  color: var(--red);
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(255, 107, 95, 0.68);
}

.stats span.unlocked {
  color: #05120a;
  border-color: rgba(87, 242, 135, 0.65);
  background: var(--green);
}

.speed-control {
  gap: 7px;
}

.speed-control strong {
  color: var(--gold);
  font-weight: 850;
}

.speed-control input {
  width: 74px;
  accent-color: var(--gold);
  cursor: pointer;
}

.actions {
  justify-content: end;
  gap: 8px;
}

.icon-button,
.primary,
.touch-pad button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: rgba(17, 21, 32, 0.96);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
  min-width: 38px;
  font-weight: 850;
}

.icon-button.is-muted {
  color: var(--muted);
  border-color: rgba(255, 107, 95, 0.45);
}

.icon-button:hover,
.primary:hover,
.touch-pad button:hover {
  border-color: rgba(37, 217, 255, 0.72);
  box-shadow: 0 0 0 3px rgba(37, 217, 255, 0.12);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
}

.touch-pad {
  position: absolute;
  right: clamp(12px, 3vw, 26px);
  bottom: clamp(12px, 3vw, 26px);
  display: grid;
  grid-template-areas:
    ". up ."
    "left down right";
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(2, 48px);
  gap: 8px;
  opacity: 0.78;
  user-select: none;
}

.touch-pad button {
  width: 48px;
  height: 48px;
  color: #061018;
  border-color: rgba(255, 210, 74, 0.58);
  background: rgba(255, 210, 74, 0.9);
  font-size: 1.05rem;
  font-weight: 950;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.34);
}

.touch-pad button[data-dir="up"] {
  grid-area: up;
}

.touch-pad button[data-dir="left"] {
  grid-area: left;
}

.touch-pad button[data-dir="down"] {
  grid-area: down;
}

.touch-pad button[data-dir="right"] {
  grid-area: right;
}

.arcade-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  border-left: 1px solid var(--line-soft);
  background:
    linear-gradient(180deg, rgba(23, 20, 36, 0.94), rgba(7, 10, 16, 0.94)),
    var(--panel-2);
  overflow: auto;
}

.score-box {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(17, 21, 32, 0.76);
  box-shadow: inset 0 0 22px rgba(37, 217, 255, 0.04);
}

.score-box h2 {
  margin: 0;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 210, 74, 0.24);
  font-size: 0.78rem;
  letter-spacing: 0;
}

#top-scores,
#level-records {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}

#top-scores li,
#level-records li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: rgba(5, 7, 13, 0.5);
  color: var(--muted);
  font-size: 0.8rem;
}

#top-scores strong,
#level-records strong {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#top-scores b,
#level-records b {
  color: var(--gold);
  font-weight: 850;
}

#level-records li {
  grid-template-columns: 32px 1fr auto;
}

#level-records b {
  color: var(--cyan);
}

.shape-box {
  color: var(--muted);
  font-size: 0.82rem;
}

.shape-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.shape {
  display: inline-block;
  width: 17px;
  height: 17px;
  background: var(--violet);
  box-shadow: 0 0 14px rgba(156, 136, 255, 0.56);
}

.shape.circle {
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 14px rgba(37, 217, 255, 0.56);
}

.shape.triangle {
  width: 0;
  height: 0;
  border-right: 9px solid transparent;
  border-bottom: 17px solid var(--pink);
  border-left: 9px solid transparent;
  background: transparent;
  box-shadow: none;
}

.shape.player-dot {
  background: var(--gold);
  box-shadow: 0 0 14px rgba(255, 210, 74, 0.6);
}

.shape.triangle.player-dot {
  border-bottom-color: var(--gold);
  background: transparent;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(5, 7, 13, 0.76);
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.level-transition {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(37, 217, 255, 0.16), transparent 34%),
    rgba(5, 7, 13, 0.5);
  animation: transition-fade 920ms ease both;
}

.level-transition[hidden] {
  display: none;
}

.level-transition div {
  display: grid;
  gap: 8px;
  text-align: center;
  text-transform: uppercase;
  filter: drop-shadow(0 0 22px rgba(37, 217, 255, 0.4));
}

.level-transition h1,
.level-transition p {
  margin: 0;
}

.level-transition h1 {
  color: var(--gold);
  font-size: clamp(2rem, 8vw, 5rem);
  line-height: 0.92;
}

.level-transition p {
  color: var(--cyan);
  font-weight: 850;
}

@keyframes transition-fade {
  0% {
    opacity: 0;
    transform: scale(0.96);
  }
  18%,
  76% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.03);
  }
}

.result {
  display: grid;
  gap: 13px;
  width: min(390px, 100%);
  padding: 24px;
  border: 1px solid rgba(87, 242, 135, 0.48);
  border-radius: 8px;
  background: rgba(17, 21, 32, 0.97);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.46), 0 0 32px rgba(37, 217, 255, 0.12);
  text-align: center;
}

.result h1,
.result p {
  margin: 0;
}

.result h1 {
  font-size: clamp(1.38rem, 5vw, 2rem);
  line-height: 1.08;
}

.result p {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.score-entry {
  display: grid;
  gap: 8px;
  margin: 0;
}

.score-entry[hidden] {
  display: none;
}

.score-entry label {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 850;
}

.score-entry div {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

.score-entry input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #070b12;
  color: var(--text);
  text-align: center;
  text-transform: uppercase;
  font-weight: 950;
  letter-spacing: 0;
}

.primary {
  min-height: 42px;
  padding: 0 16px;
  color: #06130a;
  border-color: transparent;
  background: var(--green);
  font-weight: 850;
}

@media (max-width: 980px) {
  .game-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .arcade-panel {
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: minmax(0, 1.2fr) minmax(190px, 0.8fr);
    padding: 10px;
    border-top: 1px solid var(--line-soft);
    border-left: 0;
    max-height: 28svh;
  }
}

@media (max-width: 720px) {
  .hud {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .stats {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: stretch;
    gap: 6px;
  }

  .stats span,
  .speed-control {
    flex: 1 1 30%;
    min-width: 0;
    padding: 0 6px;
    font-size: 0.68rem;
  }

  .speed-control {
    gap: 5px;
  }

  .speed-control input {
    width: min(70px, 22vw);
  }

  .touch-pad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(2, 44px);
    gap: 7px;
  }

  .touch-pad button {
    width: 44px;
    height: 44px;
  }

  .arcade-panel {
    grid-template-columns: 1fr;
    max-height: 30svh;
  }

  .shape-box {
    display: none;
  }
}

@media (max-width: 440px) {
  .brand {
    font-size: 0.82rem;
  }

  .mark {
    width: 16px;
    height: 16px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .touch-pad {
    right: 10px;
    bottom: 10px;
  }
}
