@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Outfit:wght@400;600;700&display=swap');

@font-face {
  font-family: 'SuperMarioNES';
  src: url('../Super_Mario_Bros._NES.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --winter-dark: #0a1128;
  --winter-deep-blue: #1c2541;
  --winter-ice: #e0fbfc;
  --winter-cyan: #3a86ff;
  --winter-gold: #ffbe0b;
  --winter-red: #e63946;
  --winter-snow: #f8f9fa;
  --font-retro: 'SuperMarioNES', 'Press Start 2P', monospace;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background-color: var(--winter-dark);
  background-image: 
    radial-gradient(ellipse at 50% 20%, #1b2845 0%, #080d1a 80%);
  color: var(--winter-snow);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  padding: 12px;
}

/* Background animated snow */
#ambient-snow {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1;
}

.game-container {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1024px;
  width: 100%;
}

/* Arcade Cabinet Bezel */
.cabinet-bezel {
  position: relative;
  background: linear-gradient(145deg, #1f2937, #111827);
  border: 4px solid #3b82f6;
  box-shadow: 
    0 0 25px rgba(59, 130, 246, 0.4),
    0 20px 40px rgba(0, 0, 0, 0.8),
    inset 0 0 15px rgba(0, 0, 0, 0.6);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 960px;
  transition: transform 0.2s ease;
}

/* Header marquee */
.bezel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px 14px 12px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 12px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  image-rendering: pixelated;
  border-radius: 6px;
  filter: drop-shadow(0 0 6px #60a5fa);
  animation: float 2.5s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.brand-title {
  font-family: var(--font-retro);
  font-size: 14px;
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(96, 165, 250, 0.8), 2px 2px 0px #1e3a8a;
}

.brand-subtitle {
  font-family: var(--font-retro);
  font-size: 9px;
  margin-top: 3px;
  color: #93c5fd;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.cabinet-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.btn-reset:hover {
  background: rgba(239, 68, 68, 0.28);
  border-color: #f87171;
}

.btn-autopilot {
  background: rgba(16, 185, 129, 0.2);
  border-color: #34d399;
  color: #a7f3d0;
  font-weight: 600;
}

.btn-autopilot:hover {
  background: rgba(16, 185, 129, 0.35);
  border-color: #6ee7b7;
}

.btn-autopilot.active {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border-color: #a7f3d0;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.7);
  animation: pulse-autopilot 1.4s infinite ease-in-out;
}

@keyframes pulse-autopilot {
  0%, 100% { box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
  50% { box-shadow: 0 0 18px rgba(52, 211, 153, 0.95); }
}

.btn-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0f2fe;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--font-retro);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: rgba(59, 130, 246, 0.3);
  border-color: #60a5fa;
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: translateY(1px);
}

/* Canvas Screen Wrapper */
.screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 72vh;
  max-width: min(928px, calc(72vh * 4 / 3));
  margin: 0 auto;
  background-color: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.9);
  border: 2px solid #1e293b;
}

#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* CRT Scanlines Overlay */
.crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%, 
    rgba(0, 0, 0, 0.25) 50%
  );
  background-size: 100% 4px;
  opacity: 0.6;
  z-index: 5;
  transition: opacity 0.3s;
}

.crt-overlay.disabled {
  opacity: 0;
}

/* Vignette & Glare */
.crt-glare {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 65%, rgba(0, 0, 0, 0.6) 100%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
  z-index: 6;
}

/* On-screen Floating Pause Button */
.screen-pause-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 25;
  background: rgba(15, 23, 42, 0.75);
  border: 1.5px solid rgba(56, 189, 248, 0.6);
  color: #e0f2fe;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  transition: all 0.15s ease;
  touch-action: manipulation;
  user-select: none;
}

.screen-pause-btn:hover {
  background: rgba(59, 130, 246, 0.4);
  border-color: #38bdf8;
  transform: scale(1.05);
}

.screen-pause-btn:active, .screen-pause-btn.active {
  transform: scale(0.92);
  background: #2563eb;
  border-color: #93c5fd;
}

/* Touch & Mobile Controls */
.touch-controls {
  display: none;
  width: 100%;
  margin-top: 10px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 900px), (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

/* Auxiliary Meta Bar (Pause, Reset, Auto) */
.touch-meta-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.touch-pause-btn {
  background: #1e293b;
  border: 1.5px solid #475569;
  border-radius: 20px;
  color: #38bdf8;
  font-family: var(--font-retro);
  font-size: 9px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 3px 0 #0f172a;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.1s ease;
}

.touch-pause-btn:hover {
  background: #334155;
  border-color: #60a5fa;
}

.touch-pause-btn:active, .touch-pause-btn.active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0f172a;
  background: #3b82f6;
  color: #ffffff;
  border-color: #93c5fd;
}

.touch-pause-btn .pause-icon {
  font-size: 11px;
}

.touch-reset-btn {
  color: #fca5a5;
  border-color: #7f1d1d;
}

.touch-reset-btn:hover {
  border-color: #f87171;
}

