@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800;900&family=Press+Start+2P&display=swap');

:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #311042 100%);
  --accent-pink: #ec4899;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-cyan: #06b6d4;
  --accent-violet: #8b5cf6;
  --card-bg: rgba(30, 41, 59, 0.85);
  --card-border: rgba(255, 255, 255, 0.18);
  --glass-glow: 0 12px 40px 0 rgba(236, 72, 153, 0.3);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* Header Navigation */
header {
  width: 100%;
  padding: 1.2rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-badge {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.25rem;
  background: linear-gradient(90deg, #ec4899, #f59e0b, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 16px rgba(236, 72, 153, 0.5);
  animation: logoGlow 3s infinite alternate;
}

@keyframes logoGlow {
  0% { filter: drop-shadow(0 0 4px #ec4899); }
  100% { filter: drop-shadow(0 0 12px #38bdf8); }
}

.jubilee-badge {
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid #f59e0b;
  color: #fbbf24;
  font-weight: 800;
  padding: 0.3rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.4);
}

nav {
  display: flex;
  gap: 1rem;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.6rem 1.2rem;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn:hover, .nav-btn.active {
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-violet));
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4);
  transform: translateY(-2px);
}

/* Main Container */
main {
  width: 100%;
  max-width: 1200px;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

/* Game Wrapper & HUD */
.game-container {
  width: 100%;
  max-width: 980px;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 24px;
  box-shadow: var(--glass-glow);
  backdrop-filter: blur(20px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.game-hud {
  padding: 1rem 1.5rem;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.1rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.4rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hud-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-value {
  color: #fbbf24;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.9rem;
}

canvas#gameCanvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 960 / 520;
  object-fit: contain;
  background: #0f172a;
  display: block;
  touch-action: none;
}

/* Mobile Touch D-Pad Controls */
.mobile-controls-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid var(--card-border);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dpad-group, .action-group {
  display: flex;
  gap: 0.75rem;
}

.touch-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-weight: 800;
  border-radius: 16px;
  padding: 0.75rem 1.25rem;
  font-size: 1.1rem;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-btn:active, .touch-btn.active {
  background: linear-gradient(135deg, #ec4899, #f59e0b);
  border-color: #fbbf24;
  transform: scale(0.94);
}

.dpad-btn {
  width: 54px;
  height: 54px;
  font-size: 1.4rem;
  padding: 0;
}

.action-btn.jump-btn {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #38bdf8;
}

.action-btn.hug-btn {
  background: rgba(74, 222, 128, 0.25);
  border-color: #4ade80;
  color: #4ade80;
}

/* Controls Info Bar */
.controls-bar {
  padding: 1rem 1.5rem;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  justify-content: space-around;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  border-top: 1px solid var(--card-border);
}

.key-badge {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  color: #fff;
  font-family: monospace;
  font-weight: bold;
}

/* Puzzle Gallery Section */
.puzzle-section {
  width: 100%;
  max-width: 980px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.puzzle-section.active {
  display: flex;
}

.section-title {
  font-size: 2.2rem;
  font-weight: 900;
  background: linear-gradient(90deg, #38bdf8, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  width: 100%;
}

.puzzle-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.puzzle-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
}

/* BLURRED MYSTERY PUZZLE THUMBNAIL (Revealed ONLY after assembly!) */
.puzzle-thumbnail {
  width: 100%;
  height: 200px;
  border-radius: 14px;
  background: #1e293b;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: filter 0.5s ease, transform 0.5s ease;
}

.puzzle-thumbnail.unsolved {
  filter: blur(14px) grayscale(0.6) opacity(0.5);
}

.puzzle-thumbnail.solved {
  filter: none !important;
  border-color: #10b981;
}

/* Interactive NxN Tile Puzzle Modal Overlay */
.puzzle-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 24px;
  padding: 2rem;
  max-width: 560px;
  width: 95%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  box-shadow: var(--glass-glow);
  position: relative;
}

.close-modal {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.close-modal:hover {
  background: #ef4444;
  border-color: #ef4444;
}

.puzzle-board {
  display: grid;
  gap: 0px !important;
  padding: 0px !important;
  margin: 0 auto;
  line-height: 0;
  background: #0f172a;
  border-radius: 14px;
  border: 3px solid var(--card-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transition: border-color 0.5s ease, box-shadow 0.5s ease;
}

.puzzle-board.completed {
  border-color: #10b981 !important;
  box-shadow: 0 0 40px #10b981 !important;
  animation: puzzleSuccessPulse 1.5s infinite alternate;
}

@keyframes puzzleSuccessPulse {
  0% { box-shadow: 0 0 20px #10b981; }
  100% { box-shadow: 0 0 50px #fbbf24; }
}

.puzzle-tile-wrapper {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  margin: 0 !important;
  padding: 0 !important;
  display: block;
  line-height: 0;
  border: none !important;
  overflow: hidden;
  transition: transform 0.15s ease, filter 0.15s ease, outline 0.15s ease;
}

.puzzle-tile-wrapper:active {
  cursor: grabbing;
}

.puzzle-tile-wrapper canvas {
  display: block;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.puzzle-tile-wrapper:hover {
  filter: brightness(1.25);
}

.puzzle-tile-wrapper.selected {
  outline: 3px solid #ec4899;
  z-index: 10;
  box-shadow: 0 0 16px #ec4899;
  transform: scale(1.04);
}

.puzzle-tile-wrapper.dragging {
  opacity: 0.5;
  transform: scale(0.92);
}

.puzzle-tile-wrapper.drag-over {
  outline: 3px solid #f59e0b !important;
  box-shadow: 0 0 20px #f59e0b !important;
  z-index: 12;
  transform: scale(1.06);
}

/* Celebration Confetti Canvas inside Modal */
#puzzleConfettiCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* Interactive Family Map Section */
.family-map-section {
  width: 100%;
  max-width: 980px;
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.2rem;
}

.family-map-section.active {
  display: grid;
}

.member-card {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.member-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent-pink);
}

.member-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 3px solid var(--accent-pink);
  object-fit: cover;
  box-shadow: 0 0 20px rgba(236, 72, 153, 0.4);
  cursor: pointer;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.member-avatar:hover {
  transform: scale(1.1) rotate(5deg);
  border-color: #f59e0b;
}

.member-location {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  color: var(--accent-amber);
}

footer {
  margin-top: 3rem;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

#puzzleSection,
#familySection {
  display: none;
  width: 100%;
}

.family-section {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.5rem;
  width: 100%;
  margin: 2rem 0;
}

.family-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  box-sizing: border-box;
}

.family-card:hover {
  transform: translateY(-6px);
  border-color: #ec4899;
  box-shadow: 0 10px 30px rgba(236, 72, 153, 0.25);
}

.family-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid #f59e0b;
  object-fit: cover;
  background: #1e1b4b;
}

.family-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: #f8fafc;
}

.family-flag {
  font-size: 0.85rem;
  color: #38bdf8;
  font-weight: 600;
}

.family-desc {
  font-size: 0.8rem;
  color: #94a3b8;
}
