@font-face {
  font-family: "BestTen-CRT";
  src: url("../fonts/BestTen-CRT.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #20231f;
  --lcd-ink: #1b2924;
  --lcd-left: 20.703%;
  --lcd-top: 18.26%;
  --lcd-width: 58.984%;
  --lcd-height: 57.813%;
  color: var(--ink);
  font-family: "BestTen-CRT", "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(rgba(255, 247, 230, .22), rgba(222, 241, 235, .18)),
    url("../game/page-check-bg.webp");
  background-size: auto, 360px 360px;
  background-position: center;
  background-repeat: repeat;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

body {
  min-height: 100svh;
}

button {
  appearance: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0;
  outline: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button:focus,
button:focus-visible,
.screen:focus,
.screen:focus-visible,
canvas:focus,
canvas:focus-visible {
  outline: 0;
}

.game-app {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  opacity: 1;
  transition: opacity .18s ease;
}

.game-app.is-screen-full {
  position: fixed;
  inset: 0;
  z-index: 8;
  padding: 0;
  background: #000;
}

.is-loading .game-app {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.handheld {
  position: relative;
  width: min(1536px, calc(100vw - 16px), calc((100svh - 16px) * 1.5));
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: clamp(22px, 4.2vw, 66px);
  filter: drop-shadow(0 26px 48px rgba(38, 34, 27, .22));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-app.is-screen-full .handheld {
  overflow: visible;
  border-radius: 0;
  filter: none;
}

.shell-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-app.is-screen-full .shell-canvas {
  opacity: 0;
  pointer-events: none;
}

.screen-bezel {
  position: absolute;
  left: var(--lcd-left);
  top: var(--lcd-top);
  z-index: 2;
  width: var(--lcd-width);
  height: var(--lcd-height);
  overflow: hidden;
  border-radius: clamp(5px, 1.15vw, 18px);
}

.game-app.is-screen-full .screen-bezel {
  z-index: 4;
  border-radius: var(--screen-full-radius, 30px);
  transform-origin: top left;
  will-change: transform;
}

.screen {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: inherit;
  background:
    repeating-linear-gradient(0deg, rgba(23, 35, 31, .07) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(23, 35, 31, .05) 0 1px, transparent 1px 5px),
    #c6d0c3;
  filter: contrast(1.06) saturate(.78);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-app.is-screen-full .screen {
  border-radius: var(--screen-full-radius, 30px);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.fullscreen-toggle {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  z-index: 18;
  min-width: 48px;
  min-height: 33px;
  padding: 6px 10px;
  border: 2px solid rgba(39, 47, 41, .62);
  border-radius: 7px;
  background: rgba(231, 185, 87, .9);
  color: #29251d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .42), 0 5px 12px rgba(26, 24, 18, .16);
  font-family: "BestTen-CRT", "Courier New", ui-monospace, monospace;
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .1em;
  line-height: 1;
  touch-action: manipulation;
}

.fullscreen-toggle::before {
  content: "";
  position: absolute;
  inset: -15px;
}

.fullscreen-toggle__label {
  display: inline-block;
  transform: translateY(-2px);
}

.fullscreen-toggle[aria-pressed="true"] {
  background: rgba(157, 193, 173, .92);
}

.fullscreen-start {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 17;
  width: 96px;
  height: 96px;
  transform: translateX(-50%);
  border: 2px solid rgba(255, 255, 255, .32);
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: rgba(255, 255, 255, .74);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 0 24px rgba(255, 255, 255, .08);
  font-family: "BestTen-CRT", "Courier New", ui-monospace, monospace;
  font-size: .9rem;
  font-weight: 900;
  letter-spacing: .15em;
  text-indent: .3em;
}

.game-app:not(.is-screen-full) .fullscreen-start {
  display: none;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background:
    linear-gradient(rgba(255, 247, 230, .34), rgba(222, 241, 235, .22)),
    url("../game/page-check-bg.webp");
  background-size: auto, 360px 360px;
  color: #1e2722;
}

body:not(.is-loading) .loading-screen {
  display: none;
}

.loading-screen__panel {
  width: min(380px, 100%);
  padding: 18px;
  border: 2px solid rgba(45, 57, 50, .72);
  border-radius: 8px;
  background: rgba(239, 230, 207, .92);
  box-shadow: 0 14px 26px rgba(26, 24, 18, .2);
  font-family: "BestTen-CRT", "Courier New", ui-monospace, monospace;
  text-align: center;
}

.loading-screen__title,
.loading-screen__count {
  margin: 0;
  font-weight: 900;
}

.loading-screen__title {
  font-size: 1rem;
  line-height: 1.2;
}

.loading-screen__count {
  margin-top: 10px;
  font-size: .86rem;
}

.loading-screen__bar {
  height: 14px;
  margin-top: 12px;
  overflow: hidden;
  border: 2px solid rgba(31, 39, 34, .72);
  border-radius: 999px;
  background: #c6d0c3;
}

.loading-screen__bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: #e7b957;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .36);
  transition: width .16s ease;
}

.game-app[data-state="gameover"] .handheld {
  animation: hit-shake .34s cubic-bezier(.36, .07, .19, .97) both;
}

.install-prompt {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(32, 35, 31, .18);
}

.install-prompt__panel {
  justify-self: center;
  width: min(420px, 100%);
  padding: 14px;
  border: 2px solid rgba(45, 57, 50, .72);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 247, 230, .88), rgba(229, 239, 226, .9)),
    url("../game/page-check-bg.webp");
  background-size: auto, 220px 220px;
  box-shadow: 0 14px 26px rgba(26, 24, 18, .24);
  color: #1e2722;
  font-family: "BestTen-CRT", "Courier New", ui-monospace, monospace;
}

.install-prompt__title,
.install-prompt__text {
  margin: 0;
}

.install-prompt__title {
  font-size: 1rem;
  font-weight: 900;
}

.install-prompt__text {
  margin-top: 9px;
  font-size: .86rem;
  line-height: 1.7;
}

.install-prompt__actions {
  margin-top: 12px;
  text-align: right;
}

.install-prompt__button {
  min-width: 96px;
  min-height: 38px;
  padding: 8px 14px;
  border: 2px solid rgba(31, 39, 34, .72);
  border-radius: 999px;
  background: #f2c560;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .34);
  color: #20231f;
  font-size: .9rem;
  font-weight: 900;
}

@keyframes hit-shake {
  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }

  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%,
  60% {
    transform: translate3d(4px, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-app,
  .loading-screen__bar span {
    transition: none;
  }

  .game-app[data-state="gameover"] .handheld {
    animation: none;
  }
}
