/* =============================================
   NES Controller Component
   Based on CodePen reference, scaled via transform
   for dark void scene with NES console

   Tilted forward 12deg via CSS 3D perspective.
   All shadows/gradients/highlights are tuned for
   this angle: top recedes, bottom comes toward viewer.
   ============================================= */

/* Scoped box-sizing reset (CodePen assumed global border-box) */
.ctrl-case,
.ctrl-case *,
.ctrl-case *::before,
.ctrl-case *::after {
  box-sizing: border-box;
}

/* ---- Controller Shell ---- */
.ctrl-case {
  width: 750px;
  height: 340px;
  background: #c8c8c8;
  position: absolute;
  left: calc(50% + var(--scene-offset-x) - 70px);
  top: calc(75% + var(--scene-offset-y) - 16px);
  border-radius: 10px 10px 12px 12px;
  border: 2px solid #fff;
  border-bottom: none;
  box-shadow:
    /* Ground shadow */
    0 35px 80px rgba(0, 0, 0, 0.4),
    0 12px 30px rgba(0, 0, 0, 0.25),
    /* Top edge catches light (tilted forward, faces upward) */
    inset 0 2px 4px rgba(255, 255, 255, 0.6);
  z-index: 800;
  /* Real 3D: perspective → tilt → scale */
  transform: perspective(1200px) rotateX(12deg) scale(0.32);
  transform-origin: top center;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  margin-left: -375px;
}

/* Cable notch at top */
.ctrl-case::before {
  width: 34px;
  height: 16px;
  background: linear-gradient(to bottom, #a8a8a8, #c0c0c0);
  position: absolute;
  top: 0;
  left: 199px;
  content: "";
  border-radius: 0 0 3px 3px;
  box-shadow:
    inset 0 3px 4px rgba(0, 0, 0, 0.22),
    inset 1px 0 2px rgba(0, 0, 0, 0.1),
    inset -1px 0 2px rgba(0, 0, 0, 0.1),
    inset 0 -1px 2px rgba(255, 255, 255, 0.25);
}

/* Ground shadow — elliptical pool beneath the controller */
.ctrl-case::after {
  content: "";
  position: absolute;
  width: 85%;
  height: 4px;
  background: rgba(0, 0, 0, 0.2);
  box-shadow: 0 0 15px 8px rgba(0, 0, 0, 0.12);
  bottom: -22px;
  left: 7.5%;
  z-index: -1;
  border-radius: 50%;
}

/* ---- Real 3D bottom face (perpendicular to front, hinged at bottom edge) ---- */
.ctrl-bottom-face {
  position: absolute;
  top: calc(100% - 2px);
  left: 2px;
  width: calc(100% - 4px);
  height: 60px;
  background: linear-gradient(to bottom, #a8a8a8, #989898);
  transform-origin: top center;
  transform: rotateX(-90deg);
  border-radius: 0 0 8px 8px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* ---- Lifted state: flat (0deg), enlarged, enhanced shadows ---- */
/* Shared class for both desktop hover and mobile touch */
.ctrl-case.ctrl-lifted {
  border: 2px solid #fff;
  transform: perspective(1200px) rotateX(0deg) scale(0.48) translateY(-80px);
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.8),
    inset 0 3px 6px rgba(255, 255, 255, 0.5);
}

/* Mobile: always show controller in lifted/closer state.
   Skip perspective/rotateX — Mobile Safari breaks preserve-3d rendering. */
@media (hover: none) {
  .ctrl-case {
    transform: scale(0.48) translateY(-80px);
    transform-style: flat;
    border: 2px solid #fff;
    box-shadow:
      0 30px 70px rgba(0, 0, 0, 0.8),
      inset 0 3px 6px rgba(255, 255, 255, 0.5);
  }
}

.ctrl-case.ctrl-lifted .ctrl-front-cover {
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.45),
    inset 0 -1px 2px rgba(255, 255, 255, 0.06);
}

.ctrl-case.ctrl-lifted .ctrl-middle > div.ctrl-start-buttons {
  box-shadow:
    inset 3px 3px 3px rgba(0, 0, 0, 0.2),
    inset -2px -2px 3px rgba(0, 0, 0, 0.1),
    inset 0 -1px 1px rgba(255, 255, 255, 0.3);
}

.ctrl-case.ctrl-lifted .ctrl-middle > div.ctrl-start-buttons > .ctrl-pill {
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.6);
}

