/* Pixelify Sans – SIL Open Font License, self-hosted (public/fonts/OFL.txt). */
@font-face {
  font-family: 'Pixelify Sans';
  src: url('/fonts/PixelifySans.ttf') format('truetype');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --ink: #14121c;
  --navy: #1b1f3b;
  --navy-2: #262b52;
  --paper: #f4f1e8;
  --yellow: #e8c547;
  --teal: #2bb3a3;
  --red: #d84b4b;
  --sky: #9cc8f0;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  --grass: #5fa85a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--navy);
  color: var(--paper);
  font-family: var(--font);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

a {
  color: var(--yellow);
}

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

canvas {
  image-rendering: pixelated;
}

/* ---------------- buttons ---------------- */

.btn {
  font: inherit;
  font-family: var(--pixel);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  padding: 0.6em 1.1em;
  cursor: pointer;
  min-height: 44px; /* comfortable touch target */
  transition: transform 60ms;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-big {
  font-size: 1.15rem;
  padding: 0.8em 1.4em;
}

.btn-ghost {
  background: transparent;
  color: var(--paper);
  border-color: var(--paper);
  box-shadow: 0 4px 0 #0008;
}

.btn-teal {
  background: var(--teal);
}

.btn-red {
  background: var(--red);
  color: #fff;
}

/* ---------------- landing page ---------------- */

#landing {
  max-width: 1040px;
  margin: 0 auto;
  padding: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-r)) calc(1rem + var(--safe-b))
    calc(1rem + var(--safe-l));
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
}

.logo {
  font-weight: 800;
  font-size: 1.3rem;
  text-decoration: none;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--ink);
}

.site-header nav {
  display: flex;
  gap: 1rem;
}

.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 2rem;
  align-items: center;
  padding: 2rem 0 3rem;
}

.hero h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.15;
  margin: 0 0 1rem;
  text-shadow: 4px 4px 0 var(--ink);
}

.hero h1 em {
  color: var(--yellow);
  font-style: normal;
}

.lead {
  font-size: 1.1rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1.5rem 0 1rem;
}

.hero-art {
  display: flex;
  justify-content: center;
}

.hero-art canvas {
  width: min(100%, 320px);
  height: auto;
  filter: drop-shadow(6px 6px 0 var(--ink));
}

.small {
  font-size: 0.9rem;
  opacity: 0.85;
}

.card {
  background: var(--navy-2);
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 1.25rem 1.5rem;
  margin: 0 0 2rem;
}

.card h2 {
  margin-top: 0;
  color: var(--yellow);
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
}

caption {
  text-align: left;
  font-weight: 700;
  padding-bottom: 0.4rem;
}

th,
td {
  border: 2px solid var(--ink);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--navy);
}

code {
  background: var(--ink);
  padding: 0 0.3em;
}

.site-footer {
  text-align: center;
  opacity: 0.8;
  padding: 1rem 0 2rem;
}

@media (max-width: 720px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .hero-art {
    order: -1;
  }
  .hero-art canvas {
    width: min(60%, 220px);
  }
}

/* ---------------- game app ---------------- */

body.in-app {
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--navy);
  z-index: 10;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

#game {
  position: absolute;
  inset: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

#game canvas {
  display: block;
}

/* Screens (menus, editor, game over) sit on top of the game. */
#screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(0.75rem + var(--safe-t)) calc(0.75rem + var(--safe-r)) calc(0.75rem + var(--safe-b))
    calc(0.75rem + var(--safe-l));
  background: rgba(20, 18, 28, 0.72);
  overflow-y: auto;
  touch-action: pan-y;
}

#screen:empty {
  display: none;
}

.panel {
  background: var(--navy-2);
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 1.25rem;
  width: min(100%, 560px);
  max-height: 100%;
  overflow-y: auto;
  margin: auto;
}

.panel-wide {
  width: min(100%, 900px);
}

.panel h2 {
  margin: 0 0 0.75rem;
  color: var(--yellow);
  text-transform: uppercase;
  text-shadow: 3px 3px 0 var(--ink);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.center {
  text-align: center;
  justify-content: center;
}

.menu-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem;
  align-items: center;
}

.menu-grid .preview {
  width: 140px;
}

@media (max-width: 520px) {
  .menu-grid {
    grid-template-columns: 1fr;
    justify-items: center;
  }
}

