:root {
  color-scheme: dark;
  --bg: #03050d;
  --panel: rgba(8, 16, 20, 0.82);
  --text: #f4fbff;
  --muted: #a8bac2;
  --cyan: #35e1ff;
  --lime: #fff17a;
  --rose: #ff6b23;
  --amber: #ffcc42;
  --control-height: clamp(36px, 7vh, 48px);
  --control-x: clamp(12px, 3vw, 22px);
  --control-font: clamp(12px, 2.2vh, 15px);
  --compact-height: clamp(32px, 7vh, 42px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 18%, rgba(53, 225, 255, 0.18), transparent 28%),
    radial-gradient(circle at 78% 68%, rgba(255, 107, 35, 0.16), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

button {
  position: relative;
  border: 0;
  border-radius: 8px;
  color: #051014;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  overflow: hidden;
  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0%, rgba(255, 255, 255, 0.28) 45%, transparent 70%);
  opacity: 0;
  transform: translateX(-120%);
  transition:
    opacity 160ms ease,
    transform 260ms ease;
  pointer-events: none;
}

button::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.34);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
}

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

button:active::after {
  opacity: 1;
  transform: translateX(120%);
}

button.button-pop {
  animation: buttonPop 260ms cubic-bezier(0.2, 1.25, 0.36, 1);
}

button.button-pop::after {
  opacity: 1;
  animation: buttonSweep 320ms ease-out;
}

button.button-pop::before {
  animation: buttonRipple 360ms ease-out;
}

button:focus-visible {
  outline: 2px solid rgba(255, 241, 122, 0.9);
  outline-offset: 3px;
}

@keyframes buttonPop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(0.92);
  }
  70% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes buttonSweep {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(120%);
  }
}

@keyframes buttonRipple {
  0% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(14);
  }
}

.shell {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  padding: 0;
}

.game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #03050d;
  box-shadow: none;
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud.hidden {
  display: none;
}

.hud > div {
  min-width: 76px;
  padding: 6px 8px;
  border: 1px solid rgba(244, 251, 255, 0.16);
  border-radius: 8px;
  background: rgba(7, 16, 20, 0.64);
  backdrop-filter: blur(10px);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.hud strong {
  font-size: 20px;
  line-height: 1;
}

#pauseBtn {
  margin-left: auto;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(53, 225, 255, 0.42);
  background: rgba(5, 16, 22, 0.78);
  color: var(--text);
  box-shadow:
    0 0 14px rgba(53, 225, 255, 0.18),
    inset 0 0 14px rgba(53, 225, 255, 0.12);
  pointer-events: auto;
}

#pauseBtn.hidden {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: linear-gradient(90deg, rgba(5, 9, 12, 0.92), rgba(5, 9, 12, 0.34));
  overflow: auto;
  touch-action: pan-y;
}

.overlay.hidden {
  display: none;
}

.overlay.game-over {
  align-items: center;
}

.panel {
  width: min(620px, 94vw);
  max-height: calc(100vh - 72px);
  overflow: auto;
  padding: 2px 4px 10px;
  text-align: center;
}

.kicker {
  margin: 0 0 8px;
  color: var(--lime);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 6vw, 70px);
  line-height: 0.96;
}

.copy {
  max-width: 46ch;
  margin: 12px auto 16px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.45;
}

#startBtn,
#backBtn,
#exitBtn,
.account-panel button,
.difficulty-list button,
.game-list button {
  min-width: min(170px, 100%);
  min-height: var(--control-height);
  padding: 0 var(--control-x);
  font-size: var(--control-font);
  border: 1px solid rgba(53, 225, 255, 0.42);
  background:
    linear-gradient(180deg, rgba(10, 31, 43, 0.88), rgba(5, 16, 22, 0.84));
  color: var(--text);
  box-shadow:
    inset 0 0 14px rgba(53, 225, 255, 0.1),
    0 10px 24px rgba(0, 0, 0, 0.22);
}

#startBtn {
  border-color: rgba(255, 241, 122, 0.88);
  background:
    linear-gradient(135deg, rgba(255, 241, 122, 0.98), rgba(53, 225, 255, 0.94));
  color: #041017;
  box-shadow:
    0 0 0 2px rgba(255, 241, 122, 0.14),
    0 14px 30px rgba(0, 0, 0, 0.28),
    0 0 24px rgba(53, 225, 255, 0.24);
}

