/* ==========================================================================
   NekoAdvance - Console View & Virtual Controls
   ========================================================================== */

/* Main Console Container (Horizontal Left-to-Right by Default, Responsive) */
.console-wrapper {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.5rem;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  gap: 0.25rem;
}

/* 2. Center Area: Neko Handheld Console (Pillando todo el alto posible en horizontal) */
.center-console {
  order: 2;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  height: 100%;
  max-height: 98dvh;
  width: auto;
  max-width: 100%;
  flex-shrink: 1;
}

/* Cat SVG Frame (Proporcional, ajustado al alto en horizontal) */
.cat-svg-container {
  height: 100%;
  max-height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 1084 / 1032;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  filter: drop-shadow(0 8px 22px rgba(0, 0, 0, 0.4));
}

.cat-svg {
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  display: block;
}

/* Interactive Overlay over the SVG */
.cat-interactive-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

/* FPS Counter Text (Directly on cat forehead above the screen) */
.cat-fps-text {
  position: absolute;
  top: 21.2%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: clamp(0.65rem, 1.4vw, 0.8rem);
  font-weight: 700;
  color: #94a3b8;
  letter-spacing: 0.5px;
  user-select: none;
  pointer-events: none;
  z-index: 12;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  opacity: 0.85;
}

/* GBA Screen Viewport */
.screen-viewport {
  position: absolute;
  /* Matching SVG rect: x=167/1084 (15.40%), y=266/1032 (25.77%), w=750/1084 (69.18%), h=500/1032 (48.44%) */
  width: 69.18%;
  height: 48.44%;
  left: 15.41%;
  top: 25.77%;
  background: #0f0d14;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.9), 0 0 10px rgba(81, 64, 126, 0.5);
  pointer-events: all;
  cursor: pointer;
}

/* Screen CRT / Scanline filter effect */
.screen-viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    rgba(18, 16, 26, 0) 50%, 
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.03),
    rgba(0, 255, 0, 0.01),
    rgba(0, 0, 255, 0.03)
  );
  background-size: 100% 3px, 6px 100%;
  pointer-events: none;
  opacity: 0.6;
  z-index: 5;
  transition: opacity 0.3s ease;
}

.screen-viewport.no-scanlines::after {
  display: none;
}

/* GBA Canvas (Native 240x160 scaled with crisp pixels) */
#gba-canvas {
  width: 100%;
  height: 100%;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  object-fit: contain;
  background: #000;
  display: block;
}

/* Idle Screen Placeholder */
.screen-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #241a38 0%, #151022 100%);
  color: #e2e8f0;
  z-index: 4;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.screen-placeholder.hidden {
  opacity: 0;
  pointer-events: none;
}

.screen-placeholder .logo-text {
  font-family: var(--font-retro);
  font-size: 1.2rem;
  letter-spacing: 2px;
  color: var(--accent-light);
  text-shadow: 0 0 12px rgba(167, 139, 250, 0.6);
  margin-bottom: 0.5rem;
}

.screen-placeholder .load-btn {
  background: linear-gradient(135deg, var(--accent-purple), #6366f1);
  color: white;
  border: none;
  padding: 0.6rem 1.4rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
  transition: all 0.2s var(--ease-smooth);
}

.screen-placeholder .load-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.6);
}

.screen-placeholder .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Interactive 3D Vector SVG Buttons (L, R Triggers & Nose/Snout Menu)
   ========================================================================== */

.cat-interactive-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
  overflow: visible;
}

/* Base button container in SVG */
.neko-svg-btn {
  pointer-events: all;
  cursor: pointer;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* 3D Extrusion Layer (Dark Bottom Bevel / Shadow) */
.neko-svg-btn .btn-3d-extrusion {
  fill: #14111a;
  stroke: #14111a;
  stroke-width: 4px;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: transform 0.08s ease, filter 0.08s ease;
}

.trigger-btn-l .btn-3d-extrusion {
  transform: translate(-3px, 9px);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.55));
}

.trigger-btn-r .btn-3d-extrusion {
  transform: translate(3px, 9px);
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.55));
}

.nose-menu-btn .btn-3d-extrusion {
  transform: translate(0, 8px);
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.5));
}

/* Moving Face Cap (Physically sinks down on press) */
.neko-svg-btn .btn-3d-face {
  transform: translate(0, 0);
  transition: transform 0.08s ease, filter 0.08s ease;
}