.touch-reset-btn:active {
  background: #ef4444;
  border-color: #fca5a5;
}

.touch-autopilot-btn {
  color: #a7f3d0;
  border-color: #34d399;
}

.touch-autopilot-btn.active {
  background: #10b981;
  color: #ffffff;
  border-color: #6ee7b7;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
}

/* Main Gamepad Row: D-Pad on Left, Action Buttons on Right */
.touch-gamepad-row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  touch-action: none;
}

/* D-Pad Sizing & Styling */
.d-pad {
  position: relative;
  width: 126px;
  height: 126px;
  flex-shrink: 0;
  touch-action: none;
}

.d-btn {
  position: absolute;
  width: 42px;
  height: 42px;
  background: #334155;
  border: 2px solid #64748b;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  touch-action: none;
  box-shadow: 0 4px 0 #1e293b;
  -webkit-tap-highlight-color: transparent;
}

.d-btn:active, .d-btn.active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #1e293b;
  background: #3b82f6;
  border-color: #93c5fd;
}

.d-up    { top: 0;    left: 42px; border-bottom: none; border-radius: 8px 8px 0 0; }
.d-down  { bottom: 0; left: 42px; border-top: none;    border-radius: 0 0 8px 8px; }
.d-left  { top: 42px; left: 0;    border-right: none;  border-radius: 8px 0 0 8px; }
.d-right { top: 42px; right: 0;   border-left: none;   border-radius: 0 8px 8px 0; }

.d-center {
  position: absolute;
  top: 42px;
  left: 42px;
  width: 42px;
  height: 42px;
  background: #1e293b;
  border: none;
}

/* Action Buttons (B & A) */
.action-buttons {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-shrink: 0;
  touch-action: none;
}

.action-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-retro);
  font-size: 12px;
  color: #fff;
  touch-action: none;
  border: 3px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: all 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-b {
  background: #ef4444;
  box-shadow: 0 5px 0 #991b1b;
}

.btn-b:active, .btn-b.active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #991b1b;
  background: #dc2626;
}

.btn-a {
  background: #3b82f6;
  box-shadow: 0 5px 0 #1e3a8a;
  transform: translateY(-8px);
}

.btn-a:active, .btn-a.active {
  transform: translateY(-5px);
  box-shadow: 0 2px 0 #1e3a8a;
  background: #2563eb;
}

.action-btn small {
  font-size: 8px;
  opacity: 0.85;
  margin-top: 2px;
}

/* Control guide footer */
.controls-guide {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  font-size: 11px;
  color: #94a3b8;
  background: rgba(15, 23, 42, 0.8);
  padding: 10px 18px;
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key-tag {
  background: #1e293b;
  border: 1px solid #475569;
  border-bottom: 2px solid #334155;
  color: #38bdf8;
  font-family: var(--font-retro);
  font-size: 9px;
  padding: 3px 6px;
  border-radius: 4px;
}

/* Modal dialogs */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-box {
  background: #0f172a;
  border: 3px solid #38bdf8;
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.4);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  color: #e2e8f0;
}

.modal-title {
  font-family: var(--font-retro);
  color: #38bdf8;
  font-size: 15px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 2px solid #1e293b;
  padding-bottom: 12px;
}

.modal-content {
  font-size: 13px;
  line-height: 1.6;
}

.modal-content ul {
  margin-left: 20px;
  margin-top: 8px;
  margin-bottom: 16px;
}

.modal-content li {
  margin-bottom: 6px;
}

