:root {
  --bg: #000;
  --fg-primary: #0ff;
  --fg-secondary: #f0f;
  --accent-green: #0f0;
  --accent-blue: #09f;
  --panel-bg: #111;
  --tile-bg: rgba(0,0,0,0.7);
  --font-pixel: 'Press Start 2P', monospace;
}

body {
  font-family: var(--font-pixel);
  text-align: center;
  background-color: var(--bg);
  color: var(--fg-primary);
  margin: 0 auto;
  padding: 20px;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  text-transform: uppercase;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  overflow: hidden;
  box-sizing: border-box;
}

#page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 100px;
}

#new-game {
  font-family: var(--font-pixel);
  font-size: 1.2rem;
  padding: 10px 16px;
}

#main {
  position: relative;
  flex: 1;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  gap: 20px;
}


#game-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

#game-container {
  display: grid;
  grid-template-columns: repeat(4, 80px);
  grid-template-rows: repeat(4, 80px);
  gap: 5px;
  width: max-content;
  margin: 20px auto;
  padding: 10px;
  background-color: var(--panel-bg);
  border: 4px solid var(--accent-blue);
  box-shadow: 0 0 16px var(--accent-blue);
}

@media (min-width: 600px) {
  #game-container {
    grid-template-columns: repeat(4, 100px);
    grid-template-rows: repeat(4, 100px);
  }
}

@media (min-height: 900px) {
  #game-container {
    grid-template-columns: repeat(4, 120px);
    grid-template-rows: repeat(4, 120px);
  }
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: var(--tile-bg);
  border-radius: 4px;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
  text-shadow: 0 0 4px currentColor;
  transition: transform 250ms ease, box-shadow .2s, color .2s;
}

.tile.spawn {
  animation: neon-flash 300ms ease;
}

.tile.tap {
  animation: tile-tap 150ms ease;
}

.tile.selected {
  box-shadow: 0 0 8px var(--accent-blue);
}

.tile.destroy {
  animation: shrink-fade 250ms forwards;
}

.tile.rainbow {
  background: linear-gradient(45deg, red, orange, yellow, green, blue, indigo, violet);
  color: #ffffff;
}

.tile.value-2 {
  color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.tile.value-4 {
  color: var(--fg-secondary);
  box-shadow: 0 0 8px var(--fg-secondary);
}

.tile.value-8 {
  color: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue);
}
.tile.value-16 {
  color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}
.tile.value-32 {
  color: var(--fg-secondary);
  box-shadow: 0 0 8px var(--fg-secondary);
}
.tile.value-64 {
  color: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue);
}

h1 {
  margin-bottom: 10px;
  color: var(--accent-blue);
  text-shadow: 0 0 8px var(--accent-blue);
}

button {
  background: rgba(0,0,0,0.5);
  border: 2px solid var(--accent-green);
  color: var(--accent-green);
  text-shadow: 0 0 4px var(--accent-green);
  padding: 6px 12px;
  cursor: pointer;
  transition: box-shadow .2s;
}

button:hover {
  box-shadow: 0 0 12px var(--accent-green);
}

#score {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 5px 10px;
  width: calc(100% - 40px);
  max-width: 1000px;
  color: var(--accent-blue);
  text-shadow: 0 0 6px var(--accent-blue);
  background: var(--panel-bg);
  box-shadow: 0 0 8px var(--accent-blue);
}

#instructions {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 0;
  background-color: var(--panel-bg);
  max-width: 320px;
  margin: 0;
  padding: 10px;
  border-radius: 4px;
  box-shadow: 0 0 5px rgba(0,0,0,0.5);
  text-align: left;
  color: var(--fg-secondary);
}

#instructions h2 {
  margin-top: 0;
  color: var(--accent-blue);
  text-shadow: 0 0 6px var(--accent-blue);
}

#instructions ul {
  padding-left: 20px;
}

.rainbow-emoji {
  font-weight: bold;
}

@media (max-width: 1200px) {
  #instructions {
    display: none;
  }
}

@media (pointer: coarse) {
  body {
    overflow: hidden;
    touch-action: none;
  }
}

@media (max-width: 600px) {
  body {
    padding-left: 20px;
    padding-right: 20px;
  }
}

#game-container.swipe-left { animation: swipe-left 250ms ease; }
#game-container.swipe-right { animation: swipe-right 250ms ease; }
#game-container.swipe-up { animation: swipe-up 250ms ease; }
#game-container.swipe-down { animation: swipe-down 250ms ease; }

@keyframes swipe-left { 0% { transform: translateX(0); } 50% { transform: translateX(-10px); } 100% { transform: translateX(0); } }
@keyframes swipe-right { 0% { transform: translateX(0); } 50% { transform: translateX(10px); } 100% { transform: translateX(0); } }
@keyframes swipe-up { 0% { transform: translateY(0); } 50% { transform: translateY(-10px); } 100% { transform: translateY(0); } }
@keyframes swipe-down { 0% { transform: translateY(0); } 50% { transform: translateY(10px); } 100% { transform: translateY(0); } }

@keyframes neon-flash {
  0% { transform: scale(0); box-shadow: 0 0 16px var(--accent-blue); }
  100% { transform: scale(1); box-shadow: none; }
}

@keyframes shrink-fade {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(0); opacity: 0; }
}

@keyframes tile-tap {
  0% { transform: scale(1); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

#game-over-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.75);
  color: #ffffff;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 1000;
  text-shadow: 0 0 6px #fff;
}

#game-over-overlay.show { display: flex; }
#game-over-overlay p { margin: 0; font-size: 2rem; }
#game-over-overlay small { font-size: 1rem; margin-top: 10px; }
#powerup-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: var(--panel-bg);
  border: 4px solid var(--accent-blue);
  box-shadow: 0 0 16px var(--accent-blue);
  /* Keep toolbar width stable so layout doesn't shift when button text changes */
  min-width: 120px;
}
#powerup-toolbar .powerup-button {
  padding: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  /* Ensure consistent button width */
  width: 100%;
}
#powerup-toolbar .powerup-button {
  position: relative;
}
#powerup-toolbar .powerup-button:disabled {
  opacity: 0.5;
  cursor: default;
}

#game-container.swap-mode {
  animation: pulse 500ms ease-in-out infinite alternate;
}

.tile.swap-selected {
  box-shadow: 0 0 12px var(--accent-green);
}

@keyframes pulse {
  from { box-shadow: 0 0 16px var(--accent-blue); }
  to { box-shadow: 0 0 4px var(--accent-blue); }
}

#tooltip {
  position: fixed;
  display: none;
  background: var(--panel-bg);
  border: 2px solid var(--accent-blue);
  padding: 2px 6px;
  white-space: normal;
  word-break: break-word;
  font-family: var(--font-pixel);
  font-size: 0.75rem;
  pointer-events: none;
  z-index: 1000;
  max-width: 200px;
}

