/**
 * game.css
 *
 * Purpose: Game-specific styles including card appearances (face-up, face-down),
 * card animations (flip, correct, wrong), and card grid layout.
 *
 * Dependencies: base.css, layout.css
 *
 * Key Styles:
 * - Card base styles and states
 * - Card flip animation
 * - Correct/wrong feedback animations
 * - Face-down card back image
 * - Card grid responsive sizing
 */

/* ==================== CARDS ==================== */

.card {
  /* Use flex instead of inline-block for better grid compatibility */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* Default desktop dimensions - will be overridden by grid on mobile */
  width: 130px;
  height: 182px;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 2em;
  font-weight: bold;
  cursor: pointer;
  transition:
    transform 0.3s,
    box-shadow 0.3s;
  user-select: none;
  position: relative;
  transform-style: preserve-3d;
}

.card.face-down {
  background-image: url("https://raw.githubusercontent.com/parekhkeyurkumar/iampossible-assets/refs/heads/main/images/card-backs/CardBack2.png");
  background-size: cover;
  background-position: center;
  border: 2px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card.face-up {
  background: transparent;
  padding: 0;
  overflow: hidden;
  /* Note: border handling moved to .face-down-cards rules for grid cards */
}

.card.face-up img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Ensures images fit within card without distortion */
  object-position: center; /* Centers the image within the container */
  border-radius: 8px;
  display: block; /* Prevents inline spacing issues */
  background-color: white; /* Provides consistent background for card images */
}

/* Card hover: use subtle box-shadow instead of transform to avoid layout shifts */
.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Disable hover transforms for face-down cards in grid to prevent size issues */
.face-down-cards .card:hover {
  transform: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.card.reference {
  cursor: default;
  border: 2px solid #e0e0e0 !important;
}

.card.reference:hover {
  transform: none;
}

/*
 * CRITICAL: All cards in the grid use EXPLICIT dimensions from CSS variables.
 * NO aspect-ratio, NO height:auto - this prevents size mismatches.
 * Both face-down and face-up cards MUST have identical box dimensions.
 */
.face-down-cards .card {
  width: var(--face-card-width);
  height: var(--face-card-height);
  min-width: var(--face-card-width);
  min-height: var(--face-card-height);
  max-width: var(--face-card-width);
  max-height: var(--face-card-height);
  box-sizing: border-box;
  /* Consistent border for both states to prevent size shifts */
  border: 2px solid transparent;
}

/* Face-down cards: show card back with visible border */
.face-down-cards .card.face-down {
  border-color: #e0e0e0;
}

/* Face-up cards: transparent border maintains same outer dimensions */
.face-down-cards .card.face-up {
  border-color: transparent;
  background: transparent;
  padding: 0;
  overflow: hidden;
}

/* Face-up card images fill the card exactly */
.face-down-cards .card.face-up img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Ensures PNG images fit without distortion */
  object-position: center; /* Centers the image within the card */
  display: block;
  border-radius: 6px;
  background-color: white; /* Provides consistent background for self-hosted PNG images */
}

/* ==================== CARD ANIMATIONS ==================== */

.card.flipping {
  animation: cardFlip 0.4s ease-in-out;
}

.card.correct {
  animation: correctPulse 0.6s ease-out;
  border-color: #27ae60;
  border-width: 3px;
  box-shadow: 0 0 20px rgba(39, 174, 96, 0.6);
}

/* Correct animation uses box-shadow glow instead of scale to avoid size changes */

.card.wrong {
  animation: wrongPulse 0.6s ease-out;
  border-color: #e74c3c;
  border-width: 3px;
  box-shadow: 0 0 20px rgba(231, 76, 60, 0.6);
}

/* ==================== STATS PAGE ==================== */

.stats-page {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: white;
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: #667eea #f0f0f0; /* Firefox */
}

/* Custom scrollbar for WebKit browsers (Chrome, Safari, Edge) */
.stats-page::-webkit-scrollbar {
  width: 8px;
}

.stats-page::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 4px;
}

.stats-page::-webkit-scrollbar-thumb {
  background: #667eea;
  border-radius: 4px;
}

.stats-page::-webkit-scrollbar-thumb:hover {
  background: #764ba2;
}

.stats-page.active {
  display: block;
}

.stats-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 15px 50px 15px;
  box-sizing: border-box;
  width: 100%;
}

.stats-title {
  font-size: 2.5em;
  color: #667eea;
  padding-top: 24px;
  margin-bottom: 30px;
  text-align: center;
  font-weight: 800;
}

.stats-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 15px;
  border: 1px solid #e0e0e0;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #e0e0e0;
}

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

.stats-row-label {
  font-size: 1.1em;
  color: #666;
  font-weight: 600;
}

.stats-row-value {
  font-size: 1.3em;
  color: #667eea;
  font-weight: 700;
}

