/* ===== CSS Variables - Wordle Inspired (Light Mode) ===== */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f7f8;
  --bg-card: #e4e5e6;
  --bg-card-border: #d3d6da;
  --text-primary: #1a1a1b;
  --text-secondary: #787c7e;
  --accent-young: #538d4e;
  --accent-old: #b59f3b;
  --accent-primary: #538d4e;
  --accent-primary-hover: #5a9a54;
  --accent-success: #538d4e;
  --accent-error: #b55a5a;
  --border-radius: 4px;
  --border-radius-lg: 6px;
  --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.12);
  --transition: 0.15s ease;
}

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

html {
  font-size: 16px;
}

body {
  font-family: 'Arvo', Georgia, serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== App Layout ===== */
.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 1.5rem 0;
}

.title {
  font-family: 'Alfa Slab One', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-size: 1rem;
}

.highlight-young {
  font-weight: 600;
}

.highlight-old {
  font-weight: 600;
}

/* ===== Game Container ===== */
.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ===== Loading Progress ===== */
.loading-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
}

.loading-progress.hidden {
  display: none;
}

.loading-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.loading-text span {
  color: var(--accent-primary);
  font-weight: 700;
}

.progress-bar {
  width: 100%;
  max-width: 300px;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--bg-card-border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.875rem 2rem;
  border: none;
  border-radius: var(--border-radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
  filter: brightness(1.1);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
  filter: brightness(0.95);
}

.btn-primary:disabled {
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.checks-counter {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

#checksCount {
  font-weight: 600;
}

/* ===== Photo Grid Container (Scroll Boundary) ===== */
.photo-grid-container {
  background: var(--bg-secondary);
  border: 2px solid var(--bg-card-border);
  border-radius: var(--border-radius-lg);
  padding: 0.75rem;
  transition: opacity 0.3s ease;
}

.photo-grid-container.hidden {
  display: none;
}

/* ===== Photo Grid ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
}

/* ===== Photo Card ===== */
.photo-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  border: 2px solid var(--bg-card-border);
  /* iOS Safari: prevent context menu on long press */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  /* GPU acceleration for smooth animations */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* Smooth transitions */
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

/* Desktop-only subtle hover effect */
@media (hover: hover) {
  .photo-card:hover {
    border-color: var(--text-secondary);
    transform: translateZ(0) scale(1.02);
  }
}

/* Tap-to-Swap States */
.photo-card.selected {
  border-color: var(--accent-old);
  border-width: 3px;
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(181, 159, 59, 0.5);
  z-index: 10;
  animation: selectedPulse 1.5s ease-in-out infinite;
}

@keyframes selectedPulse {

  0%,
  100% {
    box-shadow: 0 4px 16px rgba(181, 159, 59, 0.5);
  }

  50% {
    box-shadow: 0 4px 24px rgba(181, 159, 59, 0.7);
  }
}

.photo-card.swapping {
  transition: transform 0.3s ease;
  z-index: 100;
}

/* Photo card images - iOS Safari touch handling */
.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
  /* Prevent iOS Safari context menu on long press */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}

/* Fade in when loaded */
.photo-card:not(.loading) img {
  opacity: 1;
}

/* Hide during loading */
.photo-card.loading img {
  opacity: 0;
}

.photo-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.photo-card.loading .photo-loading {
  opacity: 1;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(83, 141, 78, 0.3);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Error state */
.photo-card.error {
  background: linear-gradient(135deg, var(--bg-card), #f5e0e0);
}

.photo-card.error::after {
  content: '⚠️';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2rem;
}

/* Photo Position Number */
.photo-position {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 1.75rem;
  height: 1.75rem;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  border: 1px solid var(--bg-card-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* Age Label (shown after win) */
.photo-age {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.95);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  border-top: 1px solid var(--bg-card-border);
  opacity: 0;
  transform: translateY(100%);
  transition: all 0.3s ease;
}

.photo-card.revealed .photo-age {
  opacity: 1;
  transform: translateY(0);
}

/* Correct/Incorrect/Close States */
.photo-card.correct {
  border-color: #6aaa64;
  border-width: 4px;
}

.photo-card.close {
  border-color: var(--accent-old);
  border-width: 4px;
}

.photo-card.incorrect {
  border-color: var(--accent-error);
  border-width: 4px;
  animation: shake 0.4s ease;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-5px);
  }

  40%,
  80% {
    transform: translateX(5px);
  }
}

/* ===== Win Message ===== */
.win-message {
  margin-top: 1.5rem;
  opacity: 1;
  transition: all 0.4s ease;
}

.win-message.hidden {
  display: none;
}

.win-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 2px solid #6aaa64;
  padding: 1rem 2rem;
  border-radius: var(--border-radius-lg);
  animation: slideUp 0.4s ease;
}

.win-emoji {
  font-size: 2rem;
  line-height: 1;
}

.win-text {
  text-align: left;
}

.win-text h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #6aaa64;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.win-text p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0.25rem 0 0 0;
}

@keyframes slideUp {
  0% {
    transform: translateY(20px);
    opacity: 0;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes popIn {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* Debug Buttons */
.debug-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-debug {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--bg-card-border);
  font-size: 0.75rem;
  padding: 0.5rem 1rem;
  opacity: 0.5;
  transition: all 0.15s ease;
}

.btn-debug:hover {
  opacity: 1;
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.btn-debug:active {
  transform: scale(0.98);
}

/* ===== Loading State ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-secondary);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  margin-left: 0.75rem;
  border: 3px solid rgba(83, 141, 78, 0.3);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Responsive Design ===== */

/* Tablet (3x2 grid) */
@media (max-width: 768px) {
  .photo-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
  }

  .title {
    font-size: 2rem;
  }
}

/* Mobile (2x3 grid) */
@media (max-width: 480px) {
  .app {
    padding: 0.75rem;
  }

  .header {
    padding: 1rem 0;
  }

  .title {
    font-size: 1.75rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .photo-position {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.75rem;
  }

  .btn {
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
  }

  .controls {
    gap: 1rem;
  }
}

/* ===== Solved State ===== */
.game-container.solved .photo-card {
  cursor: default;
}

.game-container.solved .photo-card:hover {
  transform: none;
}