/* CSS Custom Properties - Can be overridden at runtime via gameTheme.json */
:root {
  /* Base colors */
  --primary-color: #0d1117;
  --secondary-color: #161b22;
  --light-color: #c9d1d9;
  --accent-color: #00ffff;
  --border-color: #30363d;

  /* UI colors */
  --popup-bg-color: #161b22;
  --popup-border-color: #30363d;
  --button-bg-color: #238636;
  --button-hover-color: #2ea043;
  --button-text-color: #f0f6fc;
  --button-shadow-color: rgba(35, 134, 54, 0.3);
  --pause-button-color: #da3633;
  --pause-button-hover-color: #f85149;

  /* Game colors */
  --board-bg-color: #010409;
  --grid-line-color: #30363d;
  --score-color: #00ffff;
  --canvas-border-color: #30363d;

  /* Control colors */
  --control-btn-bg: #30363d;
  --control-btn-border-top: #5c6775;
  --control-btn-border-bottom: #1c2128;
  --rotate-btn-bg: #21262d;
  --rotate-border-top: #414a56;
  --rotate-border-bottom: #101216;
  --drop-btn-bg: #b03a36;
  --drop-border-top: #d15f5a;
  --drop-border-bottom: #852c28;

  /* Effect colors */
  --glow-color: rgba(0, 255, 255, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.5);
  --title-glow-color: rgba(0, 255, 255, 0.5);

  /* CSS-specific colors */
  --body-bg-color: #0d1117;
  --text-color: #c9d1d9;
  --title-color: #00ffff;
  --subtitle-color: #f0f6fc;
  --container-bg: rgba(22, 27, 34, 0.85);
  --hud-bg-color: #010409;
}

html {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Press Start 2P", cursive;
  background-color: var(--body-bg-color);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  /* Fallback for browsers that don't support dvh */
  height: 100dvh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
}

.game-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 15px;
  padding: 15px;
  background-color: var(--container-bg);
  border: 4px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 0 20px var(--shadow-color);
  transition: all 0.3s ease;
  max-width: 100%;
  width: auto;
  height: 100vh;
  /* Fallback */
  height: 100dvh;
  box-sizing: border-box;
  overflow: hidden;
}

/* Top Info Bar */
.top-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--hud-bg-color);
  padding: 10px 15px;
  border: 2px solid var(--border-color);
  border-radius: 5px;
  flex-wrap: wrap;
  gap: 5px;
  flex-shrink: 0;
  min-height: fit-content;
  margin: 0;
}

