body {
  overflow: hidden;
  background: #333;
  text-align: center;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

.hide {
  position: absolute !important;
  display: block !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  padding: 0 !important;
  margin: -1px !important;
  height: 1px !important;
  width: 1px !important;
  top: 0 !important;
  left: -999em !important;
}

#debug {
  position: fixed;
  cursor: default;
  background: #333;
  color: #9F3;
  font: 20px monospace;
  border: none;
  width: 100%;
  top: 0;
  left: 0;
}

#container {
  background: #aca092;
  position: fixed;
  border: 4px solid #8c8072;
  border-radius: 4px 4px 48px;
  padding: 8px 0;
  margin: 16px auto 0;
  width: 280px;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
}

#canvas-wrapper {
  position: relative;
  overflow: hidden;
  background: #4c4056;
  border-radius: 4px 4px 16px;
  margin: 24px auto 32px;
  width: 192px;
  height: 164px;
}

/* In order to get pixelated look */
.sharpen {
  image-rendering: optimizeSpeed;             /* Older versions of FF          */
  image-rendering: -moz-crisp-edges;          /* FF 6.0+                       */
  image-rendering: -webkit-optimize-contrast; /* Safari                        */
  image-rendering: -o-crisp-edges;            /* OS X & Windows Opera (12.02+) */
  image-rendering: pixelated;                 /* Awesome future-browsers       */
  -ms-interpolation-mode: nearest-neighbor;   /* IE                            */
}
#container canvas {
  position: absolute;
  background: transparent;
  margin: 0 auto;
  width: 160px;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
}
#canvas table {
  background: #000;
  border-collapse: collapse;
  color: #FFF;
  font: bold 1em/1.2em Helvetica;
  letter-spacing: 1px;
  margin: 16px auto;
}
#canvas caption,
#canvas th,
#canvas td {
  background: #000;
  border: 1px solid #FFF;
  padding: 1em;
}
#canvas td {
  padding: 0.5em 1em;
}

#palette {
  position: absolute;
  right: 0;
  top: 0;
}
#palette input[type="radio"] {
  display: none;
}
#palette label {
  display: block;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  background: lime;
  border-style: solid;
  border-width: 1px;
  text-indent: -999em;
  margin: 4px 4px 8px;
  width: 16px;
  height: 16px;
}
#palette label:hover {
  border-color: #777;
}
#palette label:after {
  position: absolute;
  content: "";
  right: 0;
  bottom: 0;
}
#palette input[type="radio"]:checked + label {
  border-color: #FFF;
}
#palette label:nth-child( 2) { background: #8bac0f; border-color: #0f380f; } /* GameBoy Olive */
#palette label:nth-child( 4) { background: #AAA; border-color: #333; } /* Gray */
#palette label:nth-child( 6) { background: #C65; border-color: #410; } /* Red */
#palette label:nth-child( 8) { background: #9C7; border-color: #240; } /* Green */
#palette label:nth-child(10) { background: #79C; border-color: #024; } /* Blue */
#palette label:nth-child(12) { background: #BB6; border-color: #330; } /* Yellow */
#palette label:nth-child(14) { background: #C96; border-color: #420; } /* Orange */
#palette label:nth-child(16) { background: #C79; border-color: #402; } /* Purple */
#palette label:nth-child(18) { background: #79C; border-color: #024; } /* Blue/Red */
#palette label:nth-child(20) { background: #BB6; border-color: #330; } /* Yellow/Purple */
/* Half-overlays */
#palette label:nth-child(18):after { border-color: transparent #C65 #C65 transparent; border-style: solid; border-width: 8px; } /* Blue/Red */
#palette label:nth-child(20):after { border-color: transparent #C79 #C79 transparent; border-style: solid; border-width: 8px; } /* Yellow/Purple */
/* Hover states */
#palette label:nth-child( 2):hover { border-color: #9bbc0f; } /* GameBoy Olive */
#palette label:nth-child( 4):hover { border-color: #EEE; } /* Gray */
#palette label:nth-child( 6):hover { border-color: #FBA; } /* Red */
#palette label:nth-child( 8):hover { border-color: #DFB; } /* Green */
#palette label:nth-child(10):hover { border-color: #BDF; } /* Blue */
#palette label:nth-child(12):hover { border-color: #EEA; } /* Yellow */
#palette label:nth-child(14):hover { border-color: #FDA; } /* Orange */
#palette label:nth-child(16):hover { border-color: #FBD; } /* Purple */
#palette label:nth-child(18):hover { border-color: #BDF; } /* Blue/Red */
#palette label:nth-child(20):hover { border-color: #FBD; } /* Yellow/Purple */

