:root {
  color-scheme: light;
  --ink: #302d32;
  --muted: #756f6b;
  --paper: #f7f0df;
  --paper-deep: #eadfc7;
  --cream: #fffaf0;
  --red: #a94a37;
  --red-dark: #7b3327;
  --sky: #b9d7d6;
  --shadow: rgba(48, 45, 50, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.82), transparent 26rem),
    linear-gradient(180deg, #f8f2e5 0%, #e9dec6 100%);
  font-family: "Segoe UI", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
canvas {
  touch-action: manipulation;
}

button {
  color: inherit;
  font: inherit;
}

.page-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px) clamp(12px, 3vw, 28px) 28px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--red);
  font: 800 0.72rem/1.2 ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 5vw, 3.15rem);
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  font-weight: 900;
  transition: transform 100ms ease, box-shadow 100ms ease, background 100ms ease;
}

.icon-button:hover,
.icon-button[aria-pressed="true"] {
  background: #f3cbb9;
}

.icon-button:active {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

.game-card {
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: 8px 9px 0 var(--ink);
}

.game-stage {
  position: relative;
  aspect-ratio: 16 / 7;
  min-height: 220px;
  overflow: hidden;
  background: var(--sky);
  isolation: isolate;
}

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

#gameCanvas:focus-visible {
  box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 7px var(--red);
}

.scoreboard {
  position: absolute;
  z-index: 2;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 18px;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 3px 3px 0 rgba(48, 45, 50, 0.9);
  font: 700 clamp(0.65rem, 2.5vw, 0.86rem)/1 ui-monospace, "Cascadia Mono", monospace;
  white-space: nowrap;
}

.scoreboard strong {
  color: var(--red-dark);
  font-weight: 900;
  letter-spacing: 0.05em;
}

.game-overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  visibility: hidden;
  opacity: 0;
  background: rgba(48, 45, 50, 0.38);
  transition: opacity 150ms ease, visibility 150ms ease;
}

.game-overlay.is-visible {
  visibility: visible;
  opacity: 1;
}

.overlay-panel {
  width: min(500px, 94%);
  padding: clamp(16px, 3vw, 28px);
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: rgba(255, 250, 240, 0.97);
  box-shadow: 7px 7px 0 var(--ink);
  text-align: center;
}

.pixel-medallion {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 8px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: #fff;
  background: var(--red);
  box-shadow: 3px 3px 0 var(--ink);
  font: 900 1.2rem/1 ui-monospace, monospace;
}

.overlay-kicker {
  margin: 0 0 4px;
  color: var(--red);
  font: 800 0.7rem/1.2 ui-monospace, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.overlay-panel h2 {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 2.3rem);
  line-height: 1;
}

.overlay-panel > p:not(.overlay-kicker, .shortcut-hint) {
  margin: 10px auto 16px;
  max-width: 34rem;
  color: var(--muted);
  font-size: clamp(0.88rem, 2vw, 1rem);
}

.primary-button {
  min-height: 48px;
  padding: 10px 22px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  color: #fff;
  background: var(--red);
  box-shadow: 4px 4px 0 var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition: transform 100ms ease, box-shadow 100ms ease, background 100ms ease;
}

.primary-button:hover {
  background: var(--red-dark);
}

.primary-button:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--ink);
}

.shortcut-hint {
  margin: 13px 0 0;
  color: var(--muted);
  font: 650 0.75rem/1.35 ui-monospace, monospace;
}

.touch-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  border-top: 3px solid var(--ink);
  background: var(--paper-deep);
}

.control-button {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  font-weight: 800;
  user-select: none;
}

.control-button:active,
.control-button.is-active {
  transform: translate(3px, 3px);
  background: #f3cbb9;
  box-shadow: 0 0 0 var(--ink);
}

.control-icon {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 7px;
  font: 900 1.1rem/1 ui-monospace, monospace;
}

.game-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 6px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.game-footer p {
  margin: 0;
}

.game-footer strong {
  color: var(--ink);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--red-dark);
}

@media (min-width: 820px) {
  .touch-controls {
    display: none;
  }
}

@media (max-width: 700px) {
  .page-shell {
    padding-top: 14px;
  }

  .game-card {
    border-radius: 12px;
    box-shadow: 5px 6px 0 var(--ink);
  }

  .game-stage {
    aspect-ratio: 4 / 3;
  }

  .scoreboard {
    top: 9px;
    right: 9px;
    gap: 8px;
  }

  .overlay-panel {
    padding: 14px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .pixel-medallion {
    width: 36px;
    height: 36px;
  }

  .shortcut-hint {
    display: none;
  }

  .game-footer {
    display: none;
  }
}

@media (max-width: 420px) {
  .site-header {
    margin-bottom: 12px;
  }

  .header-actions {
    gap: 5px;
  }

  .icon-button {
    width: 39px;
    height: 39px;
    box-shadow: 2px 2px 0 var(--ink);
  }

  .control-button {
    min-height: 54px;
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