#backBtn,
#exitBtn {
  margin-top: 10px;
}

#startBtn.button-pop,
#backBtn.button-pop,
#exitBtn.button-pop,
.account-panel button.button-pop,
.difficulty-list button.button-pop,
.game-list button.button-pop {
  box-shadow:
    0 0 0 3px rgba(255, 241, 122, 0.2),
    0 0 28px rgba(53, 225, 255, 0.34),
    0 12px 28px rgba(0, 0, 0, 0.26);
}

.account-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 14px auto 0;
  max-width: min(100%, 520px);
}

.account-panel button {
  flex: 0 1 clamp(154px, 32vw, 210px);
  min-width: min(154px, 100%);
  min-height: var(--compact-height);
  padding: 0 12px;
  border: 1px solid rgba(53, 225, 255, 0.28);
  background: rgba(5, 16, 22, 0.72);
  color: var(--text);
  box-shadow: inset 0 0 14px rgba(53, 225, 255, 0.08);
}

.account-panel button.active {
  background: var(--cyan);
  color: #041017;
}

.account-panel button.hidden {
  display: none;
}

.account-panel.signed-in {
  display: block;
  max-width: fit-content;
}

.account-panel p {
  flex: 0 0 100%;
  margin: 0;
  color: var(--lime);
  font-size: 13px;
  font-weight: 800;
}

.game-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 10px;
  margin: 14px auto 0;
  max-width: min(100%, 620px);
}

.difficulty-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(128px, 100%), 1fr));
  gap: 8px;
  margin: 18px auto 8px;
  max-width: min(100%, 520px);
}

.difficulty-list button,
.game-list button {
  width: 100%;
  border: 1px solid rgba(53, 225, 255, 0.28);
  background: rgba(5, 16, 22, 0.72);
  color: var(--text);
  box-shadow: inset 0 0 14px rgba(53, 225, 255, 0.08);
}

.difficulty-list button.active,
.game-list button.active {
  border-color: rgba(255, 241, 122, 0.95);
  background:
    linear-gradient(135deg, rgba(255, 241, 122, 0.96), rgba(53, 225, 255, 0.92));
  color: #041017;
  box-shadow:
    0 0 0 2px rgba(255, 241, 122, 0.18),
    0 14px 28px rgba(0, 0, 0, 0.28),
    0 0 24px rgba(53, 225, 255, 0.26);
  transform: translateY(-1px);
}

.difficulty-list button.active::after,
.game-list button.active::after {
  opacity: 0.18;
  transform: translateX(36%);
}

.difficulty-status {
  margin: 0 0 12px;
  color: var(--lime);
  font-size: 14px;
  font-weight: 800;
}

.difficulty-list.hidden,
.difficulty-status.hidden,
.game-list.hidden,
.account-panel.hidden,
#startBtn.hidden,
#backBtn.hidden,
#exitBtn.hidden,
.touch-pad.hidden {
  display: none;
}

.touch-pad {
  position: absolute;
  inset: 86px 0 18px;
  display: none;
  align-items: stretch;
  justify-content: space-between;
  pointer-events: none;
}

.touch-pad:not(.hidden) {
  display: flex;
}

.touch-pad button {
  position: relative;
  width: clamp(50px, 9vw, 76px);
  height: 100%;
  border: 1px solid rgba(53, 225, 255, 0.38);
  background: rgba(3, 12, 18, 0.34);
  box-shadow:
    0 0 14px rgba(53, 225, 255, 0.14),
    inset 0 0 14px rgba(53, 225, 255, 0.12);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.nav-control-left {
  border-left: 0;
  border-radius: 0 8px 8px 0;
}

.nav-control-right {
  border-right: 0;
  border-radius: 8px 0 0 8px;
}

.touch-pad button::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  opacity: 1;
  background: transparent;
  border-radius: 0;
  border-top: 4px solid rgba(244, 251, 255, 0.88);
  border-left: 4px solid rgba(244, 251, 255, 0.88);
  filter: drop-shadow(0 0 6px rgba(53, 225, 255, 0.7));
}

