:root {
  --bg: #08081c;
  --jump: clamp(92px, 27vmin, 136px);
  --hammer: clamp(66px, 19vmin, 96px);
  --focus: #ffd23f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  font-family: "Courier New", monospace;
  color: #fff;
}

#app {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-areas:
    "bar"
    "stage";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  grid-area: stage;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* The canvas wrapper carries a subtle CRT scanline and vignette layer. */
#screen {
  position: relative;
  line-height: 0;
}

#screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0) 0,
      rgba(0, 0, 0, 0) calc(var(--scanline, 3px) * 0.6),
      rgba(0, 0, 0, 0.16) calc(var(--scanline, 3px) * 0.6),
      rgba(0, 0, 0, 0.16) var(--scanline, 3px)
    ),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 62%, rgba(0, 0, 0, 0.32) 100%);
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Toolbar ---------- */

.toolbar {
  grid-area: bar;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px 10px 4px;
}

.toolbar button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: #1f1f4a;
  border: 2px solid #4a4a99;
  color: #ffffff;
  font: bold 12px/1 "Courier New", monospace;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 60ms ease-out, background-color 60ms ease-out;
}

.toolbar button:active {
  transform: scale(0.95);
  background: #3d3d85;
}

#muteBtn[aria-pressed="false"] {
  color: #ff9ab8;
  border-color: #8a0f3a;
}

/* Buttons appear only where they make sense. */
#scoresBtn,
#clearBtn,
#pauseTbBtn {
  display: none;
}

html[data-state="title"] #scoresBtn,
html[data-demo="on"] #scoresBtn,
html[data-view="table"] #clearBtn {
  display: inline-block;
}

html:not(.touch):not([data-demo="on"])[data-state="ready"] #pauseTbBtn,
html:not(.touch):not([data-demo="on"])[data-state="playing"] #pauseTbBtn,
html:not(.touch):not([data-demo="on"])[data-state="dying"] #pauseTbBtn,
html:not(.touch):not([data-demo="on"])[data-state="transition"] #pauseTbBtn,
html:not(.touch)[data-state="paused"] #pauseTbBtn {
  display: inline-block;
}

/* Toolbar buttons drop focus after a mouse click, so :focus only ever
   shows for keyboard users. */
.toolbar button:focus,
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Touch controls (shown only in touch mode) ---------- */

.controls {
  display: none;
}

.touch .controls {
  display: contents;
}

.touch #app {
  grid-template-areas:
    "bar bar"
    "stage stage"
    "hint action";
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* The whole screen is the steering surface; this just explains it. */
.swipe-hint {
  grid-area: hint;
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  margin: 8px 0 max(14px, env(safe-area-inset-bottom)) 16px;
  color: #b8c0d8;
  font: bold 11px/1.2 "Courier New", monospace;
  letter-spacing: 1px;
  white-space: nowrap;
  pointer-events: none;
}

.hint-arrows {
  color: #7fdcff;
  font-size: 14px;
  letter-spacing: 2px;
}

/* Floating stick shown under the steering finger. */
.stick {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 10;
}

.stick.visible {
  opacity: 1;
}

.stick::before {
  content: "";
  position: absolute;
  left: -40px;
  top: -40px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid rgba(127, 220, 255, 0.55);
  background: rgba(31, 31, 74, 0.35);
}

.stick-knob {
  position: absolute;
  left: -16px;
  top: -16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(46, 230, 255, 0.85);
  border: 2px solid #b8f6ff;
}

.action {
  grid-area: action;
  justify-self: end;
  align-self: center;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 8px 12px max(14px, env(safe-area-inset-bottom)) 0;
}

.action button {
  font-family: inherit;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  touch-action: none;
  transition: transform 50ms ease-out, box-shadow 50ms ease-out;
}

.jump {
  width: var(--jump);
  height: var(--jump);
  border-radius: 50%;
  background: #ff2e63;
  border: 4px solid #ff9ab8;
  box-shadow: 0 6px 0 #8a0f3a;
  font-size: calc(var(--jump) * 0.2);
  letter-spacing: 1px;
}

.jump.pressed {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #8a0f3a;
  background: #ff5a85;
}

.hammer {
  width: var(--hammer);
  height: var(--hammer);
  border-radius: 50%;
  background: #2a2a3e;
  border: 3px solid #44445e;
  color: #8a8aa8;
  font-size: calc(var(--hammer) * 0.16);
}

.hammer.active {
  background: #ffd23f;
  border-color: #fff3b8;
  box-shadow: 0 5px 0 #9a7412;
  color: #1a1020;
}

.hammer.active.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #9a7412;
}

.pause {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  background: #1f1f4a;
  border: 2px solid #3d3d85;
  font-size: 18px;
}

.pause.pressed,
.pause:active {
  background: #3d3d85;
  transform: scale(0.94);
}

html[data-state="paused"] .pause {
  background: #2ee6ff;
  border-color: #b8f6ff;
  color: var(--bg);
}

@media (orientation: landscape) {
  .touch #app {
    grid-template-areas:
      "bar stage action"
      "hint stage action";
    grid-template-columns: minmax(150px, auto) minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .touch .toolbar {
    justify-content: flex-start;
    max-width: 190px;
    padding: 12px 0 0 20px;
  }

  .swipe-hint {
    align-self: end;
    margin: 0 10px max(24px, env(safe-area-inset-bottom)) 20px;
  }

  .action {
    align-self: stretch;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    margin: 16px 20px max(24px, env(safe-area-inset-bottom)) 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
