/*
 * Page layout + NES controller styling.
 *
 * The controller rules below are a plain-CSS compile of the SCSS from CodePen
 * epzilla/AqweZk (the "NES Controller"). The Compass `@import` (vendor-prefix
 * helper) and the `$red` variable have been resolved by hand; nesting has been
 * flattened; `.pressed` selectors were added so keyboard / programmatic presses
 * light the buttons the same way `:active` does for mouse/touch.
 */

@import url(https://fonts.googleapis.com/css?family=Prosto+One);

/* ----------------------------------------------------------------------- */
/* Page layout (not from the pen)                                          */
/* ----------------------------------------------------------------------- */

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: #1a1a1a url('https://subtlepatterns.com/patterns/irongrip.png');
  color: #e8e8e8;
  font-family: "Prosto One", "Segoe UI", sans-serif;
}

.stage {
  max-width: 680px;
  margin: 0 auto;
  padding: 28px 16px 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.title {
  margin: 0;
  font-size: 56px;
  letter-spacing: 6px;
  color: #cc0000;
  text-shadow: 3px 3px 0 #000, 6px 6px 0 rgba(0, 0, 0, 0.35);
}

.subtitle {
  margin: 6px 0 22px;
  font-size: 14px;
  color: #aaa;
}

/* TV / console bezel around the game canvas. */
.tv {
  background: linear-gradient(#3a3a3a, #2a2a2a);
  padding: 18px;
  border-radius: 14px;
  box-shadow: inset 0 0 0 3px #555, 0 12px 28px rgba(0, 0, 0, 0.55);
}

.tv-screen {
  position: relative;
  width: 512px;
  max-width: 80vw;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.9);
}

#screen {
  display: block;
  width: 100%;
  height: auto;
  /* Crisp, blocky NES pixels rather than blurry upscaling. */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cc0000;
  font-size: 20px;
  letter-spacing: 2px;
  background: #000;
}

.hint {
  margin: 22px 0 30px;
  font-size: 13px;
  line-height: 2;
  color: #bbb;
}

.hint kbd {
  display: inline-block;
  padding: 2px 7px;
  margin: 0 1px;
  background: #2c2c2c;
  border: 1px solid #555;
  border-bottom-width: 3px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  color: #eee;
}

/* ----------------------------------------------------------------------- */
/* NES controller (CodePen epzilla/AqweZk, compiled SCSS -> CSS)           */
/* ----------------------------------------------------------------------- */

