body {
  background: #031921;
  color: #fff;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue",
    Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
  margin: 0;
  padding: 0;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

#game {
  display: flex;
  flex-direction: column;
  position: absolute;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#game canvas {
  object-fit: contain;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  height: 100%;
}

#controller {
  display: none;
  position: fixed;
  bottom: 0px;
  height: 210px;
  width: 100%;
  touch-action: none;
  opacity: 0.8;
}

#controller_dpad {
  position: absolute;
  bottom: 20px;
  left: 0px;
  width: 184px;
  height: 184px;
}

#controller_dpad:before {
  content: "";
  display: block;
  width: 48px;
  height: 48px;
  background: #5c5c5c;
  background: radial-gradient(
    ellipse at center,
    #5c5c5c 0%,
    #555 59%,
    #5c5c5c 60%
  );
  position: absolute;
  left: 68px;
  top: 68px;
}

#controller_left {
  position: absolute;
  left: 20px;
  top: 68px;
  width: 48px;
  height: 48px;
  background: #666;
  background: radial-gradient(ellipse at center, #666 0%, #5c5c5c 80%);
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

#controller_right {
  position: absolute;
  left: 116px;
  top: 68px;
  width: 48px;
  height: 48px;
  background: #666;
  background: radial-gradient(ellipse at center, #666 0%, #5c5c5c 80%);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

#controller_up {
  position: absolute;
  left: 68px;
  top: 20px;
  width: 48px;
  height: 48px;
  background: #666;
  background: radial-gradient(ellipse at center, #666 0%, #5c5c5c 80%);
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

#controller_down {
  position: absolute;
  left: 68px;
  top: 116px;
  width: 48px;
  height: 48px;
  background: #666;
  background: radial-gradient(ellipse at center, #666 0%, #5c5c5c 80%);
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
}

#controller_a {
  position: absolute;
  bottom: 110px;
  right: 20px;
}

#controller_b {
  position: absolute;
  bottom: 80px;
  right: 100px;
}

.roundBtn {
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  font-size: 32px;
  color: #440f1f;
  line-height: 64px;
  width: 64px;
  height: 64px;
  border-radius: 64px;
  background: #870a4c;
  background: radial-gradient(ellipse at center, #ab1465 0%, #8b1e57 100%);
  box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.2);
}

.capsuleBtn {
  font-weight: bold;
  font-size: 10px;
  color: #111;
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 40px;
  text-transform: uppercase;
  width: 64px;
  height: 32px;
  border-radius: 40px;
  background: #222;
  background: radial-gradient(ellipse at center, #666 0%, #555 100%);
  box-shadow: 0px 4px 5px rgba(0, 0, 0, 0.2);
}

#controller_start {
  position: absolute;
  bottom: 20px;
  right: 15px;
}

#controller_select {
  position: absolute;
  bottom: 20px;
  right: 100px;
}

.btnPressed {
  opacity: 0.5;
}

.spinner {
  height: 50px;
  width: 50px;
  margin: 0px auto;
  -webkit-animation: rotation 0.8s linear infinite;
  -moz-animation: rotation 0.8s linear infinite;
  -o-animation: rotation 0.8s linear infinite;
  animation: rotation 0.8s linear infinite;
  border-left: 10px solid #306850;
  border-right: 10px solid #306850;
  border-bottom: 10px solid #306850;
  border-top: 10px solid #88c070;
  border-radius: 100%;
  background-color: #031921;
}
@-webkit-keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}
@-moz-keyframes rotation {
  from {
    -moz-transform: rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg);
  }
}
@-o-keyframes rotation {
  from {
    -o-transform: rotate(0deg);
  }
  to {
    -o-transform: rotate(360deg);
  }
}
@keyframes rotation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media only screen and (max-width: 640px) {
  #game canvas {
    margin-top: 0px;
    width: 100%;
    max-width: 512px;
    border: 0px;
    border-radius: 0px;
  }
}

@media only screen and (max-device-width: 812px) and (orientation: portrait) {
  body {
    margin: 0;
  }

  #game {
    width: 100%;
    position: fixed;
    touch-action: none;
  }

  #game canvas {
    margin: 0;
    display: block;
    width: 100% !important;
    height: auto !important;
  }
}

@media only screen and (max-device-width: 320px) and (orientation: portrait) {
  #controller_dpad {
    left: -5px;
    bottom: -5px;
  }

  #controller_a {
    right: 5px;
    bottom: 95px;
  }

  #controller_b {
    right: 80px;
  }

  #controller_start {
    right: 5px;
  }

  #controller_select {
    right: 80px;
  }
}

