:root {
  --sky: #5c94fc;
  --sky-deep: #3d70db;
  --cream: #fff6d6;
  --ink: #24160e;
  --brick: #b84a28;
  --brick-dark: #71301f;
  --brick-light: #e3743f;
  --gold: #ffd83d;
  --gold-dark: #d58b00;
  --green: #3fae2a;
  --green-dark: #196b22;
  --screen: #75c96f;
  --white: #fffdf1;
  --shadow: rgba(22, 16, 10, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Courier New", "Lucida Console", monospace;
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 255, 255, 0.16) 0 4px, transparent 5px),
    radial-gradient(circle at 88% 78%, rgba(255, 255, 255, 0.12) 0 5px, transparent 6px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #68a7ff 0%, var(--sky) 46%, #3f78df 100%);
  background-size: 48px 48px, 72px 72px, 100% 8px, 100% 100%;
  overflow-x: hidden;
  image-rendering: pixelated;
}

button,
kbd {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(940px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.hud {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 14px;
  color: var(--white);
  text-shadow: 3px 3px 0 #173c87, 5px 5px 0 rgba(0, 0, 0, 0.16);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-coin {
  width: 38px;
  height: 46px;
  flex: 0 0 auto;
  background: var(--gold);
  border: 4px solid var(--ink);
  box-shadow:
    inset 4px 0 0 #fff28a,
    inset -4px 0 0 var(--gold-dark),
    4px 4px 0 rgba(0, 0, 0, 0.22);
  animation: coin-bob 1.15s steps(2, end) infinite;
}

.eyebrow {
  margin: 0 0 3px;
  color: #ffe66d;
  font-size: clamp(9px, 1.5vw, 12px);
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4.4vw, 42px);
  line-height: 0.98;
  letter-spacing: -0.08em;
}

.scoreboard {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.score-card {
  min-width: 92px;
  padding: 8px 11px 7px;
  text-align: right;
  background: #2b2019;
  border: 4px solid #111;
  box-shadow:
    inset 0 0 0 3px #684530,
    4px 4px 0 rgba(0, 0, 0, 0.2);
}

.score-card span {
  display: block;
  margin-bottom: 2px;
  color: #ffd83d;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.score-card strong {
  color: #fff;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1;
}

.best-card {
  background: #163b67;
}

.best-card span {
  color: #8ee8ff;
}

.screen-frame {
  position: relative;
  padding: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.2), transparent 18% 82%, rgba(0, 0, 0, 0.16)),
    var(--brick);
  border: 5px solid var(--ink);
  box-shadow:
    inset 0 0 0 5px var(--brick-light),
    inset 0 0 0 10px var(--brick-dark),
    0 9px 0 #1b100b,
    0 14px 24px var(--shadow);
}

.screen-bezel {
  position: relative;
  overflow: hidden;
  background: #111;
  border: 5px solid #101010;
  box-shadow: inset 0 0 0 3px #473125;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  background: var(--screen);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.screen-shine {
  position: absolute;
  inset: 17px;
  pointer-events: none;
  background: linear-gradient(116deg, rgba(255, 255, 255, 0.15) 0 7%, transparent 7.3% 100%);
  mix-blend-mode: screen;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 50% 44%, rgba(5, 14, 30, 0.2), rgba(5, 14, 30, 0.76)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 4px);
  opacity: 1;
  visibility: visible;
  transition: opacity 130ms steps(3, end), visibility 130ms;
}

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

.overlay-card {
  width: min(500px, 94%);
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
  background: var(--cream);
  border: 5px solid var(--ink);
  box-shadow:
    inset 0 0 0 5px #fff,
    inset 0 0 0 9px #e5cda4,
    8px 8px 0 rgba(0, 0, 0, 0.28);
}

.overlay-kicker {
  margin: 0 0 9px;
  color: var(--brick);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.overlay h2 {
  margin: 0 0 12px;
  color: #2d2018;
  font-size: clamp(24px, 4.2vw, 38px);
  line-height: 1.06;
  letter-spacing: -0.08em;
}

.overlay p:not(.overlay-kicker) {
  max-width: 390px;
  margin: 0 auto 18px;
  color: #5d4839;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
}

.key-guide {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
  margin: 0 0 21px;
}

.key-guide span {
  display: flex;
  gap: 4px;
}

.key-guide i {
  color: #8a725d;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 27px;
  padding: 0 5px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  background: #3b2d25;
  border: 2px solid #17100c;
  box-shadow: inset 0 -3px 0 #1a110d, 2px 2px 0 rgba(0, 0, 0, 0.17);
}

.pixel-btn {
  position: relative;
  min-height: 47px;
  padding: 12px 22px;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: var(--brick);
  border: 4px solid var(--ink);
  box-shadow:
    inset 0 0 0 3px #e77743,
    inset 0 -6px 0 var(--brick-dark),
    5px 5px 0 rgba(0, 0, 0, 0.25);
  transition: transform 70ms steps(1, end), filter 70ms;
}

.pixel-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.pixel-btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow:
    inset 0 0 0 3px #e77743,
    inset 0 -6px 0 var(--brick-dark),
    2px 2px 0 rgba(0, 0, 0, 0.25);
}

.pixel-btn:focus-visible,
.dpad:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 4px;
}

.pixel-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.55;
}

