:root {
  --paper: #101012;
  --ink: #efefec;
  --muted: #a4a49f;
  --rule: #46464a;
  --hardware: #242426;
  --hardware-dark: #111113;
  --fire: #d33a2f;
  color-scheme: dark;
  font-family: Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

button,
a { font: inherit; }

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

.mobile-shell {
  --controller-size: min(46vw, 224px, calc(33.333svh - 64px));
  display: grid;
  grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
  width: 100%;
  height: 100svh;
  overflow: hidden;
  background: #000;
}

.screen-stage {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  align-items: center;
  justify-items: center;
  width: 100%;
  margin: 0;
  background: #000;
}

.project-link {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 3;
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(239 239 236 / 18%);
  box-shadow: 0 0 6px rgb(239 239 236 / 10%);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.project-link span { opacity: .55; }
.project-link:hover,
.project-link:focus-visible,
.project-link:active {
  background: rgb(239 239 236 / 24%);
  box-shadow: 0 0 9px rgb(239 239 236 / 18%);
}
.project-link:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.game-title {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 12px 20px 4px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.game-title small {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: .02em;
  line-height: 1.25;
}

#emulatorContainer,
#emulatorSize,
#screenCanvasFs {
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
}

#emulatorContainer {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

#screenCanvas {
  display: block;
  width: 384px;
  height: 272px;
  background: #000;
  image-rendering: pixelated;
  touch-action: manipulation;
}

#mobileGameCanvas {
  display: block;
  justify-self: center;
  align-self: center;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  image-rendering: pixelated;
}

.screen-stage[data-fit="width"] #mobileGameCanvas {
  width: 100%;
  height: auto;
}

.screen-stage[data-fit="height"] #mobileGameCanvas {
  width: auto;
  height: 100%;
}

@media (min-width: 761px) {
  .mobile-shell.is-native-c64 #mobileGameCanvas {
    /* 24:17 expressed without CSS multiplication/division for wider browser support. */
    width: min(100vw, calc(141.176dvh - 494px));
    max-width: none;
    height: auto;
    max-height: 100%;
    aspect-ratio: 24 / 17;
  }
}

.touch-controller {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  padding: 4px 0 max(6px, env(safe-area-inset-bottom));
  background: #000;
  touch-action: none;
}

.controller-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(60px, 1fr) var(--controller-size) minmax(60px, 1fr);
  align-items: center;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-left));
  touch-action: none;
}

.joystick-base {
  position: relative;
  grid-column: 2;
  width: 100%;
  margin: 0;
  aspect-ratio: 1;
  border: 1px solid #39393c;
  border-radius: 13%;
  background:
    linear-gradient(145deg, #323235 0%, #1a1a1c 46%, #0e0e10 100%);
  box-shadow:
    inset 0 1px 1px rgb(255 255 255 / 10%),
    inset 0 -5px 10px rgb(0 0 0 / 42%),
    0 8px 18px rgb(0 0 0 / 28%);
  cursor: grab;
  touch-action: none;
}

.joystick-base.is-active { cursor: grabbing; }

.joystick-gate {
  position: absolute;
  inset: 10%;
  border: 1px solid #404044;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 22.5deg, rgb(255 255 255 / 3%) 0 44deg, transparent 44deg 45deg),
    radial-gradient(circle at 45% 40%, #29292c 0 38%, #151517 70%, #0b0b0d 100%);
  box-shadow:
    inset 0 4px 10px rgb(0 0 0 / 60%),
    0 1px 0 rgb(255 255 255 / 6%);
}

.joystick-stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border: 1px solid #080809;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #4a4a4e 0 7%, #242427 42%, #09090b 100%);
  box-shadow: 0 10px 14px rgb(0 0 0 / 52%), inset 0 2px 2px rgb(255 255 255 / 9%);
  pointer-events: none;
  will-change: transform;
}

.joystick-grip {
  position: absolute;
  inset: 20%;
  border: 1px solid #333336;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, #202023 0 2px, #111113 3px 5px);
}

.fire-pod {
  position: absolute;
  bottom: 6px;
  left: 6px;
  z-index: 2;
  pointer-events: none;
}

.fire-button {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  color: #fff;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}

.fire-button::before {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 1px solid #751c17;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 28%, #ef685d 0 7%, var(--fire) 45%, #811d17 100%);
  box-shadow: 0 3px 0 #651813, 0 6px 9px rgb(0 0 0 / 38%);
  content: "";
}

.fire-button span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.fire-button.is-active {
  translate: 0 2px;
}

.fire-button.is-active::before {
  box-shadow: 0 1px 0 #651813, 0 3px 6px rgb(0 0 0 / 38%);
}

.side-control {
  z-index: 2;
  display: grid;
  width: 52px;
  min-width: 52px;
  height: 52px;
  min-height: 52px;
  margin: 0;
  padding: 0;
  place-items: center;
  border: 1px solid #4b4b4f;
  border-radius: 50%;
  background: linear-gradient(145deg, #343438, #171719);
  box-shadow: inset 0 1px 1px rgb(255 255 255 / 9%), 0 5px 10px rgb(0 0 0 / 34%);
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  justify-self: center;
  touch-action: manipulation;
}

.reset-button { grid-column: 1; }
.mute-button { grid-column: 3; }

.mute-button.active {
  background: #111113;
  color: var(--muted);
}

.mute-button.is-audio-prompt {
  border-color: #4d8b5d;
  box-shadow:
    inset 0 1px 1px rgb(255 255 255 / 10%),
    0 0 12px rgb(98 210 126 / 34%),
    0 5px 10px rgb(0 0 0 / 34%);
  color: #d9ffe2;
}

.mute-button .fa { display: none; }

.touch-instruction {
  display: grid;
  min-height: 0;
  max-width: 32em;
  margin: 0 auto;
  padding: 4px 24px;
  place-items: center;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}

.touch-instruction span { display: block; }

@media (max-width: 340px) {
  .mobile-shell { --controller-size: min(44vw, 180px, calc(33.333svh - 58px)); }
  .controller-row { grid-template-columns: minmax(46px, 1fr) var(--controller-size) minmax(46px, 1fr); }
  .fire-button::before { width: 30px; height: 30px; }
  .side-control { width: 46px; min-width: 46px; height: 46px; min-height: 46px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .mobile-shell {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
    grid-template-rows: 1fr;
    align-items: start;
  }
  .screen-stage { height: 100svh; }
  .touch-controller { height: 100svh; padding-top: 10px; }
}

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