:root {
  --red: #e8352b;
  --orange: #f39019;
  --yellow: #ffcc00;
  --green: #2ca84f;
  --blue: #1f6fe0;

  --wood: #7a4a24;
  --wood-lite: #9c6534;
  --wood-dark: #4f2f16;
  --plastic: #d9c7a3;
  --plastic-dark: #b49a6e;
  --nes-gray: #d7d3c8;
  --nes-gray-d: #9a978c;
  --screen-blue: #5c94fc;
  --led-red: #ff4133;
  --led-green: #47ff6a;
}

* {
  box-sizing: border-box; margin: 0; padding: 0;
  /* kill double-tap-to-zoom from fast tapping (esp. on the game screen) */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html, body { height: 100%; }
body {
  font-family: 'Press Start 2P', monospace;
  height: 100vh;
  overflow: hidden;               /* no page scroll: everything is scaled to fit */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  color: #f5efe0;
  -webkit-user-select: none;
  user-select: none;
  /* dark 80s living-room wall + carpet vibe */
  background:
    radial-gradient(circle at 50% 0%, #3a2c22 0%, #241a13 60%, #16100b 100%);
  image-rendering: pixelated;
}

/* the whole console + labels; JS scales this down to fit the viewport */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center center;
}

/* pixel button reset feel */
button { font-family: 'Press Start 2P', monospace; cursor: pointer; }

.home-link {
  align-self: flex-start;
  position: relative; z-index: 2;
  font-size: 0.6rem;
  color: var(--yellow);
  text-decoration: none;
  margin-bottom: 1.2rem;
  padding: 0.55rem 0.7rem;
  background: #201812;
  border: 3px solid #000;
  box-shadow: 3px 3px 0 #000;
}
.home-link:hover { background: var(--yellow); color: #201812; }

.console { width: min(820px, 96vw); position: relative; z-index: 2; }

/* decorative FuncoLand coins scattered on the brown background */
.bg-coins { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-coin {
  position: absolute;
  width: 72px;
  image-rendering: pixelated;
  opacity: 0.9;
  filter: drop-shadow(0 5px 8px rgba(0,0,0,0.55));
  animation: coinfloat 6s ease-in-out infinite;
}
.bg-coin:nth-of-type(1) { top: 7%;  left: 3%;  width: 88px; animation-delay: 0s; }
.bg-coin:nth-of-type(2) { top: 27%; left: 8%;  width: 56px; animation-delay: -1.2s; }
.bg-coin:nth-of-type(3) { top: 54%; left: 2%;  width: 70px; animation-delay: -2.4s; }
.bg-coin:nth-of-type(4) { bottom: 7%; left: 6%; width: 60px; animation-delay: -0.6s; }
.bg-coin:nth-of-type(5) { top: 9%;  right: 4%; width: 82px; animation-delay: -1.8s; }
.bg-coin:nth-of-type(6) { top: 34%; right: 7%; width: 54px; animation-delay: -3s; }
.bg-coin:nth-of-type(7) { top: 61%; right: 3%; width: 72px; animation-delay: -0.9s; }
.bg-coin:nth-of-type(8) { bottom: 6%; right: 8%; width: 58px; animation-delay: -2.1s; }
@keyframes coinfloat {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-16px) rotate(6deg); }
}

/* =================== CRT TELEVISION =================== */
.tv {
  background: linear-gradient(180deg, var(--wood-lite), var(--wood) 30%, var(--wood-dark));
  border: 5px solid #000;
  border-radius: 14px 14px 10px 10px;
  padding: 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.6), inset 0 2px 0 rgba(255,255,255,0.15);
  position: relative;
}
/* faux wood grain */
.tv::before {
  content: "";
  position: absolute; inset: 5px;
  border-radius: 10px;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,0.06) 0 3px, rgba(255,255,255,0.04) 3px 6px);
  pointer-events: none;
}

