:root{--bg:#0b1020;--surface:#121832;--text:#e6e8ef;--muted:#9aa3b2;--primary:#6c8cff;--accent:#ff6b9b;--border:#223050;--radius:14px;--shadow:0 10px 30px rgba(0,0,0,.35)}
[data-theme="light"]{--bg:#f6f8ff;--surface:#fff;--text:#0f172a;--muted:#475569;--primary:#3558ff;--accent:#e5487d;--border:#e2e8f0}
*{box-sizing:border-box}
body{margin:0;font-family:Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto;background:var(--bg);color:var(--text)}
.container{max-width:1000px;margin:0 auto;padding:24px}
.header{text-align:center;margin-bottom:8px}
.title{margin:0;font-size:clamp(1.8rem,4vw,2.4rem)}
.subtitle{margin:.25rem 0;color:var(--muted)}
.controls{display:flex;align-items:center;gap:10px;background:var(--surface);border:1px solid var(--border);border-radius:12px;padding:10px;box-shadow:var(--shadow)}
.stat{background:rgba(255,255,255,.03);border:1px solid var(--border);padding:6px 10px;border-radius:10px}
.grow{flex:1}
.btn{border:none;border-radius:10px;padding:8px 12px;background:var(--primary);color:#fff;cursor:pointer}
.grid{margin-top:16px;display:grid;gap:10px}
.grid:focus{outline:2px solid var(--primary)}
.card{position:relative;width:100%;aspect-ratio:1;border-radius:12px;transform-style:preserve-3d;transition:transform .35s ease;cursor:pointer}
.card-inner{position:absolute;inset:0;border-radius:12px;border:1px solid var(--border);box-shadow:var(--shadow)}
.front,.back{position:absolute;inset:0;display:grid;place-items:center;border-radius:12px;backface-visibility:hidden}
.front{background:var(--surface)}
.back{background:linear-gradient(135deg,var(--primary),var(--accent));transform:rotateY(180deg);color:#fff;font-size:2rem}
.flipped{transform:rotateY(180deg)}
.matched{outline:2px solid var(--accent)}
.hint{color:var(--muted);text-align:center;margin-top:8px}
.theme-toggle{position:fixed;right:16px;bottom:16px;border:1px solid var(--border);background:var(--surface);color:var(--text);border-radius:999px;padding:10px 12px;cursor:pointer;box-shadow:var(--shadow)}
.sr{position:absolute;left:-9999px}

/* Enhanced styles for new features */

/* Power-up Panel */
.power-up-panel {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.power-up-panel h3 {
  margin: 0 0 12px 0;
  color: var(--text);
  font-size: 1.1rem;
}

.power-up-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.power-up-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.power-up-btn:hover:not(:disabled) {
  background: rgba(108, 140, 255, 0.1);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.power-up-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.power-up-btn.locked {
  background: var(--muted);
  border-color: var(--muted);
}

.power-up-btn.on-cooldown {
  background: rgba(255, 107, 155, 0.1);
  border-color: var(--accent);
}

.power-up-btn.can-afford {
  border-color: #44ff88;
  box-shadow: 0 0 10px rgba(68, 255, 136, 0.3);
}

.power-up-btn.ready {
  animation: powerUpPulse 2s infinite;
}

.power-up-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.power-up-name {
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.power-up-cooldown {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: bold;
  display: none;
}

.power-up-cost {
  font-size: 0.7rem;
  color: var(--muted);
}

/* Stats Panel */
.stats-panel, .achievements-panel {
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stats-header, .achievements-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
}

.stats-header h3, .achievements-header h3 {
  margin: 0;
  font-size: 1rem;
}

.stats-toggle, .achievements-toggle {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
  padding: 4px;
  border-radius: 4px;
}

.stats-toggle:hover, .achievements-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.stats-content, .achievements-content {
  padding: 16px;
  max-height: 300px;
  overflow-y: auto;
}

.stats-panel.collapsed .stats-content,
.achievements-panel.collapsed .achievements-content {
  display: none;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-item:last-child {
  border-bottom: none;
}

/* Achievements */
.achievement {
  display: flex;
  align-items: center;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  position: relative;
}

.achievement.unlocked {
  border-color: var(--primary);
  background: rgba(108, 140, 255, 0.1);
}

.achievement.locked {
  opacity: 0.6;
}

.achievement-icon {
  font-size: 1.8rem;
  margin-right: 12px;
  min-width: 40px;
  text-align: center;
}

.achievement-info {
  flex: 1;
}

.achievement-name {
  font-weight: 600;
  margin-bottom: 2px;
}

.achievement-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.achievement-points {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 500;
}

.achievement-unlocked {
  font-size: 1.2rem;
  color: #44ff88;
  margin-left: 8px;
}

/* Game Mode and Theme Selectors */
.mode-selector, .theme-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-selector label, .theme-selector label {
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
}

.mode-selector select, .theme-selector select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 0.85rem;
}

/* Enhanced Card Effects */
.card-inner.sparkle {
  animation: sparkleGlow 2s infinite ease-in-out;
}

.card-inner.hint-glow {
  animation: hintPulse 0.8s ease-in-out;
}

.card.wrong-match .card-inner {
  animation: wrongShake 0.4s ease-in-out;
}

.time.warning {
  color: var(--accent) !important;
  animation: timeWarning 1s infinite;
}

/* Modals */
.game-summary-modal, .pause-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.modal-content, .pause-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal-content h2, .pause-content h2 {
  text-align: center;
  margin: 0 0 20px 0;
  color: var(--text);
}

.summary-stats {
  margin: 20px 0;
}

.summary-stats .stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.summary-stats .stat:last-child {
  border-bottom: none;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Animations */
@keyframes sparkleGlow {
  0%, 100% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.5); }
  50% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.8); }
}

@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(108, 140, 255, 0); }
  50% { box-shadow: 0 0 20px rgba(108, 140, 255, 0.8); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes powerUpPulse {
  0%, 100% {
    box-shadow: 0 0 0 rgba(68, 255, 136, 0);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 20px rgba(68, 255, 136, 0.6);
    transform: scale(1.02);
  }
}

@keyframes timeWarning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes peekPulse {
  0%, 100% { opacity: 0; }
  50% { opacity: 0.3; }
}

@keyframes shuffleWobble {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-2deg) scale(1.02); }
  75% { transform: rotate(2deg) scale(0.98); }
}

/* Responsive Design */
@media (max-width: 768px) {
  .controls {
    flex-wrap: wrap;
    gap: 8px;
  }

  .mode-selector, .theme-selector {
    order: -1;
    flex-basis: 100%;
  }

  .power-up-grid {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  }

  .power-up-btn {
    padding: 6px;
  }

  .power-up-icon {
    font-size: 1.2rem;
  }

  .power-up-name {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card-inner, .power-up-btn {
    transition: none !important;
    animation: none !important;
  }
}

/* Instructions Panel */
.instructions-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  opacity: 1;
  transition: all 0.3s ease;
}

.instructions-panel.hidden {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
}

.instructions-content h2 {
  margin: 0 0 20px 0;
  color: var(--text);
  text-align: center;
  font-size: 1.5rem;
}

.instructions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 0.2s ease;
}

.instruction-item:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.08);
}

