@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap");

:root {
  --ink: #0a0f1f;
  --panel: #141d34;
  --panel-2: #11182a;
  --neon-cyan: #6aa7ff;
  --neon-pink: #ff5dc5;
  --neon-green: #79ffbe;
  --gold: #ffd67d;
  --text: #eef6ff;
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --locked-vw: 100vw;
  --locked-vh: 100svh;
  --title-ui-lift: 50px;
  --game-ui-lift: 50px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: "VT323", monospace;
  color: var(--text);
  background: #000;
}

.viewport {
  position: fixed;
  inset: 0;
  width: var(--locked-vw);
  height: var(--locked-vh);
  min-height: var(--locked-vh);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: var(--safe-top) 0 var(--safe-bottom) 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body.layout-fixed .viewport {
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  align-items: center;
  justify-content: center;
  padding:
    max(var(--safe-top), 6px)
    max(var(--safe-right), 6px)
    max(var(--safe-bottom), 6px)
    max(var(--safe-left), 6px);
}

.game-shell {
  position: relative;
  width: var(--locked-vw);
  height: auto;
  max-width: var(--locked-vw);
  aspect-ratio: 9 / 16;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.014) 0,
      rgba(255, 255, 255, 0.014) 2px,
      transparent 2px,
      transparent 8px
    ),
    linear-gradient(180deg, #111a30 0%, #080f1f 100%);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.4);
}

body.layout-fixed .game-shell {
  width: min(
    calc((var(--locked-vh) - var(--safe-top) - var(--safe-bottom) - 12px) * 9 / 16),
    calc(var(--locked-vw) - var(--safe-left) - var(--safe-right) - 12px),
    900px
  );
  max-width: calc(var(--locked-vw) - var(--safe-left) - var(--safe-right) - 12px);
}

.backdrop-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 22px,
      rgba(55, 240, 255, 0.03) 22px,
      rgba(55, 240, 255, 0.03) 23px
    );
}

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding: 20px 18px max(26px, calc(env(safe-area-inset-bottom) + 20px));
  background: #000 url("assets/sprites/title_bg.png") center / cover no-repeat;
}

.start-characters {
  width: min(96%, 860px);
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(10px, 4.8vw, 54px);
  margin-bottom: 2px;
  transform: translateY(calc(-1 * var(--title-ui-lift)));
}