.preview {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

.note {
  font-size: 0.85rem;
  opacity: 0.85;
}

.error {
  color: #ffb4b4;
}

/* Photo Booth / editor */
.editor {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 1.4fr;
  gap: 1.25rem;
}

@media (max-width: 680px), (max-height: 480px) and (orientation: landscape) {
  .editor {
    grid-template-columns: 1fr 1.4fr;
    gap: 0.75rem;
  }
}

@media (max-width: 480px) {
  .editor {
    grid-template-columns: 1fr;
  }
}

.editor .stage {
  background: linear-gradient(#7ec8f2, #d9f1ff 75%, #5fa85a 75%, #5fa85a 80%, #8a6243 80%);
  border: 3px solid var(--ink);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.5rem 0 1.5rem;
  min-height: 220px;
}

.editor .stage canvas {
  width: min(100%, 220px);
  height: auto;
}

fieldset {
  border: 2px solid var(--ink);
  margin: 0;
  padding: 0.5rem 0.6rem 0.6rem;
}

legend {
  font-weight: 700;
  padding: 0 0.3rem;
  font-size: 0.9rem;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.choice {
  font: inherit;
  font-size: 0.85rem;
  color: var(--paper);
  background: var(--navy);
  border: 2px solid var(--ink);
  padding: 0.35em 0.7em;
  min-height: 36px;
  cursor: pointer;
}

.choice[aria-pressed='true'] {
  background: var(--teal);
  color: var(--ink);
  font-weight: 700;
}

.choice:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.5rem;
}

.preset-grid button {
  padding: 0.3rem;
  background: var(--navy);
  border: 3px solid var(--ink);
  cursor: pointer;
}

.preset-grid button[aria-pressed='true'] {
  border-color: var(--yellow);
}

.preset-grid canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* Camera + crop */
.camera {
  position: relative;
  background: #000;
  border: 3px solid var(--ink);
}

.camera video {
  display: block;
  width: 100%;
  max-height: 55vh;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, like a real mirror */
}

.oval-guide {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  aspect-ratio: 3 / 4;
  transform: translate(-50%, -55%);
  border: 3px dashed rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  pointer-events: none;
}

.crop-box {
  position: relative;
  width: min(70vw, 256px, 50vh);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 3px solid var(--ink);
  cursor: grab;
  touch-action: none;
  overflow: hidden; /* keep the dark shade inside the box */
}

.crop-box canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

.crop-box::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(20, 18, 28, 0.55);
  pointer-events: none;
}

.dropzone {
  border: 3px dashed var(--sky);
  padding: 1rem;
  text-align: center;
}

.dropzone.over {
  background: rgba(156, 200, 240, 0.15);
}

label.slider {
  display: grid;
  grid-template-columns: 5.5em 1fr;
  align-items: center;
  gap: 0.5rem;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--yellow);
}

/* Settings toggles */
.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 0;
  border-bottom: 2px dashed #0006;
}

.toggle input {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--teal);
}

/* ---------------- HUD ---------------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: calc(0.5rem + var(--safe-t)) calc(0.75rem + var(--safe-r)) 0
    calc(0.75rem + var(--safe-l));
  font-weight: 800;
  text-shadow: 2px 2px 0 var(--ink);
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  font-size: clamp(1rem, 3.2vmin, 1.6rem);
}

.hud-stats {
  display: flex;
  gap: 1.2rem;
}

.hud-power {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8em;
}

.hud-power .bar {
  width: 70px;
  height: 10px;
  border: 2px solid var(--ink);
  background: #0006;
}

.hud-power .bar i {
  display: block;
  height: 100%;
  background: var(--yellow);
}

.pause-btn {
  pointer-events: auto;
  font: inherit;
  font-size: 1rem;
  width: 48px;
  height: 48px;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  font-size: clamp(1.2rem, 5vmin, 2.4rem);
  color: var(--yellow);
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  animation: banner 2.2s ease forwards;
}

/* RAM milestones and "he grabbed 6 GB" – small, under the score. */
.toast-line {
  position: absolute;
  left: 50%;
  top: calc(4.2rem + var(--safe-t, 0px));
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 0.25rem 0.7rem;
  font-size: clamp(0.85rem, 3.2vmin, 1.25rem);
  text-align: center;
  color: var(--paper);
  background: rgba(20, 18, 28, 0.75);
  border: 2px solid var(--ink);
  animation: banner 2.6s ease forwards;
}