.score-section,
.lines-section,
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.next-section {
  display: flex;
  flex-direction: row;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.score-section h2,
.lines-section h2,
.timer-section h2 {
  font-size: 0.7rem;
  margin: 0 0 4px 0;
  color: var(--subtitle-color);
}

.next-section h2 {
  font-size: 0.7rem;
  margin: 0;
  color: var(--subtitle-color);
}

.score-section p,
.lines-section p,
.timer-section p {
  font-size: 0.9rem;
  color: var(--score-color);
  margin: 0;
}

.pause-btn {
  background-color: var(--pause-button-color);
  color: white;
  padding: 6px 12px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.6rem;
  font-family: "Press Start 2P", monospace;
  transition: background-color 0.3s;
  margin: 0;
}

.pause-btn:hover {
  background-color: var(--pause-button-hover-color);
}

/* Game Area */
.game-area {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  overflow: hidden;
}

/* Bottom Controls - Hidden on desktop, visible on mobile */
.bottom-controls {
  background-color: var(--hud-bg-color);
  padding: 10px 15px;
  border: 2px solid var(--border-color);
  border-radius: 5px;
  flex-shrink: 0;
  min-height: fit-content;
  display: none;
  /* Hidden on desktop */
}

/* Tablet responsive layout - Both portrait and landscape */
@media (max-width: 1024px) and (min-width: 768px),
(pointer: coarse) and (min-width: 768px) and (max-width: 1024px) {
  .game-container {
    gap: 12px;
    padding: 12px;
    max-height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .top-info {
    padding: 10px 12px;
    flex-shrink: 0;
  }

  .game-area {
    flex-shrink: 1;
    min-height: 0;
    overflow: hidden;
  }

  .bottom-controls {
    display: block;
    /* Show controls on tablets */
    padding: 10px 12px;
    flex-shrink: 0;
    /* Prevent controls from being squished */
  }

  /* Show mobile controls on tablets */
  .mobile-controls {
    display: block;
  }

  .control-btn {
    min-width: 60px;
    min-height: 60px;
    font-size: 1.3rem;
  }

  .drop-btn {
    min-width: 140px;
  }

  .control-row {
    gap: 12px;
    margin-bottom: 12px;
  }

  .control-row:last-child {
    margin-bottom: 0;
  }
}

/* Tablet landscape specific adjustments - Hide controls on landscape tablets (like Nest Hub) */
@media (max-width: 1024px) and (min-width: 768px) and (orientation: landscape),
(pointer: coarse) and (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
  .bottom-controls {
    display: none;
    /* Hide controls on landscape tablets - not enough vertical space */
  }

  .mobile-controls {
    display: none;
  }

  .game-container {
    gap: 10px;
    padding: 10px;
  }
}

/* Mobile responsive layout - Using touch capability detection */
@media (pointer: coarse) and (orientation: portrait),
(max-width: 768px) and (orientation: portrait) {
  body {
    padding: 0;
    margin: 0;
  }

  .game-container {
    gap: 2px;
    padding: 0;
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    /* Fallback */
    max-height: 100dvh;
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    border-radius: 0;
    border: none;
    background-color: #010409;
  }

  .top-info {
    flex-direction: row;
    justify-content: space-around;
    gap: 5px;
    padding: 3px 6px;
    border-width: 0;
    border-bottom: 1px solid #30363d;
    border-radius: 0;
    min-height: fit-content;
  }

  .score-section,
  .lines-section,
  .timer-section,
  .next-section {
    flex-direction: row;
    gap: 5px;
    align-items: center;
    white-space: nowrap;
  }

  .score-section h2,
  .lines-section h2,
  .timer-section h2,
  .next-section h2 {
    font-size: 0.65rem;
    margin-bottom: 0;
    margin: 0;
    white-space: nowrap;
  }

  .score-section p,
  .lines-section p,
  .timer-section p {
    font-size: 0.8rem;
    white-space: nowrap;
  }

  #next-piece-canvas {
    width: 42px;
    height: 42px;
    border-width: 1px;
  }

  .bottom-controls {
    display: block;
    /* Show on mobile */
    padding: 3px 6px;
    border-width: 0;
    border-top: 1px solid #30363d;
    border-radius: 0;
    flex-shrink: 0;
  }
}


canvas {
  background-color: var(--board-bg-color);
  border: 2px solid var(--canvas-border-color);
  border-radius: 5px;
  transition: all 0.3s ease;
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Minimal canvas border on mobile - Using touch detection */
@media (pointer: coarse),
(max-width: 768px) {
  canvas {
    border-width: 0;
    border-radius: 0;
  }
}

/* Mobile canvas scaling - Using touch detection */
@media (pointer: coarse),
(max-width: 768px) {
  #tetris {
    margin: 0 auto;
  }

  .game-area {
    padding: 0;
    margin: 0;
  }
}

/* Removed old sidebar and desktop controls styles */

.key {
  display: inline-block;
  background-color: var(--control-btn-bg);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
}

#next-piece-canvas {
  background-color: var(--primary-color);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  display: block;
  margin: 0 auto;
  transition: all 0.3s ease;
  width: 50px;
  height: 50px;
}

#start-button,
#restart-button {
  background-color: #238636;
  color: white;
  padding: 15px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
  text-transform: uppercase;
  transition: background-color 0.3s;
}

#start-button:hover,
#restart-button:hover {
  background-color: #2ea043;
}

#restart-button {
  background-color: #da3633;
}

#restart-button:hover {
  background-color: #f85149;
}

/* Menu Overlays */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  /* Fallback */
  height: 100dvh;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  overflow: auto;
}

.menu-content {
  background-color: var(--popup-bg-color);
  padding: 50px;
  border-radius: 15px;
  text-align: center;
  border: 4px solid var(--popup-border-color);
  box-shadow: 0 0 30px var(--glow-color);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  /* Fallback */
  max-height: 90dvh;
  overflow-y: auto;
}

/* Start Menu Styles */
.game-title {
  font-size: 3rem;
  margin-bottom: 30px;
  color: var(--title-color);
  text-shadow: 0 0 20px var(--title-glow-color);
  letter-spacing: 3px;
}

