/* === FONT FACE === */
@font-face {
  font-family: "nabla";
  src: url(fonts/nabla-regular-variable-font.ttf) format("truetype");
}

@font-face {
  font-family: "Milchroma";
  src: url("fonts/Michroma/Michroma-Regular.ttf") format("truetype");
}

@font-face {
  font-family: "Roboto";
  src: url("fonts/Roboto/Roboto-VariableFont_wdth,wght.ttf") format("truetype");
}

@font-face {
  font-family: "Sofia_Sans";
  src: url("fonts/Sofia_Sans/SofiaSans-VariableFont_wght.ttf") format("truetype");
}

/* === ROOT VARIABLES === */
:root {
  --z-base: 1;
  --z-canvas: 150;
  --z-ui-base: 5000;
  --z-menu: 5001;
  --z-buttons: 5002;
  --z-overlays: 5400;
  --z-footer: 5500;
  --z-modals: 7000;
  
  /* === COLOR PALETTE === */
  --btn-primary: #960b06;
  --btn-primary-hover: #eb1111;
  --accent-cyan: #0ff;
  --text-dark: #0a0a0a;
  --border-dark: #222;
  --bg-overlay: rgba(255,255,255,0.76);
  --bg-popup: rgba(14,163,233,0.699);
  --bg-dark: rgba(0,0,0,0.699);
  
  /* === SPACING === */
  --btn-radius: clamp(12px, 2vw, 20px);
  --btn-padding: clamp(3px, 1vw, 5px) clamp(6px, 2vw, 8px);
  --content-width: clamp(300px, 95%, 720px);
}

/* === BASE STYLES === */
* { box-sizing: border-box; }

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  background: url(img_pollo_locco/img/5_background/layers/background-mesico.jpeg) center/cover;
  overflow: hidden;
}

h1 {
  position: relative;
  color: #000;
  font: clamp(24px, 5vw, 60px)/1 "nabla", Arial, Helvetica, sans-serif;
  letter-spacing: 3px;
  text-align: center;
  text-shadow: 2px 2px 0 #661515, -6px -6px 0 #661515, 2px -2px 0 #661515, -2px 2px 0 #661515;
}

/* === CANVAS STYLES === */
#titleCanvas, canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#titleCanvas { height: clamp(60px, 10vh, 100px); }

#game-container {
  padding-bottom: clamp(50px, 7vh, 70px);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* === LAYOUT CONTAINERS === */
#content, .start-screen, .controls-screen, .end-screen, .story-container {
  position: absolute;
  left: 50%;
  width: var(--content-width);
  height: auto;
  aspect-ratio: 3/2;
  max-height: 480px;
}

.controls-screen, .story-container {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
  margin-right: 7px;
}

#content {
  top: clamp(50px, 10vh, 100px);
  transform: translateX(-50%);
  pointer-events: none !important;
  z-index: 0 !important;
}