.row {
  display: flex;
  justify-content: space-around;
  margin: 32px 0 48px;
}

#d-pad {
  width: 108px;
  height: 108px;
}
#buttons {
}
#start-select {
  position: relative;
  margin: 48px 0 32px;
}
#d-pad,
#buttons {
  position: relative;
  display: inline-block;
}

button {
  cursor: pointer;
  color: #221044;
  border-style: solid;
  border-color: #777;
  border-width: 2px 0 0 2px;
}

#d-pad:before,
#d-pad:after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
}
#d-pad:before {
  background: #120c0c;
  border-color: #333;
  border-style: solid;
  border-width: 2px 0 0 2px;
  margin: -14px auto 0;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
}
#d-pad:after {
  display: block;
  border: 2px solid #333;
  border-radius: 100%;
  margin: -8px auto 0;
  width: 16px;
  height: 16px;
  box-sizing: border-box;
}
#d-pad button {
  position: absolute;
  background: #120c0c;
  padding: 0;
}
#d-pad button:hover {
  background-color: #444;
}
#d-pad button.active {
  background-color: #333;
}
#d-pad button:before,
#d-pad button:after {
  content: "";
  position: absolute;
  border-style: solid;
  width: 0;
  height: 0;
}
#up-button,
#down-button {
  margin: 0 auto;
  left: 0;
  right: 0;
}
#up-button {
  top: 0;
}
#down-button {
  border-top-width: 0;
  bottom: 0;
}
#left-button,
#right-button {
  margin: -14px 0 0 0;
  top: 50%;
}
#left-button {
  left: 0;
}
#right-button {
  border-left-width: 0;
  right: 0;
}

#up-button:before,
#down-button:before {
  border-width: 14px 6px;
  margin: -14px auto;
  left: 0;
  right: 0;
}
#left-button:before,
#right-button:before {
  border-width: 6px 14px;
  margin: -6px auto;
  top: 50%;
}
#up-button:before {
  border-color: transparent transparent #777;
  top: 25%;
}
#down-button:before {
  border-color: #777 transparent transparent;
  top: 75%;
}
#left-button:before {
  border-color: transparent #777 transparent transparent;
  right: 15px;
}
#right-button:before {
  border-color: transparent transparent transparent #777;
  left: 15px;
}
#up-button:after,
#down-button:after {
  border-width: 12px 5px;
  left: 0;
  right: 0;
}
#left-button:after,
#right-button:after {
  border-width: 5px 12px;
  margin: -5px auto;
  top: 50%;
}
#up-button:after {
  border-color: transparent transparent #120c0c;
  margin: -11px auto;
  top: 25%;
}
#down-button:after {
  border-color: #120c0c transparent transparent;
  margin: -13px auto;
  top: 75%;
}
#left-button:after {
  border-color: transparent #120c0c transparent transparent;
  transform: translateX(1px);
  right: 17px;
}
#right-button:after {
  border-color: transparent transparent transparent #120c0c;
  transform: translateX(-1px);
  left: 17px;
}
#up-button:hover:after {
  border-bottom-color: #444;
}
#down-button:hover:after {
  border-top-color: #444;
}
#left-button:hover:after {
  border-right-color: #444;
}
#right-button:hover:after {
  border-left-color: #444;
}
#up-button.active:after {
  border-bottom-color: #333;
}
#down-button.active:after {
  border-top-color: #333;
}
#left-button.active:after {
  border-right-color: #333;
}
#right-button.active:after {
  border-left-color: #333;
}
#left-button {
  margin-right: 24px;
}
#up-button, #down-button {
  width: 28px;
  height: 40px;
  display: block;
  margin: 0 auto;
}
#left-button, #right-button {
  width: 40px;
  height: 28px;
}

#a-button {
  margin-left: 56px;
}
#b-button {
  margin-right: 56px;
}
#a-button,
#b-button {
  display: block;
  background: #6c0935;
  border-color: #ac4975;
  border-radius: 100%;
  width: 48px;
  height: 48px;
}
#a-button:hover,
#b-button:hover {
  background-color: #8c2955;
}
#a-button.active,
#b-button.active {
  background-color: #7c1945;
}

#select-button,
#start-button {
  display: inline-block;
  background: #4c4056;
  border-color: #7c7086;
  border-radius: 8px;
  width: 56px;
  height: 16px;
}
#select-button:hover,
#start-button:hover {
  background-color: #6c6076;
}

