:root {
  --bg-color: #f0f0f0;
  --text-color: #111;
  --border-color: #ccc;
  --strong-border-color: #333;
  --item-bg-color: #ccc;
  --button-bg-color: #efefef;
  --button-border-color: #767676;
  --selected-outline-color: black;
  
  /* Responsive sizing */
  --cell-size: 40px;
  --palette-size: 50px;
  --icon-btn-size: 52px;
}

/* Desktop scaling */
@media (min-width: 1024px) {
  :root {
    --cell-size: 45px;
    --palette-size: 55px;
    --icon-btn-size: 55px;
  }
}

@media (min-width: 1440px) {
  :root {
    --cell-size: 48px;
    --palette-size: 58px;
    --icon-btn-size: 58px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #121212;
    --text-color: #f0f0f0;
    --border-color: #444;
    --strong-border-color: #666;
    --item-bg-color: #333;
    --button-bg-color: #2a2a2a;
    --button-border-color: #888;
    --selected-outline-color: #0099ff;
  }
}

/* Base styles */
html, body { 
  height: 100%; 
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  display: flex; 
  flex-direction: column; 
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 10px;
  box-sizing: border-box;
}

h1 { 
  margin: 10px 0 5px; 
  font-size: 24px; 
  font-weight: 600;
  text-align: center;
}

@media (min-width: 1024px) {
  h1 { 
    font-size: 28px; 
    margin: 8px 0 5px; 
  }
  body { 
    padding: 10px 5px; 
  }
}

/* Palette styles */
#palette {
  display: flex; 
  gap: 10px; 
  margin: 8px; 
  flex-wrap: wrap; 
  justify-content: center;
}

@media (min-width: 1024px) {
  #palette { 
    gap: 12px; 
    margin: 10px; 
  }
}

.palette-item {
  width: var(--palette-size); 
  height: var(--palette-size); 
  background: var(--item-bg-color); 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  cursor: pointer; 
  font-size: 26px; 
  border-radius: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (min-width: 1024px) {
  .palette-item { 
    font-size: 28px; 
  }
}

.palette-item:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.palette-item.selected { 
  outline: 3px solid var(--selected-outline-color);
  transform: scale(1.1);
}

/* Board styles */
#board {
  display: grid; 
  grid-template-columns: repeat(10, var(--cell-size)); 
  grid-template-rows: repeat(15, var(--cell-size));
  border: 3px solid var(--strong-border-color);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.cell { 
  border: 1px solid var(--border-color); 
  width: var(--cell-size); 
  height: var(--cell-size); 
  position: relative;
  transition: background-color 0.2s ease;
}

.cell:hover {
  background-color: rgba(33, 150, 243, 0.1);
}

/* Component styles */
.component { 
  width: 100%; 
  height: 100%; 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  font-size: calc(var(--cell-size) * 0.6);
}

.target { 
  font-weight: 700; 
  font-size: calc(var(--cell-size) * 0.5);
}

.target.red { color: red; } 
.target.blue { color: blue; } 
.target.green { color: green; }

/* Ball styles */
.ball { 
  width: 60%; 
  height: 60%; 
  border-radius: 50%; 
  position: absolute; 
  top: 20%; 
  left: 20%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.red { background: red; } 
.blue { background: blue; } 
.green { background: green; }

/* Game state styles */
body.running #board { 
  pointer-events: none; 
}

body.running .palette-item { 
  opacity: .5; 
  pointer-events: none; 
}

body.running .cell { 
  cursor: not-allowed; 
}

/* Pause button flashing animation */
#startBtn.flashing {
  animation: pauseFlash 1s ease-in-out infinite !important;
}

@keyframes pauseFlash {
  0% { background-color: #00c853 !important; }
  50% { background-color: #f44336 !important; }
  100% { background-color: #00c853 !important; }
}

/* Game paused state styles */
body.paused #board { 
  pointer-events: none; 
}

body.paused .palette-item { 
  opacity: .3; 
  pointer-events: none; 
}

body.paused .cell { 
  cursor: not-allowed; 
}

/* Override running state when paused */
body.running.paused #board { 
  pointer-events: none; 
}

body.running.paused .palette-item { 
  opacity: .3; 
  pointer-events: none; 
}

body.running.paused .cell { 
  cursor: not-allowed; 
}

/* Control styles */
#controls { 
  margin: 15px 0 10px; 
  display: flex; 
  gap: 12px; 
  flex-wrap: wrap; 
  justify-content: center; 
}

@media (min-width: 1024px) {
  #controls { 
    gap: 15px; 
    margin: 18px 0 10px; 
  }
}

