:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", Arial, sans-serif;
  background: #070817;
  color: #f6f5ff;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --muted: #9c9cbe;
  --cyan: #62f4e3;
  --line: rgb(164 169 255 / 14%);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(ellipse at 50% 0%, rgb(91 58 164 / 16%), transparent 48%),
    #070817;
}

.game-shell {
  width: min(1100px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #0b0d27;
  box-shadow: 0 30px 100px rgb(0 0 0 / 45%), 0 0 70px rgb(89 63 185 / 10%);
}

.topbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1.5fr 0.55fr 0.55fr;
  align-items: center;
  gap: 28px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(110deg, rgb(29 30 72 / 65%), rgb(13 15 43 / 88%));
}

.brand,
.level-info,
.score-info,
.progress-info,
.progress-label {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
  color: #f7f5ff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.17em;
}

.brand-icon {
  color: var(--cyan);
  font-size: 22px;
  filter: drop-shadow(0 0 10px rgb(98 244 227 / 75%));
}

.level-info,
.score-info {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.eyebrow {
  color: var(--muted);
  font-family: "Courier New", monospace;
  font-size: 9px;
  letter-spacing: 0.16em;
}

.level-info strong,
.score-info strong {
  font-size: 20px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.coin-info strong {
  color: #ffd767;
}

#level-value {
  font-size: 12px;
  white-space: nowrap;
}

.progress-info {
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
}

.progress-label {
  justify-content: space-between;
  color: #d7d5f0;
  font-family: "Courier New", monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 8%);
  border-radius: 999px;
  background: rgb(4 5 20 / 80%);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8270ff, #62f4e3);
  box-shadow: 0 0 12px rgb(98 244 227 / 65%);
  transition: width 120ms linear;
}

.game-frame {
  position: relative;
  overflow: hidden;
  background: #101237;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  touch-action: none;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 24px;
  background: linear-gradient(90deg, rgb(7 8 25 / 40%), rgb(7 8 25 / 8%), rgb(7 8 25 / 38%));
  text-align: center;
  transition: opacity 180ms ease, visibility 180ms ease;
  overflow-y: auto;
  touch-action: pan-y;
}

.game-overlay.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  width: min(470px, 100%);
  flex: 0 0 auto;
  margin: auto;
  padding: 28px 30px;
  border: 1px solid rgb(191 187 255 / 18%);
  border-radius: 18px;
  background: rgb(13 15 44 / 82%);
  box-shadow: 0 16px 70px rgb(2 3 19 / 45%), inset 0 1px rgb(255 255 255 / 6%);
  backdrop-filter: blur(12px);
}

.overlay-kicker {
  color: var(--cyan);
  font-family: "Courier New", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
}

.overlay-card h1 {
  margin: 12px 0 9px;
  font-size: clamp(24px, 4vw, 37px);
  line-height: 1.1;
}

.overlay-card p {
  margin: 0 auto 22px;
  color: #c1c0dd;
  font-size: 14px;
  line-height: 1.55;
}

.level-picker {
  display: grid;
  grid-template-columns: auto 80px auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 13px;
}

.level-picker[hidden],
#choose-level[hidden],
[hidden] {
  display: none;
}

.level-picker input,
.overlay-card button {
  border: 1px solid rgb(185 190 255 / 35%);
  border-radius: 7px;
  padding: 8px;
  background: #22264f;
  color: #fff;
  font: inherit;
}

.level-picker input {
  width: 80px;
  touch-action: manipulation;
}

.overlay-card button {
  cursor: pointer;
  touch-action: manipulation;
}

.overlay-card button:focus-visible,
.level-picker input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

#unlocked-level {
  color: #c1c0dd;
  font-size: 11px;
}

#start-button,
.level-error {
  grid-column: 1 / -1;
}

.level-error {
  display: block;
  color: #ffb59b;
  font-size: 11px;
}

#choose-level {
  margin-bottom: 12px;
}

#open-shop {
  margin-bottom: 10px;
}

.skin-shop h2 {
  margin: 4px 0;
  font-size: 19px;
}

.secret-code {
  margin: 4px 0;
  text-align: right;
}

.secret-code summary {
  display: inline-block;
  padding: 6px 10px;
  color: #8987a9;
  font-size: 16px;
  cursor: pointer;
  list-style: none;
}