.nes-controller {
  position: relative;   /* pen used absolute; relative lets us center it in flow */
  margin: 0 auto;
  width: 600px;
  height: 250px;
  border-radius: 5px;
  background-color: #ccc;
  /* The page centers its text (title/hint); reset so the controller's own
     relatively-positioned text (e.g. the "Nintendo" logo) isn't shoved right. */
  text-align: left;
  /* keep on-screen taps from selecting text / scrolling / zooming */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.nes-inset-area {
  position: absolute;
  width: 550px;
  height: 175px;
  top: 50px;
  left: 25px;
  border-radius: 5px;
  background-color: #202020;
}

.nes-nintendo-text {
  position: relative;
  top: 40px;
  left: 383px;
  color: #cc0000;
  font-size: 24px;
  font-family: "Prosto One", sans-serif;
}

.nes-mid-stripe {
  position: relative;
  width: 180px;
  height: 175px;
  top: -27px;
  left: 165px;
}

.nes-mid-stripe .stripe {
  width: 100%;
  background-color: #777;
}

.nes-mid-stripe .nes-stripe1 {
  height: 25px;
  border-bottom-right-radius: 5px;
  border-bottom-left-radius: 5px;
}

.nes-mid-stripe .nes-stripe2 {
  height: 25px;
  margin-top: 7px;
  border-radius: 5px;
}

.nes-mid-stripe .nes-stripe3 {
  height: 25px;
  margin-top: 7px;
  border-radius: 5px;
}

.nes-mid-stripe .nes-stripe4 {
  height: 15px;
  margin-top: 71px;
  border-top-right-radius: 5px;
  border-top-left-radius: 5px;
}

.nes-fill-tri-top {
  position: absolute;
  width: 0;
  height: 0;
  left: 608px;
  top: 13px;
  border-left: 15px solid #aaa;
  border-top: 20px solid transparent;
}

.nes-fill-tri-bottom {
  position: absolute;
  width: 0;
  height: 0;
  left: 12px;
  top: 258px;
  border-top: 15px solid #aaa;
  border-left: 20px solid transparent;
}

.nes-bottom {
  position: absolute;
  width: 570px;
  height: 12px;
  left: 12px;
  top: 258px;
  border-top: 15px solid #aaa;
  border-left: 20px solid transparent;
}

.nes-right {
  position: absolute;
  width: 12px;
  height: 225px;
  left: 608px;
  top: 13px;
  border-left: 15px solid #aaa;
  border-top: 20px solid transparent;
}

.nes-fill-tri-bottom-right {
  position: absolute;
  width: 0;
  height: 0;
  left: 602px;
  top: 253px;
  border-left: 15px solid #aaa;
  border-top: 20px solid transparent;
  z-index: -1;
}

.nes-fill-circle {
  position: absolute;
  width: 20px;
  height: 30px;
  left: 602px;
  top: 243px;
  border-radius: 50%;
  background-color: #aaa;
  z-index: -1;
}

.button-box {
  position: absolute;
  width: 50px;
  height: 50px;
  background-color: #eee;
  border-radius: 5px;
}

.button-box .red-button {
  height: 42px;
  width: 42px;
  margin-top: 2px;
  margin-left: 2px;
  background-color: #cc0000;
  border-radius: 50%;
  border-bottom: 4px solid #660000;
  border-right: 4px solid #660000;
  cursor: pointer;
}

.button-box .red-button::before {
  content: "";
  position: absolute;
  display: block;
  width: 34px;
  height: 34px;
  left: 4px;
  top: 4px;
  border-radius: 50%;
  border-top: 2px solid #880000;
  border-left: 2px solid #880000;
  border-bottom: 2px solid #ccc;
  border-right: 2px solid #ccc;
  background-color: #cc0000;
}

.nes-a-box {
  left: 450px;
  top: 100px;
}

.nes-a-box::after {
  content: "A";
  font-weight: bolder;
  position: absolute;
  right: 0;
  top: 53px;
  color: #cc0000;
}

.nes-a-box .nes-a-button:active,
.nes-a-box .nes-a-button.pressed {
  margin-top: 6px;
  margin-left: 6px;
  border: 0px;
}

.nes-a-box .nes-a-button:active::before,
.nes-a-box .nes-a-button.pressed::before {
  content: "";
  position: absolute;
  display: block;
  width: 34px;
  height: 34px;
  left: 6px;
  top: 6px;
  border-radius: 50%;
  border-top: 2px solid #880000;
  border-left: 2px solid #880000;
  border-bottom: 2px solid #ccc;
  border-right: 2px solid #ccc;
  background-color: #cc0000;
}

.nes-b-box {
  left: 390px;
  top: 100px;
}

.nes-b-box::after {
  content: "B";
  font-weight: bolder;
  position: absolute;
  right: 0;
  top: 53px;
  color: #cc0000;
}

.nes-b-box .nes-b-button:active,
.nes-b-box .nes-b-button.pressed {
  margin-top: 6px;
  margin-left: 6px;
  border: 0px;
}

.nes-b-box .nes-b-button:active::before,
.nes-b-box .nes-b-button.pressed::before {
  content: "";
  position: absolute;
  display: block;
  width: 34px;
  height: 34px;
  left: 6px;
  top: 6px;
  border-radius: 50%;
  border-top: 2px solid #880000;
  border-left: 2px solid #880000;
  border-bottom: 2px solid #ccc;
  border-right: 2px solid #ccc;
  background-color: #cc0000;
}

.nes-middle-buttons {
  position: absolute;
  width: 170px;
  height: 45px;
  top: 155px;
  left: 198px;
  background-color: #eee;
  border-radius: 5px;
  border: 5px inset white;
}

.nes-middle-buttons .middle-button {
  position: absolute;
  width: 50px;
  height: 20px;
  background-color: #202020;
  font-size: 15px;
  border-radius: 10px;
  box-shadow: 2px 2px #888;
  cursor: pointer;
}

.nes-middle-buttons .nes-select {
  left: 25px;
  top: 15px;
}

.nes-middle-buttons .nes-select::before {
  content: "SELECT";
  position: absolute;
  color: #cc0000;
  top: -50px;
  left: -5px;
}

.nes-middle-buttons .nes-select:active,
.nes-middle-buttons .nes-select.pressed {
  left: 27px;
  top: 17px;
  box-shadow: 0px 0px #000;
}

.nes-middle-buttons .nes-select:active::before,
.nes-middle-buttons .nes-select.pressed::before {
  content: "SELECT";
  position: absolute;
  color: #cc0000;
  top: -52px;
  left: -7px;
}

.nes-middle-buttons .nes-start {
  left: 95px;
  top: 15px;
}

.nes-middle-buttons .nes-start::before {
  content: "START";
  position: absolute;
  color: #cc0000;
  top: -50px;
}

.nes-middle-buttons .nes-start:active,
.nes-middle-buttons .nes-start.pressed {
  left: 97px;
  top: 17px;
  box-shadow: 0px 0px #000;
}

.nes-middle-buttons .nes-start:active::before,
.nes-middle-buttons .nes-start.pressed::before {
  content: "START";
  position: absolute;
  color: #cc0000;
  top: -52px;
  left: -2px;
}

.nes-d-pad {
  position: absolute;
  top: 110px;
  left: 65px;
  height: 100px;
  width: 100px;
}

.nes-d-pad .d-pad-button {
  position: absolute;
  height: 34px;
  width: 34px;
  background-color: black;
  color: #444;
  font-size: 28px;
  text-align: center;
  border-bottom-right-radius: 5px;
  border-bottom-left-radius: 5px;
  cursor: pointer;
}

.nes-d-pad .nes-up-button {
  left: 33px;
  box-shadow: -3px 0 0 #888;
  transform: rotate(180deg);
}

.nes-d-pad .nes-up-button:active,
.nes-d-pad .nes-up-button.pressed {
  transform: rotate(180deg) rotate3d(1, 0, 0, 30deg);
  box-shadow: -1px 0 0 #888;
}

.nes-d-pad .nes-left-button {
  top: 33px;
  box-shadow: 3px 0px 0px #888;
  transform: rotate(90deg);
}

.nes-d-pad .nes-left-button:active,
.nes-d-pad .nes-left-button.pressed {
  transform: rotate(90deg) rotate3d(1, 0, 0, 20deg);
  box-shadow: 1px 0 0 #888;
}

.nes-d-pad .nes-right-button {
  top: 33px;
  left: 66px;
  box-shadow: -3px 3px 0 #888;
  transform: rotate(270deg);
}

.nes-d-pad .nes-right-button:active,
.nes-d-pad .nes-right-button.pressed {
  transform: rotate(270deg) rotate3d(1, 0, 0, 20deg);
  box-shadow: -1px 1px 0 #888;
}

.nes-d-pad .nes-down-button {
  left: 33px;
  top: 66px;
  box-shadow: 3px 1px 0px #888;
}

.nes-d-pad .nes-down-button:active,
.nes-d-pad .nes-down-button.pressed {
  transform: rotate3d(1, 0, 0, 30deg);
  box-shadow: 1px 0 0 #888;
}

.nes-d-pad .nes-middle-part {
  position: absolute;
  height: 34px;
  width: 34px;
  top: 33px;
  left: 33px;
  background-color: black;
}

.nes-d-pad .nes-middle-part::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 20px;
  width: 20px;
  border-right: 1px solid #999;
  border-bottom: 1px solid #999;
  border-radius: 50%;
}

