:root {
  color-scheme: dark;
  --shell: #eee5d6;
  --shell-edge: #8a8378;
  --panel: #c7b692;
  --panel-edge: #8f7d5f;
  --bezel: #2f3531;
  --lcd: #aeb8a7;
  --ink: #151a15;
  --red: #d83b2a;
  --red-shadow: #7a1d13;
  --metal: #d8d1c5;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(0.5rem, 2vw, 1.5rem);
  background:
    linear-gradient(135deg, #151515 0%, #2a2926 52%, #101010 100%);
  font-family: Arial, Helvetica, sans-serif;
}

.handheld {
  width: min(86rem, 98vw);
  display: grid;
  grid-template-columns: minmax(5.2rem, 7.2rem) minmax(0, 1fr) minmax(5.8rem, 7.8rem);
  gap: clamp(0.45rem, 1vw, 0.8rem);
  align-items: stretch;
  padding: clamp(0.55rem, 1.2vw, 1rem);
  border: 0.16rem solid #4e4b43;
  border-radius: 1rem;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 12%, rgba(0, 0, 0, 0.1) 100%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 0.12rem, transparent 0.12rem 0.32rem),
    linear-gradient(180deg, #f7f1e5 0%, var(--shell) 48%, #c9bdab 100%);
  box-shadow:
    inset 0 0 0 0.18rem rgba(255, 255, 255, 0.55),
    inset 0 -0.3rem 0.85rem rgba(74, 62, 47, 0.28),
    0 1.3rem 3rem rgba(0, 0, 0, 0.58);
}

.left-panel,
.right-panel {
  display: grid;
  align-content: space-between;
  min-width: 0;
  padding: clamp(0.5rem, 1.2vw, 0.9rem) 0;
}

.left-panel {
  align-content: end;
}

.screen-shell {
  min-width: 0;
  display: grid;
  align-items: center;
  padding: clamp(0.45rem, 1.05vw, 0.9rem);
  border-radius: 0.35rem;
  border: 0.16rem solid var(--panel-edge);
  background:
    linear-gradient(180deg, #e1d2ad, var(--panel) 55%, #a89470);
  box-shadow:
    inset 0.32rem 0 0 rgba(255, 255, 255, 0.35),
    inset -0.32rem 0 0 rgba(86, 65, 43, 0.16),
    0 0.18rem 0.24rem rgba(0, 0, 0, 0.25);
}

.screen-bezel {
  position: relative;
  padding: clamp(0.38rem, 0.75vw, 0.62rem);
  border: 0.18rem solid #f8f0df;
  border-radius: 0.68rem;
  background:
    linear-gradient(180deg, #f6f1e8, #d0cabf);
  box-shadow:
    inset 0 0 0 0.22rem var(--bezel),
    inset 0 0 0 0.44rem #e7e0d4,
    0 0.22rem 0.44rem rgba(0, 0, 0, 0.38);
}

canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1569 / 1002;
  display: block;
  border: 0.14rem solid #1a201d;
  border-radius: 0.36rem;
  background: var(--lcd);
  box-shadow:
    inset 0 0 1.15rem rgba(17, 24, 17, 0.48),
    inset 0 0 0 0.28rem rgba(235, 242, 223, 0.12);
}

.mode-stack {
  display: grid;
  gap: clamp(0.34rem, 0.9vw, 0.54rem);
  justify-items: center;
}

.mode-button {
  appearance: none;
  display: grid;
  gap: 0.14rem;
  justify-items: center;
  align-content: start;
  width: clamp(3.6rem, 6vw, 4.5rem);
  min-height: clamp(2.15rem, 4.5vw, 2.7rem);
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: clamp(0.62rem, 1.35vw, 0.82rem);
  font-weight: 900;
  letter-spacing: 0;
}

.mode-cap {
  width: clamp(2.05rem, 4vw, 2.7rem);
  height: clamp(1rem, 2vw, 1.25rem);
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.72), transparent 28%),
    linear-gradient(180deg, #f4f0e8, #aaa297 58%, #706a61);
  box-shadow:
    inset 0 0.12rem 0.12rem rgba(255, 255, 255, 0.62),
    inset 0 -0.18rem 0.18rem rgba(45, 40, 34, 0.34),
    0 0 0 0.12rem #777064,
    0 0.14rem 0.18rem rgba(0, 0, 0, 0.3);
}

.mode-label {
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 0.06rem 0 rgba(255, 255, 255, 0.62);
}

.mode-button:active .mode-cap,
.mode-button.is-active .mode-cap {
  transform: translateY(0.08rem);
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.6), transparent 28%),
    linear-gradient(180deg, #ddd7cc, #8d867b 58%, #625d55);
  box-shadow:
    inset 0 0.16rem 0.24rem rgba(31, 26, 21, 0.28),
    0 0 0 0.12rem #5d574f;
}

