@import url("https://fonts.googleapis.com/css2?family=Silkscreen:wght@400;700&display=swap");

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Silkscreen", "Lucida Console", "Courier New", monospace;
  background:
    linear-gradient(180deg, #080c14 0%, #0c1220 100%);
  color: #d9eeff;
  min-height: 100svh;
  touch-action: manipulation;
}

.game-shell {
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  place-items: start center;
  padding:
    max(16px, env(safe-area-inset-top))
    12px
    max(18px, env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.game-panel {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 24px);
  display: grid;
  grid-template-areas:
    "hud"
    "stage"
    "footer";
  grid-template-rows: auto auto auto;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 28px;
  background: #121a28;
  border: 4px solid #27354f;
  box-shadow:
    0 0 0 4px #0a1019,
    0 12px 0 #060a11;
  box-sizing: border-box;
}

.hud {
  grid-area: hud;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.game-eyebrow,
.hud-label,
.game-footer p {
  margin: 0;
  color: #ffef8f;
}

.hud-card {
  min-width: 112px;
  padding: 8px 14px;
  border-radius: 14px;
  background: #192338;
  border: 3px solid #314262;
  display: grid;
  gap: 4px;
  box-shadow:
    inset 0 0 0 3px #23324d,
    0 5px 0 #0b111b;
}

.hud-card strong {
  font-size: 1.2rem;
  line-height: 1.1;
}

.hud-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: auto;
}

.hud-toggle-button {
  appearance: none;
  border: 3px solid #8a4900;
  border-radius: 999px;
  min-width: 58px;
  min-height: 50px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1;
  color: #6d3200;
  background: linear-gradient(180deg, #fff2a4 0%, #ffbb57 100%);
  cursor: pointer;
  box-shadow: 0 4px 0 #6d3200;
}

.hud-toggle-button-compact {
  min-width: 50px;
  width: 50px;
  max-width: 50px;
  min-height: 50px;
  height: 50px;
  padding: 0;
  flex: 0 0 auto;
  position: relative;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
}

.hud-toggle-button-text {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hud-toggle-button-compact.is-muted {
  opacity: 0.68;
}

.hud-toggle-button-compact.is-muted::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 50%;
  height: 3px;
  border-radius: 999px;
  background: #6d3200;
  transform: translateY(-50%) rotate(-35deg);
}

.game-stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#gameCanvas {
  width: min(100%, calc((100vh - 234px) * 16 / 9));
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 234px);
  aspect-ratio: 16 / 9;
  display: block;
  border-radius: 24px;
  cursor: pointer;
  background: #111a2a;
  box-shadow:
    inset 0 0 0 3px #1d2940,
    0 8px 0 #0b111b;
  touch-action: manipulation;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 12, 20, 0.72);
  border-radius: 24px;
  overflow: hidden;
}

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

.game-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.game-overlay-card {
  width: min(460px, calc(100% - 32px));
  padding: 18px;
  border-radius: 18px;
  background: #192338;
  border: 4px solid #314262;
  text-align: center;
  box-shadow:
    inset 0 0 0 4px #23324d,
    0 8px 0 #0b111b;
  position: relative;
  z-index: 1;
}

.game-overlay-card h2,
.game-overlay-card p {
  margin-top: 0;
}

.leaderboard-form,
.leaderboard-panel {
  margin: 14px 0 0;
}

.leaderboard-form[hidden],
.leaderboard-panel[hidden] {
  display: none;
}

.leaderboard-form {
  display: grid;
  gap: 10px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.leaderboard-label,
.leaderboard-title {
  color: #ffe26e;
  font-weight: 700;
}

.leaderboard-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 3px solid #314262;
  background: #111a2a;
  color: #fffef9;
  font: inherit;
  box-sizing: border-box;
}

.leaderboard-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.leaderboard-status {
  margin: 0;
  min-height: 1.2em;
  color: #d8f6ff;
  font-size: 0.92rem;
}

.leaderboard-form + .game-button,
.game-overlay-card .game-button {
  margin-top: 10px;
}

.leaderboard-panel {
  padding: 12px;
  border-radius: 14px;
  background: #111a2a;
  border: 3px solid #314262;
  text-align: left;
  box-shadow:
    inset 0 0 0 3px #1d2940,
    0 5px 0 #0b111b;
}

.leaderboard-panel-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.leaderboard-title {
  display: block;
  width: 100%;
  text-align: center;
}

.leaderboard-refresh {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 700;
  color: #10306d;
  background: #d7f7ff;
  cursor: pointer;
}

.leaderboard-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
  color: #fffef9;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.leaderboard-entry-self {
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.overlay-changelog {
  display: inline-grid;
  gap: 8px;
  text-align: left;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 14px;
  background: #111a2a;
  border: 3px solid #314262;
  box-shadow:
    inset 0 0 0 3px #1d2940,
    0 5px 0 #0b111b;
}

.overlay-changelog-title {
  color: #ffe26e;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.overlay-changelog-version {
  color: #fffef9;
  font-weight: 700;
}

.overlay-changelog-list {
  margin: 0;
  padding-left: 18px;
}

.overlay-changelog-list li {
  margin: 0;
}

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

.leaderboard-score {
  color: #ffe26e;
  font-weight: 700;
}

.game-footer {
  grid-area: footer;
  min-height: 0;
  text-align: center;
}

.game-footer p {
  font-size: 0.95rem;
}

.game-version {
  margin-top: 4px;
  color: #d8f3ff;
  font-size: 0.84rem;
}