.nes-notSoSecretCode {
  position: absolute;
  left: 700px;
  color: white;
  font-size: 60px;
  display: none;
}

.blink {
  animation: blink 0.8s linear infinite;
}

@keyframes blink {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ----------------------------------------------------------------------- */
/* Mobile / narrow viewports                                               */
/* ----------------------------------------------------------------------- */

/* Tighten the page chrome and let the game canvas use the full width. */
@media (max-width: 700px) {
  html, body { overflow-x: hidden; }
  .stage { padding: 18px 8px 36px; }
  .title { font-size: 11vw; letter-spacing: 3px; text-shadow: 2px 2px 0 #000; }
  .subtitle { font-size: 12px; margin: 4px 0 16px; }
  .tv { padding: 10px; border-radius: 10px; }
  .tv-screen { max-width: 94vw; }
  .hint { font-size: 12px; line-height: 1.9; margin: 16px 0 22px; }
}

/* The NES controller is a fixed 600x250px absolute-positioned layout, so it
   can't reflow. Shrink it with `zoom` (not `transform: scale`) so its layout
   box shrinks too — otherwise the box stays 600px wide and forces horizontal
   page overflow on phones. */
@media (max-width: 640px) { .nes-controller { zoom: 0.62; } }
@media (max-width: 420px) { .nes-controller { zoom: 0.50; } }
@media (max-width: 340px) { .nes-controller { zoom: 0.44; } }

/* Two-player: both controllers side by side, centered, scaled to share the
   row (2 x 600px * zoom + gap). */
.pads {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

.pad {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.pad-label {
  margin: 0 0 8px;
  font-size: 14px;
  color: #aaa;
}

.pad-label[hidden],
.pad[hidden] {
  display: none;
}

.pad.local .pad-label {
  color: #fff;
}

/* The other player's controller only mirrors their presses. */
.pad.remote .nes-controller {
  pointer-events: none;
}

.pads.two-player .nes-controller { zoom: 0.55; }
@media (max-width: 700px) { .pads.two-player { gap: 8px; } .pads.two-player .nes-controller { zoom: 0.36; } }
@media (max-width: 480px) { .pads.two-player .nes-controller { zoom: 0.27; } }
@media (max-width: 360px) { .pads.two-player .nes-controller { zoom: 0.23; } }

/* ----------------------------------------------------------------------- */
/* Lobby + online status (not from the pen)                                */
/* ----------------------------------------------------------------------- */

.lobby {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 12px;
}

.lobby[hidden],
.lobby-panel[hidden],
.lobby-btn[hidden],
.net-status[hidden] {
  display: none;
}

.lobby-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.lobby-panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
  color: #fff;
}

.lobby-panel p {
  margin: 0;
  font-size: 13px;
  color: #bbb;
}

.lobby-btn {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 2px solid #cc0000;
  border-radius: 6px;
  background: #cc0000;
  color: #fff;
  cursor: pointer;
}

.lobby-btn:hover,
.lobby-btn:focus-visible {
  background: #e01818;
  outline: none;
}

.lobby-btn-quiet {
  background: transparent;
  border-color: #666;
  color: #ccc;
}

.lobby-btn-quiet:hover,
.lobby-btn-quiet:focus-visible {
  background: #333;
}

.join-form {
  display: flex;
  gap: 8px;
  margin: 0;
}

.join-form input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 3px;
  text-transform: uppercase;
  text-align: center;
  padding: 8px;
  border: 2px solid #666;
  border-radius: 6px;
  background: #111;
  color: #fff;
}

.room-code {
  font-size: 32px !important;
  letter-spacing: 6px;
  color: #ffd84a !important;
}

.net-status {
  margin: 12px 0 0;
  font-size: 13px;
  color: #ccc;
}

.net-status.bad {
  color: #ff7070;
}

.invite-link {
  font-family: "Segoe UI", sans-serif;
  font-size: 12px;
  padding: 7px 8px;
  border: 2px solid #666;
  border-radius: 6px;
  background: #111;
  color: #ffd84a;
  text-align: center;
}

.invite-link[hidden],
.room-players[hidden] {
  display: none;
}

.room-players {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  text-align: left;
  font-size: 14px;
}

.room-players li {
  padding: 5px 8px;
  border-bottom: 1px solid #333;
  color: #777;
}

.room-players li.here {
  color: #fff;
}
