/* ===== CSS Variables / Design System ===== */
:root {
  /* Colors */
  --background: 222 47% 8%;
  --foreground: 210 40% 98%;
  --card: 222 47% 11%;
  --card-foreground: 210 40% 98%;
  --primary: 24 95% 53%;
  --primary-foreground: 0 0% 100%;
  --secondary: 217 33% 17%;
  --secondary-foreground: 210 40% 98%;
  --muted: 217 33% 17%;
  --muted-foreground: 215 20% 55%;
  --accent: 47 100% 50%;
  --accent-foreground: 222 47% 8%;
  --destructive: 0 84% 60%;
  --border: 217 33% 20%;
  
  /* Fonts */
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Inter', sans-serif;
  
  /* Spacing */
  --radius: 12px;
  
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px hsla(var(--primary) / 0.3);
  
  /* Mobile-friendly touch target size */
  --touch-target: 48px;
}

/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  /* Prevent pull-to-refresh on mobile */
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  background: linear-gradient(135deg, hsl(222, 47%, 6%) 0%, hsl(222, 47%, 11%) 50%, hsl(240, 40%, 8%) 100%);
  color: hsl(var(--foreground));
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Prevent text selection on game elements */
  -webkit-user-select: none;
  user-select: none;
  /* Prevent zoom on double-tap */
  touch-action: manipulation;
  /* Prevent overscroll bounce */
  overscroll-behavior: none;
  position: fixed;
  width: 100%;
  overflow-y: auto;
}

a {
  color: hsl(var(--primary));
  text-decoration: none;
  transition: opacity 0.2s;
}