.nav-control-left::before {
  transform: translate(-38%, -50%) rotate(-45deg);
}

.nav-control-right::before {
  transform: translate(-62%, -50%) rotate(135deg);
}

.touch-pad button.button-pop::before {
  animation: none;
}

.touch-pad button:active {
  background: rgba(53, 225, 255, 0.22);
  transform: translateX(0) scale(0.96);
}

@media (hover: none), (max-width: 760px) {
  .shell {
    padding: 0;
  }

  .game-wrap {
    height: 100vh;
  }

  .overlay {
    padding: 12px;
    align-items: flex-start;
  }

  .overlay.game-over {
    align-items: center;
  }

  .overlay.game-over .panel {
    max-height: calc(100vh - 24px);
    padding-top: 0;
  }

  .panel {
    width: min(580px, 96vw);
    max-height: calc(100vh - 32px);
  }

  .kicker {
    font-size: 12px;
    margin-bottom: 5px;
  }

  h1 {
    font-size: clamp(30px, 7vw, 46px);
  }

  .copy {
    margin: 8px auto 10px;
    font-size: 14px;
    line-height: 1.3;
  }

  #startBtn,
  #backBtn,
  #exitBtn,
  .account-panel button,
  .difficulty-list button,
  .game-list button {
    min-height: var(--compact-height);
    padding: 0 clamp(10px, 3vw, 14px);
    font-size: var(--control-font);
  }

  .game-list {
    gap: 8px;
    margin-top: 10px;
  }

  .account-panel {
    margin-top: 10px;
  }

  .difficulty-list {
    margin: 10px 0 6px;
  }

  .difficulty-status {
    margin-bottom: 8px;
    font-size: 13px;
  }

  .touch-pad {
    inset: 74px 0 12px;
    display: flex;
  }

  .touch-pad.hidden {
    display: none;
  }

  .hud strong {
    font-size: 20px;
  }

  .hud > div {
    min-width: 70px;
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  .overlay {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .panel {
    width: 100%;
    max-height: calc(100vh - 28px);
  }

  .account-panel {
    display: grid;
    grid-template-columns: 1fr;
    max-width: 280px;
  }

  .account-panel button {
    width: 100%;
    min-width: 0;
  }

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

@media (max-height: 460px) and (orientation: landscape) {
  .overlay {
    align-items: center;
    padding: 10px 12px;
  }

  .touch-pad {
    inset: 58px 0 8px;
  }

  .panel {
    width: min(620px, 92vw);
    max-height: calc(100vh - 20px);
    padding: 0;
  }

  .kicker {
    margin-bottom: 3px;
    font-size: 11px;
  }

  h1 {
    font-size: clamp(32px, 6vh + 12px, 44px);
    line-height: 0.98;
  }

  .copy {
    margin: 6px auto 8px;
    font-size: 13px;
    line-height: 1.25;
  }

  .account-panel {
    max-width: min(100%, 440px);
    justify-content: center;
    gap: 7px;
    margin-top: 8px;
  }

  .account-panel button {
    flex-basis: clamp(132px, 20vw, 176px);
    min-height: var(--compact-height);
    padding: 0 clamp(8px, 2vw, 12px);
    font-size: var(--control-font);
  }

  .difficulty-list button,
  .game-list button,
  #startBtn,
  #backBtn,
  #exitBtn {
    min-height: var(--compact-height);
    min-width: min(96px, 100%);
    padding: 0 clamp(8px, 2vw, 12px);
    font-size: var(--control-font);
  }

  #startBtn {
    min-width: 112px;
  }

  #backBtn,
  #exitBtn {
    min-width: 72px;
  }

  .account-panel p {
    font-size: 11px;
  }

  .game-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(132px, 100%), 1fr));
    gap: 7px;
    margin-top: 8px;
    max-width: min(100%, 520px);
  }

  .difficulty-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(116px, 100%), 1fr));
    gap: 7px;
    margin: 8px 0 6px;
    max-width: min(100%, 460px);
  }

  .difficulty-status {
    margin-bottom: 7px;
    font-size: 12px;
  }

  .overlay.game-over .panel {
    width: min(520px, 88vw);
  }
}