.tv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-logo { height: 34px; background: #fff; padding: 3px 6px; border: 3px solid #000; }
.brand-text { display: flex; flex-direction: column; gap: 3px; }
.brand-fun { font-size: 0.85rem; color: var(--yellow); text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
.brand-sys { font-size: 0.4rem; color: #efe6d0; }
.power { display: flex; align-items: center; gap: 6px; font-size: 0.42rem; color: #efe6d0; }
.led {
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9a92, var(--led-red));
  box-shadow: 0 0 8px var(--led-red), inset 0 0 3px rgba(0,0,0,0.4);
  animation: ledpulse 2.2s ease-in-out infinite;
}
@keyframes ledpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.tv-body {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 14px;
  position: relative;
  z-index: 1;
}

/* the black plastic bezel around the tube */
.bezel {
  background: linear-gradient(145deg, #2c2c2c, #101010);
  border: 4px solid #000;
  border-radius: 22px;
  padding: 16px;
  box-shadow: inset 0 3px 10px rgba(255,255,255,0.08), inset 0 -6px 16px rgba(0,0,0,0.8);
}

.screen {
  position: relative;
  width: 100%;
  aspect-ratio: 360 / 540;
  overflow: hidden;
  background: #000;
  /* CRT tube curvature */
  border-radius: 34px / 26px;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.9);
}
#game {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated;
  /* subtle bulge */
  transform: scale(1.015);
}

/* CRT overlays */
.crt-vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
  border-radius: 34px / 26px;
}
.scanlines {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.28) 0 2px, transparent 2px 4px);
}
.glass {
  position: absolute; inset: 0; pointer-events: none; border-radius: 34px / 26px;
  background: linear-gradient(135deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.04) 22%, transparent 45%);
}
.flicker {
  position: absolute; inset: 0; pointer-events: none; background: rgba(255,255,255,0.03);
  animation: flick 0.14s steps(2) infinite;
}
@keyframes flick { 0% { opacity: 0.5; } 50% { opacity: 0; } 100% { opacity: 0.35; } }

