/* CSS Variables & Core Theme Settings */
:root {
  --font-title: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette */
  --bg-app: #120f0e;
  --bg-card: #201a18;
  --bg-card-glass: rgba(32, 26, 24, 0.85);
  --border-glass: rgba(217, 119, 6, 0.25);
  
  --text-primary: #f5f0eb;
  --text-muted: #a39790;
  
  --accent-gold: #d97706;
  --accent-gold-hover: #b45309;
  --accent-gold-glow: rgba(217, 119, 6, 0.4);
  
  --accent-green: #10b981;
  --accent-green-hover: #059669;
  
  --accent-red: #ef4444;
  --accent-red-hover: #dc2626;
  
  /* Boundary Borders */
  --grid-border-color: #3e332f;
  --region-border-color: #ffffff;
  
  /* Grid settings */
  --grid-size: 5;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Title Screen Styling */
.title-screen-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 440px;
  height: 100vh;
  padding: 2rem;
  text-align: center;
  animation: fadeIn 0.4s ease-out;
  gap: 1.5rem;
}

.title-logo-box {
  margin-bottom: 0.5rem;
}

.title-emoji-float {
  font-size: 5rem;
  animation: floatBounce 2.5s ease-in-out infinite alternate;
  margin-bottom: 0.5rem;
}

.title-logo {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 3rem;
  color: var(--accent-gold);
  letter-spacing: -1px;
  text-shadow: 0 0 20px var(--accent-gold-glow);
}

.title-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 4px;
}

.title-stats-card {
  width: 100%;
  display: flex;
  gap: 12px;
  background: var(--bg-card-glass);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 16px;
}

.title-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title-stat .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.title-stat .stat-val {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.title-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.title-btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.title-btn.primary {
  background: var(--accent-gold);
  color: var(--text-primary);
  box-shadow: 0 4px 15px var(--accent-gold-glow);
}

.title-btn.primary:hover {
  background: var(--accent-gold-hover);
  transform: translateY(-2px);
}

.title-btn.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
}

.title-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-gold);
  transform: translateY(-2px);
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  height: 100vh;
  padding: 1rem;
  justify-content: space-between;
  animation: fadeIn 0.4s ease-out;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-glass);
}

.logo {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.logo:hover {
  opacity: 0.8;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.select-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  padding: 4px 10px;
  border-radius: 20px;
  color: var(--accent-gold);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.select-btn:hover {
  background: var(--accent-gold);
  color: var(--text-primary);
}

.chevron {
  font-size: 0.6rem;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.level-badge {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--accent-gold);
}

.timer-badge {
  font-family: monospace;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

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

.star-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(217, 119, 6, 0.15);
  border: 1px solid var(--border-glass);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-gold-glow);
}

/* Main Container & Breed Banner */
.game-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1rem 0;
}

.dog-breed-banner {
  background: var(--bg-card-glass);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  padding: 6px 16px;
  border-radius: 30px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dog-breed-banner strong {
  color: var(--accent-gold);
  font-weight: 600;
}

/* Game Grid */
.grid-outer-wrapper {
  width: 100%;
  max-width: min(90vw, 420px);
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border-radius: 16px;
  padding: 8px;
  border: 2px solid var(--border-glass);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  grid-template-rows: repeat(var(--grid-size), 1fr);
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--grid-border-color);
  gap: 1px;
}

/* Grid Cell */
.grid-cell {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.15s ease, filter 0.15s ease;
  aspect-ratio: 1 / 1;
}

.grid-cell:hover {
  filter: brightness(1.2);
}

/* Region Border Boundaries */
.grid-cell.b-t { border-top: 3px solid var(--region-border-color); }
.grid-cell.b-r { border-right: 3px solid var(--region-border-color); }
.grid-cell.b-b { border-bottom: 3px solid var(--region-border-color); }
.grid-cell.b-l { border-left: 3px solid var(--region-border-color); }

/* Cell Content - Emojis & Images */
.cell-emoji {
  font-size: min(6vw, 2.2rem);
  user-select: none;
  animation: scaleUp 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.cell-dog-image {
  width: min(8vw, 3rem);
  height: min(8vw, 3rem);
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  animation: scaleUp 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Error/Conflict Highlighting */
.grid-cell.conflict {
  animation: errorShake 0.4s ease-in-out;
  box-shadow: inset 0 0 10px rgba(239, 68, 68, 0.7);
}

/* Footer Controls */
.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-glass);
}

