:root {
  --night: #07111b;
  --night-soft: #102337;
  --panel: rgba(7, 17, 27, 0.82);
  --panel-solid: #0c1c2a;
  --line: rgba(169, 245, 255, 0.28);
  --text: #f5fbff;
  --muted: #9db3c2;
  --cyan: #31e7df;
  --cyan-deep: #0cb8c3;
  --violet: #8f5dff;
  --danger: #ff5b78;
  --shadow: rgba(0, 0, 0, 0.42);
  --hud-height: 72px;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
}

body {
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
a {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

.app-shell,
.game-world {
  width: 100%;
  min-height: 100dvh;
}

.game-world {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--night);
  touch-action: none;
  user-select: none;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.game-hud {
  position: absolute;
  z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  height: var(--hud-height);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto minmax(240px, 1fr);
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 16px 42px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(16px) saturate(135%);
  -webkit-backdrop-filter: blur(16px) saturate(135%);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 0 12px rgba(49, 231, 223, 0.32));
}

.brand span,
.score-card__label,
.overlay__eyebrow,
.flight-counter,
.control-hint,
.wallet-state,
.contract-badge,
.overlay__facts {
  font-family: Consolas, "Courier New", monospace;
  font-weight: 800;
  text-transform: uppercase;
}

.brand span {
  overflow: hidden;
  font-size: 1rem;
  letter-spacing: 0.14em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-strip {
  min-width: 260px;
  height: 52px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(3, 11, 18, 0.54);
}

.score-card {
  min-width: 0;
  padding: 7px 18px;
  display: grid;
  align-content: center;
  gap: 2px;
}

.score-card + .score-card {
  border-left: 1px solid var(--line);
}

.score-card--right {
  text-align: right;
}

.score-card__label {
  color: var(--muted);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
}

.score-card strong {
  overflow: hidden;
  color: var(--cyan);
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-size: 1.25rem;
  line-height: 1;
  text-overflow: ellipsis;
}

.hud-actions {
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.profile-chip {
  min-width: 116px;
  height: 42px;
  padding: 5px 11px;
  display: grid;
  align-content: center;
  justify-items: end;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: rgba(3, 11, 18, 0.66);
  cursor: pointer;
}

.profile-chip[hidden] {
  display: none;
}

.profile-chip__name,
.profile-chip__score {
  max-width: 130px;
  overflow: hidden;
  font-family: Consolas, "Courier New", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip__name {
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 900;
}

.profile-chip__score {
  color: var(--cyan);
  font-size: 0.52rem;
  font-weight: 800;
}

.wallet-button,
.icon-button,
.play-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.wallet-button {
  min-width: 174px;
  height: 42px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: rgba(143, 93, 255, 0.18);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.wallet-button:hover,
.icon-button:hover {
  border-color: var(--cyan);
  background: rgba(49, 231, 223, 0.14);
}

.wallet-button:active,
.icon-button:active,
.play-button:active {
  transform: translateY(1px) scale(0.985);
}

.wallet-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.wallet-button__status {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(157, 179, 194, 0.12);
}

.wallet-button[data-connected="true"] .wallet-button__status {
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 11, 18, 0.66);
  font-size: 1.1rem;
  font-weight: 900;
}

.leaderboard-button {
  font-family: "Arial Black", "Segoe UI", sans-serif;
  color: var(--cyan);
}

.sound-toggle__off {
  display: none;
}

.sound-toggle[aria-pressed="true"] .sound-toggle__on {
  display: none;
}

.sound-toggle[aria-pressed="true"] .sound-toggle__off {
  display: inline;
}

.wallet-state {
  position: absolute;
  z-index: 6;
  top: calc(max(12px, env(safe-area-inset-top)) + var(--hud-height) + 7px);
  right: max(18px, env(safe-area-inset-right));
  max-width: 340px;
  margin: 0;
  color: rgba(225, 239, 247, 0.66);
  font-size: 0.56rem;
  line-height: 1.35;
  letter-spacing: 0.04em;
  text-align: right;
  text-transform: none;
  pointer-events: none;
}

.wallet-state[data-tone="success"] {
  color: var(--cyan);
}

.wallet-state[data-tone="error"] {
  color: #ff9aab;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: calc(var(--hud-height) + 44px) 24px 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  background:
    radial-gradient(circle at 50% 48%, rgba(10, 33, 48, 0.22), rgba(4, 12, 19, 0.6) 64%, rgba(3, 9, 14, 0.84)),
    linear-gradient(90deg, rgba(3, 10, 16, 0.46), transparent 28%, transparent 72%, rgba(3, 10, 16, 0.46));
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay[hidden] {
  display: grid;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay__content {
  width: min(520px, 100%);
  min-width: 0;
  padding: 30px 36px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 1px solid rgba(169, 245, 255, 0.34);
  border-radius: var(--radius);
  background: rgba(5, 15, 24, 0.84);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.52), inset 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px) saturate(125%);
  -webkit-backdrop-filter: blur(18px) saturate(125%);
}

.overlay__coin {
  width: 74px;
  height: 74px;
  margin-bottom: 9px;
  object-fit: contain;
  filter: drop-shadow(0 0 18px rgba(49, 231, 223, 0.34));
}

.overlay__eyebrow {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
}

.overlay h1 {
  width: 100%;
  min-width: 0;
  margin: 0;
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-size: clamp(3.2rem, 6vw, 4.5rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 0 7px 0 rgba(10, 184, 195, 0.32), 0 0 32px rgba(49, 231, 223, 0.18);
}

.overlay__tagline {
  margin: 13px 0 0;
  color: #dff9ff;
  font-size: clamp(0.95rem, 2vw, 1.08rem);
  font-weight: 800;
}

.overlay__copy {
  max-width: 420px;
  margin: 10px 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.overlay__result {
  margin: -3px 0 18px;
  display: grid;
  gap: 3px;
}

.overlay__result[hidden] {
  display: none;
}

.overlay__result span:first-child {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.overlay__result strong {
  color: var(--cyan);
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-size: 2.3rem;
  line-height: 1;
}

.play-button {
  width: min(340px, 100%);
  min-height: 56px;
  padding: 0 14px 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  color: #031014;
  background: var(--cyan);
  border-color: #a9ffff;
  box-shadow: 0 6px 0 var(--cyan-deep), 0 16px 32px rgba(12, 184, 195, 0.24);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.88rem;
  font-weight: 900;
}

.play-button:hover:not(:disabled) {
  background: #8efff7;
}

.play-button:disabled {
  color: rgba(220, 234, 240, 0.48);
  background: #263745;
  border-color: #435767;
  box-shadow: 0 5px 0 #172632;
  cursor: wait;
}

.play-button__key {
  padding: 5px 7px;
  border: 1px solid rgba(3, 16, 20, 0.36);
  border-radius: 4px;
  font-size: 0.55rem;
}

.contract-badge {
  appearance: none;
  width: min(340px, 100%);
  min-height: 34px;
  margin-top: 16px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(49, 231, 223, 0.28);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(49, 231, 223, 0.06);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  cursor: copy;
  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.contract-badge strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--cyan);
  font-size: inherit;
  white-space: nowrap;
}

.contract-badge:not(:disabled):hover {
  border-color: rgba(49, 231, 223, 0.68);
  background: rgba(49, 231, 223, 0.12);
  transform: translateY(-1px);
}

.contract-badge:not(:disabled):focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.contract-badge:disabled {
  cursor: default;
}

.contract-badge.is-copied {
  border-color: rgba(104, 255, 145, 0.72);
  background: rgba(104, 255, 145, 0.12);
}

.contract-badge__action {
  flex: 0 0 auto;
  padding-left: 8px;
  border-left: 1px solid rgba(49, 231, 223, 0.24);
  color: #a8bcc5;
  font-size: 0.5rem;
}

.overlay__facts {
  margin-top: 10px;
  display: flex;
  gap: 20px;
  color: var(--muted);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
}

.overlay__facts b {
  color: var(--cyan);
}

.flight-counter,
.control-hint {
  position: absolute;
  z-index: 5;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.flight-counter {
  left: max(16px, env(safe-area-inset-left));
  padding: 9px 12px;
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
}

.flight-counter strong {
  margin-left: 6px;
  color: var(--cyan);
  font-size: 0.9rem;
}

.control-hint {
  left: 50%;
  padding: 9px 14px;
  display: flex;
  gap: 9px;
  color: rgba(225, 239, 247, 0.7);
  font-size: 0.58rem;
  letter-spacing: 0.04em;
  transform: translateX(-50%);
}

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

.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  padding: 88px 18px 24px;
  display: grid;
  place-items: center;
  background: rgba(2, 8, 13, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.modal[hidden] {
  display: none;
}

.modal__panel {
  width: min(620px, 100%);
  max-height: min(680px, calc(100dvh - 112px));
  padding: 24px;
  overflow: auto;
  border: 1px solid rgba(169, 245, 255, 0.38);
  border-radius: var(--radius);
  background: rgba(5, 15, 24, 0.96);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.62), inset 0 1px rgba(255, 255, 255, 0.08);
}

.modal__panel--compact {
  width: min(440px, 100%);
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.modal__eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.modal h2 {
  margin: 0;
  font-family: "Arial Black", "Segoe UI", sans-serif;
  font-size: clamp(1.65rem, 5vw, 2.35rem);
  line-height: 1;
}

.modal__copy {
  margin: 12px 0 20px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.field-label,
.field-help,
.form-error,
.leaderboard-status {
  font-family: Consolas, "Courier New", monospace;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--cyan);
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

#nicknameInput {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #07131d;
  font: 800 1rem Consolas, "Courier New", monospace;
}

#nicknameInput:focus {
  border-color: var(--cyan);
  outline: 2px solid rgba(49, 231, 223, 0.2);
}

.field-help,
.form-error {
  min-height: 18px;
  margin: 7px 0 0;
  font-size: 0.62rem;
  line-height: 1.4;
}

.field-help {
  color: var(--muted);
}

.form-error {
  color: #ff9aab;
}

.modal-action {
  width: 100%;
  min-height: 50px;
  margin-top: 8px;
  border: 1px solid #a9ffff;
  border-radius: var(--radius);
  color: #031014;
  background: var(--cyan);
  box-shadow: 0 5px 0 var(--cyan-deep);
  font: 900 0.82rem Consolas, "Courier New", monospace;
  cursor: pointer;
}

.modal-action:disabled {
  opacity: 0.55;
  cursor: wait;
}

.modal__close {
  flex: 0 0 auto;
  font: 900 0.74rem Consolas, "Courier New", monospace;
}

.leaderboard-status {
  margin: 18px 0 10px;
  color: var(--muted);
  font-size: 0.66rem;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
  list-style: none;
  counter-reset: ranking;
}

.leaderboard-row {
  min-height: 54px;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(169, 245, 255, 0.16);
  border-radius: 6px;
  background: rgba(13, 31, 44, 0.72);
}

.leaderboard-row[data-player="true"] {
  border-color: var(--cyan);
  background: rgba(49, 231, 223, 0.1);
}

.leaderboard-row__rank {
  color: var(--cyan);
  font: 900 0.88rem Consolas, "Courier New", monospace;
}

.leaderboard-row__identity {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.leaderboard-row__identity strong,
.leaderboard-row__identity span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-row__identity strong {
  font-size: 0.86rem;
}

.leaderboard-row__identity span {
  color: var(--muted);
  font: 700 0.55rem Consolas, "Courier New", monospace;
}

.leaderboard-row__score {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.leaderboard-row__score strong {
  color: var(--cyan);
  font: 900 1rem "Arial Black", "Segoe UI", sans-serif;
}

.leaderboard-row__score span {
  color: var(--muted);
  font: 700 0.54rem Consolas, "Courier New", monospace;
}

@media (max-width: 760px) {
  :root {
    --hud-height: 62px;
  }

  .game-hud {
    top: max(7px, env(safe-area-inset-top));
    left: max(7px, env(safe-area-inset-left));
    right: max(7px, env(safe-area-inset-right));
    padding: 7px;
    grid-template-columns: 34px minmax(94px, 1fr) auto;
    gap: 6px;
  }

  .brand {
    gap: 0;
  }

  .brand img {
    width: 34px;
    height: 34px;
  }

  .brand span {
    display: none;
  }

  .score-strip {
    min-width: 0;
    height: 46px;
  }

  .score-card {
    padding: 5px 6px;
  }

  .score-card__label {
    font-size: 0.46rem;
  }

  .score-card strong {
    font-size: 1rem;
  }

  .wallet-button {
    min-width: 68px;
    width: 68px;
    height: 36px;
    padding: 0 5px;
    gap: 6px;
    font-size: 0.54rem;
  }

  .profile-chip {
    display: none;
  }

  .leaderboard-button {
    width: 36px;
    height: 36px;
  }

  .wallet-button__status {
    width: 10px;
    height: 10px;
  }

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

  .wallet-state {
    display: none;
  }

  .overlay {
    padding: calc(var(--hud-height) + 20px) 14px 56px;
  }

  .overlay__content {
    width: min(420px, 100%);
    padding: 22px 18px 20px;
  }

  .overlay__coin {
    width: 58px;
    height: 58px;
    margin-bottom: 6px;
  }

  .overlay h1 {
    font-size: clamp(2.65rem, 13vw, 3.7rem);
  }

  .overlay__tagline {
    font-size: 0.84rem;
  }

  .overlay__copy {
    margin-bottom: 16px;
    font-size: 0.76rem;
  }

  .overlay__facts {
    gap: 12px;
    font-size: 0.5rem;
  }

  .control-hint {
    display: none;
  }

  .flight-counter {
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 50%;
    padding: 7px 10px;
    transform: translateX(-50%);
  }

  .modal {
    padding: 76px 10px 14px;
  }

  .modal__panel {
    max-height: calc(100dvh - 90px);
    padding: 18px;
  }

  .leaderboard-row {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    padding-inline: 9px;
  }
}

@media (max-height: 590px) and (orientation: landscape) {
  .overlay {
    padding-top: calc(var(--hud-height) + 16px);
  }

  .overlay__content {
    max-width: 600px;
    padding: 16px 24px;
  }

  .overlay__coin,
  .overlay__copy,
  .contract-badge,
  .overlay__facts {
    display: none;
  }

  .overlay h1 {
    font-size: clamp(2.8rem, 10vh, 4.6rem);
  }

  .overlay__tagline {
    margin-bottom: 12px;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .game-hud,
  .overlay__content,
  .flight-counter,
  .control-hint {
    background: var(--panel-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

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