/* overlays (start / game over) */
.overlay {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 0.9rem; padding: 1.2rem;
  background: rgba(4, 10, 20, 0.78);
}
.overlay.hidden { display: none; }
.overlay-cat { width: 128px; image-rendering: pixelated; animation: bob 1.3s steps(2) infinite; }
@keyframes bob { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-7px);} }
.overlay-title { font-size: 2.1rem; color: var(--yellow); text-shadow: 3px 3px 0 #000; letter-spacing: 1px; }
.overlay-title.small { color: var(--red); }
.overlay-tag { font-size: 0.78rem; line-height: 1.8; color: #fff; }
.overlay-hint { font-size: 0.54rem; color: #8fd6b0; line-height: 1.6; }
.final { color: var(--led-green); font-size: 1.6rem; }
.newbest { font-size: 0.7rem; color: var(--yellow); animation: blink 0.6s steps(1) infinite; }
.newbest.hidden { display: none; }

.pixel-btn {
  font-size: 0.8rem;
  color: #000;
  background: var(--yellow);
  border: 3px solid #000;
  padding: 0.9rem 1.3rem;
  box-shadow: 4px 4px 0 #000;
}
.pixel-btn:hover { background: #fff; }
.pixel-btn:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 #000; }

/* tv side controls */
.tv-side { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.readout {
  width: 100%;
  background: #0a0f0a;
  border: 3px solid #000;
  border-radius: 4px;
  padding: 6px 5px;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.9);
}
.readout-row { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 4px; }
.readout-row:last-child { margin-bottom: 0; }
.readout-label { font-size: 0.44rem; color: #6f6; opacity: 0.7; }
.readout-val {
  font-family: 'VT323', monospace;
  font-size: 2.1rem; line-height: 1;
  color: var(--led-green);
  text-shadow: 0 0 8px rgba(71,255,106,0.8);
}
.readout-val.hi { color: var(--led-red); text-shadow: 0 0 8px rgba(255,65,51,0.7); }

.knobs { display: flex; gap: 8px; }
.knob {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #4a4a4a, #1a1a1a);
  border: 2px solid #000;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 3px rgba(0,0,0,0.5);
}
.knob span { width: 3px; height: 11px; background: #cfcfcf; border-radius: 1px; }
.knob:last-child span { transform: rotate(60deg); }
.speaker {
  width: 100%; height: 46px; border-radius: 4px;
  background:
    radial-gradient(circle, #000 1px, transparent 1.6px) 0 0 / 7px 7px,
    linear-gradient(180deg, #2a1c10, #1a1109);
  border: 3px solid #000;
}

/* =================== NES CONTROLLER =================== */
.pad {
  margin: 18px auto 0;
  width: min(640px, 96vw);
  position: relative; z-index: 2;
  background: linear-gradient(180deg, #e6e2d6, var(--nes-gray) 40%, var(--nes-gray-d));
  border: 5px solid #000;
  border-radius: 10px;
  padding: 16px 16px 18px;
  box-shadow: 0 12px 24px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.5);
}
.pad-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }

/* d-pad */
.dpad { position: relative; width: 76px; height: 76px; }
.dpad-v, .dpad-h {
  position: absolute; background: #2a2a2a; border: 2px solid #000; border-radius: 3px;
}
.dpad-v { left: 27px; top: 2px; width: 22px; height: 72px; }
.dpad-h { top: 27px; left: 2px; height: 22px; width: 72px; }
.dpad-dot {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #4a4a4a, #151515);
  z-index: 2;
}

/* middle: cartridge slot + select/start */
.pad-mid { display: flex; flex-direction: column; align-items: center; gap: 9px; }
.cart-slot {
  width: 100%;
  background: #24160c;
  border: 3px solid #000;
  border-radius: 4px;
  padding: 6px 4px;
  text-align: center;
}
.cart-slot span { font-size: 0.4rem; color: var(--yellow); }
.se-btns { display: flex; gap: 12px; }
.se-btn {
  background: linear-gradient(180deg, #3a3a3a, #161616);
  border: 2px solid #000;
  border-radius: 9px;
  padding: 6px 4px;
  width: 62px;
  box-shadow: 0 4px 0 #000;
}
.se-btn span {
  display: inline-block;
  background: #b21f16;
  color: #fff;
  font-size: 0.36rem;
  padding: 3px 5px;
  border-radius: 2px;
}
.se-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }

/* A / B buttons */
.ab { display: flex; flex-direction: column; align-items: center; gap: 5px; transform: rotate(-12deg); }
.ab-btn-wrap { display: flex; gap: 12px; }
.ab-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff6a5e, #c11d13 65%, #7c0f08);
  border: 3px solid #000;
  color: #ffd9d5; font-size: 0.75rem;
  box-shadow: 0 6px 0 #5c0a05, 0 8px 10px rgba(0,0,0,0.4), inset 0 3px 5px rgba(255,255,255,0.35);
}
.ab-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #5c0a05, inset 0 3px 5px rgba(255,255,255,0.35); }
.ab-labels { display: flex; gap: 30px; font-size: 0.5rem; color: #7c0f08; }

.disclaimer {
  max-width: 460px; margin-top: 1.6rem; text-align: center;
  position: relative; z-index: 2;
  font-size: 0.5rem; line-height: 2; color: rgba(245,239,224,0.5);
}

/* hide the scattered coins when the console fills the viewport (avoid overlap) */
@media (max-width: 1024px) {
  .bg-coins { display: none; }
}

@media (max-width: 480px) {
  .tv-body { grid-template-columns: 1fr; }
  .tv-side { flex-direction: row; justify-content: space-between; flex-wrap: wrap; }
  .readout { width: auto; flex: 1; }
  .ab { transform: rotate(-8deg); }
  .dpad { width: 66px; height: 66px; }
  .dpad-v { left: 23px; width: 20px; height: 62px; }
  .dpad-h { top: 23px; width: 62px; height: 20px; }
}