.ctrl-case.ctrl-lifted .ctrl-ab-buttons .ctrl-btn-container .ctrl-btn-well .ctrl-press-btn {
  background: linear-gradient(#b3000e, #ff1a2c);
  box-shadow:
    inset 0 3px 2px rgba(255, 255, 255, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.6);
}

/* ---- Front Cover (dark inset panel) ---- */
.ctrl-front-cover {
  background-color: #1e1e1e;
  background-image: url("../../public/images/otis-redding.png");
  width: 710px;
  height: 260px;
  border-radius: 6px 6px 10px 10px;
  margin: 60px 20px 20px 20px;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  border: 1px solid #fff;
  box-shadow:
    inset 0 5px 8px rgba(0, 0, 0, 0.55),
    inset 0 -2px 4px rgba(255, 255, 255, 0.12);
  opacity: 0.95;
}

.ctrl-front-cover > div {
  flex-grow: 1;
}

/* ---- Left Section (D-pad) ---- */
.ctrl-left {
  width: 210px;
}

.ctrl-dpad {
  width: 130px;
  height: 130px;
  margin: 90px 40px 0;
  position: relative;
}

/* D-pad visual — canvas-based cross with CSS well */
.ctrl-dpad-visual {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  font-size: 15px;
}

/* White cross well (recessed background behind d-pad) */
.ctrl-dpad-pane {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2.6em;
  height: 2.6em;
}

.ctrl-dpad-pane::before,
.ctrl-dpad-pane::after {
  content: "";
  background-color: #ddd;
  width: 100%;
  height: 280%;
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  border-radius: 0.3em;
}

.ctrl-dpad-pane::after {
  transform: translateY(-50%) rotate(90deg);
}

/* Black cross hole (inner recess) */
.ctrl-dpad-hole {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.ctrl-dpad-hole::before,
.ctrl-dpad-hole::after {
  content: "";
  background-color: #000;
  width: 86%;
  height: 265%;
  position: absolute;
  top: 50%;
  left: 7%;
  transform: translateY(-50%);
  border-radius: 0.2em;
  z-index: 1;
}

.ctrl-dpad-hole::after {
  transform: translateY(-50%) rotate(90deg);
}

/* Interactive d-pad element — fills the visual area for proper arrow centering */
.ctrl-dpad-pad {
  position: absolute;
  z-index: 2;
  top: -1px;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Center pit (concave bowl) — dark top shadow, bright bottom catch */
.ctrl-dpad-pad::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 1.2em;
  height: 1.2em;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 1em;
  background: radial-gradient(ellipse 120% 60% at 50% 85%, rgba(160, 160, 160, 0.15) 0%, transparent 50%),
    linear-gradient(to bottom, #111 0%, #222 40%, #444 85%, #666 100%);
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.8),
    0 -1px 1px rgba(255, 255, 255, 0.15),
    0 1px 1px rgba(0, 0, 0, 0.4);
}

/* Canvas (draws the cross body) */
.ctrl-dpad-body {
  position: absolute;
  left: calc(50% - 1px);
  top: calc(50% - 4px);
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* ---- Embossed arrow indicators ---- */
.ctrl-dpad-arrow {
  position: absolute;
  z-index: 3;
  width: 2em;
  height: 2em;
  pointer-events: none;
}

/* Chevron top part (triangle) */
.ctrl-dpad-arrow::before {
  content: "";
  display: block;
  position: absolute;
  margin: 0 0.55em;
  width: 0.8em;
  height: 0.8em;
  border-width: 0.1em;
  border-style: solid;
  transform: rotate(315deg);
}

/* Chevron bottom part (bar) */
.ctrl-dpad-arrow::after {
  content: "";
  display: block;
  position: absolute;
  margin: 0.5em 0.5em 0;
  width: 0.8em;
  height: 0.45em;
  border-width: 0.1em;
  border-style: solid;
}

/* Arrow positions — centered on each arm of the cross */
.ctrl-dpad-arr-up {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(-1.75em) translateY(-3px);
}
.ctrl-dpad-arr-up::before { border-color: #151515 #444 transparent transparent; }
.ctrl-dpad-arr-up::after { border-color: transparent #444 #444 #151515; }

.ctrl-dpad-arr-right {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateX(1.75em) translateY(-2px) rotate(90deg);
}
.ctrl-dpad-arr-right::before { border-color: #444 #444 transparent transparent; }
.ctrl-dpad-arr-right::after { border-color: transparent #444 #151515 #151515; }

.ctrl-dpad-arr-down {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateY(1.75em) translateY(-3px) translateX(-2px) rotate(180deg);
}
.ctrl-dpad-arr-down::before { border-color: #444 #151515 transparent transparent; }
.ctrl-dpad-arr-down::after { border-color: transparent #151515 #151515 #444; }

.ctrl-dpad-arr-left {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) translateX(-1.75em) translateY(-5px) rotate(270deg);
}
.ctrl-dpad-arr-left::before { border-color: #444 #151515 transparent transparent; }
.ctrl-dpad-arr-left::after { border-color: transparent #151515 #444 #444; }

/* D-pad directional hit zones — invisible buttons over each arm */
.ctrl-dpad-hit {
  position: absolute;
  z-index: 10;
  cursor: pointer;
  background: transparent;
}

.ctrl-dpad-hit-up {
  width: 50px;
  height: 50px;
  top: 0;
  left: 40px;
}

.ctrl-dpad-hit-down {
  width: 50px;
  height: 50px;
  bottom: 0;
  left: 40px;
}

.ctrl-dpad-hit-left {
  width: 50px;
  height: 50px;
  top: 40px;
  left: 0;
}

.ctrl-dpad-hit-right {
  width: 50px;
  height: 50px;
  top: 40px;
  right: 0;
}

/* D-pad tilt — JS adds .ctrl-dpad-up/down/left/right on mousedown */
.ctrl-dpad .ctrl-dpad-pad {
  transition: all 0.05s ease;
}

.ctrl-dpad.ctrl-dpad-up .ctrl-dpad-pad {
  transform: rotate(0.4deg) scaleY(0.98);
  margin-top: -2px;
}

.ctrl-dpad.ctrl-dpad-right .ctrl-dpad-pad {
  transform: rotate(0.5deg) scaleX(1.02);
  margin-top: 1px;
  margin-left: 1px;
}

.ctrl-dpad.ctrl-dpad-down .ctrl-dpad-pad {
  transform: scaleY(1.01);
  margin-top: 3px;
}

.ctrl-dpad.ctrl-dpad-left .ctrl-dpad-pad {
  transform: rotate(-0.8deg) scaleX(0.97);
  margin-top: 1px;
  margin-left: -1px;
}

/* ---- Middle Section (Select/Start) ---- */
.ctrl-middle {
  display: flex;
  width: 210px;
  flex-direction: column;
  justify-content: space-between;
}

.ctrl-middle > div {
  background: #a8b0a5;
  height: 35px;
  border-radius: 8px;
}

.ctrl-middle > div:first-child {
  border-top-right-radius: 0;
  border-top-left-radius: 0;
  height: 50px;
}

.ctrl-middle > div:last-child {
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
  height: 25px;
}

.ctrl-middle > div.ctrl-button-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.ctrl-middle > div.ctrl-button-labels > p {
  color: var(--nes-text);
  text-transform: uppercase;
  font-family: 'Coda Caption', var(--font-pixel);
  font-weight: bold;
  font-size: 20px;
}

.ctrl-middle > div.ctrl-start-buttons {
  background: #ddd;
  height: 70px;
  border: 5px solid #ddd;
  box-shadow:
    inset 3px 4px 6px rgba(0, 0, 0, 0.28),
    inset -3px -3px 6px rgba(0, 0, 0, 0.18),
    inset 0 -1px 1px rgba(255, 255, 255, 0.15),
    inset 0 1px 1px rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.ctrl-middle > div.ctrl-start-buttons > .ctrl-pill {
  background: #444;
  width: 70px;
  height: 20px;
  border-radius: 10px;
  border: 2px solid rgba(0, 0, 0, 0.3);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.15),
    inset 0 -1px 2px rgba(255, 255, 255, 0.14),
    0 7px 18px rgba(0, 0, 0, 0.7);
  cursor: pointer;
}

.ctrl-middle > div.ctrl-start-buttons > .ctrl-pill:active {
  position: relative;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.3),
    0 0px 1px rgba(0, 0, 0, 0.4);
  transform: scale(0.96);
  background: #3a3a3a;
}

/* ---- Right Section (A/B + Nintendo) ---- */
.ctrl-right {
  width: 290px;
  position: relative;
}

.ctrl-brand {
  padding: 60px 0 0 60px;
}

.ctrl-brand img {
  width: 160px;
  height: auto;
}

/* A/B button area */
.ctrl-ab-buttons {
  width: 180px;
  height: 120px;
  margin-left: 40px;
  position: absolute;
  bottom: 0;
}

.ctrl-ab-buttons .ctrl-btn-container {
  width: 80px;
  height: 120px;
  float: left;
}

.ctrl-ab-buttons .ctrl-btn-container:last-child {
  margin-left: 20px;
}

.ctrl-ab-buttons .ctrl-btn-container .ctrl-btn-well {
  width: 80px;
  height: 80px;
  background: #ddd;
  border-radius: 6px;
  position: relative;
}

.ctrl-ab-buttons .ctrl-btn-container .ctrl-btn-well::after {
  content: "A";
  position: absolute;
  top: 100%;
  color: var(--nes-text);
  font-family: 'Coda Caption', var(--font-pixel);
  font-weight: bold;
  font-size: 20px;
  right: 5px;
  line-height: 40px;
}

.ctrl-ab-buttons .ctrl-btn-container:first-child .ctrl-btn-well::after {
  content: "B";
}

.ctrl-ab-buttons .ctrl-btn-container .ctrl-btn-well .ctrl-press-btn {
  width: 62px;
  height: 62px;
  border-radius: 100%;
  /* Convex dome: dark top edge (curves away) → bright face (catches light) */
  /* Tilted 12deg: surface faces light more, so overall brighter + lighter top shadow */
  background: linear-gradient(#c2080f 0%, #e8162a 40%, #ff3545 100%);
  box-shadow:
    /* Specular highlight on dome crown */
    inset 0 3px 4px rgba(255, 255, 255, 0.35),
    /* Drop shadow */
    0 7px 18px rgba(0, 0, 0, 0.7);
  display: block;
  top: 9px;
  left: 9px;
  position: absolute;
  border: 2px solid rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  cursor: pointer;
}

.ctrl-ab-buttons .ctrl-btn-container .ctrl-btn-well .ctrl-press-btn:active {
  top: 12px;
  background: linear-gradient(#9a000c, #e0001a);
  box-shadow:
    inset 0 1px 4px rgba(0, 0, 0, 0.4),
    0 0px 2px rgba(0, 0, 0, 0.5);
  transform: scale(0.97);
}