.game-button {
  appearance: none;
  border: 3px solid #8a4900;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  color: #6d3200;
  background: linear-gradient(180deg, #fff2a4 0%, #ffbb57 100%);
  cursor: pointer;
  box-shadow: 0 4px 0 #6d3200;
}

.game-button-secondary {
  color: #d8f6ff;
  background: #192338;
  border: 3px solid #314262;
  box-shadow:
    inset 0 0 0 3px #23324d,
    0 4px 0 #0b111b;
}

.game-button:disabled {
  opacity: 0.45;
  cursor: default;
  filter: none;
}

.game-button:hover {
  filter: brightness(1.04);
}

.game-button:active {
  transform: translateY(1px);
}

@media (max-width: 900px) {
  .game-shell {
    padding:
      max(10px, env(safe-area-inset-top))
      8px
      max(14px, env(safe-area-inset-bottom));
  }

  .game-panel {
    width: min(1180px, calc(100vw - 24px));
    max-height: calc(100vh - 16px);
    padding: 10px;
    border-radius: 20px;
  }

  #gameCanvas {
    width: min(100%, calc((100vh - 208px) * 16 / 9));
    max-height: calc(100vh - 208px);
  }
}

@media (max-width: 820px), (max-height: 820px) {
  .game-shell {
    min-height: 100dvh;
    padding:
      max(4px, env(safe-area-inset-top))
      4px
      max(6px, env(safe-area-inset-bottom));
  }

  .game-panel {
    width: min(100%, calc(100vw - 8px));
    min-height: calc(100dvh - max(4px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom)) - 8px);
    max-height: calc(100dvh - max(4px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom)) - 8px);
    grid-template-areas:
      "hud"
      "stage"
      "footer";
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 5px;
    padding: 6px;
    border-radius: 16px;
  }

  .game-stage {
    min-height: 0;
    align-self: stretch;
    padding: 2px 0 8px;
    box-sizing: border-box;
  }

  .hud {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }

  .hud-card {
    min-width: 0;
  }

  .hud-card {
    padding: 7px 10px;
  }

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

  .hud-toggle-button,
  .game-button {
    min-height: 46px;
  }

  .hud-actions {
    grid-column: 1 / -1;
    margin-left: 0;
    display: grid;
    grid-template-columns: 46px 46px minmax(0, 1fr);
    width: 100%;
  }

  .hud-actions .game-button,
  .hud-actions .hud-toggle-button-compact {
    width: 100%;
    padding-left: 12px;
    padding-right: 12px;
  }

  .hud-actions .hud-toggle-button-compact {
    width: 46px;
    min-width: 46px;
    max-width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
  }

  .hud-actions .game-button-secondary {
    min-width: 0;
    font-size: 0.78rem;
    padding-left: 10px;
    padding-right: 10px;
  }

  #gameCanvas {
    width: auto;
    height: calc(100% - 8px);
    min-width: 100%;
    max-width: none;
    max-height: none;
    border-radius: 16px;
    justify-self: center;
  }

  .game-overlay {
    border-radius: 16px;
    position: absolute;
    inset: 0;
    z-index: 5;
  }

  .game-overlay-card {
    width: min(380px, calc(100% - 36px));
    max-height: calc(100% - 20px);
    overflow: auto;
    padding: 14px;
    border-radius: 16px;
  }

  .game-overlay-card h2 {
    margin-bottom: 10px;
    font-size: 1.95rem;
    line-height: 1.05;
  }

  .game-eyebrow {
    font-size: 0.95rem;
  }

  .leaderboard-row {
    grid-template-columns: 1fr;
    justify-items: stretch;
    gap: 6px;
  }

  .leaderboard-input {
    min-width: 0;
  }

  .leaderboard-entry {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .overlay-changelog {
    width: 100%;
    box-sizing: border-box;
    gap: 6px;
    padding: 8px 10px;
  }

  .game-footer p {
    font-size: 0.82rem;
  }

  .game-version {
    font-size: 0.76rem;
  }

}

@media (max-width: 520px) {
  .game-shell {
    padding:
      max(2px, env(safe-area-inset-top))
      2px
      max(4px, env(safe-area-inset-bottom));
  }

  .game-panel {
    width: calc(100vw - 4px);
    min-height: calc(100dvh - max(2px, env(safe-area-inset-top)) - max(4px, env(safe-area-inset-bottom)) - 4px);
    max-height: calc(100dvh - max(2px, env(safe-area-inset-top)) - max(4px, env(safe-area-inset-bottom)) - 4px);
    padding: 5px;
    gap: 4px;
    border-radius: 14px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud-card {
    padding: 6px 9px;
  }

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

  .hud-card strong {
    font-size: 0.94rem;
  }

  .hud-toggle-button,
  .game-button {
    font-size: 0.92rem;
  }

  .hud-toggle-button {
    font-size: 1.2rem;
  }

  .hud-toggle-button-text {
    font-size: 0.54rem;
  }

  .hud-actions {
    grid-template-columns: 42px 42px minmax(0, 1fr);
    gap: 6px;
  }

  .hud-actions .hud-toggle-button-compact {
    width: 42px;
    min-width: 42px;
    max-width: 42px;
    height: 42px;
    min-height: 42px;
  }

  .game-stage {
    min-height: 0;
    padding-bottom: 10px;
  }

  .game-overlay-card {
    width: min(340px, calc(100% - 28px));
    max-height: calc(100% - 16px);
    padding: 12px;
  }

  .game-overlay-card h2 {
    font-size: 1.65rem;
  }

  .overlay-changelog-title {
    font-size: 0.92rem;
  }

  .overlay-changelog-list {
    font-size: 0.92rem;
  }
}
