:root {
  color-scheme: dark;
  --game-background: #090b1f;
  --game-background-bottom: #170638;
  --game-text: #f9f8ff;
  --game-muted: #c4c2d8;
  --game-line: rgba(255, 255, 255, 0.15);
  --game-surface: rgba(255, 255, 255, 0.1);
  --game-focus: #57d8ff;
  --game-nav-height: 74px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

html {
  overflow: hidden;
  background: var(--game-background);
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", sans-serif;
}

button,
a {
  font: inherit;
}

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

.game-body {
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  color: var(--game-text);
  background:
    radial-gradient(circle at 50% 60%, rgba(89, 36, 169, 0.17), transparent 36rem),
    linear-gradient(180deg, #090b1f 0%, #0b0924 62%, var(--game-background-bottom) 100%);
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  color: #090b1f;
  background: var(--game-focus);
  font-weight: 800;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.game-nav {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 48px;
  align-items: center;
  min-height: var(--game-nav-height);
  padding: 0 clamp(20px, 3vw, 38px);
  border-bottom: 1px solid var(--game-line);
  background: rgba(6, 8, 29, 0.42);
  backdrop-filter: blur(14px);
}

.game-brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 12px;
  color: var(--game-text);
  font-size: 1.18rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: block;
  width: 38px;
  height: 30px;
}

.brand-mark span {
  position: absolute;
  left: 1px;
  width: 34px;
  height: 9px;
  border-radius: 4px;
  background: linear-gradient(90deg, #783cff, #34d6f2, #ff718a);
  box-shadow: 0 4px 9px rgba(0, 0, 0, 0.22);
}

.brand-mark span:nth-child(1) {
  top: 0;
  width: 27px;
  left: 7px;
}

.brand-mark span:nth-child(2) {
  top: 10px;
  width: 31px;
  left: 3px;
}

.brand-mark span:nth-child(3) {
  top: 20px;
}

.game-links {
  display: flex;
  align-items: center;
  gap: clamp(18px, 3vw, 38px);
  padding-right: clamp(24px, 4vw, 54px);
}

.game-links a,
.back-link,
.overlay-panel a {
  color: var(--game-muted);
  font-size: 0.94rem;
  font-weight: 700;
  text-decoration: none;
}

.game-links a:hover,
.game-links a:focus-visible,
.back-link:hover,
.back-link:focus-visible,
.overlay-panel a:hover,
.overlay-panel a:focus-visible {
  color: var(--game-text);
}

.pause-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 50%;
  color: var(--game-text);
  background: var(--game-surface);
  cursor: pointer;
}

.pause-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.pause-button:focus-visible,
.control-rail:focus-visible,
.game-stage:focus-visible,
.overlay-panel button:focus-visible {
  outline: 3px solid var(--game-focus);
  outline-offset: 3px;
}

.pause-glyph {
  display: flex;
  gap: 5px;
}

.pause-glyph span {
  width: 5px;
  height: 19px;
  border-radius: 2px;
  background: currentColor;
}

.pause-button.is-paused .pause-glyph {
  width: 0;
  height: 0;
  margin-left: 3px;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 15px solid currentColor;
}

.pause-button.is-paused .pause-glyph span {
  display: none;
}

.play-main {
  position: relative;
  height: calc(100vh - var(--game-nav-height));
  height: calc(100svh - var(--game-nav-height));
  min-height: 480px;
}

.game-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: manipulation;
}

.game-hud {
  position: absolute;
  z-index: 3;
  top: clamp(34px, 6vh, 62px);
  left: clamp(34px, 7vw, 110px);
  right: clamp(34px, 7vw, 110px);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: start;
  pointer-events: none;
}

.hud-stat {
  display: grid;
  gap: 0;
  margin: 0;
}

.hud-stat-center {
  justify-self: center;
  text-align: center;
}

.hud-stat-multiplier {
  justify-self: end;
  text-align: center;
}

.hud-stat strong {
  color: var(--game-text);
  font-size: clamp(2.25rem, 5vw, 4.25rem);
  font-weight: 950;
  line-height: 0.95;
  letter-spacing: -0.04em;
  text-shadow: 0 6px 22px rgba(0, 0, 0, 0.2);
}

.hud-stat-multiplier strong {
  font-size: clamp(2rem, 4.4vw, 3.75rem);
}

.hud-label {
  grid-row: 1;
  margin-bottom: 6px;
  color: var(--game-muted);
  font-size: clamp(0.72rem, 1.3vw, 0.9rem);
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.hud-stat-multiplier .hud-label {
  grid-row: auto;
  margin: 6px 0 0;
}

.placement-feedback {
  position: absolute;
  z-index: 4;
  top: 43%;
  left: 50%;
  margin: 0;
  color: var(--game-text);
  font-size: clamp(1.45rem, 3.2vw, 2.35rem);
  font-weight: 950;
  letter-spacing: -0.02em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0);
  white-space: nowrap;
  text-shadow: 0 7px 28px rgba(87, 26, 148, 0.55);
}

.placement-feedback.is-visible {
  opacity: 1;
}

.control-rail {
  position: absolute;
  z-index: 5;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: min(650px, calc(100% - 48px));
  min-height: 56px;
  padding: 0 28px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: var(--game-text);
  background: rgba(12, 10, 40, 0.64);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(16px);
  cursor: pointer;
  transform: translateX(-50%);
}

.control-rail:hover {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(31, 20, 71, 0.84);
}

.control-rail span {
  font-size: clamp(0.74rem, 1.5vw, 0.92rem);
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.mobile-instruction,
.back-link {
  display: none;
}

.game-overlay {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 25, 0.72);
  backdrop-filter: blur(14px);
}

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

.overlay-panel {
  display: grid;
  justify-items: center;
  width: min(420px, 100%);
  padding: clamp(30px, 6vw, 48px);
  border: 1px solid var(--game-line);
  border-radius: 28px;
  background: rgba(22, 17, 58, 0.94);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

.overlay-panel h1 {
  margin: 0;
  color: var(--game-text);
  font-size: clamp(2.25rem, 7vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.overlay-panel p {
  margin: 12px 0 26px;
  color: var(--game-muted);
}

.overlay-score-label {
  margin: 0 0 4px !important;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.overlay-score {
  margin: 0 0 20px !important;
  color: var(--game-text) !important;
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 950;
  line-height: 1;
}

.overlay-panel button {
  width: 100%;
  min-height: 54px;
  margin-top: 12px;
  border-radius: 15px;
  font-size: 1rem;
  font-weight: 850;
  cursor: pointer;
}

.overlay-primary {
  border: 0;
  color: #10082b;
  background: linear-gradient(100deg, #57d8ff, #a6ebff);
}

.overlay-secondary {
  border: 1px solid var(--game-line);
  color: var(--game-text);
  background: rgba(255, 255, 255, 0.07);
}

.overlay-panel a {
  margin-top: 24px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 640px) {
  :root {
    --game-nav-height: 68px;
  }

  .game-nav {
    grid-template-columns: 1fr 46px;
    padding:
      max(0px, env(safe-area-inset-top))
      max(18px, env(safe-area-inset-right))
      0
      max(18px, env(safe-area-inset-left));
  }

  .game-brand {
    font-size: 1.08rem;
  }

  .brand-mark {
    transform: scale(0.9);
    transform-origin: left center;
  }

  .game-links {
    display: none;
  }

  .pause-button {
    width: 42px;
    height: 42px;
  }

  .game-hud {
    top: 82px;
    left: 26px;
    right: 26px;
  }

  .hud-stat strong {
    font-size: clamp(2.45rem, 13vw, 3.35rem);
  }

  .hud-stat-multiplier strong {
    font-size: clamp(2.2rem, 11vw, 3rem);
  }

  .hud-label {
    font-size: 0.72rem;
  }

  .placement-feedback {
    top: 32%;
    font-size: 1.65rem;
  }

  .control-rail {
    bottom: calc(58px + env(safe-area-inset-bottom));
    gap: 13px;
    width: calc(100% - 44px);
    min-height: 58px;
    padding: 0 18px;
  }

  .control-rail span {
    font-size: clamp(0.64rem, 3vw, 0.78rem);
    letter-spacing: 0.13em;
  }

  .desktop-instruction {
    display: none;
  }

  .mobile-instruction {
    display: inline;
  }

  .back-link {
    position: absolute;
    z-index: 5;
    bottom: calc(18px + env(safe-area-inset-bottom));
    left: 50%;
    display: block;
    transform: translateX(-50%);
  }
}

@media (max-height: 690px) {
  .game-hud {
    top: 24px;
  }

  .control-rail {
    min-height: 50px;
  }

  .placement-feedback {
    top: 35%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
