@font-face {
  font-family: "PressStart";
  src: local("Courier New");
}

:root {
  color-scheme: dark;
  --bg: #111217;
  --ink: #f7f1df;
  --muted: #a9b1bd;
  --panel: rgba(22, 24, 31, 0.92);
  --line: rgba(255, 255, 255, 0.16);
  --red: #ff4f67;
  --yellow: #ffd166;
  --green: #2de2a6;
  --blue: #45b7ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(24, 191, 192, 0.2), transparent 26rem),
    radial-gradient(circle at 82% 86%, rgba(255, 210, 74, 0.14), transparent 28rem),
    linear-gradient(135deg, #151a1d 0%, #0e1016 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.game-shell {
  position: relative;
  width: min(100vw, 1440px);
  height: min(100vh, 820px);
  min-width: 960px;
  min-height: 620px;
  background: #0f1118;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.score {
  position: absolute;
  top: 24px;
  right: 28px;
  z-index: 2;
  font-family: "Courier New", monospace;
  font-weight: 900;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0;
  text-align: right;
  pointer-events: none;
}

.score-line {
  display: block;
  white-space: nowrap;
}

.score-high {
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.42), 3px 3px 0 #3c2d0d;
}

.score-run {
  margin-top: 3px;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.28), 3px 3px 0 #111;
}

.controls-note {
  position: absolute;
  left: 24px;
  bottom: 18px;
  z-index: 2;
  color: rgba(247, 241, 223, 0.62);
  font-size: 14px;
  pointer-events: none;
}

.power-label {
  position: absolute;
  left: 50%;
  bottom: 40px;
  z-index: 4;
  min-width: 300px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  padding: 14px 20px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(16, 18, 24, 0.86);
  color: var(--ink);
  text-align: center;
  font-family: "Courier New", monospace;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.34);
  pointer-events: none;
}

.power-label.show {
  animation: powerToast 3s ease forwards;
}

@keyframes powerToast {
  0%,
  8% {
    opacity: 0;
    transform: translateX(-50%) translateY(18px);
  }
  14%,
  66% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(0);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 40px;
  background: rgba(9, 10, 15, 0.68);
  backdrop-filter: blur(7px);
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(560px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.48);
}

.start-panel {
  width: min(760px, 94vw);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(27, 30, 42, 0.95), rgba(13, 15, 22, 0.95)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 2px, transparent 2px 6px);
}

.menu-view.hidden {
  display: none;
}

.retro-start-art {
  position: relative;
  aspect-ratio: 1672 / 941;
  max-height: 300px;
  height: auto;
  margin: -4px 0 18px;
  border: 3px solid rgba(255, 209, 102, 0.62);
  border-radius: 8px;
  overflow: hidden;
  background: #090b10;
  box-shadow:
    inset 0 0 0 4px rgba(0,0,0,0.28),
    0 14px 34px rgba(0, 0, 0, 0.34);
}

.retro-start-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: saturate(1.08) contrast(1.04);
}

.retro-start-art::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.12), transparent 30%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.06) 0 1px, transparent 1px 5px);
  mix-blend-mode: screen;
  opacity: 0.38;
}

.start-panel input {
  width: 100%;
  margin-bottom: 12px;
}

.start-button {
  width: 100%;
  height: 60px;
  margin-top: 4px;
  font-family: "Courier New", monospace;
  font-size: 24px;
  text-transform: uppercase;
  box-shadow: 0 8px 0 #75530b;
}

.menu-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.menu-buttons button {
  width: 100%;
}

.auth-message {
  min-height: 22px;
  margin: -4px 0 10px;
  color: var(--yellow);
  font-family: "Courier New", monospace;
  font-weight: 900;
}

.sort-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.sort-button {
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  color: var(--ink);
  font-size: 13px;
}

.sort-button.active {
  background: var(--yellow);
  color: #17130a;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: none;
  overflow: auto;
  padding-right: 4px;
}

.rules-grid article {
  min-height: 96px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
}

.rules-grid img {
  float: left;
  width: 44px;
  height: 44px;
  object-fit: contain;
  margin: 0 10px 6px 0;
}

.rules-grid strong {
  display: block;
  color: var(--yellow);
  font-family: "Courier New", monospace;
  font-size: 14px;
}

