/* === Global Defaults === */
html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  min-height: 100vh;
  min-width: 100vw;
  background: linear-gradient(135deg, #1a1a1a, #000000);
  font-family: 'Courier New', monospace;
  color: #eee;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

/* === Arcade Shell === */
#arcade-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
}

/* === Insert Coin Button === */
#tetris-toggle {
  font-family: 'Courier New', monospace;
  font-size: 2.5rem;
  padding: 24px 48px;
  touch-action: manipulation;
  background: #00ffff;
  color: #000;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5000;
  box-shadow: 0 0 12px #0ff;
  transition: all 0.3s ease;
}

#tetris-toggle:hover {
  background: #0ff;
  box-shadow: 0 0 16px #0ff;
}

/* === Game Wrapper === */
#tetris-wrapper {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #111;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  box-sizing: border-box;
}

/* === Layout === */
#game-area {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

/* === Canvas & Container === */
#tetris-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  border: 4px ridge #0ff;
  background: repeating-linear-gradient(0deg, #000, #000 2px, #111 2px, #111 4px);
  box-shadow: 0 0 20px #0ff inset;
  box-sizing: border-box;
}

#tetris {
  display: block;
  background: rgba(0, 0, 0, 0.85);
  border: 4px double #0ff;
  image-rendering: pixelated;
  box-shadow: 0 0 10px #0f0, 0 0 40px #0ff;
}

/* === Preview Box === */
#info-panel #preview-box {
  display: block;
  border: 2px dashed #0ff;
  background: rgba(0, 0, 0, 0.5);
  image-rendering: pixelated;
  margin-bottom: 6px;
}

/* === Scoreboard === */
#scoreboard {
  margin-top: 6px;
  font-size: 1rem;
  text-align: center;
  color: #00ffcc;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 6px;
  border: 1px solid #00ffcc;
  border-radius: 6px;
  text-shadow: 1px 1px 2px black;
  width: 100%;
  box-sizing: border-box;
}

#score, #level, #lines, #highScore {
  font-size: 12px;
  color: #0f0;
  text-shadow: 0 0 2px #0f0;
}

/* === Touch Controls === */
#touch-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;

  /* Prevent accidental text selection */
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;

  /* Disable tap highlight and delay on mobile */
  -webkit-tap-highlight-color: transparent;

  /* Ensure touch actions are handled immediately */
  touch-action: manipulation;
}

#touch-controls button {
  flex: 1 1 40%;
  font-size: 2rem;
  padding: 14px;
  border: none;
  border-radius: 6px;
  background: #222;
  color: #fff;
  cursor: pointer;

  /* Smooth transition for visual feedback */
  transition: 
    background-color 0.1s ease,
    color 0.1s ease,
    transform 0.05s ease,
    filter 0.1s ease;

  /* Remove default button outline, but keep focus visible */
  outline: none;
}

/* Hover – desktop only */
#touch-controls button:hover {
  background: #00ffff;
  color: #000;
}

/* Active/Focus – for keyboard and touch */
#touch-controls button:active,
#touch-controls button.active {
  background: #0ff;
  color: #000;
  transform: scale(0.95);
  filter: brightness(1.3) contrast(1.1);
}

/* Optional: Slightly larger hit area on mobile */
@media (max-width: 768px) {
  #touch-controls button {
    padding: 18px 14px; /* Taller for easier tapping */
    font-size: 2.1rem;
  }
}

/* Focus indicator for accessibility (visible only when using keyboard) */
#touch-controls button:focus-visible {
  box-shadow: 0 0 0 3px rgba(0, 255, 255, 0.6);
  transform: scale(1.02);
}

/* === Info Panel === */
#info-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
}

/* === Fullscreen Button === */
#fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.5rem;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #00ffff;
  color: #000;
  cursor: pointer;
  box-shadow: 0 0 8px #0ff;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  z-index: 6000;
}

#fullscreen-btn:hover {
  background: #00aaff;
  box-shadow: 0 0 12px #00aaff;
}

/* === Overlay === */
#ready-overlay {
  font-size: 4rem;
  pointer-events: none;
  z-index: 10000;
}

#crt-flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: white;
  opacity: 0;
  z-index: 9999;
  pointer-events: none;
}

@keyframes crt-flash {
  0%   { opacity: 1; }
  30%  { opacity: 0.4; }
  60%  { opacity: 0.9; }
  100% { opacity: 0; }
}

@keyframes flashPulse {
  0% { filter: brightness(1.5) saturate(1.5); }
  50% { filter: brightness(2) saturate(2); }
  100% { filter: brightness(1.5) saturate(1.5); }
}

.tetris-flash {
  animation: screenFlash 0.2s ease-in-out alternate 2;
}