@media only screen and (max-width: 500px) and (max-height: 400px) {
  #controller {
    display: none;
  }
}

/* Small devices in landscape */
@media only screen and (max-device-width: 300px) and (orientation: landscape) {
  html,
  body {
    height: 100%;
  }
  body {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  #game:after {
    content: "PLEASE ROTATE ↻";
    font-size: 24px;
    font-weight: bold;
    color: #fff;
  }

  #game canvas {
    display: none;
    max-width: 480px;
  }

  #controller {
    display: none;
  }
}

/* Devices large enough for landscape */
@media only screen and (min-width: 300px) and (orientation: landscape) {
  #controller {
    bottom: 50%;
    transform: translateY(50%);
    opacity: 0.5;
  }
}

#debug {
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:10px;
  position:fixed;
  top:0px;
  left:0px;
  right:0px;
  bottom:0px;
  background:rgba(0,0,0,0.5);
}

#debug div {
  background: white;
  color: black;
  border: 1px solid #ddd;
  border-radius: 4px;
  transform: position;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  display: flex;
  align-items: center;
}

#debug span {
  padding: 5px 8px;
}

#debug button {
  background: transparent;
  border: none;
  border-left: 1px solid #ddd;
  display: flex;
  align-items: center;
  height: 100%;
}

#debug button:hover {
  background: #eee;
}

#debug button:active {
  background: #ddd;
}

/* Gem Quest presentation shell — the emulator and its original controls stay intact. */
html,
body {
  min-height: 100%;
}