.stats-footer {
  text-align: center;
  color: #999;
  font-size: 0.85em;
  margin-top: 30px;
  padding: 20px;
}

/* Stats Player Section */
.stats-player {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
}

.stats-player-label {
  font-size: 0.9em;
  color: #999;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stats-player-name {
  font-size: 2em;
  color: #667eea;
  font-weight: 700;
}

/* ==================== MILESTONE JOURNEY SECTION ==================== */

.milestone-section {
  margin-top: 30px;
  margin-bottom: 15px;
}

.milestone-title {
  font-size: 2.5em;
  color: #667eea;
  margin-bottom: 10px;
  text-align: center;
  font-weight: 800;
}

.milestone-subtitle {
  text-align: center;
  font-size: 1.15em;
  color: #666;
  margin-bottom: 25px;
  font-weight: 600;
}

.milestone-subtitle span {
  color: #667eea;
  font-weight: 700;
  font-size: 1.1em;
}

.milestone-cards {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.milestone-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #e0e0e0;
  text-align: center;
}

.milestone-card-title {
  font-size: 1.1em;
  color: #666;
  font-weight: 600;
  margin-bottom: 8px;
}

.milestone-card-title .milestone-icon {
  margin-right: 8px;
}

.milestone-card-requirement {
  font-size: 0.9em;
  color: #999;
  font-weight: 400;
  margin-bottom: 0;
}

.milestone-card-levels-to-go {
  font-size: 0.85em;
  color: #667eea;
  font-weight: 600;
  margin-top: 6px;
}

.milestone-progress {
  text-align: center;
  color: #999;
  font-size: 0.85em;
  margin-top: 20px;
  padding: 10px 20px;
}

.milestone-progress span {
  color: #667eea;
  font-weight: 700;
}

/* ==================== INTERACTIVE MILESTONE CARDS ==================== */

/* Make milestone cards interactive */
.milestone-card {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Desktop hover effect */
.milestone-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
  background: #f0f2f9;
}

/* Active/pressed state (mobile tap and desktop click) */
.milestone-card:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.15);
  background: #e8eaf5;
}

/* Unlocked milestone card - slightly different hover */
.milestone-card.unlocked:hover {
  background: #e8f5e9;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.2);
}

.milestone-card.unlocked:active {
  background: #c8e6c9;
}