#select-button.active,
#start-button.active {
  background-color: #5c5066;
}
#select-button {
  margin-right: 16px;
}

#a-button,
#b-button,
#select-button,
#start-button {
  position: relative;
}
#a-button:after,
#b-button:after,
#select-button:after,
#start-button:after {
  position: absolute;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  left: 0;
  right: 0;
  margin: 0 auto;
}
#a-button:after,
#b-button:after {
  font-size: 24px;
  top: 56px;
}
#select-button:after,
#start-button:after {
  font-size: 12px;
  top: 24px;
}
#a-button:after { content: "A"; }
#b-button:after { content: "B"; }
#select-button:after { content: "SELECT"; }
#start-button:after { content: "START"; }

#audio-controls {
  position: absolute;
  background: #654;
  color: #FFF;
  font: 16px monospace;
  border: 4px solid #987;
  border-radius: 4px;
  padding: 12px 6px;
  top: 8px;
  left: -16px;
}
#audio-controls .audio-unavailable {
  display: none;
}
/* Gray out controls and display message that audio is unavailable */
#audio-controls.disabled {
  background: #777;
  width: 80px;
}
#audio-controls.disabled .audio-available {
  display: none;
}
#audio-controls.disabled .audio-unavailable {
  display: block;
  line-height: 1.4;
  margin: 0;
}

#mute + label {
  position: relative;
  display: block;
  overflow: hidden;
  cursor: pointer;
  text-indent: -999em;
  margin: 0 0 8px;
  width: 36px;
  height: 28px;
}
#mute + label:before,
#mute + label:after {
  content: "";
  position: absolute;
  border-color: transparent #FFF transparent transparent;
  border-radius: 100%;
  border-style: solid;
  border-width: 4px;
  top: 50%;
}
#mute + label:before {
  margin-top: -14px;
  width: 20px;
  height: 20px;
  left: 0px;
}
#mute + label:after {
  margin-top: -20px;
  width: 32px;
  height: 32px;
  left: -4px;
}
#mute:checked + label:before,
#mute:checked + label:after {
  background: #FFF;
  border: 0;
  border-radius: 0;
  margin-top: -2px;
  width: 16px;
  height: 4px;
  left: 20px;
}
#mute:checked + label:before {
  transform: rotate(45deg);
}
#mute:checked + label:after {
  transform: rotate(-45deg);
}

.speaker {
  position: absolute;
  display: block;
  background: #FFF;
  width: 10px;
  height: 10px;
  top: calc(50% - 5px);
  left: 0;
}
.speaker:after {
  content: "";
  position: absolute;
  border-color: transparent #FFF transparent transparent;
  border-radius: 100%;
  border-style: solid;
  border-width: 16px;
  top: -11px;
  left: -15px;
}

#volume {
  display: block;
  margin: 0 auto;
  width: 24px;
  height: 88px;
  -webkit-appearance: slider-vertical; /* Webkit */
  writing-mode: bt-lr; /* IE */
}

#key-controls {
  display: none;
}

@media screen and (min-width: 464px) and (min-height: 608px) {
  #container {
    border-radius: 4px 4px 64px;
    width: 448px;
  }

  #container canvas {
    width: 320px;
  }

  #canvas-wrapper {
    border-radius: 4px 4px 24px;
    margin-top: 16px;
    width: 384px;
    height: 328px;
  }

  #audio-controls {
    top: 32px;
    left: -72px;
  }

}

@media screen and (min-width: 976px) and (min-height: 936px) {
  #container {
    border-radius: 4px 4px 80px;
    width: 960px;
  }

  #container canvas {
    width: 640px;
  }

  #canvas-wrapper {
    border-radius: 4px 4px 32px;
    width: 768px;
    height: 656px;
  }

  #a-button {
  margin-left: 72px;
  }
  #b-button {
    margin-right: 72px;
  }
}

@media screen and (min-width: 1024px) {
  #key-controls {
    display: table;
    position: absolute;
    background: #aca092;
    font-family: monospace;
    border-collapse: collapse;
    bottom: 0;
    right: 0;
  }

  #key-controls td,
  #key-controls th {
    border: 1px solid #8c8072;
    padding: 4px 8px;
  }
  #key-controls td:nth-child(2n + 1) {
    text-align: right;
  }
  #key-controls td:nth-child(2n) {
    text-align: left;
  }
}