body {
  display: grid;
  place-items: center;
  overflow: auto;
  background: radial-gradient(circle at 50% 5%, #5f668e, #1d2349 58%, #10142c);
  padding: 28px 16px;
  box-sizing: border-box;
}

.chromatic {
  width: min(100%, 720px);
  box-sizing: border-box;
  padding: 20px 28px 18px;
  border: 5px solid #24263d;
  border-radius: 24px 24px 42px 24px;
  color: #24263d;
  background: linear-gradient(135deg, #d7d9ec, #aeb4d5 60%, #9198bf);
  box-shadow: 0 18px 0 #11142a, 0 29px 48px rgba(0, 0, 0, 0.52), inset 2px 2px rgba(255,255,255,.65);
}

.device-topline,
.device-mark {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  letter-spacing: .12em;
}

.device-topline { font-size: 11px; margin: 0 3px 13px; }
.device-topline span:last-child { color: #8c2f66; }

.screen-bezel {
  position: relative;
  padding: 24px 24px 28px;
  border: 5px solid #30334f;
  border-radius: 13px 13px 28px 13px;
  background: #22253b;
  box-shadow: inset 0 0 0 3px #111329, inset 4px 4px #424664;
}

.screen-label {
  position: absolute;
  top: 7px;
  left: 27px;
  color: #d6d8e8;
  font-family: monospace;
  font-size: 8px;
  letter-spacing: .1em;
}

#game {
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 256 / 224;
  display: block;
  overflow: hidden;
  background: #202850;
}

#game canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.power-led {
  position: absolute;
  left: 9px;
  bottom: 16px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ee4e72;
  box-shadow: 0 0 7px #ee4e72;
}

.device-mark { margin: 13px 5px 2px; }
.device-mark strong { font-size: 18px; font-style: italic; letter-spacing: .07em; }
.device-mark span { font-size: 8px; letter-spacing: .08em; }

.hardware-controls {
  position: relative;
  height: 137px;
  margin: 0 6px;
}

.dpad-ornament,
.dpad-ornament::before,
.dpad-ornament::after {
  position: absolute;
  border-radius: 4px;
  background: linear-gradient(135deg, #5b5c6e, #303140);
  box-shadow: inset 2px 2px rgba(255,255,255,.22), 2px 3px 3px rgba(0,0,0,.28);
}

.dpad-ornament {
  left: 17px;
  top: 23px;
  width: 35px;
  height: 92px;
}

.dpad-ornament::before,
.dpad-ornament::after { content: ""; }
.dpad-ornament::before { width: 92px; height: 35px; left: -29px; top: 29px; }
.dpad-ornament::after { width: 28px; height: 28px; left: 4px; top: 32px; border-radius: 50%; background: #484958; box-shadow: inset 1px 1px rgba(0,0,0,.35); }

.button-ornament {
  position: absolute;
  right: 12px;
  top: 27px;
  display: flex;
  gap: 18px;
  transform: rotate(-12deg);
}

.button-ornament b {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: #510f35;
  font-size: 27px;
  background: radial-gradient(circle at 35% 28%, #d74188, #9b215c 72%);
  box-shadow: inset 2px 2px rgba(255,255,255,.28), 2px 4px 3px rgba(0,0,0,.28);
}

.small-buttons {
  position: absolute;
  right: 24px;
  top: 98px;
  display: flex;
  gap: 15px;
  transform: rotate(-12deg);
}

.small-buttons i {
  padding: 8px 10px;
  border-radius: 999px;
  color: #1e2031;
  background: #686a7c;
  font-size: 7px;
  font-style: normal;
  font-weight: 800;
  box-shadow: inset 1px 1px rgba(255,255,255,.2), 1px 2px 2px rgba(0,0,0,.22);
}

#controller {
  display: block;
  position: relative;
  bottom: auto;
  width: 100%;
  height: 145px;
  opacity: 1;
}

#controller_dpad {
  left: 3px;
  bottom: -5px;
  transform: scale(.72);
  transform-origin: left bottom;
}

#controller_a,
#controller_b { bottom: 43px; }
#controller_a { right: 20px; }
#controller_b { right: 105px; }
#controller_start,
#controller_select { bottom: 8px; }
#controller_start { right: 28px; }
#controller_select { right: 113px; }

.keyboard-help {
  margin: 0;
  text-align: center;
  color: #404565;
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 520px) {
  body { padding: 12px 6px; }
  .chromatic { padding: 14px 15px 13px; border-radius: 18px 18px 33px 18px; }
  .screen-bezel { padding: 22px 13px 24px; }
  .device-mark strong { font-size: 14px; }
  .device-mark span { font-size: 6px; }
  .hardware-controls { height: 96px; transform: scale(.82); transform-origin: top left; width: 122%; }
  #controller { height: 125px; }
  #controller_dpad { transform: scale(.58); }
  #controller_a, #controller_b { transform: scale(.78); transform-origin: bottom right; bottom: 36px; }
  #controller_a { right: 7px; }
  #controller_b { right: 67px; }
  #controller_start, #controller_select { transform: scale(.78); transform-origin: bottom right; bottom: 3px; }
  #controller_start { right: 12px; }
  #controller_select { right: 76px; }
  .keyboard-help { font-size: 9px; }
}

/* Keep GB Studio's original controller event targets, but place them over the
   visible hardware controls above. This makes the device buttons clickable. */
.hardware-controls #controller {
  display: block !important;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 137px;
  opacity: 1;
  pointer-events: none;
}

.hardware-controls #controller > * { pointer-events: auto; }
.hardware-controls #controller_dpad {
  position: absolute;
  left: 0;
  top: 0;
  width: 92px;
  height: 122px;
  bottom: auto;
  transform: none;
}
.hardware-controls #controller_dpad::before {
  content: none !important;
  display: none !important;
}

.hardware-controls #controller_dpad > div,
.hardware-controls #controller_a,
.hardware-controls #controller_b,
.hardware-controls #controller_start,
.hardware-controls #controller_select {
  position: absolute;
  display: block;
  margin: 0;
  padding: 0;
  opacity: 0;
  background: transparent;
  box-shadow: none;
  color: transparent;
  line-height: 1;
}

.hardware-controls #controller_left { left: 0; top: 52px; width: 31px; height: 35px; }
.hardware-controls #controller_right { left: 61px; top: 52px; width: 31px; height: 35px; }
.hardware-controls #controller_up { left: 30px; top: 23px; width: 35px; height: 30px; }
.hardware-controls #controller_down { left: 30px; top: 81px; width: 35px; height: 33px; }
.hardware-controls #controller_b { right: 84px; top: 27px; width: 54px; height: 54px; bottom: auto; }
.hardware-controls #controller_a { right: 12px; top: 27px; width: 54px; height: 54px; bottom: auto; }
.hardware-controls #controller_select { right: 94px; top: 98px; width: 56px; height: 28px; bottom: auto; }
.hardware-controls #controller_start { right: 23px; top: 98px; width: 56px; height: 28px; bottom: auto; }

.hardware-controls #controller_dpad > div:active,
.hardware-controls #controller_a:active,
.hardware-controls #controller_b:active,
.hardware-controls #controller_start:active,
.hardware-controls #controller_select:active { opacity: .24; background: #fff; }