.start-screen {
  z-index: var(--z-ui-base);
  background: url(img_pollo_locco/img/9_intro_outro_screens/start/startscreen_1.png) no-repeat center/100% 100%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.menu {
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 10px;
}

/* === BUTTONS === */
.button-start-screen, .button-popup, .button-footer, button {
  background: var(--btn-primary);
  border: clamp(1px, 0.5vw, 4px) solid var(--border-dark) !important;
  color: var(--accent-cyan);
  padding: var(--btn-padding);
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font: clamp(13px, 2vw, 20px)/1 "Roboto", "Sofia_Sans", "Milchroma";
  cursor: pointer;
  border-radius: var(--btn-radius);
  margin: 0 8px;
  transition: transform 0.3s, font-size 0.3s, padding 0.3s, box-shadow 0.3s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 1.5px 0 #000;
  position: relative;
  z-index: inherit;
  will-change: transform;
  backface-visibility: hidden;
}

.button-start-screen:hover, .button-footer:hover, .button-popup:hover, button:hover {
  background: var(--btn-primary-hover);
  transform: scale(1.1);
}

/* === MODAL SCREENS === */
.controls-screen, .end-screen, .story-container {
  top: 50%;
  transform: translate(-50%, -50%);
  background: url(img_pollo_locco/img/11_others/background-gamepad.png) no-repeat center/100% 100%;
  color: rgb(13, 14, 14);
  padding: clamp(10px, 2vw, 20px);
  font-size: clamp(12px, 1.5vw, 15px);
  border-radius: 10px;
  text-align: center;
  display: none;
  z-index: var(--z-modals);
}

.controls, .fs-centered {
  font-family: "Roboto", "Sofia_Sans";
  font-size: 10px; 
  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls { align-items: flex-start; }

.controls-container {
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: clamp(5px, 1vh, 10px);
  padding-left: 0;
}

.controls-container .box.jc-center:first-child {
  justify-content: flex-start;
  width: 30%;
  padding-left: 0;
}

.controls-container .box.jc-center:last-child {
  justify-content: flex-start;
  width: 60%;
}

.controls-container img {
  margin: 0 clamp(5px, 1vw, 10px) 0 0;
  max-width: 50px;
  width: 20vw;
  height: auto;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
}

.controls-container .box.jc-center img {
  background: var(--bg-overlay);
  border-radius: 10px;
  padding: 8px;
}

/* === POPUP === */
.popup {
  position: fixed;
  top: 27%;
  left: 83%;
  transform: translate(-50%, -50%);
  background: var(--bg-popup);
  padding: clamp(1px, 0.5vw, 4px);
  border: clamp(1px, 0.3vw, 2px) solid var(--border-dark);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  z-index: 5300;
  font-size: clamp(9px, 1vw, 14px);
  text-align: center;
  max-width: 200px;
}

/* === GAME SCREENS === */
.game-over-screen, .game-won-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-overlays);
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-over-screen {
  background: url("img_pollo_locco/img/5_background/layers/background-mesico.jpeg") center/cover no-repeat;
}

.game-over-screen img { max-width: clamp(30%, 50%, 60%); }

.game-won-screen {
  background: url("img_pollo_locco/img/11_others/Designer.png") center/cover no-repeat; 
  flex-direction: column;
}

.game-won-screen h1 {
  color: white;
  font-size: clamp(30px, 6vw, 68px);
}

/* === FOOTER === */
footer {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  min-height: 40px;
  background: var(--accent-cyan);
  z-index: var(--z-footer);
  padding: 5px 10px;
  
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.footer-left, .footer-right { 
  display: flex; 
  gap: 8px; 
}

.footer-center { 
  font-size: clamp(14px, 3vw, 17px); 
  text-align: center; 
  font-family: "Roboto", "Sofia_Sans", "Milchroma"; 
}

#play-again-button { 
  display: inline-block; 
}

.footer-right #play-again-button.button-footer {
  display: inline-block;
}

.start-screen-active .footer-content {
  justify-content: center !important;
  align-items: center !important;
  gap: 20px !important;
  height: 27px;
}

/* === MOBILE CONTROLS === */
#mobile-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 10px;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  z-index: var(--z-canvas);
  pointer-events: none;
}

.mobile-button-container-bottom-left, .mobile-button-container-bottom-right {
  display: flex;
  pointer-events: auto;
}

.mobile-button-container-bottom-left { justify-content: flex-start; }
.mobile-button-container-bottom-right { justify-content: flex-end; }

.mobile-button-container-bottom-settings {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  pointer-events: auto;
}

.mobile-btn {
  background: var(--accent-cyan);
  border: 2px solid var(--border-dark);
  border-radius: 8px;
  padding: 3px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 1.5px 0 #000;
  touch-action: manipulation;
  display: flex;
  pointer-events: auto !important;
  will-change: transform;
  backface-visibility: hidden;
}

.mobile-btn img {
  width: 35px;
  height: 35px;
  pointer-events: none;
}

/* === ROTATE OVERLAY === */
#rotate-device-overlay {
  display: none;
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: url("img_pollo_locco/img/5_background/layers/background-mesico.jpeg") center/cover no-repeat;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.rotate-container { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
}

.rotate-arrow {
  font-size: 2.5rem;
  color: #000;
  text-shadow: 2px 2px 6px #fdfdfd;
  font-weight: bold;
  margin: -20px 0 20px 0;
  animation: arrowMove 2s infinite alternate;
  text-align: center;
}

@keyframes arrowMove {
  0% { transform: translateY(0); opacity: 0.5; }
  100% { transform: translateY(20px); opacity: 1; }
}

#rotate-phone-img {
  width: clamp(50px, 10vw, 100px);
  transition: transform 1s;
  animation: rotatePhone 2s infinite alternate;
}

@keyframes rotatePhone {
  0% { transform: rotate(0deg) scale(1); }
  100% { transform: rotate(90deg) scale(1.1); }
}

.rotate-text {
  font-size: clamp(0.9rem, 2.5vw, 1.4rem);
  color: #fff;
  text-align: center;
  text-shadow: 2px 2px 6px #000;
  font-weight: bold;
  padding: clamp(6px, 2vw, 14px) clamp(12px, 4vw, 24px);
  background: var(--bg-dark);
  border-radius: 12px;
  margin-top: 20px;
}

/* === UTILITY CLASSES === */
.box.jc-center { display: flex; justify-content: center; }

.screen-title, .controls-container span, .story-container p {
  background: var(--bg-overlay);
  color: var(--text-dark);
  font-size: clamp(7px, 2.5vw, 20px);
  padding: clamp(3px, 1vw, 10px) clamp(6px, 2vw, 18px);
  border-radius: clamp(4px, 2vw, 8px);
  font-weight: bold;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.55);
  margin-right: 7px;
}