/* Tiny RAM stick next to the GB count (CSS pixels, no image). */
.ram-ico {
  display: inline-block;
  width: 1.1em;
  height: 0.55em;
  margin-right: 0.3em;
  vertical-align: 0.1em;
  background:
    linear-gradient(
        90deg,
        #14121c 0 18%,
        transparent 18% 30%,
        #14121c 30% 48%,
        transparent 48% 60%,
        #14121c 60% 78%,
        transparent 78%
      )
      50% 30% / 80% 45% no-repeat,
    linear-gradient(#2f8a4a 0 75%, #e8c547 75%);
  border: 2px solid #14121c;
}

.chase {
  color: #ff6b6b;
  top: 15%;
  animation: blink 0.5s steps(2) infinite;
}

.hint {
  position: absolute;
  left: 50%;
  top: 34%; /* above the play area, so it never hides an obstacle */
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  padding: 0.4em 0.8em;
  font-size: clamp(0.9rem, 3.5vmin, 1.3rem);
  text-shadow: none;
  text-align: center;
}

@keyframes banner {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

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

@keyframes fadeout {
  70% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
  }
}

/* ---------------- overlays ---------------- */

#flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
}

#flash.on {
  animation: flash 350ms ease-out;
}

@keyframes flash {
  0% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
  }
}

.digitizer {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(20, 18, 28, 0.85);
  font-weight: 800;
  text-transform: uppercase;
  color: var(--yellow);
}

.digitizer canvas {
  width: min(40vmin, 220px);
  height: auto;
}

.digitizer .scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 0, 0, 0.25) 3px 4px);
  pointer-events: none;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 0.5rem 0.9rem;
  font-weight: 700;
  max-width: calc(100% - 2rem);
}

#toast:empty {
  display: none;
}

#toast .btn {
  min-height: 36px;
  padding: 0.3em 0.8em;
}

/* Respect "reduce motion" (OS setting or the in-game toggle). */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}

.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition: none !important;
}

/* Banners and touch hints are removed by a timer in JS, so with reduced
   motion they simply appear and disappear (no fade). */
.reduced-motion .banner {
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .banner {
    animation: none !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.screen-root {
  display: contents;
}

.crop-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
}

.crop-row .crop-box {
  margin: 0;
}

/* Cut-out mode: a checkerboard shows what is transparent; no round shade. */
.crop-box.cutout {
  background: repeating-conic-gradient(#3a3f66 0% 25%, #262b52 0% 50%) 0 0 / 16px 16px;
}

.crop-box.cutout::after {
  display: none;
}

.crop-preview {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
}

.crop-preview canvas {
  width: 128px;
  height: 128px;
  background: linear-gradient(#7ec8f2, #d9f1ff);
  border: 3px solid var(--ink);
}

/* ---------------- HUD v2 ---------------- */

.hud-top .stat {
  display: inline-block;
}

.stat.bump {
  animation: bump 220ms ease-out;
}

@keyframes bump {
  40% {
    transform: scale(1.3);
    color: var(--yellow);
  }
}

.pause-btn {
  width: auto;
  min-width: 52px;
  height: 52px;
  padding: 0 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.pad-toggle {
  pointer-events: auto;
  font: inherit;
  font-family: var(--pixel);
  font-size: 0.85rem;
  min-height: 44px;
  margin-left: auto;
  margin-right: 0.5rem;
  padding: 0 0.7rem;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.pause-btn small {
  font-size: 0.6rem;
  opacity: 0.7;
  margin-top: 2px;
}

.announce {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 10vmin, 5rem);
  color: var(--yellow);
  text-shadow: 5px 5px 0 var(--ink);
  animation: announce 800ms ease-out forwards;
}

@keyframes announce {
  0% {
    transform: translate(-50%, -50%) scale(2.2);
    opacity: 0;
  }
  25% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.hint kbd {
  display: inline-block;
  font: inherit;
  font-weight: 800;
  background: var(--ink);
  color: var(--paper);
  padding: 0.05em 0.45em;
  border-bottom: 3px solid #000;
  border-radius: 3px;
  animation: keypress 0.8s steps(2) infinite;
}

@keyframes keypress {
  50% {
    transform: translateY(2px);
    border-bottom-width: 1px;
  }
}

.hint-nice {
  background: var(--teal);
}

.touch-guide {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}

.touch-guide .zone {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10%;
  text-align: center;
  font-size: clamp(1rem, 4vmin, 1.6rem);
  opacity: 0;
}

.touch-guide[data-zone='left'] .left,
.touch-guide[data-zone='right'] .right {
  opacity: 1;
  background: rgba(232, 197, 71, 0.18);
  border: 4px dashed var(--yellow);
  animation: glow 0.9s ease-in-out infinite;
}

@keyframes glow {
  50% {
    background: rgba(232, 197, 71, 0.32);
  }
}

.reduced-motion .announce {
  animation: none !important;
}

/* ---------------- type ---------------- */

h1,
h2,
h3,
.logo,
.hud-top,
.announce,
.banner,
.hint,
.choice,
legend,
.loader-text {
  font-family: var(--pixel);
}

h1,
h2,
.panel h2 {
  text-transform: none;
  letter-spacing: 0.01em;
}

/* ---------------- loader ---------------- */

.loader {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: var(--navy);
  padding: 1rem;
}

[data-loader] .loader {
  position: static;
  background: transparent;
}

.loader-screen {
  position: relative;
  width: min(80vw, 320px);
  aspect-ratio: 16 / 9;
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  overflow: hidden;
}

.loader-screen canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.loader-screen .scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 0, 0, 0.18) 3px 4px);
  pointer-events: none;
}

.loader-text {
  margin: 0;
  color: var(--yellow);
  font-size: 1.1rem;
}

.loader-bar {
  width: min(70vw, 260px);
  height: 12px;
  border: 3px solid var(--ink);
  background: var(--navy-2);
  overflow: hidden;
}

.loader-bar i {
  display: block;
  height: 100%;
  width: 40%;
  background: repeating-linear-gradient(90deg, var(--yellow) 0 8px, #b8902a 8px 12px);
  animation: digitize 1.1s steps(10) infinite;
}

@keyframes digitize {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(250%);
  }
}

/* ---------------- landing v2 + pages ---------------- */

#landing,
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-r)) calc(1rem + var(--safe-b))
    calc(1rem + var(--safe-l));
}