.menu-info h3 {
  font-size: 1.5rem;
  color: var(--subtitle-color);
  margin-bottom: 20px;
  margin-top: 30px;
}

.controls-info {
  background-color: var(--primary-color);
  padding: 20px;
  border-radius: 10px;
  margin-bottom: 30px;
}

.controls-info p {
  margin: 8px 0;
  font-size: 0.9rem;
}

/* Show desktop instructions by default, hide mobile */
.desktop-instructions {
  display: block;
}

.mobile-instructions {
  display: none;
}

/* Theme Selector Styles */
.theme-selector {
  margin-bottom: 30px;
}

.theme-dropdown {
  background-color: var(--primary-color);
  color: var(--subtitle-color);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 20px;
  font-family: "Press Start 2P", monospace;
  font-size: 0.9rem;
  width: 100%;
  max-width: 250px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.theme-dropdown:hover {
  border-color: var(--accent-color);
  box-shadow: 0 0 10px var(--glow-color);
}

.theme-dropdown:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 15px var(--title-glow-color);
}

.theme-dropdown option {
  background-color: var(--primary-color);
  color: var(--subtitle-color);
  padding: 10px;
}

/* Game Over Menu Styles */
.game-over-title {
  font-size: 3rem;
  margin-bottom: 30px;
  color: #f85149;
  text-shadow: 0 0 20px rgba(248, 81, 73, 0.5);
  letter-spacing: 2px;
}

.score-display {
  background-color: var(--primary-color);
  padding: 25px;
  border-radius: 10px;
  margin-bottom: 30px;
}

.score-display h3 {
  font-size: 1.2rem;
  color: var(--subtitle-color);
  margin-bottom: 15px;
}

.final-score-value {
  font-size: 2.5rem;
  color: var(--accent-color);
  text-shadow: 0 0 15px var(--title-glow-color);
  margin: 0;
}

/* Menu Buttons */
.menu-button {
  background: var(--button-bg-color);
  color: var(--button-text-color);
  border: none;
  padding: 15px 30px;
  font-size: 1.1rem;
  font-family: "Press Start 2P", monospace;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 10px;
  min-width: 200px;
  box-shadow: 0 4px 15px var(--button-shadow-color);
}

.menu-button:hover {
  background: var(--button-hover-color);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--button-shadow-color);
}