.pixel-btn.primary {
  min-width: 170px;
  background: #e49a1f;
  box-shadow:
    inset 0 0 0 3px #ffe16a,
    inset 0 -6px 0 #a85b00,
    5px 5px 0 rgba(0, 0, 0, 0.25);
}

.pixel-btn.primary:active:not(:disabled) {
  box-shadow:
    inset 0 0 0 3px #ffe16a,
    inset 0 -6px 0 #a85b00,
    2px 2px 0 rgba(0, 0, 0, 0.25);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 11px 13px;
  background: rgba(24, 32, 42, 0.88);
  border: 4px solid #101010;
  box-shadow: inset 0 0 0 3px #435064, 5px 5px 0 rgba(0, 0, 0, 0.22);
}

.status-light {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #d8e6f3;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.status-dot {
  width: 13px;
  height: 13px;
  background: #7a8795;
  border: 3px solid #101010;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
}

.status-dot.active {
  background: #55e653;
  animation: blink 0.7s steps(2, end) infinite;
}

.status-dot.paused {
  background: #ffd83d;
}

.status-dot.over {
  background: #ff4b35;
}

.tool-buttons {
  display: flex;
  gap: 10px;
}

.pixel-btn.small {
  min-height: 39px;
  padding: 8px 12px;
  font-size: 11px;
  background: #3d75bd;
  box-shadow:
    inset 0 0 0 3px #6ea9ef,
    inset 0 -5px 0 #1d477a,
    4px 4px 0 rgba(0, 0, 0, 0.22);
}

.pixel-btn.small:active:not(:disabled) {
  box-shadow:
    inset 0 0 0 3px #6ea9ef,
    inset 0 -5px 0 #1d477a,
    2px 2px 0 rgba(0, 0, 0, 0.22);
}

.btn-icon {
  display: inline-block;
  margin-right: 4px;
  color: #ffe66d;
  font-weight: 900;
}

.mobile-pad {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  justify-content: center;
  gap: 7px;
  margin: 20px auto 4px;
  user-select: none;
}

.dpad {
  color: #fff;
  font-size: 19px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  background: #3d75bd;
  border: 4px solid #111;
  box-shadow:
    inset 0 0 0 3px #79b6f4,
    inset 0 -6px 0 #1d477a,
    4px 4px 0 rgba(0, 0, 0, 0.24);
}

.dpad:active {
  transform: translate(2px, 2px);
  box-shadow:
    inset 0 0 0 3px #79b6f4,
    inset 0 -4px 0 #1d477a,
    2px 2px 0 rgba(0, 0, 0, 0.24);
}

.dpad.up { grid-column: 2; grid-row: 1; }
.dpad.left { grid-column: 1; grid-row: 2; }
.dpad.down { grid-column: 2; grid-row: 2; }
.dpad.right { grid-column: 3; grid-row: 2; }

.footer-tip {
  margin: 20px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  text-shadow: 2px 2px 0 rgba(24, 49, 104, 0.8);
}

.footer-tip kbd {
  min-width: 24px;
  height: 22px;
  margin: 0 2px;
  font-size: 10px;
  vertical-align: 1px;
}

@keyframes coin-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes blink {
  50% { opacity: 0.42; }
}

@media (max-width: 720px) {
  .game-shell {
    width: min(100% - 18px, 620px);
    padding-top: 15px;
  }

  .hud {
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand-coin {
    width: 26px;
    height: 33px;
    border-width: 3px;
  }

  .eyebrow {
    display: none;
  }

  .scoreboard {
    gap: 6px;
  }

  .score-card {
    min-width: 70px;
    padding: 6px 7px 5px;
    border-width: 3px;
  }

  .score-card span {
    font-size: 8px;
  }

  .score-card strong {
    font-size: 18px;
  }

  .screen-frame {
    padding: 5px;
    border-width: 4px;
    box-shadow:
      inset 0 0 0 3px var(--brick-light),
      inset 0 0 0 6px var(--brick-dark),
      0 6px 0 #1b100b,
      0 10px 18px var(--shadow);
  }

  .screen-bezel {
    border-width: 3px;
  }

  .overlay {
    padding: 11px;
  }

  .overlay-card {
    padding: 17px 13px;
    border-width: 4px;
    box-shadow:
      inset 0 0 0 3px #fff,
      inset 0 0 0 6px #e5cda4,
      5px 5px 0 rgba(0, 0, 0, 0.28);
  }

  .overlay h2 {
    margin-bottom: 7px;
    font-size: 23px;
  }

  .overlay p:not(.overlay-kicker) {
    margin-bottom: 11px;
    font-size: 11px;
    line-height: 1.5;
  }

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

  .key-guide {
    margin-bottom: 12px;
  }

  kbd {
    min-width: 24px;
    height: 23px;
    font-size: 10px;
  }

  .pixel-btn.primary {
    min-width: 145px;
    min-height: 40px;
    padding: 9px 15px;
  }

  .toolbar {
    margin-top: 12px;
    padding: 8px;
    gap: 8px;
  }

  .status-light {
    font-size: 10px;
  }

  .pixel-btn.small {
    min-height: 35px;
    padding: 6px 8px;
    font-size: 9px;
  }

  .mobile-pad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(2, 52px);
    margin-top: 17px;
  }

  .footer-tip {
    display: none;
  }
}

@media (max-width: 430px) {
  .game-shell {
    width: calc(100% - 12px);
  }

  .score-card {
    min-width: 60px;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .pixel-btn.small {
    justify-content: center;
  }
}

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