.pad {
  display: grid;
  gap: clamp(0.85rem, 2vw, 1.35rem);
  justify-items: center;
}

.red-button {
  position: relative;
  appearance: none;
  width: clamp(3.2rem, 6.6vw, 4.7rem);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  touch-action: manipulation;
  background:
    radial-gradient(circle at 32% 27%, #f07a61 0 11%, transparent 13%),
    radial-gradient(circle at 45% 43%, #d64831 0 46%, var(--red) 48% 66%, var(--red-shadow) 68% 100%);
  box-shadow:
    0 0 0 0.35rem var(--metal),
    0 0 0 0.52rem #827a70,
    inset 0.12rem 0.2rem 0.14rem rgba(255, 255, 255, 0.28),
    inset -0.2rem -0.28rem 0.22rem rgba(42, 6, 4, 0.55),
    0 0.2rem 0.22rem rgba(0, 0, 0, 0.42);
}

.red-button:active,
.red-button.is-active {
  transform: translateY(0.12rem);
  box-shadow:
    0 0 0 0.35rem var(--metal),
    0 0 0 0.52rem #827a70,
    inset 0.14rem 0.22rem 0.35rem rgba(42, 6, 4, 0.56),
    0 0.08rem 0.12rem rgba(0, 0, 0, 0.35);
}

.arrow {
  position: absolute;
  width: 0;
  height: 0;
  filter: drop-shadow(0 0.04rem 0 rgba(255, 255, 255, 0.3));
}

.arrow-left {
  left: -1.4rem;
  top: 50%;
  transform: translateY(-50%);
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
  border-right: 0.95rem solid var(--ink);
}

.arrow-right {
  right: -1.4rem;
  top: 50%;
  transform: translateY(-50%);
  border-top: 0.42rem solid transparent;
  border-bottom: 0.42rem solid transparent;
  border-left: 0.95rem solid var(--ink);
}

.arrow-up {
  left: 50%;
  top: -1.2rem;
  transform: translateX(-50%);
  border-left: 0.42rem solid transparent;
  border-right: 0.42rem solid transparent;
  border-bottom: 0.95rem solid var(--ink);
}

.arrow-down {
  left: 50%;
  bottom: -1.2rem;
  transform: translateX(-50%);
  border-left: 0.42rem solid transparent;
  border-right: 0.42rem solid transparent;
  border-top: 0.95rem solid var(--ink);
}

body.mobile-page {
  min-height: 100svh;
  display: block;
  padding: 0;
  overflow-x: hidden;
}

.mobile-game {
  width: min(100vw, 54rem);
  max-width: 100vw;
  min-height: 100svh;
  margin: 0 auto;
  display: grid;
  align-content: start;
  gap: clamp(0.55rem, 2vw, 0.95rem);
  padding: clamp(0.45rem, 1.8vw, 0.85rem);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 16%, rgba(0, 0, 0, 0.12) 100%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 0.12rem, transparent 0.12rem 0.32rem),
    linear-gradient(180deg, #f7f1e5 0%, var(--shell) 48%, #c9bdab 100%);
}

.mobile-game > * {
  min-width: 0;
  max-width: 100%;
}

.mobile-screen {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  justify-items: stretch;
}

.mobile-page .screen-bezel,
.mobile-page canvas {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.mobile-controls {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: grid;
  gap: clamp(0.9rem, 4vw, 1.4rem);
  justify-items: center;
  padding: clamp(0.75rem, 3vw, 1.2rem);
  border: 0.16rem solid #4e4b43;
  border-radius: 0.9rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0.12)),
    linear-gradient(180deg, #eee5d6, #cdbfae);
  box-shadow:
    inset 0 0 0 0.18rem rgba(255, 255, 255, 0.45),
    inset 0 -0.24rem 0.64rem rgba(74, 62, 47, 0.22),
    0 0.8rem 1.8rem rgba(0, 0, 0, 0.32);
}

.mobile-mode-stack {
  width: 100%;
  max-width: 28rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.35rem, 2vw, 0.7rem);
  justify-items: center;
}

.mobile-page .mode-button {
  width: auto;
  min-width: 0;
  min-height: 2.45rem;
  font-size: clamp(0.68rem, 2.8vw, 0.86rem);
}

.mobile-pad-grid {
  width: min(25rem, 88vw);
  display: grid;
  grid-template-columns: repeat(2, minmax(5.6rem, 1fr));
  gap: clamp(1.1rem, 6vw, 2.1rem) clamp(3rem, 16vw, 5.4rem);
  justify-items: center;
  padding: 0.5rem clamp(0.6rem, 3vw, 1rem) 0.7rem;
}

.mobile-page .red-button {
  width: clamp(4.4rem, 20vw, 5.8rem);
}

body.rotated-page {
  min-height: 100svh;
  width: 100vw;
  overflow: hidden;
  padding: 0;
}

.rotated-handheld {
  width: min(64vh, 118vw, 42rem);
  transform: rotate(90deg);
  transform-origin: center;
}

@media (max-width: 760px) {
  .handheld {
    grid-template-columns: 3.8rem minmax(0, 1fr) 4.3rem;
    gap: 0.28rem;
    padding: 0.42rem;
    border-radius: 0.85rem;
  }

  .screen-bezel {
    padding: 0.34rem;
  }

  .left-panel,
  .right-panel {
    padding: 0.25rem 0;
  }

  .arrow-left {
    left: -0.72rem;
    border-top-width: 0.28rem;
    border-bottom-width: 0.28rem;
    border-right-width: 0.58rem;
  }

  .arrow-right {
    right: -0.72rem;
    border-top-width: 0.28rem;
    border-bottom-width: 0.28rem;
    border-left-width: 0.58rem;
  }

  .arrow-up {
    top: -0.7rem;
    border-left-width: 0.28rem;
    border-right-width: 0.28rem;
    border-bottom-width: 0.58rem;
  }

  .arrow-down {
    bottom: -0.7rem;
    border-left-width: 0.28rem;
    border-right-width: 0.28rem;
    border-top-width: 0.58rem;
  }

  .mobile-page .arrow-left {
    left: -0.95rem;
    border-top-width: 0.34rem;
    border-bottom-width: 0.34rem;
    border-right-width: 0.72rem;
  }

  .mobile-page .arrow-right {
    right: -0.95rem;
    border-top-width: 0.34rem;
    border-bottom-width: 0.34rem;
    border-left-width: 0.72rem;
  }

  .mobile-page .arrow-up {
    top: -0.88rem;
    border-left-width: 0.34rem;
    border-right-width: 0.34rem;
    border-bottom-width: 0.72rem;
  }

  .mobile-page .arrow-down {
    bottom: -0.88rem;
    border-left-width: 0.34rem;
    border-right-width: 0.34rem;
    border-top-width: 0.72rem;
  }
}