.menu-button.secondary {
  background: linear-gradient(135deg, #6e7681, #8b949e);
  box-shadow: 0 4px 15px rgba(110, 118, 129, 0.3);
}

.menu-button.secondary:hover {
  background: linear-gradient(135deg, #8b949e, #6e7681);
  box-shadow: 0 6px 20px rgba(110, 118, 129, 0.4);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

/* Hide game over modal by default */
#game-over-modal {
  display: none;
}

/* Mobile Touch Controls */
.mobile-controls {
  display: none;
  background-color: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

.control-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-btn {
  background-color: var(--control-btn-bg);
  color: var(--light-color);
  border-radius: 0;
  /* sharp corners */
  border-top: 4px solid var(--control-btn-border-top);
  border-left: 4px solid var(--control-btn-border-top);
  border-right: 4px solid var(--control-btn-border-bottom);
  border-bottom: 4px solid var(--control-btn-border-bottom);
  font-size: 1.2rem;
  font-family: "Press Start 2P", monospace;
  cursor: pointer;
  min-width: 50px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: 4px;
  /* Adjust text position with border */
}

.control-btn:active {
  border-top: 4px solid var(--control-btn-border-bottom);
  border-left: 4px solid var(--control-btn-border-bottom);
  border-right: 4px solid var(--control-btn-border-top);
  border-bottom: 4px solid var(--control-btn-border-top);
}

/* Specific button styles for a retro feel */
.rotate-btn {
  background-color: var(--rotate-btn-bg);
  border-top-color: var(--rotate-border-top);
  border-left-color: var(--rotate-border-top);
  border-right-color: var(--rotate-border-bottom);
  border-bottom-color: var(--rotate-border-bottom);
}

.rotate-btn:active {
  border-top-color: var(--rotate-border-bottom);
  border-left-color: var(--rotate-border-bottom);
  border-right-color: var(--rotate-border-top);
  border-bottom-color: var(--rotate-border-top);
}

.drop-btn {
  background-color: var(--drop-btn-bg);
  border-top-color: var(--drop-border-top);
  border-left-color: var(--drop-border-top);
  border-right-color: var(--drop-border-bottom);
  border-bottom-color: var(--drop-border-bottom);
  min-width: 120px;
}

.drop-btn:active {
  border-top-color: var(--drop-border-bottom);
  border-left-color: var(--drop-border-bottom);
  border-right-color: var(--drop-border-top);
  border-bottom-color: var(--drop-border-top);
}

/* Show mobile controls on mobile devices - Using touch detection */
@media (pointer: coarse) and (orientation: portrait),
(max-width: 768px) and (orientation: portrait) {
  .mobile-controls {
    display: block;
  }

  /* Optimize control button sizes for full-width canvas */
  .control-btn {
    min-width: 48px;
    min-height: 48px;
    font-size: 1.1rem;
  }

  .drop-btn {
    min-width: 110px;
  }

  .control-row {
    gap: 6px;
    margin-bottom: 5px;
  }

  .control-row:last-child {
    margin-bottom: 0;
  }
}

/* Very small screens - Using touch detection */
@media (pointer: coarse) and (max-width: 480px) and (orientation: portrait),
(max-width: 480px) and (orientation: portrait) {
  .game-container {
    gap: 2px;
    padding: 0;
  }

  .top-info {
    padding: 2px 4px;
    gap: 3px;
    min-height: fit-content;
  }

  .score-section h2,
  .lines-section h2,
  .timer-section h2,
  .next-section h2 {
    font-size: 0.55rem;
    margin: 0;
    white-space: nowrap;
  }

  .score-section p,
  .lines-section p,
  .timer-section p {
    font-size: 0.7rem;
    white-space: nowrap;
  }

  #next-piece-canvas {
    width: 38px;
    height: 38px;
  }

  .bottom-controls {
    display: block;
    /* Show on mobile */
    padding: 2px 4px;
    flex-shrink: 0;
  }

  .control-btn {
    min-width: 40px;
    min-height: 40px;
    font-size: 0.9rem;
  }

  .drop-btn {
    min-width: 90px;
  }

  .control-row {
    gap: 5px;
    margin-bottom: 4px;
  }

  .control-row:last-child {
    margin-bottom: 0;
  }
}

/* Tablet menu optimizations */
@media (max-width: 1024px) and (min-width: 768px) {

  /* Show mobile instructions on tablets too */
  .desktop-instructions {
    display: none;
  }

  .mobile-instructions {
    display: block;
  }
}

/* Mobile menu optimizations - Using touch detection */
@media (pointer: coarse),
(max-width: 768px) {
  .menu-content {
    padding: 25px 15px;
    max-width: 90vw;
    width: 90vw;
    max-height: 90vh;
    /* Fallback */
    max-height: 90dvh;
  }

  .game-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
  }

  .menu-info h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    margin-top: 15px;
  }

  .controls-info {
    padding: 12px;
    margin-bottom: 15px;
  }

  .controls-info p {
    font-size: 0.7rem;
    margin: 5px 0;
  }

  /* Show mobile instructions, hide desktop on mobile */
  .desktop-instructions {
    display: none;
  }

  .mobile-instructions {
    display: block;
  }

  .menu-button {
    font-size: 0.85rem;
    padding: 10px 18px;
    min-width: 140px;
    margin: 6px;
  }

  .theme-dropdown {
    font-size: 0.75rem;
    padding: 10px 12px;
  }

  .game-over-title {
    font-size: 1.8rem;
    margin-bottom: 15px;
  }

  .final-score-value {
    font-size: 1.8rem;
  }
}

@media (pointer: coarse) and (max-width: 480px),
(max-width: 480px) {
  .menu-content {
    padding: 20px 12px;
    max-width: 95vw;
    width: 95vw;
    max-height: 92vh;
    /* Fallback */
    max-height: 92dvh;
  }

  .game-title {
    font-size: 1.4rem;
    letter-spacing: 1px;
    margin-bottom: 12px;
  }

  .menu-info h3 {
    font-size: 0.9rem;
    margin-top: 12px;
    margin-bottom: 10px;
  }

  .menu-button {
    font-size: 0.75rem;
    padding: 10px 15px;
    min-width: 110px;
  }

  .score-display {
    padding: 15px;
    margin-bottom: 20px;
  }

  /* Show mobile instructions, hide desktop on small screens */
  .desktop-instructions {
    display: none;
  }

  .mobile-instructions {
    display: block;
  }
}