.start-cat-gif {
  position: absolute;
  left: 50%;
  bottom: calc(clamp(12px, 2.6vh, 32px) + 25px);
  transform: translateX(-50%);
  width: clamp(152px, 26vw, 264px);
  height: auto;
  opacity: 1;
  z-index: 1;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.start-character {
  position: relative;
  z-index: 2;
  width: clamp(188px, 30vw, 316px);
  max-height: 52vh;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.start-character.nav {
  transform: translateX(clamp(12px, 1.8vw, 24px));
}

.start-character.thug {
  transform: translateX(clamp(-24px, -1.8vw, -12px));
}

.start-menu {
  margin-top: 2px;
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: min(88%, 332px);
  transform: translateY(calc(-1 * var(--title-ui-lift) - 20px));
}

.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.mode-prompt {
  margin: 0;
  text-align: center;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  color: #bde8ff;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.mode-btn {
  appearance: none;
  border: 1px solid rgba(106, 167, 255, 0.58);
  background: rgba(8, 14, 25, 0.95);
  color: #cdeeff;
  box-shadow: 0 0 0 1px rgba(106, 167, 255, 0.24) inset;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 10px 8px;
  text-transform: uppercase;
  cursor: pointer;
}

.mode-btn.active {
  border-color: rgba(255, 93, 197, 0.7);
  color: #fff5fc;
  background: rgba(25, 10, 29, 0.96);
  box-shadow:
    0 0 0 1px rgba(255, 93, 197, 0.25) inset,
    0 0 16px rgba(255, 93, 197, 0.18);
}

.start-menu-btn {
  appearance: none;
  border: 1px solid rgba(106, 167, 255, 0.66);
  background: rgba(7, 13, 24, 0.96);
  color: #e9f8ff;
  box-shadow: 0 0 0 1px rgba(106, 167, 255, 0.24) inset;
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  padding: 12px 12px;
  text-transform: uppercase;
  cursor: pointer;
}

.credits-box {
  position: absolute;
  left: 50%;
  top: max(14px, calc(env(safe-area-inset-top) + 8px));
  transform: translateX(-50%);
  border: 1px solid rgba(255, 93, 197, 0.56);
  background: rgba(12, 12, 20, 0.95);
  padding: 10px 12px;
  width: min(86%, 340px);
  text-align: center;
}

.credits-box p {
  margin: 0;
  color: #eaf7ff;
  font-size: 19px;
}

.credits-box a {
  color: #9fdfff;
}

.bottom-hud {
  position: absolute;
  z-index: 6;
  left: 9px;
  right: 9px;
  bottom: calc(9px + var(--game-ui-lift));
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  grid-template-rows: 1fr;
  align-items: start;
  height: 88px;
  pointer-events: none;
  padding: 8px;
  border: 1px solid rgba(255, 93, 197, 0.5);
  background: rgba(8, 13, 24, 0.9);
  box-shadow:
    0 0 0 1px rgba(255, 93, 197, 0.15) inset,
    0 0 12px rgba(255, 93, 197, 0.18);
}

.hud {
  position: static;
  display: flex;
  gap: 7px;
  grid-column: 1;
  grid-row: 1;
  align-self: start;
}

.hud-card {
  min-width: 86px;
  padding: 6px 8px;
  background: rgba(9, 15, 28, 0.86);
  border: 1px solid rgba(55, 240, 255, 0.46);
  box-shadow: 0 0 0 1px rgba(55, 240, 255, 0.16) inset;
}

.hud-card span {
  display: block;
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  color: #9fdfff;
}

.hud-card strong {
  display: block;
  margin-top: 2px;
  font-size: 28px;
  line-height: 1;
  color: #9fdfff;
  text-shadow: 0 0 8px rgba(159, 223, 255, 0.6);
}

.hud-message {
  grid-column: 2;
  grid-row: 1;
  justify-self: stretch;
  align-self: start;
  width: 100%;
  min-width: 0;
  margin: 0 2px 0 0;
  max-width: none;
  height: 60px;
  min-height: 60px;
  max-height: 60px;
  overflow: hidden;
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: clamp(13px, 1.45vw, 17px);
  line-height: 1.14;
  text-align: left;
  color: #eef7ff;
  text-shadow: 0 0 10px rgba(55, 240, 255, 0.46);
}

.canvas-wrap {
  position: absolute;
  inset: 0;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.leaderboard-overlay {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  padding: 14px;
  pointer-events: auto;
  background:
    radial-gradient(circle at 50% 30%, rgba(55, 240, 255, 0.13), transparent 52%),
    rgba(2, 6, 14, 0.86);
}

.leaderboard-modal {
  width: min(92%, 640px);
  border: 1px solid rgba(55, 240, 255, 0.5);
  background: rgba(8, 12, 24, 0.95);
  box-shadow:
    0 0 0 1px rgba(55, 240, 255, 0.18) inset,
    0 0 22px rgba(55, 240, 255, 0.2);
  padding: 14px;
}

.leaderboard-title {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  color: #9fdfff;
  font-size: 16px;
}

.leaderboard-final {
  margin: 8px 0 10px;
  color: #d6f2ff;
  font-size: 20px;
}

.leaderboard-final strong {
  color: #9fdfff;
}

.leaderboard-list {
  margin: 0;
  padding-left: 22px;
  max-height: 330px;
  overflow-y: auto;
  border: 1px solid rgba(55, 240, 255, 0.24);
  background: rgba(6, 11, 20, 0.88);
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 6px 8px 6px 0;
  color: #e9f7ff;
  font-size: 19px;
}

.leaderboard-list li:not(:last-child) {
  border-bottom: 1px solid rgba(55, 240, 255, 0.15);
}

.leaderboard-list .row-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.leaderboard-list .row-score {
  color: #9fdfff;
}

.leaderboard-message {
  margin: 8px 0 0;
  min-height: 20px;
  color: #c4eaff;
  font-size: 16px;
}

.leaderboard-message.error {
  color: #ff9fc8;
}

.leaderboard-actions,
.submit-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.leaderboard-btn {
  appearance: none;
  border: 1px solid rgba(106, 167, 255, 0.58);
  background: rgba(11, 20, 36, 0.96);
  color: #dff7ff;
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  padding: 9px 10px;
  cursor: pointer;
  text-transform: uppercase;
}

.leaderboard-btn.submit {
  border-color: rgba(255, 93, 197, 0.58);
  box-shadow: 0 0 0 1px rgba(255, 93, 197, 0.22) inset;
}

.leaderboard-btn.retry {
  box-shadow: 0 0 0 1px rgba(106, 167, 255, 0.26) inset;
}

.leaderboard-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.submit-form {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(255, 93, 197, 0.36);
  background: rgba(11, 16, 30, 0.96);
}

.leaderboard-overlay.submit-mode .leaderboard-list,
.leaderboard-overlay.submit-mode .leaderboard-actions {
  display: none;
}

.submit-label {
  display: block;
  color: #bce6ff;
  font-size: 16px;
  margin-bottom: 4px;
}

.submit-form input {
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid rgba(106, 167, 255, 0.52);
  background: rgba(4, 10, 18, 0.92);
  color: #f1fbff;
  padding: 8px;
  font-family: "VT323", monospace;
  font-size: 22px;
}

.submit-disclaimer {
  margin: 8px 0 0;
  color: #9eb8cc;
  font-size: 11px;
  line-height: 1.24;
}

@media (max-height: 760px) {
  .start-screen {
    gap: 10px;
    padding: 14px 14px max(20px, calc(env(safe-area-inset-bottom) + 14px));
  }

  .start-character {
    width: clamp(148px, 24vw, 224px);
    max-height: 40vh;
  }

  .start-cat-gif {
    width: clamp(132px, 22vw, 208px);
    bottom: calc(clamp(8px, 2vh, 22px) + 25px);
  }

  .start-menu {
    width: min(90%, 286px);
    gap: 8px;
  }

  .mode-btn {
    font-size: 9px;
    padding: 9px 8px;
  }

  .mode-prompt {
    font-size: 9px;
  }

  .start-menu-btn {
    font-size: 10px;
    padding: 10px;
  }

  .credits-box {
    width: min(90%, 300px);
    padding: 8px 10px;
  }

  .hud-message {
    min-height: 46px;
    max-height: 46px;
    height: 46px;
    font-size: 12px;
    line-height: 1.12;
  }

  .bottom-hud {
    height: 78px;
    padding: 6px;
  }
}

@media (max-width: 430px) {
  .start-character {
    width: 44vw;
    max-width: 212px;
  }

  .start-cat-gif {
    width: clamp(128px, 44vw, 196px);
    bottom: calc(clamp(8px, 1.8vh, 16px) + 25px);
  }

  .start-character.nav {
    transform: translateX(10px);
  }

  .start-character.thug {
    transform: translateX(-10px);
  }

  .start-menu {
    width: min(92%, 286px);
  }

  .mode-selector {
    gap: 6px;
  }

  .mode-btn {
    font-size: 8px;
  }

  .mode-prompt {
    font-size: 8px;
  }
}
