* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --accent-1: #0f3460;
  --accent-2: #e94560;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0b0;
  --card-back: #0f3460;
  --card-border: #533483;
  --player1-color: #00b4d8;
  --player2-color: #f77f00;
  --match-glow: #06d6a0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary));
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

#app {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--player1-color), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--accent-1);
  border-radius: 12px;
  padding: 12px 20px;
  gap: 10px;
}

.player-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.3s, box-shadow 0.3s;
}

.player-info.active {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

#player1-info .player-label { color: var(--player1-color); }
#player2-info .player-label { color: var(--player2-color); }

.player-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.score {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

#player1-info .score { color: var(--player1-color); }
#player2-info .score { color: var(--player2-color); }

.misses {
  font-size: 0.65rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

#center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}

#timer-display {
  position: relative;
  width: 48px;
  height: 48px;
}

#timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--accent-1);
  stroke-width: 3;
}

.ring-fg {
  fill: none;
  stroke: var(--match-glow);
  stroke-width: 3;
  stroke-dasharray: 113.1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
  stroke-linecap: round;
}

.ring-fg.warn {
  stroke: var(--accent-2);
}

#timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

#turn-indicator {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
}

#message-area {
  font-size: 0.9rem;
  color: var(--accent-2);
  min-height: 24px;
  text-align: center;
}

#board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 600px;
}

.cell {
  aspect-ratio: 1;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  perspective: 600px;
  transition: transform 0.15s;
}

.cell:hover:not(.matched):not(.flipped) {
  transform: scale(1.05);
}

.cell:active:not(.matched):not(.flipped) {
  transform: scale(0.97);
}

.cell-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
  border-radius: 10px;
}

.cell.flipped .cell-inner,
.cell.matched .cell-inner {
  transform: rotateY(180deg);
}

.cell-front,
.cell-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.cell-back {
  background: var(--card-back);
  border: 2px solid var(--card-border);
}

.cell-back img {
  width: 60%;
  height: 60%;
  object-fit: contain;
  opacity: 0.7;
}

.cell-front {
  background: var(--bg-secondary);
  border: 2px solid var(--card-border);
  transform: rotateY(180deg);
}

.cell-front img {
  width: 85%;
  height: 85%;
  object-fit: contain;
}

.cell.matched {
  pointer-events: none;
}

.cell.matched .cell-front {
  border-color: var(--match-glow);
  box-shadow: 0 0 12px rgba(6, 214, 160, 0.4);
}

.cell.pulse {
  animation: pulse-anim 0.3s ease;
}

@keyframes pulse-anim {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

#game-over-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#game-over-screen.hidden {
  display: none;
}

.overlay {
  background: rgba(26, 26, 46, 0.95);
  border: 1px solid var(--accent-1);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 300px;
}

.overlay h2 {
  font-size: 1.6rem;
}

#new-game-btn {
  padding: 12px 28px;
  border: none;
  border-radius: 8px;
  background: var(--accent-2);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

#new-game-btn:hover {
  background: #d63050;
  transform: scale(1.03);
}

@media (max-width: 480px) {
  #board {
    gap: 6px;
  }
  header h1 {
    font-size: 1.4rem;
  }
  .player-label {
    font-size: 0.65rem;
  }
  .score {
    font-size: 1.4rem;
  }
  .misses {
    font-size: 0.55rem;
  }
  #timer-display {
    width: 40px;
    height: 40px;
  }
  #timer-text {
    font-size: 0.75rem;
  }
  #status-bar {
    padding: 8px 10px;
  }
  .player-info {
    padding: 6px 8px;
  }
}