.footer-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.footer-btn:hover:not(:disabled) {
  border-color: var(--accent-gold);
  background: rgba(217, 119, 6, 0.05);
  transform: translateY(-2px);
}

.footer-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.footer-btn.danger:hover {
  border-color: var(--accent-red);
  background: rgba(239, 68, 68, 0.05);
}

.btn-icon {
  font-size: 1.2rem;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

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

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
}

.modal-content {
  position: relative;
  background: var(--bg-card-glass);
  border: 2px solid var(--border-glass);
  border-radius: 24px;
  width: 92%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.7);
  z-index: 1001;
  animation: modalEnter 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.1) forwards;
}

.modal-content.large {
  max-width: 500px;
}

.modal-header {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.4rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  text-align: center;
}

.modal-body {
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: center;
}

.modal-btn {
  padding: 10px 24px;
  border-radius: 12px;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.modal-btn.primary {
  background: var(--accent-gold);
  color: var(--text-primary);
}

.modal-btn.primary:hover {
  background: var(--accent-gold-hover);
  box-shadow: 0 4px 12px var(--accent-gold-glow);
}

.modal-btn.secondary {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-glass);
}

.modal-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.modal-btn.success {
  background: var(--accent-green);
  color: var(--text-primary);
  font-weight: 800;
}

.modal-btn.success:hover {
  background: var(--accent-green-hover);
  transform: scale(1.02);
}

/* Rules Styles */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.rule-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: rgba(255, 255, 255, 0.02);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.rule-num {
  background: rgba(217, 119, 6, 0.1);
  color: var(--accent-gold);
  font-weight: 800;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  font-size: 0.85rem;
  border: 1px solid var(--border-glass);
}

/* Level Select Header Summary & Jump Button */
.level-stats-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-glass);
  padding: 10px 14px;
  border-radius: 12px;
}

.summary-text {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.jump-btn {
  background: var(--accent-gold);
  border: none;
  border-radius: 10px;
  padding: 6px 12px;
  color: var(--text-primary);
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 4px 10px var(--accent-gold-glow);
  transition: all 0.2s ease;
}

.jump-btn:hover {
  background: var(--accent-gold-hover);
  transform: translateY(-1px);
}

/* Packs Selection Layout */
.packs-nav-header, .levels-nav-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-family: var(--font-title);
  font-weight: 800;
  color: var(--text-primary);
}

.nav-arrow {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  color: var(--accent-gold);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
}

.nav-arrow:hover:not(:disabled) {
  border-color: var(--accent-gold);
  background: rgba(217, 119, 6, 0.1);
}

.nav-arrow:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

.back-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  color: var(--accent-gold);
  padding: 4px 12px;
  border-radius: 8px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.back-btn:hover {
  background: rgba(217, 119, 6, 0.1);
  border-color: var(--accent-gold);
}

/* 4x5 grids for Level select & Pack select */
.packs-grid, .levels-grid-4x5 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
  max-height: 48vh;
  overflow-y: auto;
  padding-right: 4px;
}

/* Cards (High-Contrast Refinements) */
.pack-card, .level-card {
  aspect-ratio: 1 / 1;
  background: #2d2421; /* High-contrast solid dark brown */
  border: 1px solid var(--accent-gold); /* Solid bright gold border */
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  color: var(--text-primary);
}

.pack-card .num, .level-card .num {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-primary);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.pack-card .stars, .level-card .stars {
  font-size: 0.65rem;
  margin-top: 4px;
  color: var(--accent-gold);
  font-weight: 700;
}

.pack-card .label {
  font-size: 0.55rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 700;
}

/* Locked Card Style (High contrast dashed outline, visible lock) */
.pack-card.locked, .level-card.locked {
  background: #171312; /* Distinct solid black-gray background */
  border: 1px dashed #5a4b46; /* Clear dashed boundary border */
  opacity: 1; /* Fully visible, not faded */
  cursor: not-allowed;
}

.pack-card.locked .num, .level-card.locked .num {
  color: #7a6a63; /* Readable dark gray text */
}

.pack-card.locked .lock-icon, .level-card.locked .lock-icon {
  font-size: 1.1rem;
  margin-top: 2px;
  filter: drop-shadow(0 1px 1px black);
}