.screen-title { margin-bottom: 10px; }

#btn-audio {
  touch-action: manipulation;
  display: flex;
}

#music-toggle-button { 
  display: inline-block; 
}

body.start-screen-active #music-toggle-button {
  display: none !important;
}

body.start-screen-active #play-again-button {
  display: none !important;
}

#btn-audio img { pointer-events: none; }

.hidden-mobile { display: block; }
.visible-mobile { display: none; }

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
  .mobile-btn, .button-start-screen, .button-footer, .button-popup, button,
  .rotate-arrow, #rotate-phone-img {
    transition: none !important;
    animation: none !important;
  }
}

/* ================================ RESPONSIVE DESIGN ================================ */

/* === Mobile Portrait === */
@media (max-width: 599px) {
  #canvas { 
    width: 100vw !important; 
    height: 100vh !important; 
    max-width: 100vw !important; 
    max-height: 80vh !important; 
    z-index: 1 !important; 
  }
  
  #content, .start-screen {
    position: fixed !important;
    left: 0 !important;
    top: -10px !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    transform: none !important;
    aspect-ratio: unset !important;
    background-size: 100% 100% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    z-index: var(--z-ui-base) !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    padding-top: clamp(24px, 8%, 48px) !important;
    flex-direction: column !important;
  }
  
  .game-won-screen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    background: url("img_pollo_locco/img/11_others/designer-congratulations-show-mobile.jpeg") center/cover no-repeat !important;
    background-size: cover !important;
    background-position: center !important;
    z-index: var(--z-overlays) !important;
    transform: none !important;
    aspect-ratio: unset !important;
  }
  
  .game-won-screen h1 {
    color: white !important;
    font-size: clamp(20px, 5vw, 40px) !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8) !important;
    margin-top: 20vh !important;
  }
  
  .menu { z-index: var(--z-menu) !important; position: relative; }
  .button-start-screen { z-index: var(--z-buttons) !important; position: relative; font-size: 12px; }
  #titleCanvas, h1 { display: none !important; }
  
 .start-screen-active footer {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

  .mobile-btn { padding: 7px; border-radius: 8px; }
  .mobile-btn img { width: 13px; height: 13px; }
  
  .game-over-screen { 
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: var(--z-overlays) !important; 
  }
  
  .controls-screen, .story-container {
    width: 95vw;
    max-width: 99vw;
    max-height: 98vh;
    height: 100vh;
    padding: 8px;
    font-size: 12px;
    z-index: var(--z-modals) !important;
  }
  
  .popup { 
    top: 27% !important; 
    left: 83% !important; 
  }
  
  .controls-container img { max-width: 20px; width: 10vw; }
  .controls-container span { font-size: 12px; line-height: 1 !important; }
  .controls-container .box.jc-center img { 
    padding: 2px; 
    border-radius: 6px; 
    margin-right: 1px;
  }
  
  footer {
    padding: 5px;
    z-index: var(--z-footer) !important;
    align-items: center !important;
  }
  
  .footer-content { justify-content: center; gap: 5px; }
  .footer-center { font-size: 12px; }
  
  .button-footer {
    padding: 3px 6px;
    font-size: 12px;
    border-width: 1px;
    z-index: 5501 !important;
    position: relative;
  }
  
  .hidden-mobile { display: none !important; }
  .visible-mobile, #btn-play-again { display: block !important; }
}

/* === Tablet Portrait === */
@media (min-width: 600px) and (max-width: 767px) {
  #titleCanvas { width: 720px !important; height: 100px !important; }
  
  #canvas {
    height: 330px !important;
    position: absolute !important;
    top: 48% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 1 !important;
  }
  
  #content, .start-screen {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    transform: none !important;
    aspect-ratio: unset !important;
    background-size: 100% 100% !important;
    z-index: var(--z-ui-base) !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    padding-top: clamp(24px, 8%, 38px) !important;
    flex-direction: column !important;
  }
  
  .game-won-screen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: url("img_pollo_locco/img/11_others/designer-congratulations-show-mobile.jpeg") center/cover no-repeat !important;
    z-index: var(--z-overlays) !important;
  }
  
  #titleCanvas, h1 { display: none !important; }
  
  .start-screen-active footer {
    min-height: 55px !important;
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: var(--z-footer) !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  .menu { z-index: var(--z-menu) !important; position: relative; }
  .button-start-screen { z-index: var(--z-buttons) !important; position: relative; }
  
  .controls-screen, .story-container {
    width: 95vw;
    max-width: 99vw;
    max-height: 100vh;
    height: 100vh;
    padding: 10px;
    font-size: 13px;
    z-index: var(--z-modals) !important;
  }
  
  .popup { 
    width: clamp(120px, 35vw, 180px) !important; 
    top: 34% !important; 
    left: 83% !important; 
  }
}