.modal-close {
  display: block;
  width: 100%;
  margin-top: 18px;
  background: #2563eb;
  color: #fff;
  border: none;
  font-family: var(--font-retro);
  font-size: 11px;
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-close:hover {
  background: #3b82f6;
}

/* Corner Creator Credit Badge */
.creator-badge {
  position: fixed;
  bottom: 12px;
  right: 16px;
  z-index: 50;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(56, 189, 248, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #e2e8f0;
  font-family: var(--font-retro), var(--font-body);
  font-size: 9px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  letter-spacing: 0.3px;
}

@media (max-width: 900px) {
  .creator-badge {
    position: static;
    margin-top: 12px;
    text-align: center;
  }
}

/* ==========================================
   Comprehensive Mobile & Tablet Responsiveness
   ========================================== */

@media (max-width: 768px) {
  body {
    padding: 4px 2px;
    justify-content: flex-start;
  }

  .game-container {
    max-width: 100%;
    width: 100%;
  }

  /* Maximize screen width inside the arcade bezel */
  .cabinet-bezel {
    padding: 6px 4px 10px 4px;
    border-width: 2px;
    border-radius: 12px;
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.3), 0 8px 24px rgba(0, 0, 0, 0.85);
    width: 100%;
  }

  /* Compact, sleek marquee header to give maximum vertical height to the canvas */
  .bezel-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 2px 2px 6px 2px;
    margin-bottom: 6px;
    gap: 4px;
    width: 100%;
  }

  .brand-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .brand-icon {
    width: 24px;
    height: 24px;
  }

  .brand-title {
    font-size: 10px;
    letter-spacing: 0.5px;
    white-space: nowrap;
  }

  .brand-subtitle {
    display: none;
  }

  .cabinet-controls {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    width: auto;
  }

  /* On mobile portrait, hide redundant Pause & Reset in the header because
     the dedicated touch-meta-bar and on-screen pause button are right at thumb level */
  .cabinet-controls #btn-pause,
  .cabinet-controls #btn-reset {
    display: none;
  }

  .btn-icon {
    font-size: 7.5px;
    padding: 4px 6px;
    border-radius: 4px;
    gap: 3px;
    white-space: nowrap;
  }

  /* Enlarged game canvas wrapper */
  .screen-wrapper {
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 60vh;
    border-radius: 6px;
    border-width: 1.5px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.9), 0 2px 10px rgba(0, 0, 0, 0.6);
  }

  /* Sleek, responsive touch controls below canvas */
  .touch-controls {
    margin-top: 6px;
    gap: 6px;
    width: 100%;
  }

  .touch-meta-bar {
    gap: 8px;
    width: 100%;
  }

  .touch-pause-btn {
    font-size: 8px;
    padding: 5px 12px;
  }

  .touch-gamepad-row {
    padding: 0 4px;
  }

  .d-pad {
    width: 120px;
    height: 120px;
  }

  .d-btn {
    width: 40px;
    height: 40px;
    font-size: 15px;
  }

  .d-up    { left: 40px; }
  .d-down  { left: 40px; }
  .d-left  { top: 40px; }
  .d-right { top: 40px; }
  .d-center { top: 40px; left: 40px; width: 40px; height: 40px; }

  .action-buttons {
    gap: 12px;
  }

  .action-btn {
    width: 56px;
    height: 56px;
    font-size: 11.5px;
  }

  .action-btn small {
    font-size: 7.5px;
  }

  /* Hide Desktop Keyboard Guide on mobile */
  .controls-guide {
    display: none !important;
  }

  .creator-badge {
    position: static;
    margin-top: 6px;
    margin-bottom: 4px;
    text-align: center;
    padding: 4px 10px;
    font-size: 7.5px;
    opacity: 0.8;
  }
}

/* Extra small mobile adjustments (screen width < 420px) */
@media (max-width: 420px) {
  body {
    padding: 2px 0;
  }

  .cabinet-bezel {
    padding: 4px 2px 8px 2px;
    border-radius: 8px;
    border-width: 1.5px;
  }

  .brand-title {
    font-size: 9px;
  }

  .btn-icon {
    font-size: 7px;
    padding: 3px 4px;
    gap: 2px;
  }

  .d-pad {
    width: 114px;
    height: 114px;
  }

  .d-btn {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }

  .d-up    { left: 38px; }
  .d-down  { left: 38px; }
  .d-left  { top: 38px; }
  .d-right { top: 38px; }
  .d-center { top: 38px; left: 38px; width: 38px; height: 38px; }

  .action-btn {
    width: 52px;
    height: 52px;
    font-size: 11px;
  }

  .action-btn small {
    font-size: 7px;
  }

  .action-buttons {
    gap: 10px;
  }
}

/* Mobile Landscape Optimization - Full Console Handheld Mode */
@media (max-height: 550px) and (orientation: landscape) {
  body {
    padding: 0;
    margin: 0;
    overflow: hidden;
    height: 100vh;
    justify-content: center;
    align-items: center;
  }

  .game-container {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .cabinet-bezel {
    width: 100vw;
    height: 100vh;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .bezel-header {
    display: none !important;
  }

  .controls-guide {
    display: none !important;
  }

  .creator-badge {
    display: none !important;
  }

  /* Fill almost entire landscape viewport with the 4:3 canvas */
  .screen-wrapper {
    height: 94vh;
    width: auto;
    max-width: calc(94vh * 4 / 3);
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    border: 2px solid #3b82f6;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.95);
    margin: 0 auto;
  }

  /* Flanking handheld touch controls in landscape (Switch / Game Boy style) */
  .touch-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    pointer-events: none;
    display: flex !important;
    flex-direction: column;
    justify-content: flex-end;
    z-index: 40;
  }

  .touch-meta-bar {
    position: fixed;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    pointer-events: auto;
    z-index: 50;
    gap: 8px;
  }

  .touch-pause-btn {
    font-size: 8px;
    padding: 4px 10px;
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .touch-gamepad-row {
    width: 100%;
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
  }

  .d-pad {
    pointer-events: auto;
    width: 108px;
    height: 108px;
    opacity: 0.88;
  }

  .d-btn {
    width: 36px;
    height: 36px;
    font-size: 13px;
    background: rgba(51, 65, 85, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .d-up    { left: 36px; }
  .d-down  { left: 36px; }
  .d-left  { top: 36px; }
  .d-right { top: 36px; }
  .d-center { top: 36px; left: 36px; width: 36px; height: 36px; }

  .action-buttons {
    pointer-events: auto;
    opacity: 0.88;
    gap: 12px;
  }

  .action-btn {
    width: 48px;
    height: 48px;
    font-size: 11px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
}