/* Active Highlight Style */
.pack-card.active, .level-card.active {
  background: rgba(217, 119, 6, 0.22);
  border: 2px solid var(--accent-gold);
  box-shadow: 0 0 10px var(--accent-gold-glow);
}

/* Card Hover Transformations */
.pack-card:not(.locked):hover, .level-card:not(.locked):hover {
  background: var(--accent-gold);
  color: #120f0e;
  border-color: #f5f0eb;
  transform: translateY(-3px);
  box-shadow: 0 6px 16px var(--accent-gold-glow);
}

.pack-card:not(.locked):hover .num, .level-card:not(.locked):hover .num {
  color: #120f0e;
  text-shadow: none;
}

.pack-card:not(.locked):hover .stars, .level-card:not(.locked):hover .stars {
  color: #120f0e;
}

.pack-card:not(.locked):hover .label, .level-card:not(.locked):hover .label {
  color: #3e332f;
}

/* Win Modal Specifics */
.win-content {
  text-align: center;
}

.win-emoji-burst {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: celebrate 1s ease-in-out infinite alternate;
}

.win-subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
}

.win-stars-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 1rem 0;
}

.win-stars-display .star {
  font-size: 2.5rem;
  filter: grayscale(1);
  transform: scale(0.8);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.win-stars-display .star.earned {
  filter: grayscale(0);
  transform: scale(1.1);
  text-shadow: 0 0 15px var(--accent-gold);
}

.win-stats-container {
  display: flex;
  justify-content: space-around;
  gap: 12px;
  margin-bottom: 1rem;
}

.win-stat-card {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.win-stat-card .stat-title {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.win-stat-card .stat-value {
  font-family: monospace;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--accent-gold);
}

/* Trivia Card */
.trivia-card {
  background: rgba(217, 119, 6, 0.05);
  border: 1px solid var(--border-glass);
  padding: 12px;
  border-radius: 12px;
  text-align: left;
  margin-top: 0.5rem;
}

.trivia-header {
  font-family: var(--font-title);
  font-weight: 800;
  color: var(--accent-gold);
  font-size: 0.85rem;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.trivia-text {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.large-btn {
  width: 100%;
}

/* Animations */
@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes floatBounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-10px) scale(1.05); }
}

@keyframes scaleUp {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes modalEnter {
  0% { transform: scale(0.9) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes celebrate {
  0% { transform: translateY(0) rotate(-5deg); }
  100% { transform: translateY(-8px) rotate(5deg); }
}

.animate-star {
  display: inline-block;
}

.star.earned:nth-child(1) { animation: starPop 0.4s ease-out 0.1s both; }
.star.earned:nth-child(2) { animation: starPop 0.4s ease-out 0.3s both; }
.star.earned:nth-child(3) { animation: starPop 0.4s ease-out 0.5s both; }

@keyframes starPop {
  0% { transform: scale(0); filter: grayscale(1); }
  70% { transform: scale(1.3); }
  100% { transform: scale(1.1); filter: grayscale(0); }
}

/* Custom Scrollbars */
.packs-grid::-webkit-scrollbar,
.levels-grid-4x5::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
  width: 6px;
}

.packs-grid::-webkit-scrollbar-track,
.levels-grid-4x5::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.packs-grid::-webkit-scrollbar-thumb,
.levels-grid-4x5::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
  background: var(--border-glass);
  border-radius: 4px;
}

.packs-grid::-webkit-scrollbar-thumb:hover,
.levels-grid-4x5::-webkit-scrollbar-thumb:hover,
.modal-content::-webkit-scrollbar-thumb:hover {
  background: var(--accent-gold);
}

/* Responsive Scaling for Grid */
@media (max-width: 400px) {
  .app-container {
    padding: 0.5rem;
  }
  .logo {
    font-size: 1.2rem;
  }
  .select-btn {
    padding: 2px 8px;
    font-size: 0.75rem;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 1rem;
  }
  .footer-btn {
    padding: 6px 0;
  }
  .btn-icon {
    font-size: 1rem;
  }
  .win-emoji-burst {
    font-size: 2.2rem;
  }
  .packs-grid, .levels-grid-4x5 {
    grid-template-columns: repeat(3, 1fr);
  }
}