/* Focus styles for keyboard accessibility */
.milestone-card:focus {
  outline: 2px solid #667eea;
  outline-offset: 2px;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.milestone-card:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.milestone-card:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* ==================== RESPONSIVE - SMALL MOBILE ==================== */

/* Smaller mobile: 550px and below - compact 3-column layout */
@media (max-width: 550px) {
  .control-panel {
    padding: 8px 15px 10px 15px;
    gap: 6px;
  }

  .control-label {
    font-size: 0.8em;
  }

  .control-row {
    gap: 8px;
    padding: 0 3px;
  }

  .control-row .stat-pill.left,
  .control-row .stat-pill.right {
    min-width: 82px;
  }

  .stat-pill {
    padding: 8px 14px;
    font-size: 1em;
    gap: 6px;
  }

  .stat-pill.right {
    padding: 7px 12px;
    gap: 4px;
  }

  .stat-pill.right .pill-row {
    gap: 6px;
  }

  .pill-dots .progress-dot {
    width: 8px;
    height: 8px;
  }

  .pill-emoji {
    font-size: 1.1em;
  }

  .pill-label {
    font-size: 0.9em;
  }

  .pill-value {
    font-size: 1.05em;
  }

  /* Reference card - increased size for 550px (~25% larger) */
  .control-panel .card.reference {
    width: 88px;
    height: 123px;
  }

  .card-panel {
    padding: 8px 10px;
  }

  .cards-section .section-label {
    font-size: 0.8em;
    margin-bottom: 8px;
  }

  .message {
    margin-top: 6px;
    font-size: 0.95em;
    min-height: 22px;
  }
}

@media (max-width: 480px) {
  .game-container {
    margin: 0 8px 20px 8px;
    height: 95vh;
    max-height: 100dvh;
  }

  .game-header {
    padding: 8px 14px;
  }

  .game-title {
    font-size: 1.2em;
    margin-bottom: 3px;
  }

  .game-subtitle {
    font-size: 0.65em;
  }

  .game-subtitle-line2 {
    font-size: 0.55em; /* Smaller on mobile but still visible */
  }

  .hamburger-btn {
    width: 28px;
    height: 28px;
  }

  .hamburger-btn::before {
    font-size: 18px;
  }

  .hamburger-menu {
    width: 220px;
  }

  .game-content {
    padding: 0 10px 10px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Compact 3-column layout for 480px */
  .control-panel {
    padding: 6px 12px 8px 12px;
    gap: 5px;
  }

  .control-label {
    font-size: 0.75em;
  }

  .control-row {
    gap: 6px;
    padding: 0 2px;
  }

  .control-row .stat-pill.left,
  .control-row .stat-pill.right {
    min-width: 72px;
  }

  .stat-pill {
    padding: 6px 10px;
    font-size: 0.9em;
    gap: 4px;
  }

  .stat-pill.right {
    padding: 5px 9px;
    gap: 3px;
  }

  .stat-pill.right .pill-row {
    gap: 5px;
  }

  .pill-dots .progress-dot {
    width: 7px;
    height: 7px;
  }

  .pill-emoji {
    font-size: 1em;
  }

  .pill-label {
    font-size: 0.8em;
  }

  .pill-value {
    font-size: 0.95em;
  }

  /* Reference card - increased size for 480px (~25% larger) */
  .control-panel .card.reference {
    width: 82px;
    height: 115px;
  }

  .card-panel {
    padding: 6px 8px;
  }

  .cards-section .section-label {
    font-size: 0.75em;
    margin-bottom: 6px;
  }

  .face-down-cards {
    max-width: 360px;
  }

  .stats-player-name {
    font-size: 1.5em;
  }

  .message {
    font-size: 0.9em;
    margin-top: 5px;
    min-height: 20px;
  }
}

/* Very small mobile: 375px and below - compact 3-column layout */
@media (max-width: 375px) {
  .game-container {
    margin: 0 4px 15px 4px;
    height: 97vh;
  }

  .game-header {
    padding: 6px 10px;
  }

  .game-title {
    font-size: 1.1em;
    margin-bottom: 2px;
  }

  .game-subtitle {
    font-size: 0.6em;
  }

  .game-content {
    padding: 0 6px 6px 6px;
    overflow: hidden;
  }

  /* Compact 3-column layout for 375px */
  .control-panel {
    padding: 5px 10px 6px 10px;
    gap: 4px;
  }

  .control-label {
    font-size: 0.7em;
  }

  .control-row {
    gap: 5px;
    padding: 0 2px;
  }

  .control-row .stat-pill.left,
  .control-row .stat-pill.right {
    min-width: 65px;
  }

  .stat-pill {
    padding: 5px 8px;
    font-size: 0.85em;
    gap: 3px;
  }

  .stat-pill.right {
    padding: 4px 7px;
    gap: 2px;
  }

  .stat-pill.right .pill-row {
    gap: 4px;
  }

  .pill-dots .progress-dot {
    width: 6px;
    height: 6px;
  }

  .pill-emoji {
    font-size: 0.95em;
  }

  .pill-label {
    font-size: 0.75em;
  }

  .pill-value {
    font-size: 0.9em;
  }

  /* Reference card - increased size for 375px (~25% larger) */
  .control-panel .card.reference {
    width: 70px;
    height: 98px;
  }

  .card-panel {
    padding: 5px 6px;
  }

  .cards-section .section-label {
    font-size: 0.7em;
    margin-bottom: 5px;
  }

  .face-down-cards {
    max-width: 320px;
  }

  .message {
    font-size: 0.85em;
    margin-top: 4px;
    min-height: 18px;
  }
}

/* Tiny mobile: 320px and below - compact 3-column layout */
@media (max-width: 320px) {
  .game-container {
    margin: 0 2px 10px 2px;
    height: 98vh;
  }

  .game-header {
    padding: 5px 8px;
  }

  .game-title {
    font-size: 1em;
    margin-bottom: 1px;
  }

  .game-subtitle {
    font-size: 0.55em;
  }

  .game-content {
    padding: 0 4px 4px 4px;
    overflow: hidden;
  }

  /* Compact 3-column layout for 320px */
  .control-panel {
    padding: 4px 8px 5px 8px;
    gap: 3px;
  }

  .control-label {
    font-size: 0.65em;
  }

  .control-row {
    gap: 4px;
    padding: 0 2px;
  }

  .control-row .stat-pill.left,
  .control-row .stat-pill.right {
    min-width: 58px;
  }

  .stat-pill {
    padding: 4px 6px;
    font-size: 0.75em;
    gap: 2px;
  }

  .stat-pill.right {
    padding: 3px 5px;
    gap: 2px;
  }

  .stat-pill.right .pill-row {
    gap: 3px;
  }

  .pill-dots .progress-dot {
    width: 5px;
    height: 5px;
  }

  .pill-emoji {
    font-size: 0.85em;
  }

  .pill-label {
    font-size: 0.68em;
  }

  .pill-value {
    font-size: 0.8em;
  }

  /* Reference card - increased size for 320px (~25% larger) */
  .control-panel .card.reference {
    width: 60px;
    height: 84px;
  }

  .card-panel {
    padding: 4px 5px;
  }

  .cards-section .section-label {
    font-size: 0.65em;
    margin-bottom: 4px;
  }

  .face-down-cards {
    max-width: 290px;
  }

  .message {
    font-size: 0.8em;
    margin-top: 3px;
    min-height: 16px;
  }
}