.site-header nav {
  flex-wrap: wrap;
  align-items: center;
}

.site-header nav a {
  font-family: var(--pixel);
  color: var(--paper);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 3px solid transparent;
}

.site-header nav a:hover,
.site-header nav a[aria-current='page'] {
  border-bottom-color: var(--yellow);
}

.site-header nav .nav-play {
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  padding: 0.2rem 0.8rem;
}

.hero h1 {
  font-size: clamp(2rem, 5.5vw, 3.4rem);
  line-height: 1.08;
}

.lead {
  max-width: 34em;
  line-height: 1.55;
}

/* The tablet: the one bold thing on the page – the "digitizer" from the cartoon. */
.tablet {
  margin: 0;
  justify-self: center;
  width: min(100%, 440px);
  padding: 18px 18px 34px;
  background: #3a3f66;
  border: 4px solid var(--ink);
  border-radius: 22px;
  box-shadow:
    inset 0 -6px 0 #2a2e4f,
    8px 8px 0 var(--ink);
  position: relative;
  transform: rotate(-2deg);
}

.tablet-screen {
  position: relative;
  border: 4px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #7ec8f2;
}

.tablet-screen canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tablet-screen .scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 0, 0, 0.12) 3px 4px);
  pointer-events: none;
}

.tablet-button {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  border-radius: 50%;
  background: var(--yellow);
  border: 3px solid var(--ink);
}

.steps {
  list-style: none;
  counter-reset: step;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  padding: 0;
  margin: 0 0 3rem;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 3rem;
  line-height: 1.45;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -0.1rem;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  font-family: var(--pixel);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--ink);
  background: var(--grass);
  border: 3px solid var(--ink);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.card-link {
  display: block;
  color: var(--paper);
  text-decoration: none;
  background: var(--navy-2);
  border: 3px solid var(--ink);
  padding: 1rem 1.1rem;
  box-shadow: 4px 4px 0 var(--ink);
}

.card-link h2 {
  margin: 0 0 0.35rem;
  font-size: 1.3rem;
  color: var(--yellow);
}

.card-link p {
  margin: 0;
  opacity: 0.9;
}

.card-link:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ink);
}

@media (max-width: 760px) {
  .steps,
  .cards {
    grid-template-columns: 1fr;
  }
  .tablet {
    transform: none;
  }
}

/* Detail pages */
.prose {
  max-width: 44rem;
  line-height: 1.6;
  padding-bottom: 2rem;
}