/* Official-player-inspired page layout */
body {
  display: block;
  min-height: 100vh;
  padding: 0;
  background-color: #f8f4eb;
  background-image: radial-gradient(#ded4eb 1px, transparent 1px);
  background-size: 8px 8px;
  color: #322a47;
}

.player-page { max-width: 1040px; margin: 0 auto; padding: 28px 24px 44px; }
.player-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 3px solid #6d5a85;
  margin-bottom: 20px;
  padding: 0 4px 12px;
}
.player-header h1 { margin: 0; font-size: clamp(26px, 4vw, 38px); letter-spacing: -.04em; }
.player-header span { font-family: monospace; font-weight: 800; font-size: 12px; letter-spacing: .12em; }
.player-stage {
  display: grid;
  place-items: center;
  gap: 16px;
  min-height: 0;
  padding: 28px 20px 22px;
  border: 3px solid #6d5a85;
  background: rgba(248, 243, 255, .78);
}

.player-stage .chromatic {
  width: min(92vw, 300px);
  box-sizing: border-box;
  padding: 14px 17px 15px;
  border-width: 4px;
  border-radius: 20px 20px 36px 20px;
  box-shadow: 0 10px 0 #282039, 0 17px 28px rgba(40, 23, 65, .28), inset 2px 2px rgba(255,255,255,.65);
}
.player-stage .device-topline { margin-bottom: 8px; }
.player-stage .screen-bezel { padding: 19px 16px 22px; }
.player-stage .screen-label { left: 18px; top: 6px; font-size: 6px; }
.player-stage .power-led { left: 7px; bottom: 12px; }
.player-stage .device-mark { margin: 9px 3px 0; }
.player-stage .device-mark strong { font-size: 15px; }
.player-stage .device-mark span { font-size: 6px; }
.player-stage .hardware-controls { height: 106px; transform: scale(.88); transform-origin: top left; width: 114%; margin-bottom: -13px; }
.player-stage .keyboard-help { display: none; }

.player-tools { display: grid; place-items: center; gap: 12px; }
.color-row, .player-action-row { display: flex; align-items: center; justify-content: center; gap: 11px; }
.console-swatch {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 2px solid #665272;
  box-shadow: 2px 2px 0 rgba(42, 29, 61, .3);
  cursor: pointer;
}
.console-swatch.is-selected { outline: 3px solid #272033; outline-offset: 3px; }
.console-swatch[data-shell="cloud"] { background: #d7d9ec; }
.console-swatch[data-shell="midnight"] { background: #2e314e; }
.console-swatch[data-shell="wave"] { background: #73a9cf; }
.console-swatch[data-shell="leaf"] { background: #82ad6d; }
.console-swatch[data-shell="inferno"] { background: #d97253; }
.console-swatch[data-shell="volt"] { background: #ead66e; }
.console-swatch[data-shell="bubblegum"] { background: #d79abb; }
.player-action {
  width: 42px;
  height: 40px;
  border: 2px solid #5f5071;
  box-shadow: 3px 3px 0 #c6b9d1;
  color: #342946;
  background: #fffdf6;
  font: 800 21px/1 monospace;
  cursor: pointer;
}
.player-action:hover, .player-action:focus-visible { background: #eadff4; }
.official-help { margin: 0; font-size: 12px; font-weight: 700; }

body.shell-midnight .chromatic { background: linear-gradient(135deg, #434967, #252a45 60%, #1d2137); color: #eceeff; }
body.shell-wave .chromatic { background: linear-gradient(135deg, #c9e8f5, #76b5d9 60%, #5991bd); }
body.shell-leaf .chromatic { background: linear-gradient(135deg, #d4e7c1, #8cbb72 60%, #669952); }
body.shell-inferno .chromatic { background: linear-gradient(135deg, #f4c6a9, #d9775e 60%, #ad4c49); }
body.shell-volt .chromatic { background: linear-gradient(135deg, #fff2ae, #e5cb4e 60%, #be9d28); }
body.shell-bubblegum .chromatic { background: linear-gradient(135deg, #f5cce2, #d98abb 60%, #b96096); }

@media (max-width: 560px) {
  .player-page { padding: 18px 10px 28px; }
  .player-stage { min-height: 0; padding: 20px 7px; }
  .player-header span { display: none; }
  .official-help { text-align: center; font-size: 10px; }
}