@keyframes screenFlash {
  from { background-color: #fff; }
  to { background-color: #000; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

#insert-coin {
  animation: blink 1s infinite;
}

/* === Portrait Mobile Full Vertical + Horizontal Centering === */
@media (max-width: 600px) and (orientation: portrait) {
  #tetris-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center; /* vertical centering */
    align-items: center;     /* horizontal centering */
    height: 100vh;
    width: 100vw;
    padding: 0 5px;          /* optional breathing room */
  }

  #game-area {
    flex-direction: column;      /* stack board + info vertically */
    align-items: center;         /* horizontal centering */
    justify-content: center;     /* vertical centering of content */
    gap: 10px;
    width: 100%;
    height: auto;
  }

  #tetris-container {
    max-width: 90vw;
    max-height: 65vh;  /* leave space for touch controls */
    margin: 0 auto;
  }

  #tetris {
    max-width: 100%;
    max-height: 100%;
    margin: 0 auto;
  }

  #touch-controls {
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
  }

  #touch-controls button {
    flex: 1 1 40%;
    font-size: 1.8rem;
    padding: 12px;
  }

  #preview-box {
    width: 22vw;
    height: 22vw;
    max-width: 75px;
    max-height: 75px;
    margin-bottom: 4px;
  }

  #scoreboard {
    font-size: 0.9rem;
    padding: 3px 4px;
    max-width: 240px;
    margin-top: 4px;
  }
}

/* === Background Screensaver === */
#tepris-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -9999;
  background: linear-gradient(270deg, #0f0c29, #302b63, #24243e);
  background-size: 800% 800%;
  animation: bgScreensaver 30s ease infinite;
  filter: brightness(0.7) blur(3px) saturate(1.2);
  pointer-events: none;
}

@keyframes bgScreensaver {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* === Pause Menu Overlay === */
#pause-menu {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #000c;
  color: #0f0;
  padding: 24px 28px 20px 28px;
  border: 2.5px solid #0ff;
  border-radius: 14px;
  font-family: 'Press Start 2P', monospace;
  z-index: 10000;
  min-width: 320px;
  box-shadow: 0 0 20px #0ff3, 0 2px 18px #001;
}

#pause-menu button {
  display: block;
  width: 100%;
  margin: 12px 0;
  padding: 12px 0;
  font-size: 1.08rem;
  background: #00161b;
  color: #0ff;
  border: 2px solid #0ff7;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 7px #0ff3 inset;
}

#pause-menu button:hover,
#pause-menu button.selected,
#pause-menu button:focus {
  background: #0ff;
  color: #00161b;
  box-shadow: 0 0 16px #0ff, 0 0 2px #0ff inset;
  border-color: #fff;
  outline: 2px solid #fff;
}

/* === Controls Layout Panel === */
#pause-menu #controls-layout {
  margin-top: 20px;
  background: rgba(10, 20, 20, 0.95);
  padding: 18px 20px 16px 20px;
  border-radius: 12px;
  border: 2px solid #0ff6;
  color: #fff;
  font-size: 1rem;
  text-align: left;
  box-shadow: 0 0 14px #0ff4, inset 0 0 6px #022;
  max-width: 95%;         /* keep it safe on mobile */
  box-sizing: border-box;
}

/* === Controls Title === */
#pause-menu .controls-title {
  text-align: center;
  font-weight: bold;
  color: #0ff;
  margin-bottom: 12px;
  font-size: 1.25rem;
  letter-spacing: 0.15em;
  text-shadow: 0 0 8px #0ff, 0 0 14px #0ff;
}

/* === Section Headers (Movement / Rotation / Drop / Utility) === */
#pause-menu .controls-section {
  margin-top: 12px;
  margin-bottom: 6px;
  font-size: 1.05rem;
  font-weight: bold;
  color: #0ff;
  text-shadow: 0 0 6px #0ff;
  border-bottom: 1px solid rgba(0,255,255,0.3);
  padding-bottom: 3px;
  letter-spacing: 0.06em;
}

/* === Control Rows === */
#pause-menu .controls-row {
  margin: 4px 0 6px 12px;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  line-height: 1.35;
  display: flex;
  flex-wrap: wrap;    /* let keys wrap instead of overflow */
  gap: 4px;
  align-items: center;
}

/* === Glowing Button Capsules === */
#pause-menu .btn-key {
  display: inline-block;
  background: #0ff;
  color: #000;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 2px 8px;
  border-radius: 6px;
  box-shadow: 0 0 6px #0ff, inset 0 0 3px #fff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.2;
  white-space: nowrap;   /* prevent breaking mid-key */
}

#pause-menu .btn-key.alt {
  background: #ff0;
  box-shadow: 0 0 6px #ff0, inset 0 0 3px #fff;
}

#pause-menu .btn-key.danger {
  background: #f33;
  color: #fff;
  box-shadow: 0 0 6px #f33, inset 0 0 3px #fff;
}

/* === Divider Line === */
#pause-menu hr {
  border: none;
  border-top: 2px solid #088;
  margin: 12px 0 15px 0;
}

/* === Responsive Controls for Small Screens === */
@media (max-width: 600px) {
  #pause-menu #controls-layout {
    font-size: 0.9rem;
    padding: 12px 14px;
  }

  #pause-menu .controls-title {
    font-size: 1.1rem;
  }

  #pause-menu .controls-section {
    font-size: 0.9rem;
  }

  #pause-menu .controls-row {
    font-size: 0.8rem;
    margin-left: 6px;
  }

  #pause-menu .btn-key {
    font-size: 0.7rem;
    padding: 2px 6px;
    margin-bottom: 3px;
  }
}