.prose h1 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  line-height: 1.1;
  margin: 1.5rem 0 1rem;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--ink);
}

.prose h2 {
  margin-top: 2.2rem;
  color: var(--yellow);
}

.prose dt {
  font-weight: 700;
  margin-top: 0.6rem;
}

.prose dd {
  margin-left: 0;
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose table {
  min-width: 0;
}

kbd {
  font-family: var(--pixel);
  background: var(--ink);
  color: var(--paper);
  padding: 0 0.4em;
  border-bottom: 3px solid #000;
  border-radius: 3px;
}

.control-set {
  background: var(--navy-2);
  border: 3px solid var(--ink);
  padding: 0.5rem 1rem 0.75rem;
  margin-bottom: 1rem;
}

.control-set h3 {
  margin: 0.4rem 0;
}

details summary {
  cursor: pointer;
  font-family: var(--pixel);
  color: var(--yellow);
  margin-bottom: 0.75rem;
}

.creator .links {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.site-footer p {
  margin: 0.3rem 0;
}

a.btn {
  display: inline-block;
  text-decoration: none;
}

/* ---------------- title screen ---------------- */

.title-screen {
  text-align: center;
  width: min(100%, 520px);
}

.game-title {
  font-size: clamp(2rem, 7vmin, 3rem);
  margin-bottom: 0.5rem;
}

.title-scene {
  position: relative;
  border: 4px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  margin: 0 auto 1rem;
  max-width: 360px;
  background: #7ec8f2;
}

.title-scene canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.title-scene .scan {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0, 0, 0, 0.12) 3px 4px);
}

@media (max-height: 520px) and (orientation: landscape) {
  .title-screen {
    width: min(100%, 760px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
    align-items: center;
  }
  .game-title,
  .title-screen .stats,
  .title-screen .note {
    grid-column: 1 / -1;
  }
  .title-scene {
    margin: 0;
  }
}

.stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 1rem 0 0.5rem;
}

.stats div {
  text-align: center;
}

.stats dt {
  font-size: 0.8rem;
  opacity: 0.75;
}

.stats dd {
  margin: 0;
  font-family: var(--pixel);
  font-size: 1.2rem;
  color: var(--yellow);
}

.menu-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1rem;
}

.linklike {
  font: inherit;
  color: var(--yellow);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------------- Photo Booth tabs ---------------- */

.tabs {
  display: flex;
  gap: 0.3rem;
  border-bottom: 3px solid var(--ink);
}

.tab {
  font: inherit;
  font-family: var(--pixel);
  font-size: 1rem;
  color: var(--paper);
  background: var(--navy);
  border: 3px solid var(--ink);
  border-bottom: 0;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  min-height: 44px;
}

.tab[aria-selected='true'] {
  background: var(--yellow);
  color: var(--ink);
}

.tabpanel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 0.5rem;
}

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--paper);
  background: linear-gradient(#7ec8f2, #d9f1ff);
  border: 3px solid var(--ink);
  padding: 0.3rem 0.2rem 0.25rem;
  cursor: pointer;
}

.thumb canvas {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.thumb-body canvas {
  height: 80px;
}

.thumb span {
  background: var(--ink);
  padding: 0 0.3rem;
  width: 100%;
}

.thumb[aria-pressed='true'] {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px var(--yellow);
}

.thumb:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.6);
}

/* Phone fixes: never wider than the screen. */
.editor > * {
  min-width: 0;
}

@media (max-width: 480px) {
  .editor {
    grid-template-columns: minmax(0, 1fr);
  }
}

.tabs {
  flex-wrap: wrap;
}

.loader.loader-fixed {
  position: fixed;
  z-index: 60;
}

/* ---------------- v0.3: header, footer, mobile ---------------- */

/* Footer stays at the bottom of the screen on short pages. */
#landing,
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#landing > main,
.page > main {
  flex: 1;
}

.site-header {
  position: relative;
  gap: 0.75rem;
}

.site-header nav a[aria-current='page'] {
  border-bottom-color: var(--yellow);
  color: var(--yellow);
}

.header-play,
.menu-btn {
  display: none;
}

.menu-btn {
  width: 48px;
  height: 48px;
  background: var(--navy-2);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  place-items: center;
  padding: 0;
}

.menu-btn span,
.menu-btn span::before,
.menu-btn span::after {
  display: block;
  width: 22px;
  height: 3px;
  background: var(--paper);
  position: relative;
  content: '';
}

