:root {
  --paper: #f7f1df;
  --paper-deep: #e9dfc7;
  --ink: #17243b;
  --blue: #2778d0;
  --red: #e14a5a;
  --yellow: #f1bd36;
  --green: #2b9b68;
  --shadow: rgba(35, 42, 52, 0.2);
  font-family: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  touch-action: none;
}

button {
  font: inherit;
}

.game-shell,
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
  background: var(--paper);
}

.back-link {
  position: fixed;
  top: 13px;
  left: 14px;
  z-index: 55;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
  text-decoration: none;
  text-shadow: 0 1px var(--paper);
}

.hud {
  position: fixed;
  z-index: 20;
  top: 46px;
  left: 50%;
  width: min(680px, calc(100vw - 24px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  pointer-events: none;
}

.hud > div,
.best-row > div {
  padding: 9px 10px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  background: rgba(247, 241, 223, 0.9);
  box-shadow: 3px 3px 0 rgba(23, 36, 59, 0.18);
  text-align: center;
}

.hud span,
.best-row span,
.score-hero span {
  display: block;
  color: var(--blue);
  font: 0.52rem "Press Start 2P", monospace;
  line-height: 1.4;
}

.hud strong,
.best-row strong {
  display: block;
  margin-top: 5px;
  font-size: 1.05rem;
}

.draw-hint {
  position: fixed;
  z-index: 18;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%) rotate(-1deg);
  margin: 0;
  color: var(--blue);
  font: clamp(0.55rem, 2vw, 0.72rem) "Press Start 2P", monospace;
  pointer-events: none;
  animation: hintPulse 1.1s ease-in-out infinite alternate;
}

@keyframes hintPulse {
  to {
    opacity: 0.42;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 36, 59, 0.24);
  backdrop-filter: blur(3px);
}

.hidden {
  display: none !important;
}

.paper-card {
  position: relative;
  width: min(570px, 100%);
  padding: clamp(22px, 5vw, 38px);
  border: 3px solid var(--ink);
  border-radius: 4px 9px 5px 7px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 31px, rgba(39, 120, 208, 0.12) 31px 33px),
    var(--paper);
  box-shadow: 10px 12px 0 rgba(23, 36, 59, 0.24);
  text-align: center;
  transform: rotate(-0.35deg);
}

.paper-card::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 42px;
  width: 2px;
  background: rgba(225, 74, 90, 0.25);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--red);
  font: 0.58rem "Press Start 2P", monospace;
  line-height: 1.5;
}

h1,
h2 {
  position: relative;
  margin: 0;
  color: var(--ink);
  font-family: "Patrick Hand", cursive;
  line-height: 0.95;
}

h1 {
  font-size: clamp(3rem, 12vw, 5.4rem);
}

h2 {
  font-size: clamp(2rem, 8vw, 3.4rem);
}

.lead,
.small-copy {
  position: relative;
  margin: 18px auto;
  max-width: 440px;
  line-height: 1.55;
}

.lead {
  font-size: clamp(0.95rem, 3vw, 1.12rem);
}

.small-copy {
  margin-bottom: 0;
  color: #596377;
  font-size: 0.78rem;
}

.demo-line {
  position: relative;
  height: 75px;
  margin: 4px auto 15px;
}

.demo-line i {
  position: absolute;
  left: 24%;
  bottom: 14px;
  width: 48%;
  height: 5px;
  background: var(--blue);
  transform: rotate(-12deg);
  border-radius: 50%;
}

.demo-line b {
  position: absolute;
  right: 16%;
  bottom: 3px;
  color: var(--red);
  font: 2.4rem "Patrick Hand", cursive;
}

.runner-icon {
  position: absolute;
  left: 18%;
  bottom: 22px;
  font: 2rem "Patrick Hand", cursive;
  transform: rotate(8deg);
}

.best-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.best-row.three {
  grid-template-columns: repeat(3, 1fr);
}

.primary-btn,
.secondary-btn {
  position: relative;
  min-height: 48px;
  border: 3px solid var(--ink);
  border-radius: 5px 8px 4px 7px;
  padding: 11px 18px;
  color: var(--paper);
  background: var(--blue);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 1000;
  cursor: pointer;
}

.secondary-btn {
  color: var(--ink);
  background: var(--yellow);
}

.primary-btn:hover,
.secondary-btn:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-hero {
  margin: 18px 0;
}

.score-hero strong {
  display: block;
  color: var(--green);
  font: clamp(2.8rem, 12vw, 5rem) "Patrick Hand", cursive;
  line-height: 1;
}

.new-best {
  color: var(--red);
  font: 0.7rem "Press Start 2P", monospace;
}

@media (max-width: 620px) {
  .hud {
    top: 43px;
    grid-template-columns: 1fr 1fr;
  }

  .paper-card {
    padding: 22px 18px;
  }

  .paper-card::before {
    left: 24px;
  }

  .best-row.three {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .paper-card {
    width: min(760px, 94vw);
    padding: 16px 22px;
  }

  .lead,
  .small-copy {
    margin: 9px auto;
  }

  .demo-line {
    display: none;
  }

  .best-row {
    margin: 8px 0;
  }
}