/* === Tablet Landscape === */
@media (min-width: 768px) and (max-width: 1023px) {
  #titleCanvas { width: 720px !important; height: 100px !important; }
  
  #canvas {
    width: 720px !important;
    height: 400px !important;
    position: absolute !important;
    top: 48% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 1 !important;
  }
  
  .start-screen { z-index: var(--z-ui-base) !important; }
  .menu { padding-top: clamp(10px, 25vh, 85px) !important; z-index: var(--z-menu) !important; }
  .button-start-screen { z-index: var(--z-buttons) !important; position: relative; }
  
  .start-screen-active footer {
    min-height: 68px !important;
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: var(--z-footer) !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  .game-active footer { display: none !important; }
  
  .mobile-btn { padding: 5px; border-radius: 8px; }
  .mobile-btn img { width: 35px; height: 35px; }
  
  .popup {
    width: clamp(150px, 25vw, 200px) !important;
    top: 37% !important;
    left: 75% !important;
    font-size: clamp(14px, 1.2vw, 16px);
  }
  
  .game-over-screen img { max-width: clamp(30%, 40%, 60%); }
  
}

/* === Small Desktop === */
@media (min-width: 1024px) and (max-width: 1280px) {
  #titleCanvas { width: 720px !important; height: 100px !important; }
  
  #canvas {
    width: 720px !important;
    height: 480px !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 1 !important;
  }
  
  .start-screen { top: 50% !important; z-index: var(--z-ui-base) !important; }
  .menu { padding-top: clamp(40px, 10vh, 80px) !important; z-index: var(--z-menu) !important; }
  
  .start-screen-active footer {
    min-height: 90px !important;
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: var(--z-footer) !important;
    justify-content: center !important;
    align-items: center !important;
  }
  
  .game-active footer { display: none !important; }
  
  .popup {
    width: clamp(150px, 20vw, 200px) !important;
    top: 39% !important; 
    left: 69% !important;  
    font-size: clamp(14px, 1vw, 16px);
  }
}

/* === Large Desktop === */
@media (min-width: 1281px) {
  #titleCanvas { width: 720px !important; height: 100px !important; }
  
  .start-screen { z-index: var(--z-ui-base) !important; }
  
  .start-screen-active footer {
    min-height: 100px !important;
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: var(--z-footer) !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .menu {
    padding-top: clamp(10px, 2vh, 20px);
  }
  
  .game-over-screen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: var(--z-overlays) !important;
  }

  .popup {
    width: clamp(150px, 20vw, 200px) !important;
    top: 48% !important; 
    left: 62% !important;  
    font-size: clamp(14px, 1vw, 16px);
  }
  
  .game-active footer { display: none !important; }
}

/* === Footer visible only on large desktop monitors NON-TOUCH === */
@media (min-width: 1400px) and (pointer: fine) and (hover: hover) {
  footer {
    min-height: 80px !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .game-active footer {
    display: flex !important;
    min-height: 80px !important;
  }

  .popup {
    width: clamp(150px, 20vw, 200px) !important;
    top: 49% !important; 
    left: 56% !important;  
    font-size: clamp(14px, 1vw, 16px);
  }
}

/* === Footer hidden during game on tablets/touch devices === */
@media (pointer: coarse) {
  .game-active footer {
    display: none !important;
  }
}

/* === Special Cases === */
@media (max-height: 920px) {
  canvas { z-index: 1 !important; }
  .controls-screen, .story-container, .end-screen { 
    height: 100vh; 
    z-index: var(--z-modals) !important; 
  }

  .mobile-btn { padding: 3px; border-radius: 8px; }
  .mobile-btn img { width: 21px; height: 21px; }
}

/* === Landscape Mobile Devices === */
@media (max-width: 658px) and (max-height: 320px) {
  .mobile-btn img { width: 18px !important; height: 18px !important; }
  #canvas { height: 310px !important; top: 40% !important; }
}

@media (max-width: 896px) and (max-height: 414px) and (orientation: landscape),
      (max-width: 844px) and (max-height: 390px) and (orientation: landscape) {
  .mobile-btn img { width: 18px !important; height: 18px !important; }
}

@media (max-width: 882px) and (max-height: 344px) and (orientation: landscape) {
  .mobile-btn img { width: 15px !important; height: 15px !important; }
  #canvas { height: 332px !important; top: 48% !important; }
  .start-screen-active footer { min-height: 45px !important; align-items: center !important; }
  .menu { top: 2% !important; z-index: var(--z-menu) !important; }
}

@media (max-width: 915px) and (max-height: 412px) and (orientation: landscape) {
  .mobile-btn { padding: 2px !important; border-radius: 8px !important; margin-left: 0px; }
  .mobile-btn img { width: 15px !important; height: 15px !important; gap: 5px; }
}