.rules-grid span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.34;
}

.responsible {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.kicker {
  margin: 0 0 10px;
  color: var(--green);
  font-family: "Courier New", monospace;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0 0 22px;
  font-family: "Courier New", monospace;
  font-size: 34px;
  line-height: 1.12;
  letter-spacing: 0;
}

label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-weight: 700;
}

.name-row,
.button-row,
.leaderboard-head {
  display: flex;
  gap: 10px;
  align-items: center;
}

input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0e1016;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(69, 183, 255, 0.18);
}

button {
  height: 48px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  background: var(--yellow);
  color: #17130a;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease;
}

button:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--blue);
  color: #06111a;
}

button.ghost {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.hint {
  margin: 14px 0 22px;
  color: var(--muted);
  line-height: 1.45;
}

.leaderboard {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.leaderboard-head {
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--ink);
  font-weight: 900;
}

ol {
  display: grid;
  gap: 0;
  margin: 0;
  padding-left: 0;
  list-style: none;
  color: var(--muted);
}

#leaderboard-list li {
  display: grid;
  grid-template-columns: 42px minmax(140px, 1.45fr) minmax(94px, 0.8fr) minmax(74px, 0.6fr) minmax(132px, 0.9fr);
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
}

#leaderboard-list strong {
  color: var(--ink);
}

#leaderboard-list .rank {
  color: var(--yellow);
  font-weight: 900;
}

#leaderboard-list .metric {
  color: var(--ink);
  font-weight: 800;
}

li::marker {
  color: var(--yellow);
  font-weight: 900;
}

.result-text {
  min-height: 28px;
  color: var(--green);
  font-weight: 900;
}

.death-message {
  min-height: 0;
  margin: 0 0 12px;
  color: var(--red);
  font-family: "Courier New", monospace;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.25;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
}

.game-over-panel {
  text-align: center;
}

.game-over-panel .button-row {
  justify-content: center;
}

#game-over-main.hidden {
  display: none;
}

.report-button {
  height: 30px;
  min-width: 116px;
  margin-top: 12px;
  font-size: 12px;
}

.bug-report-panel.hidden {
  display: none;
}

.bug-report-panel textarea {
  width: 100%;
  min-height: 140px;
  margin: 8px 0 12px;
  padding: 12px 14px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0e1016;
  color: var(--ink);
  font: 700 15px/1.45 "Courier New", monospace;
  outline: none;
}

.bug-report-panel textarea:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.18);
}

.bug-report-status {
  min-height: 24px;
  margin: 0 0 10px;
}

.mobile-controls {
  display: none;
}

.mobile-control.hidden {
  display: none !important;
}