/* Button Surface Texture & Sleek Border */
.neko-svg-btn .btn-surface {
  fill: url(#neko-btn-grad);
  stroke: #3c344d;
  stroke-width: 2.5px;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: fill 0.1s ease, stroke 0.1s ease, filter 0.1s ease;
}

.neko-svg-btn .snout-surface {
  stroke-width: 2px;
}

/* Letter Labels (L / R) */
.neko-svg-btn .btn-label {
  fill: #e2e8f0;
  stroke: #e2e8f0;
  stroke-width: 0.5px;
  transition: fill 0.1s ease, stroke 0.1s ease, filter 0.1s ease;
}

/* --- Hover States --- */
.neko-svg-btn:hover .btn-surface {
  fill: url(#neko-btn-hover-grad);
  stroke: #554a6b;
}

.neko-svg-btn:hover .btn-label {
  fill: #ffffff;
  stroke: #ffffff;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
}

/* --- Active / Pressed State (Hundimiento Físico 3D) --- */
.trigger-btn-l:active .btn-3d-face,
.trigger-btn-l.active .btn-3d-face {
  transform: translate(-2px, 7px);
}

.trigger-btn-r:active .btn-3d-face,
.trigger-btn-r.active .btn-3d-face {
  transform: translate(2px, 7px);
}

.nose-menu-btn:active .btn-3d-face,
.nose-menu-btn.active .btn-3d-face {
  transform: translate(0, 6px);
}

.neko-svg-btn:active .btn-surface,
.neko-svg-btn.active .btn-surface {
  fill: url(#neko-btn-active-grad);
  stroke: var(--accent-purple);
}

.neko-svg-btn:active .btn-label,
.neko-svg-btn.active .btn-label {
  fill: var(--accent-light);
  stroke: var(--accent-light);
  filter: drop-shadow(0 0 8px #a78bfa);
}

.neko-svg-btn:active .btn-3d-extrusion,
.neko-svg-btn.active .btn-3d-extrusion {
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.4));
}

/* ==========================================================================
   Tactile Control Frames (Left Frame: D-Pad ^ / Select v | Right Frame: A/B ^ / Start v)
   ========================================================================== */

/* Generic Frame Chassis */
.control-frame {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0.25rem;
  box-sizing: border-box;
  position: relative;
  z-index: 10;
  flex: 1 1 0;
  width: auto;
  max-width: none;
  min-width: 0;
  height: 100%;
  max-height: 100%;
}

/* 1. Left Frame (Order 1 in horizontal): D-Pad on top, Select on bottom */
.left-frame {
  order: 1;
}

/* 3. Right Frame (Order 3 in horizontal): A/B on top, Start on bottom */
.right-frame {
  order: 3;
}

/* D-Pad Container (Cruceta) */
.dpad-container {
  position: relative;
  width: clamp(160px, 22vw, 210px);
  height: clamp(160px, 22vw, 210px);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  margin: auto 0;
}

.dpad-btn {
  position: absolute;
  width: clamp(52px, 7.5vw, 68px);
  height: clamp(52px, 7.5vw, 68px);
  background: #252030;
  border: 2px solid #3c344d;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 5px 0 #14111a, 0 8px 12px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.1s ease;
  pointer-events: all;
  touch-action: manipulation;
}

.dpad-btn svg {
  width: clamp(24px, 3.5vw, 32px);
  height: clamp(24px, 3.5vw, 32px);
  fill: none;
  stroke: #c4b5fd;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.dpad-btn:hover {
  background: #2e283c;
  border-color: #554a6b;
}

.dpad-btn:active, .dpad-btn.active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #14111a, 0 3px 6px rgba(0, 0, 0, 0.4);
  background: #1c1824;
  border-color: var(--accent-purple);
}

.dpad-btn:active svg, .dpad-btn.active svg {
  stroke: #ffffff;
}

/* D-Pad Positions */
.dpad-up {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}
.dpad-up:active, .dpad-up.active {
  transform: translateX(-50%) translateY(4px);
}

.dpad-down {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}
.dpad-down:active, .dpad-down.active {
  transform: translateX(-50%) translateY(4px);
}

.dpad-left {
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}
.dpad-left:active, .dpad-left.active {
  transform: translateY(-50%) translateY(4px);
}

.dpad-right {
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}
.dpad-right:active, .dpad-right.active {
  transform: translateY(-50%) translateY(4px);
}

/* Action Buttons A & B (Diagonal Layout on top of Right Frame) */
.action-buttons {
  position: relative;
  width: clamp(170px, 24vw, 230px);
  height: clamp(140px, 19vw, 180px);
  flex-shrink: 0;
  margin: auto 0;
}

.action-btn {
  position: absolute;
  width: clamp(66px, 9vw, 84px);
  height: clamp(66px, 9vw, 84px);
  border-radius: 50%;
  background: #252030;
  border: 2px solid #3c344d;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 6px 0 #14111a, 0 10px 16px rgba(0, 0, 0, 0.5);
  font-family: var(--font-sans);
  font-size: clamp(1.45rem, 2.2vw, 1.85rem);
  font-weight: 800;
  color: #e2e8f0;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.1s ease;
  pointer-events: all;
  touch-action: manipulation;
}

.action-btn:hover {
  background: #2f273d;
  border-color: #554a6b;
}

.action-btn:active, .action-btn.active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #14111a, 0 3px 6px rgba(0, 0, 0, 0.4);
  background: #1a1622;
  color: var(--accent-light);
  border-color: var(--accent-purple);
}