.instruction-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 12px;
}

.instruction-item p {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.4;
}

.instructions-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(108, 140, 255, 0.3);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 24px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-2px);
}

/* Game Status Banner */
.game-status {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.game-status::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: shimmer 2s infinite;
}

.game-status.hidden {
  opacity: 0;
  transform: translateY(-10px);
  margin-bottom: 0;
  padding: 0;
}

.game-status.success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
}

.game-status.warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.game-status.error {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Tutorial Overlay */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.tutorial-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.tutorial-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
}

.tutorial-content h3 {
  margin: 0 0 16px 0;
  color: var(--text);
  font-size: 1.3rem;
}

.tutorial-content p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.tutorial-pointer {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  animation: tutorialPulse 1.5s infinite;
  pointer-events: none;
}

/* Tutorial card highlighting */
.card.tutorial-highlight {
  position: relative;
  z-index: 1001;
}

.card.tutorial-highlight::before {
  content: '';
  position: absolute;
  inset: -4px;
  background: linear-gradient(45deg, var(--primary), var(--accent));
  border-radius: 16px;
  z-index: -1;
  animation: tutorialGlow 1.5s infinite;
}

.card.tutorial-highlight .card-inner {
  background: white;
  box-shadow: 0 0 30px rgba(108, 140, 255, 0.6);
}

/* Tutorial highlighting for any element */
.tutorial-highlight {
  position: relative;
  z-index: 2001;
  animation: tutorialPulse 2s infinite;
  box-shadow: 0 0 0 4px var(--primary), 0 0 20px rgba(108, 140, 255, 0.6) !important;
  border-radius: 12px !important;
}

/* Tutorial pointer */
.tutorial-pointer {
  position: fixed;
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 15px solid var(--primary);
  z-index: 2002;
  display: none;
  animation: tutorialBounce 1s infinite;
}

/* Tutorial continue button */
.tutorial-continue {
  margin-top: 16px;
  min-width: 120px;
}

/* Game status banner type variations */
.game-status.success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.game-status.warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
}

.game-status.error {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.game-status.info {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
}

/* Hidden utility class */
.hidden {
  display: none !important;
}

/* Enhanced button styles */
.btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

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

/* New animations */
@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

@keyframes tutorialPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5);
    opacity: 0.5;
  }
}

@keyframes tutorialGlow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(108, 140, 255, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(108, 140, 255, 0);
  }
}

@keyframes tutorialBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .instructions-grid {
    grid-template-columns: 1fr;
  }

  .instructions-actions {
    flex-direction: column;
  }

  .tutorial-content {
    padding: 20px;
  }

  .instruction-item {
    flex-direction: column;
    text-align: center;
    gap: 8px;
  }

  .instruction-icon {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }

  /* Improved mobile controls */
  .controls {
    flex-wrap: wrap;
    justify-content: center;
    padding: 12px;
  }

  .stat {
    font-size: 0.85rem;
    padding: 4px 8px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  /* Enhanced mobile card experience */
  .card {
    border-radius: 8px;
  }

  .card-inner {
    border-radius: 8px;
  }

  /* Mobile-friendly game status */
  .game-status {
    margin: 8px;
    padding: 10px;
    font-size: 0.9rem;
  }
}

/* Mobile portrait mode optimizations */
@media (max-width: 480px) {
  .container {
    padding: 16px;
  }

  .instructions-panel {
    padding: 16px;
    margin-bottom: 16px;
  }

  .instructions-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .instruction-item {
    padding: 12px;
  }

  .instruction-icon {
    font-size: 24px;
  }

  .instructions-actions {
    flex-direction: column;
    gap: 8px;
  }

  .tutorial-overlay .tutorial-content {
    margin: 16px;
    padding: 20px;
    max-width: calc(100vw - 32px);
  }

  .game-status {
    margin: 8px 16px;
    padding: 12px;
    font-size: 14px;
  }

  /* Improved touch targets */
  .card {
    min-height: 60px;
  }

  .btn {
    min-height: 44px;
    min-width: 44px;
  }
}