.menu-btn span::before {
  position: absolute;
  top: -7px;
}

.menu-btn span::after {
  position: absolute;
  top: 7px;
}

.menu-open .menu-btn span {
  background: transparent;
}

.menu-open .menu-btn span::before {
  top: 0;
  transform: rotate(45deg);
}

.menu-open .menu-btn span::after {
  top: 0;
  transform: rotate(-45deg);
}

@media (max-width: 640px) {
  .site-header {
    flex-wrap: nowrap;
  }
  .site-header .logo {
    margin-right: auto;
  }
  .header-play {
    display: inline-block;
    font-family: var(--pixel);
    text-decoration: none;
    color: var(--ink);
    background: var(--yellow);
    border: 3px solid var(--ink);
    box-shadow: 0 3px 0 var(--ink);
    padding: 0.55rem 0.9rem;
    min-height: 44px;
  }
  .menu-btn {
    display: grid;
  }
  .site-header nav {
    display: none;
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--navy-2);
    border: 3px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
  }
  .menu-open nav {
    display: flex;
  }
  .site-header nav a {
    padding: 0.9rem 1rem;
    font-size: 1.15rem;
    border-bottom: 2px solid var(--ink);
  }
  .site-header nav a[aria-current='page'] {
    border-bottom-color: var(--ink);
    background: var(--navy);
  }
  .site-header nav .nav-play {
    display: none;
  }
}

/* Footer */
.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1.5rem 0 calc(1.5rem + var(--safe-b));
  border-top: 3px solid var(--ink);
  margin-top: 1rem;
}

.site-footer .made {
  font-family: var(--pixel);
  font-size: 1.1rem;
  margin: 0;
}

.heart {
  color: var(--red);
  display: inline-block;
  animation: beat 1.4s ease-in-out infinite;
}

@keyframes beat {
  0%,
  60%,
  100% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.3);
  }
}

.social {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0;
  margin: 0;
}

.social a {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--paper);
  background: var(--navy-2);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
}

.social a:hover {
  color: var(--ink);
  background: var(--yellow);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1.25rem;
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.icon {
  display: block;
}

.feedback {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.feedback p {
  margin: 0;
}

.feedback .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.icon-btn {
  font: inherit;
  font-size: 1.1rem;
  width: 44px;
  height: 44px;
  color: var(--paper);
  background: transparent;
  border: 3px solid transparent;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--paper);
}

.title-screen {
  position: relative;
}

.exit-btn {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
}

.toast-close {
  color: var(--ink);
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* Sticky "Play now" bar on phones (shows once the hero button scrolls away). */
.sticky-play {
  display: none;
}

@media (max-width: 640px) {
  .sticky-play {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    padding: 0.6rem 1rem calc(0.6rem + var(--safe-b));
    background: rgba(27, 31, 59, 0.92);
    border-top: 3px solid var(--ink);
    transform: translateY(110%);
    visibility: hidden; /* hidden bar is not a button for screen readers or taps */
    transition:
      transform 200ms ease-out,
      visibility 0s 200ms;
  }
  .sticky-play.show {
    transform: none;
    visibility: visible;
    transition: transform 200ms ease-out;
  }
  .sticky-play .btn {
    width: 100%;
  }
  #landing {
    padding-bottom: 5rem;
  }
  /* Phone landing: title, tablet, Play – in that order. */
  .hero {
    gap: 1.25rem;
    padding: 0.5rem 0 2rem;
  }
  .hero-text {
    display: contents;
  }
  .hero h1 {
    order: 1;
    margin: 0;
  }
  .tablet {
    order: 2;
  }
  .hero .lead {
    order: 3;
    margin: 0;
  }
  .hero-actions {
    order: 4;
    margin: 0;
  }
  .hero-actions .btn-big {
    flex: 1;
  }
  .hero .small {
    order: 5;
    margin: 0;
  }
  .steps {
    gap: 0.9rem;
    margin-bottom: 2rem;
  }
  .card-link {
    padding: 0.8rem 1rem;
  }
  .prose {
    font-size: 1.02rem;
  }
}

/* ---------------- v0.3: touch pad, screens above it ---------------- */

#screen {
  z-index: 20;
}

#hud {
  z-index: 10;
}

#pad {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(1rem + var(--safe-r)) calc(1.25rem + var(--safe-b)) calc(1rem + var(--safe-l));
  pointer-events: none;
}