/* Button A (Bottom-Left) */
.btn-a {
  bottom: 6px;
  left: 6px;
}
.btn-a:active, .btn-a.active {
  transform: translateY(5px);
}

/* Button B (Top-Right) */
.btn-b {
  top: 6px;
  right: 6px;
}
.btn-b:active, .btn-b.active {
  transform: translateY(5px);
}

/* System Button Slots (Select / Start) */
.system-btn-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: auto;
  padding-bottom: 0.5rem;
}

.capsule-btn {
  background: #231e2d;
  border: 1.5px solid #3d354d;
  color: var(--text-muted);
  font-size: clamp(0.75rem, 1.1vw, 0.9rem);
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: clamp(8px, 1.4vh, 12px) clamp(22px, 3vw, 32px);
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 3px 0 #131018, 0 5px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.08s ease;
  pointer-events: all;
  touch-action: manipulation;
}

.capsule-btn:hover {
  background: #2c2538;
  color: #fff;
  border-color: #594c70;
}

.capsule-btn:active, .capsule-btn.active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #131018, 0 2px 4px rgba(0, 0, 0, 0.4);
  background: #17141e;
  color: var(--accent-light);
  border-color: var(--accent-purple);
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================= */

/* Vertical / Portrait Mode (Orientation portrait or screen narrower than tall) */
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  .console-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "neko neko"
      "left right";
    max-width: 520px;
    margin: 0 auto;
    padding: 0.25rem 0.5rem 0.75rem 0.5rem;
    gap: 0.5rem;
    justify-items: center;
    align-items: center;
  }

  .center-console {
    grid-area: neko;
    width: 100%;
    max-width: 100%;
    max-height: 48vh;
    height: auto;
  }

  .cat-svg-container {
    width: 100%;
    height: auto;
  }

  .control-frame {
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: auto;
    padding: 0.25rem;
    background: transparent;
    border: none;
    box-shadow: none;
    justify-content: space-evenly;
  }

  .left-frame {
    grid-area: left;
  }

  .right-frame {
    grid-area: right;
  }

  .dpad-container {
    width: clamp(150px, 42vw, 195px);
    height: clamp(150px, 42vw, 195px);
    margin: 0 auto;
  }

  .dpad-btn {
    width: clamp(48px, 13vw, 62px);
    height: clamp(48px, 13vw, 62px);
  }

  .dpad-btn svg {
    width: clamp(22px, 5.5vw, 28px);
    height: clamp(22px, 5.5vw, 28px);
  }

  .action-buttons {
    width: clamp(150px, 42vw, 195px);
    height: clamp(130px, 36vw, 165px);
    margin: 0 auto;
  }

  .action-btn {
    width: clamp(60px, 16vw, 76px);
    height: clamp(60px, 16vw, 76px);
    font-size: clamp(1.35rem, 4.5vw, 1.7rem);
  }

  .system-btn-slot {
    padding-bottom: 0.25rem;
  }

  .capsule-btn {
    padding: 8px 24px;
    font-size: 0.75rem;
  }
}

/* Small Landscape Screens (Mobile landscape with short vertical height) */
@media (orientation: landscape) and (max-height: 520px) {
  .console-wrapper {
    padding: 0.2rem 0.35rem;
    gap: 0.25rem;
  }

  .control-frame {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    min-width: 0;
    padding: 0.15rem;
    background: transparent;
    border: none;
    box-shadow: none;
    max-height: 100%;
  }

  .dpad-container {
    width: clamp(135px, 20vw, 175px);
    height: clamp(135px, 20vw, 175px);
  }

  .dpad-btn {
    width: clamp(44px, 6.5vw, 56px);
    height: clamp(44px, 6.5vw, 56px);
  }

  .dpad-btn svg {
    width: 22px;
    height: 22px;
  }

  .action-buttons {
    width: clamp(145px, 22vw, 190px);
    height: clamp(115px, 17vw, 150px);
  }

  .action-btn {
    width: clamp(56px, 8.5vw, 70px);
    height: clamp(56px, 8.5vw, 70px);
    font-size: clamp(1.2rem, 2.2vw, 1.5rem);
  }

  .system-btn-slot {
    padding-bottom: 0.25rem;
  }

  .capsule-btn {
    padding: 6px 18px;
    font-size: 0.7rem;
  }

  .center-console {
    max-height: 98dvh;
  }
}
