@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap");

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

:root {
  --bg-color: #34ace0;
  --accent-red: #ff5252;
  --accent-yellow: #f1c40f;
  --dark-blue: #08276c;
}

html, body {
    margin: 0; padding: 0; width: 100%; height: 100%;
    overflow: hidden; 
    background-color: var(--bg-color);
    font-family: 'Fredoka', sans-serif;
    
    /* Lock the body to prevent scroll bounce */
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    overscroll-behavior: none;
}

.canvas-wrapper {
    /* Fixed positioning to ignore the address bar area */
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    height: 100dvh; /* Dynamic Viewport Height */
    
    display: flex; 
    justify-content: center; 
    align-items: center;
    box-sizing: border-box;
    z-index: 0;
}

.game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--dark-blue);
}

canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 950 / 650;
  border-radius: 12px;
  background-image: url("assets/city_bg.webp");
  background-size: cover;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* --- HUD OVERLAY SYSTEM --- */
.status-bar {
  position: absolute;
  top: 20px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 30px;
  z-index: 10;
  pointer-events: none;
}

.compact-badge {
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 18px;
  border-radius: 50px;
  border: 3px solid #2c3e50;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  white-space: nowrap;
}

.compact-badge .label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #7f8c8d;
}
.compact-badge .value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2c3e50;
}

.action-group {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn,
.restart-btn {
  border: 3px solid #2c3e50;
  border-radius: 50px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 #2c3e50;
  transition: transform 0.1s;
}

.icon-btn {
  background: #3498db;
  color: white;
  width: 38px;
  height: 38px;
}
.restart-btn {
  background: var(--accent-red);
  color: white;
  padding: 0 15px;
  font-size: 0.8rem;
  height: 38px;
}

footer { 
    position: absolute; 
    top: 75px; 
    left: 30px; 
    color: rgba(255, 255, 255, 0.8); 
    z-index: 5; 
    font-size: 0.7rem;
    pointer-events: none; 
}

footer p { margin: 0; }
footer a { 
    color: var(--accent-yellow); 
    text-decoration: none; 
    font-weight: 700;
    pointer-events: auto; 
}

/* Ensure the text is visible on top of the modal image */
.modal-text-side h1 {
  color: var(--dark-blue);
  margin-top: 0;
}

.modal-image-side img {
  max-width: 150px;
  height: auto;
  display: block;
}

/* Fix for buttons overlapping text on very small screens */
@media screen and (max-height: 400px) {
  .overlay-content {
    gap: 10px;
    padding: 10px;
  }
  .modal-image-side img {
    max-width: 100px;
  }
}

/* --- MOBILE LANDSCAPE OPTIMIZATIONS --- */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .canvas-wrapper {
    padding: 0;
  }
  canvas {
    border-radius: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
  }

  .status-bar {
    top: 10px;
    padding: 0 15px;
  }
  .compact-badge {
    padding: 4px 12px;
    border-width: 2px;
  }
  .icon-btn,
  .restart-btn {
    height: 32px;
    border-width: 2px;
  }
  .icon-btn {
    width: 32px;
  }

  footer {
    display: none;
  }
  footer a {
        color: var(--accent-red);
  }

  /* Horizontal Layout for Modals */
  .overlay-content {
    flex-direction: row !important;
    max-width: 90vw;
    width: auto;
    padding: 15px 25px;
    align-items: center;
    gap: 20px;
  }

  .modal-image-side {
    display: block !important;
  }

  .modal-text-side {
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .overlay h1 {
    font-size: 1.5rem;
    margin: 0 0 5px 0;
  }
  .instructions {
    font-size: 0.8rem;
    padding: 8px;
  }
}

/* --- MODALS & DIALOGS --- */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 39, 108, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
.modal-image-side { 
    display: block; 
    flex-shrink: 0;
} 

.modal-image-side img { 
    width: 120px; 
    height: 120px; 
    border-radius: 15px; 
    border: 3px solid #2c3e50; 
    object-fit: cover; 
}

.overlay-content { 
    background: white; 
    padding: 25px; 
    border-radius: 20px; 
    border: 4px solid #2c3e50; 
    text-align: center; 
    max-width: 450px; 
    width: 90%; 
    display: flex; 
    flex-direction: column; 
    align-items: center;
    gap: 15px; 
}

.instructions {
  background: #f1f2f6;
  padding: 10px;
  border-radius: 12px;
  text-align: left;
  font-size: 0.9rem;
  border: 2px dashed #bdc3c7;
}
.big-btn {
  background: var(--accent-yellow);
  color: #2c3e50;
  font-size: 1.2rem;
  padding: 12px;
  border-radius: 12px;
  border: 4px solid #2c3e50;
  box-shadow: 0 5px 0 #2c3e50;
  cursor: pointer;
  font-weight: 800;
}
.hidden {
  display: none !important;
}

#dialog-box {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  padding: 15px;
  border-radius: 15px;
  border: 4px solid #2c3e50;
  z-index: 200;
  text-align: center;
  width: 80%;
  max-width: 300px;
}

#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  z-index: 9999;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  text-align: center;
}
@media screen and (max-width: 600px) and (orientation: portrait) {
  #rotate-overlay {
    display: flex;
  }
  .game-container {
    display: none;
  }
}

.overlay-content .big-btn {
  margin-top: 15px;
}

@media screen and (max-height: 500px) and (orientation: landscape) {
  footer {
    display: block !important;
    position: absolute;
    bottom: auto;
    top: 55px;
    left: 30px;
    transform: none;
    font-size: 0.6rem;
    z-index: 5;
    background: none;
    padding: 0;
    text-align: left;
  }

  footer p {
    margin: 0;
    color: rgba(255, 255, 255, 0.8);
  }
  footer a {
    color: var(--accent-red);
    font-weight: 700;
  }

  .status-bar {
    top: 10px;
    padding: 0 20px;
  }
}