.secret-code summary::-webkit-details-marker {
  display: none;
}

.secret-code summary:hover,
.secret-code summary:focus-visible {
  color: var(--cyan);
}

#cheat-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin: 4px 0;
}

#cheat-code {
  width: 90px;
  padding: 6px;
  color: #fff;
  background: #171531;
  border: 1px solid #7467e8;
  border-radius: 6px;
}

#cheat-form button {
  padding: 6px 10px;
  font-size: 11px;
}

#cheat-message {
  flex-basis: 100%;
  color: #ffce75;
  font-size: 12px;
}

.skin-shop p {
  margin: 0 0 8px;
}

.skin-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 8px 0;
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.skin-options button[aria-pressed="true"] {
  border-color: var(--cyan);
  background: #315160;
}

.skin-options button::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: 3px;
  vertical-align: middle;
  background: var(--skin-preview);
}

.skin-options button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

#shop-message {
  display: block;
  min-height: 1em;
  margin: 4px 0;
  color: #ffce75;
  font-size: 11px;
}

.space-key,
.game-footer {
  display: flex;
  align-items: center;
}

.space-key {
  justify-content: center;
  gap: 12px;
  color: #e5e3fa;
  font-size: 12px;
}

kbd {
  min-width: 61px;
  padding: 7px 10px;
  border: 1px solid rgb(185 190 255 / 25%);
  border-bottom-width: 3px;
  border-radius: 7px;
  background: rgb(67 67 121 / 38%);
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-align: center;
}

.game-footer {
  min-height: 54px;
  justify-content: center;
  gap: 16px;
  padding: 10px 20px;
  color: var(--muted);
  font-size: 11px;
}

.game-footer kbd {
  min-width: auto;
  margin-right: 5px;
  padding: 4px 7px;
  font-size: 8px;
}

.footer-divider {
  color: #7975d7;
  font-size: 12px;
}

@media (max-width: 650px) {
  body {
    padding: 12px;
  }

  .game-shell {
    border-radius: 14px;
  }

  .topbar {
    min-height: 72px;
    grid-template-columns: 1fr auto auto auto;
    gap: 14px;
    padding: 12px 15px;
  }

  .brand {
    font-size: 10px;
    letter-spacing: 0.1em;
  }

  .brand-icon {
    font-size: 17px;
  }

  .progress-info {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .level-info,
  .score-info {
    justify-self: end;
  }

  .game-overlay {
    padding: 6px;
  }

  .overlay-card {
    padding: 10px;
  }

  .overlay-card h1 {
    margin: 5px 0;
    font-size: clamp(17px, 5vw, 25px);
  }

  .overlay-card p {
    margin-bottom: 6px;
    font-size: 10px;
    line-height: 1.3;
  }

  .overlay-kicker {
    font-size: 8px;
  }

  .space-key {
    font-size: 10px;
  }

  .level-picker {
    gap: 4px;
    margin-bottom: 5px;
    font-size: 11px;
  }

  .level-picker input,
  .overlay-card button {
    padding: 4px 8px;
  }

  .game-footer {
    min-height: 48px;
    gap: 8px;
    padding: 8px;
    font-size: 9px;
  }

  .game-footer kbd {
    padding: 3px 5px;
  }
}

@media (max-width: 650px), (max-height: 820px) {
  body {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .game-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }

  .topbar,
  .game-footer {
    flex: none;
  }

  .game-frame {
    flex: 1 1 0;
    min-height: 0;
  }

  canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .overlay-card button,
  .level-picker input {
    min-height: 44px;
  }
}

@media (max-height: 500px) and (min-width: 651px) {
  .topbar {
    min-height: 58px;
    gap: 16px;
    padding: 8px 18px;
  }

  .game-footer {
    min-height: 40px;
    padding: 6px 12px;
  }
}

@media (max-height: 500px) and (max-width: 650px) {
  .topbar {
    min-height: 0;
    gap: 4px 10px;
    padding: 6px 12px;
  }

  .progress-info {
    gap: 3px;
  }

  .score-info strong {
    font-size: 16px;
  }

  .game-footer {
    min-height: 32px;
    padding: 4px 8px;
  }
}

@media (max-width: 380px) {
  .topbar {
    grid-template-columns: 1fr auto auto;
  }

  .brand {
    display: none;
  }
}