@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100svh;
    overflow: hidden;
    overscroll-behavior: none;
    background: #111217;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .game-shell {
    width: 100vw;
    height: 100svh;
    min-width: 0;
    min-height: 0;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    touch-action: none;
  }

  canvas {
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .score {
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
    font-size: clamp(15px, 4.5vw, 21px);
  }

  .power-label {
    top: calc(max(12px, env(safe-area-inset-top)) + 58px);
    bottom: auto;
    z-index: 9;
    min-width: min(86vw, 360px);
    max-width: 90vw;
    padding: 11px 13px;
    font-size: clamp(12px, 3.5vw, 17px);
    line-height: 1.2;
    transform: translateX(-50%) translateY(-14px);
  }

  .power-label.show {
    animation: mobilePowerToast 3s ease forwards;
  }

  @keyframes mobilePowerToast {
    0%,
    8% {
      opacity: 0;
      transform: translateX(-50%) translateY(-14px);
    }
    14%,
    66% {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }
    100% {
      opacity: 0;
      transform: translateX(-50%) translateY(0);
    }
  }

  .overlay {
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
    place-items: center;
  }

  .panel {
    width: min(94vw, 560px);
    max-height: calc(100svh - 34px);
    overflow: auto;
    padding: 20px;
    touch-action: pan-y;
  }

  .rules-grid {
    grid-template-columns: 1fr;
    max-height: calc(100svh - 190px);
  }

  .rules-grid article {
    min-height: 88px;
  }

  .retro-start-art {
    aspect-ratio: 1672 / 941;
  }

  input,
  button {
    touch-action: manipulation;
  }

  h1,
  h2 {
    font-size: clamp(24px, 7vw, 34px);
  }

  .name-row,
  .button-row {
    flex-wrap: wrap;
  }

  .name-row button,
  .button-row button {
    flex: 1 1 130px;
  }

  .hint {
    display: none;
  }

  .mobile-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 8;
    display: grid;
    grid-template-columns: 1fr 0.72fr 1fr;
    grid-template-rows: 62px 46px;
    gap: 8px;
    padding: 8px 16px calc(9px + env(safe-area-inset-bottom));
    background:
      linear-gradient(180deg, rgba(40, 92, 35, 0), rgba(30, 90, 35, 0.46) 14%, rgba(22, 90, 40, 0.78) 100%),
      repeating-linear-gradient(90deg, rgba(255, 220, 94, 0.24) 0 18px, rgba(208, 101, 40, 0.16) 18px 36px);
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .mobile-control {
    position: relative;
    display: grid;
    place-items: center;
    height: 100%;
    min-height: 46px;
    border: 3px solid rgba(255, 255, 255, 0.62);
    border-radius: 8px;
    background:
      linear-gradient(180deg, rgba(255, 247, 176, 0.98), rgba(225, 163, 35, 0.98)),
      radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.68), transparent 24%);
    color: transparent;
    font-size: 0;
    line-height: 0;
    box-shadow: 0 9px 0 rgba(82, 53, 12, 0.78), 0 18px 26px rgba(0, 0, 0, 0.34);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
  }

  .mobile-control::before,
  .mobile-control::after {
    content: "";
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .mobile-control::before {
    width: min(14vw, 54px);
    height: min(14vw, 54px);
    filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, 0.28));
  }

  .mobile-control:active,
  .mobile-control.pressed {
    transform: translateY(6px);
    filter: brightness(1.08);
    box-shadow: 0 3px 0 rgba(82, 53, 12, 0.88), 0 10px 18px rgba(0, 0, 0, 0.28);
  }

  .mobile-control-side {
    grid-row: 1 / 3;
  }

  .mobile-control-left::before,
  .mobile-control-right::before,
  .mobile-control-jump::before {
    background: linear-gradient(180deg, #fff7ce, #5a3300);
    clip-path: polygon(72% 5%, 18% 50%, 72% 95%, 72% 68%, 100% 68%, 100% 32%, 72% 32%);
  }

  .mobile-control-right::before {
    transform: scaleX(-1);
  }

  .mobile-control-jump {
    grid-column: 2;
    grid-row: 1;
    background:
      linear-gradient(180deg, rgba(100, 207, 255, 0.98), rgba(20, 115, 196, 0.98)),
      radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.74), transparent 25%);
  }

  .mobile-control-jump::before {
    background: linear-gradient(180deg, #ffffff, #06345e);
    transform: rotate(90deg);
  }

  .mobile-control-shoot {
    grid-column: 2;
    grid-row: 2;
    background:
      linear-gradient(180deg, rgba(255, 103, 90, 0.98), rgba(170, 16, 30, 0.98)),
      radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.7), transparent 26%);
  }

  .mobile-control-shoot::before {
    width: min(12vw, 42px);
    height: min(12vw, 42px);
    border-radius: 50%;
    background:
      radial-gradient(circle at 62% 34%, #fff8bf 0 16%, transparent 17%),
      radial-gradient(circle, #40f2e6 0 42%, #009688 43% 68%, #053b37 69% 100%);
    box-shadow:
      -12px 0 0 -4px #fff09b,
      12px 0 0 -6px #fffbdb,
      0 0 18px rgba(64, 242, 230, 0.92);
  }

  .death-message {
    font-size: clamp(20px, 6vw, 30px);
  }

  #leaderboard-list li {
    grid-template-columns: 30px minmax(88px, 1.2fr) minmax(58px, 0.7fr);
    gap: 7px;
  }

  #leaderboard-list .level-cell,
  #leaderboard-list .boss-cell {
    font-size: 12px;
  }

  .bug-report-panel textarea {
    min-height: 128px;
    font-size: 16px;
    user-select: text;
    -webkit-user-select: text;
  }
}