.pad-btn {
  pointer-events: auto;
  width: clamp(84px, 24vmin, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid rgba(20, 18, 28, 0.85);
  background: rgba(244, 241, 232, 0.28);
  color: #fff;
  font-family: var(--pixel);
  font-size: 1rem;
  text-shadow: 2px 2px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pad-btn span {
  font-size: 1.4rem;
  line-height: 1;
}

.pad-jump {
  background: rgba(232, 197, 71, 0.45);
}

.pad-btn.down {
  transform: scale(0.92);
  background: rgba(232, 197, 71, 0.75);
}

.pad-btn.glow {
  box-shadow: 0 0 0 4px var(--yellow);
  animation: glow 0.9s ease-in-out infinite;
}

select {
  font: inherit;
  font-size: 1rem;
  color: var(--paper);
  background: var(--navy);
  border: 3px solid var(--ink);
  padding: 0.4rem 0.5rem;
  min-height: 44px;
}

.mobile-only {
  display: none;
}

/* ---------------- Photo Booth on phones ---------------- */

@media (max-width: 640px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: inline-block;
  }
  #screen {
    padding: calc(0.25rem + var(--safe-t)) 0.25rem calc(0.25rem + var(--safe-b));
  }
  .booth {
    width: 100%;
    padding: 0.75rem 0.75rem 0;
    box-shadow: none;
  }
  .booth h2 {
    font-size: 1.3rem;
    margin-bottom: 0.4rem;
  }
  .booth .editor {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
  }
  /* Small preview that stays in view while you scroll the options. */
  .booth .stage {
    position: sticky;
    top: -0.75rem;
    z-index: 2;
    min-height: 0;
    height: 30vh;
    padding: 0.25rem 0 0.75rem;
  }
  .booth .stage canvas {
    width: auto;
    height: 100%;
  }
  .booth .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .booth .tab {
    flex: 0 0 auto;
  }
  .booth .thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .booth .thumb canvas {
    width: 56px;
    height: 56px;
  }
  /* Main actions in the thumb zone. */
  .booth-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0.75rem -0.75rem 0;
    padding: 0.6rem 0.75rem calc(0.6rem + var(--safe-b));
    background: var(--navy-2);
    border-top: 3px solid var(--ink);
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .booth-actions .btn {
    flex: 1;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    font-size: 0.95rem;
  }
  .booth-actions .btn-big {
    flex: 1 1 100%;
    order: -1;
  }
}

/* ---------------- share sheet + challenge ---------------- */

.challenge {
  display: inline-block;
  margin: 0 0 0.5rem;
  padding: 0.4rem 0.8rem;
  font-family: var(--pixel);
  color: var(--ink);
  background: #9cf3ff;
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
}

.challenge-result {
  font-family: var(--pixel);
  color: #9cf3ff;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 18, 28, 0.6);
}

.sheet-panel {
  width: min(100%, 520px);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--navy-2);
  border: 4px solid var(--ink);
  border-bottom: 0;
  padding: 1rem 1rem calc(1rem + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: left;
  animation: sheet-up 180ms ease-out;
}

@keyframes sheet-up {
  from {
    transform: translateY(40%);
    opacity: 0;
  }
}

@media (min-width: 641px) {
  .sheet {
    align-items: center;
  }
  .sheet-panel {
    border-bottom: 4px solid var(--ink);
    box-shadow: 8px 8px 0 var(--ink);
  }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet h3,
.sheet h4 {
  margin: 0;
  font-family: var(--pixel);
  color: var(--yellow);
}

.share-icons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.share-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 0.3rem;
  min-height: 72px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--paper);
  text-decoration: none;
  background: var(--navy);
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.share-icon:hover {
  background: var(--yellow);
  color: var(--ink);
}

.tablet-caption {
  position: absolute;
  left: 50%;
  bottom: -2.4rem;
  transform: translateX(-50%) rotate(2deg);
  white-space: nowrap;
  font-family: var(--pixel);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  padding: 0.15rem 0.6rem;
}

@media (max-width: 640px) {
  .tablet {
    margin-bottom: 1.5rem;
  }
}

/* Parody notes (About page box, footer line). */
.parody {
  padding: 0.6rem 0.8rem;
  border: 2px dashed var(--yellow);
}

.parody-note {
  opacity: 0.75;
  text-align: center;
}
