/* Responsive and fullscreen tweaks for Tetris */

body, html {
  height: 100%;
  min-height: 100vh;
}

body {
  max-height: 100vh;
  /* overflow-y: auto; */
}

.container.py-5 {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
}

#game-screen, #welcome-screen, #game-over-screen {
  max-height: 100vh;
  /* overflow-y: auto; */
}

.game-container {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

#tetris-canvas {
  max-height: 70vh;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
}

@media (max-width: 768px) {
  html, body {
    height: 100vh;
    overflow: hidden;
  }
  .container.py-5 {
    min-height: 100vh;
    max-height: 100vh;
    padding: 0 !important;
  }
  #game-screen, #welcome-screen, #game-over-screen {
    max-height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    padding: 0;
  }
  .game-container {
    max-height: 100vh;
    min-height: 100vh;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  /* Only hide non-canvas elements during actual gameplay on mobile */
  #game-screen .game-sidebar,
  #game-screen .game-info,
  #game-screen .highscores,
  #game-screen .controls {
    display: none !important;
  }

  #tetris-canvas {
    display: block;
    margin: 0 auto;
    width: 100vw !important;
    height: auto !important;
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 10/20;
    background: #222;
  }
  /* Show next piece preview as floating overlay in top right on mobile */
  #next-piece-canvas {
    position: fixed;
    top: 8px;
    right: 8px;
    width: 64px !important;
    height: 64px !important;
    z-index: 100;
    background: rgba(34,34,34,0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px #000a;
    display: block !important;
  }
}

/* Desktop: Make Tetris canvas the dominant, largest element */
@media (min-width: 769px) {
  .game-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
    max-width: 100vw;
    padding: 2rem 0;
  }
  #tetris-canvas {
    max-height: 90vh;
    width: auto;
    height: auto;
    aspect-ratio: 10/20;
    flex: 0 1 auto;
    box-shadow: 0 0 24px 4px #000a;
    background: #222;
    margin: 0;
    display: block;
  }
  /* De-emphasize side/info panels */
  .game-sidebar, .game-info, .highscores, .controls {
    flex: 0 0 220px;
    max-width: 220px;
    font-size: 0.95em;
    opacity: 0.8;
    background: none;
    box-shadow: none;
    color: #bbb;
  }
}

/* Hide game-over-screen when welcome-screen is visible (mobile and desktop) */
#welcome-screen:visible ~ #game-over-screen,
#welcome-screen[style*="display: block"] ~ #game-over-screen,
#welcome-screen[style*="display: flex"] ~ #game-over-screen {
  display: none !important;
}

/* Always honor Bootstrap's d-none utility -- MUST BE LAST */
.d-none {
  display: none !important;
}