.icon-btn { 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  width: var(--icon-btn-size); 
  height: var(--icon-btn-size); 
  padding: 0; 
  border-radius: 12px; 
  border: none; 
  color: #fff; 
  cursor: pointer; 
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.icon-btn:hover { 
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn svg { 
  width: calc(var(--icon-btn-size) * 0.5); 
  height: calc(var(--icon-btn-size) * 0.5); 
  fill: currentColor; 
}

#shareBtn svg { 
  width: calc(var(--icon-btn-size) * 0.54); 
  height: calc(var(--icon-btn-size) * 0.54); 
}

.sr-only { 
  position: absolute; 
  width: 1px; 
  height: 1px; 
  padding: 0; 
  margin: -1px; 
  overflow: hidden; 
  clip: rect(0,0,1,1); 
  border: 0; 
}

/* Button colors */
#startBtn { background: #00c853; }
#startOverBtn { background: #ff9800; }
#newPuzzleBtn { background: #2196f3; }
#shareBtn { background: #9c27b0; }

/* Animations */
.flipbit { 
  animation: flipbit .3s ease-in-out; 
}

.wobble { 
  animation: wobble .3s ease-in-out; 
}

.switch { 
  color: #004488; 
}

.passthrough { 
  color: #666666; 
}

@keyframes flipbit { 
  0% { transform: rotate(0); }
  50% { transform: rotate(90deg); }
  100% { transform: rotate(0); }
}

@keyframes wobble { 
  0% { transform: rotate(0); }
  25% { transform: rotate(5deg); }
  75% { transform: rotate(-5deg); }
  100% { transform: rotate(0); }
}

/* Overlay styles */
#fullscreenPrompt, 
#gameOverOverlay, 
#victoryOverlay { 
  position: fixed; 
  inset: 0; 
  z-index: 10000; 
  display: none; 
}

#fullscreenPrompt { 
  background: #000; 
  color: #fff; 
  display: none; 
  align-items: center; 
  justify-content: center; 
  flex-direction: column; 
  font-size: 24px; 
  gap: 12px; 
}

#gameOverOverlay, 
#victoryOverlay { 
  background: rgba(0,0,0,.8); 
  color: #fff; 
  display: none; 
  align-items: center; 
  justify-content: center; 
  flex-direction: column; 
  font-size: 24px; 
  gap: 20px; 
}

/* Tutorial overlay styles */
#tutorialOverlay,
#newGameOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
  box-sizing: border-box;
}

#tutorialBox,
#newGameBox {
  background: var(--bg-color);
  color: var(--text-color);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  border: 2px solid var(--border-color);
  text-align: center;
  position: relative;
}

#tutorialIcon,
#newGameIcon {
  font-size: 48px;
  margin-bottom: 16px;
}

#tutorialTitle,
#newGameTitle {
  margin: 0 0 12px 0;
  font-size: 20px;
  color: var(--text-color);
  font-weight: 600;
}

#tutorialMessage,
#newGameMessage {
  margin: 0 0 20px 0;
  line-height: 1.5;
  color: var(--text-color);
  font-size: 16px;
}

#tutorialGotIt {
  background: #4CAF50 !important;
  margin: 0 auto;
  width: auto;
  height: auto;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

#tutorialGotIt:hover {
  background: #45a049 !important;
  transform: translateY(-1px);
}

#tutorialGotIt:active {
  transform: translateY(0);
}

/* New Game confirmation buttons */
#newGameButtons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

#newGameConfirm,
#newGameCancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: auto;
  height: auto;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  border: none;
  color: white;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

#newGameConfirm {
  background: #4CAF50 !important;
}

#newGameConfirm:hover {
  background: #45a049 !important;
  transform: translateY(-1px);
}

#newGameCancel {
  background: #f44336 !important;
}

#newGameCancel:hover {
  background: #da190b !important;
  transform: translateY(-1px);
}

#newGameConfirm:active,
#newGameCancel:active {
  transform: translateY(0);
}

/* Responsive tutorial and new game styles */
@media (max-width: 480px) {
  #tutorialBox,
  #newGameBox {
    padding: 20px;
    margin: 10px;
  }
  
  #tutorialIcon,
  #newGameIcon {
    font-size: 40px;
    margin-bottom: 12px;
  }
  
  #tutorialTitle,
  #newGameTitle {
    font-size: 18px;
  }
  
  #tutorialMessage,
  #newGameMessage {
    font-size: 14px;
  }
  
  #newGameButtons {
    flex-direction: column;
    gap: 12px;
  }
  
  #newGameConfirm,
  #newGameCancel {
    width: 100%;
  }
}