a:hover {
  opacity: 0.8;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  background: hsl(var(--secondary));
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.text-primary { color: hsl(var(--primary)); }
.text-accent { color: hsl(var(--accent)); }
.text-muted { color: hsl(var(--muted-foreground)); }

.text-gradient {
  background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(var(--accent)) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.glass {
  background: hsla(var(--card) / 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid hsla(var(--border) / 0.5);
  border-radius: var(--radius);
}

/* ===== App Container ===== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Hero Section ===== */
.hero {
  position: relative;
  padding: 60px 20px;
  text-align: center;
  overflow: hidden;
}

.hero-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 600px;
  background: hsla(var(--primary) / 0.1);
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(48px, 10vw, 80px);
  font-weight: 700;
  margin-bottom: 16px;
  line-height: 1.1;
}

.hero-subtitle {
  font-size: clamp(16px, 3vw, 20px);
  color: hsl(var(--muted-foreground));
  max-width: 600px;
  margin: 0 auto 32px;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 48px;
}

.stat {
  text-align: center;
}

.stat-value {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
}

.stat-label {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding: 0 20px 60px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Category Filter ===== */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
}

.category-btn {
  padding: 10px 20px;
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.category-btn:hover {
  background: hsla(var(--primary) / 0.2);
}

.category-btn.active {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

/* ===== Game Grid ===== */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.game-card {
  position: relative;
  padding: 20px;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s;
  text-decoration: none;
  color: inherit;
}

.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.1;
  transition: opacity 0.3s;
}

.game-card:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

.game-card:hover::before {
  opacity: 0.2;
}

.game-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.game-card-icon {
  font-size: 36px;
}

.game-card-badges {
  display: flex;
  gap: 4px;
}

.badge {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 500;
}

.badge-grid {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.badge-hard {
  background: hsla(var(--destructive) / 0.2);
  color: hsl(var(--destructive));
}

.badge-easy {
  background: hsla(142, 76%, 36% / 0.2);
  color: hsl(142, 76%, 50%);
}

.badge-endless {
  background: hsla(280, 80%, 60% / 0.2);
  color: hsl(280, 80%, 70%);
}

.game-card-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
  transition: color 0.2s;
}

.game-card:hover .game-card-title {
  color: hsl(var(--primary));
}

.game-card-desc {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

.game-card-glow {
  position: absolute;
  bottom: -48px;
  right: -48px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  opacity: 0;
  filter: blur(40px);
  transition: opacity 0.3s;
}

.game-card:hover .game-card-glow {
  opacity: 0.3;
}

/* ===== Footer ===== */
.footer {
  padding: 32px 20px;
  text-align: center;
  border-top: 1px solid hsla(var(--border) / 0.5);
  color: hsl(var(--muted-foreground));
  font-size: 14px;
}

/* ===== Game Page ===== */
.game-page {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Breadcrumb */
.breadcrumb {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  margin-bottom: 16px;
}

.breadcrumb a {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Game Header */
.game-header {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.game-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.home-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: hsl(var(--secondary));
  border-radius: 8px;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
}

.home-btn:hover {
  color: hsl(var(--foreground));
  background: hsla(var(--primary) / 0.2);
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-icon {
  font-size: 32px;
}

.game-description {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

.game-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  background: hsl(var(--secondary));
  padding: 8px 16px;
  border-radius: 8px;
  text-align: center;
  min-width: 70px;
}

.score-label {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.score-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.restart-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: hsl(var(--secondary));
  border-radius: 8px;
  color: hsl(var(--muted-foreground));
  transition: all 0.2s;
}

.restart-btn:hover {
  color: hsl(var(--primary));
  background: hsla(var(--primary) / 0.2);
}

/* Game Container */
.game-container {
  position: relative;
  touch-action: none;
  user-select: none;
  margin-bottom: 24px;
  /* Prevent context menu on long press */
  -webkit-touch-callout: none;
  /* Ensure touch events work properly */
  -webkit-user-select: none;
}

.game-board {
  position: relative;
  background: hsl(var(--secondary));
  border-radius: 12px;
  padding: 8px;
  /* Touch feedback */
  -webkit-tap-highlight-color: transparent;
}

/* Swipe indicator overlay - shows during swipe */
.swipe-indicator {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: hsla(var(--background) / 0.3);
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
}

.swipe-indicator.active {
  opacity: 1;
}

.swipe-indicator svg {
  width: 48px;
  height: 48px;
  color: hsl(var(--primary));
  filter: drop-shadow(0 0 10px hsla(var(--primary) / 0.5));
}

.grid-background {
  display: grid;
  gap: 8px;
}

.grid-cell {
  background: hsla(var(--muted) / 0.5);
  border-radius: 6px;
}

.tiles-container {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  transition: left 100ms ease-out, top 100ms ease-out;
  will-change: left, top, transform;
}

.tile.new {
  animation: tile-pop 150ms ease-out;
}

.tile.merged {
  animation: tile-merge 150ms ease-out;
}

@keyframes tile-pop {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

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

/* Game Overlay */
.game-overlay {
  position: absolute;
  inset: 0;
  background: hsla(var(--background) / 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  z-index: 100;
}

.overlay-content {
  text-align: center;
  padding: 32px;
}

.overlay-content h2 {
  font-family: var(--font-display);
  font-size: 36px;
  margin-bottom: 8px;
}

.overlay-content p {
  color: hsl(var(--muted-foreground));
  margin-bottom: 24px;
}

.overlay-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
}

.btn-secondary:hover {
  background: hsla(var(--primary) / 0.2);
}

/* Mobile Controls */
.mobile-controls {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: hsla(var(--secondary) / 0.5);
  border-radius: 16px;
}

.control-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.control-spacer {
  width: 64px;
  height: 64px;
}

.control-btn {
  width: 64px;
  height: 64px;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: hsl(var(--secondary));
  border: 2px solid hsla(var(--border) / 0.5);
  border-radius: 12px;
  font-size: 28px;
  color: hsl(var(--foreground));
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Better touch feedback */
  -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
  transform: scale(0.9);
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
}

/* Touch hint for mobile */
.touch-hint {
  text-align: center;
  padding: 12px 20px;
  background: hsla(var(--primary) / 0.1);
  border: 1px dashed hsla(var(--primary) / 0.3);
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

.touch-hint strong {
  color: hsl(var(--primary));
}

/* Instructions */
.instructions {
  padding: 12px 20px;
  text-align: center;
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  margin-bottom: 24px;
}

.instructions .divider {
  margin: 0 8px;
}

.target-tile {
  color: hsl(var(--primary));
  font-weight: 600;
}

.endless-badge {
  color: hsl(280, 80%, 70%);
  margin-left: 8px;
}

/* Related Section */
.related-section {
  width: 100%;
  max-width: 600px;
  margin-bottom: 32px;
}

.related-section h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.related-card {
  padding: 12px;
  border-radius: 12px;
  transition: all 0.2s;
}

.related-card:hover {
  transform: scale(1.02);
}

.related-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.related-card-icon {
  font-size: 24px;
}

.related-card-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
}

.related-card-badges {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.related-card-badges .badge {
  font-size: 10px;
  padding: 2px 6px;
}

.related-card-desc {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.category-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
}

.category-links span {
  color: hsl(var(--muted-foreground));
}

/* FAQ Section */
.faq-section {
  width: 100%;
  max-width: 600px;
  margin-bottom: 32px;
}

.faq-section h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.faq-item {
  border-radius: 12px;
  overflow: hidden;
}

.faq-question {
  width: 100%;
  padding: 16px;
  background: transparent;
  color: hsl(var(--foreground));
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-question::after {
  content: '▼';
  font-size: 10px;
  color: hsl(var(--muted-foreground));
  transition: transform 0.2s;
}

.faq-item.open .faq-question::after {
  transform: rotate(180deg);
}

.faq-answer {
  padding: 0 16px 16px;
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  line-height: 1.6;
  display: none;
}

.faq-item.open .faq-answer {
  display: block;
}

/* Reviews Section */
.reviews-section {
  width: 100%;
  max-width: 600px;
  margin-bottom: 32px;
}

.reviews-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.reviews-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

.rating-summary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stars {
  color: #facc15;
  font-size: 16px;
}

.rating-text {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

.reviews-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.review-card {
  padding: 16px;
  border-radius: 12px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.review-author {
  font-weight: 600;
  font-size: 14px;
}

.review-location {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

.review-stars {
  color: #facc15;
  font-size: 12px;
}

.review-text {
  font-size: 13px;
  color: hsl(var(--muted-foreground));
  line-height: 1.5;
}

/* Game Footer */
.game-footer {
  width: 100%;
  max-width: 600px;
  text-align: center;
  padding-top: 24px;
  border-top: 1px solid hsla(var(--border) / 0.5);
}

.game-footer p {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
  margin-bottom: 12px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
}

.footer-links span {
  color: hsl(var(--muted-foreground));
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  body {
    position: relative;
    overflow-y: auto;
  }
  
  .hero {
    padding: 40px 16px;
  }
  
  .hero-stats {
    gap: 24px;
  }
  
  .game-grid {
    grid-template-columns: 1fr;
  }
  
  .mobile-controls {
    display: flex;
  }
  
  .touch-hint {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
  
  .related-grid {
    grid-template-columns: 1fr;
  }
  
  .reviews-grid {
    grid-template-columns: 1fr;
  }
  
  .game-page {
    padding: 12px;
    padding-bottom: 40px;
  }
  
  .game-board {
    padding: 6px;
  }
  
  .grid-background {
    gap: 6px;
  }
  
  .tiles-container {
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: 6px;
  }
  
  .tile {
    border-radius: 4px;
  }
  
  .breadcrumb {
    font-size: 12px;
    margin-bottom: 12px;
  }
  
  .score-box {
    padding: 6px 12px;
    min-width: 60px;
  }
  
  .score-value {
    font-size: 18px;
  }
}

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }
  
  .touch-hint {
    display: none;
  }
}

@media (max-width: 480px) {
  .game-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .game-header-left {
    justify-content: center;
    text-align: center;
  }
  
  .game-title-wrap {
    text-align: center;
  }
  
  .game-title {
    justify-content: center;
    font-size: 20px;
  }
  
  .game-icon {
    font-size: 28px;
  }
  
  .game-header-right {
    justify-content: center;
  }
  
  .scores {
    flex: 1;
    justify-content: center;
  }
  
  .home-btn, .restart-btn {
    width: 44px;
    height: 44px;
  }
  
  .control-btn {
    width: 72px;
    height: 72px;
    font-size: 32px;
  }
  
  .control-spacer {
    width: 72px;
    height: 72px;
  }
  
  .faq-question {
    font-size: 13px;
    padding: 14px;
  }
  
  .faq-answer {
    font-size: 13px;
    padding: 0 14px 14px;
  }
}

/* Landscape mobile optimization */
@media (max-height: 600px) and (orientation: landscape) {
  .game-page {
    padding: 8px;
  }
  
  .breadcrumb {
    display: none;
  }
  
  .game-header {
    margin-bottom: 8px;
  }
  
  .mobile-controls {
    display: none;
  }
  
  .touch-hint {
    display: none;
  }
  
  .instructions {
    margin-bottom: 8px;
    padding: 8px 16px;
    font-size: 12px;
  }
  
  .related-section,
  .faq-section,
  .reviews-section,
  .game-footer {
    display: none;
  }
}

/* Safe area insets for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .game-page {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  
  .mobile-controls {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
