#controller-body {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 250px;
  max-height: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px max(24px, calc((100% - 630px) / 2));
  background:
    repeating-linear-gradient(0deg, #ffffff12 0 1px, #00000005 1px 2px),
    linear-gradient(105deg, #aeaeae, #e5e5e5 30%, #c1c1c1 67%, #979797);
  border-top: 1px solid #f9f9f9;
  box-shadow: inset 0 2px 3px #fff9;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#controller-body:before,
#controller-body:after {
  content: "−";
  position: absolute;
  top: 14px;
  width: 12px;
  height: 12px;
  font: 12px/10px monospace;
  text-align: center;
  border-radius: 50%;
  color: #636363;
  background: linear-gradient(130deg, #ebebeb, #7e7e7e);
  box-shadow:
    0 1px 2px #0008,
    inset 0 1px #fff9;
}
#controller-body:before {
  left: 12px;
}
#controller-body:after {
  right: 12px;
}
.dpad-zone {
  position: relative;
  width: 130px;
  height: 150px;
  flex: none;
  touch-action: none;
}
.action-zone {
  position: relative;
  width: 190px;
  height: 150px;
  flex: none;
  touch-action: none;
}
.action-btn {
  position: absolute;
  display: none;
  width: 52px;
  height: 52px;
  border: 0;
  padding: 0;
  background: transparent;
  border-radius: 50%;
  isolation: isolate;
  color: #393939;
  font: bold 13px monospace;
  text-shadow: 0 1px #fff8;
  box-shadow:
    0 5px 1px #606060,
    0 8px 12px #0006;
  touch-action: none;
  transition:
    transform 0.045s,
    box-shadow 0.045s;
  overflow: hidden;
}
.metal-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}
.action-btn:after,
.analog-stick:after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    #fff7 25deg,
    transparent 60deg,
    #18181825 120deg,
    transparent 180deg,
    #fff6 205deg,
    transparent 240deg
  );
  mix-blend-mode: soft-light;
  animation: studio 18s linear infinite;
  pointer-events: none;
  z-index: -1;
}
.action-btn.active {
  transform: translateY(4px);
  box-shadow:
    0 1px 1px #515151,
    0 2px 4px #0006;
}
.action-btn.active:after {
  opacity: 0.35;
}
@keyframes studio {
  to {
    transform: rotate(360deg);
  }
}
.sys-btn {
  border: 1px solid #929292;
  color: #3a3a3a;
  background:
    repeating-linear-gradient(0deg, #ffffff12 0 1px, transparent 1px 2px),
    linear-gradient(#ebebeb, #a2a2a2);
  box-shadow:
    0 3px 0 #6a6a6a,
    0 5px 7px #0003,
    inset 0 1px #fff9;
  border-radius: 4px;
  min-width: 64px;
  min-height: 36px;
  font: 9px monospace;
  letter-spacing: 1px;
  touch-action: none;
}
.sys-btn.active {
  transform: translateY(3px);
  box-shadow: 0 1px 1px #636363;
}
.system-zone {
  position: absolute;
  bottom: max(15px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
}
.btn-shoulder {
  display: none;
  position: absolute;
  top: 12px;
  width: 85px;
}
.btn-shoulder.l {
  left: max(30px, calc((100% - 560px) / 2));
}
.btn-shoulder.r {
  right: max(30px, calc((100% - 560px) / 2));
}
.theme-snes .btn-shoulder {
  display: block;
}
.analog-base {
  position: absolute;
  inset: 10px 5px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: repeating-radial-gradient(circle, #818181 0 1px, #a4a4a4 2px 4px);
  border: 2px solid #cbcbcb;
  box-shadow:
    inset 0 5px 12px #0008,
    0 1px #fff;
  display: grid;
  place-items: center;
}
.analog-stick {
  position: relative;
  isolation: isolate;
  width: 67px;
  height: 67px;
  border-radius: 50%;
  box-shadow:
    0 12px 15px #0006,
    0 4px 2px #4c4c4c;
  pointer-events: none;
}
.theme-arcade .analog-stick {
  width: 73px;
  height: 73px;
}
.dpad {
  position: absolute;
  inset: 8px 3px;
  width: 124px;
  height: 124px;
  filter: drop-shadow(0 5px 2px #41414188);
}
.dpad-axis {
  position: absolute;
  border-radius: 5px;
  background: linear-gradient(110deg, #f0f0f0, #afafaf 50%, #d3d3d3);
  border: 1px solid #909090;
  box-shadow: inset 0 1px #fff;
}
.dpad-axis.vertical {
  width: 42px;
  height: 124px;
  left: 41px;
}
.dpad-axis.horizontal {
  height: 42px;
  width: 124px;
  top: 41px;
}
.dpad-center {
  position: absolute;
  left: 48px;
  top: 48px;
  width: 28px;
  height: 28px;
  border: 1px solid #858585;
  border-radius: 50%;
  background: radial-gradient(circle, #939393, #dcdcdc);
}
.dpad-btn {
  position: absolute;
  width: 41px;
  height: 41px;
  background: transparent;
  border: 0;
}
.dpad-btn.up {
  top: 0;
  left: 41px;
}
.dpad-btn.down {
  bottom: 0;
  left: 41px;
}
.dpad-btn.left {
  top: 41px;
  left: 0;
}
.dpad-btn.right {
  top: 41px;
  right: 0;
}
.dpad-btn.active {
  background: #58585855;
  border-radius: 4px;
}
.theme-arcade .action-btn:is(.a, .b, .c, .d),
.theme-snes .action-btn:is(.s-y, .s-x, .s-b, .s-a),
.theme-genesis .action-btn:is(.g-a, .g-b, .g-c, .g-x, .g-y, .g-z),
.theme-nes .action-btn:is(.n-b, .n-a) {
  display: block;
}
/* 52px faces, ~64px neighbour pitch. Centers follow a consistent thumb arc. */
.theme-arcade .a { left:0; top:84px; }
.theme-arcade .b { left:44px; top:38px; }
.theme-arcade .c { left:108px; top:38px; }
.theme-arcade .d { left:152px; top:84px; }
.theme-arcade .action-zone { width:204px; }
.s-y { left:24px; top:49px; }
.s-x { left:69px; top:4px; }
.s-b { left:69px; top:94px; }
.s-a { left:114px; top:49px; }
.s-y .metal-svg,.s-x .metal-svg { transform:rotate(180deg); }
/* A single 64px lattice rotated by 8.6 degrees: both rows have identical pitch. */
.g-x { left:0; top:24px; }
.g-y { left:63.28px; top:14.44px; }
.g-z { left:126.56px; top:4.88px; }
.g-a { left:9.56px; top:87.28px; }
.g-b { left:72.84px; top:77.72px; }
.g-c { left:136.12px; top:68.16px; }
.n-b { left:32px; top:65px; }
.n-a { left:99px; top:53px; }
.theme-nes .action-btn { width:56px; height:56px; }
.theme-arcade .sys-btn {
  border-radius: 2px;
}
.theme-snes #controller-body {
  border-radius: 0 0 70px 70px;
}
.theme-nes #controller-body {
  background:
    repeating-linear-gradient(0deg, #ffffff14 0 1px, transparent 1px 2px),
    linear-gradient(110deg, #afafaf, #e1e1e1, #b9b9b9);
}
@media (max-width: 400px) {
 #controller-body { padding-left:12px;padding-right:12px; }
 .dpad-zone { width:120px; }
 .action-zone { transform:scale(.94);transform-origin:right center;width:190px; }
 .theme-arcade .action-zone { width:204px;transform:scale(.88);margin-left:-12px; }
}
@media (max-width: 350px) {
 .dpad-zone { transform:scale(.86);transform-origin:left center;width:112px; }
 .action-zone { transform:scale(.88);margin-left:-8px;width:190px; }
 .theme-arcade .action-zone { transform:scale(.81);margin-left:-20px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  #controller-body {
    position: absolute;
    inset: 52px 0 0;
    max-height: none;
    min-height: 0;
    width: 100%;
    height: calc(100% - 52px);
    background: none !important;
    border: 0;
    box-shadow: none;
    pointer-events: none;
    padding: 10px;
  }
  .dpad-zone {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: auto;
  }
  .action-zone {
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%) scale(0.88);
    transform-origin: right center;
    pointer-events: auto;
  }
  .system-zone {
    left: 85px;
    bottom: 12px;
    gap: 5px;
    pointer-events: auto;
  }
  .sys-btn {
    min-width: 58px;
  }
  .btn-shoulder {
    pointer-events: auto;
  }
  .btn-shoulder.l {
    left: 35px;
  }
  .btn-shoulder.r {
    right: 40px;
  }
  #controller-body:before,
  #controller-body:after {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .action-btn:after,
  .analog-stick:after {
    animation: none;
  }
}
