/* =========================================================
   MUNCHI MEMORY GAME - MODERN ARCADE DESIGN SYSTEM
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Outfit:wght@400;600;700;800;900&display=swap');

:root {
  --primary-gold: #fecb00;
  --gold-glow: #ffdf00;
  --munchee-red: #e61c24;
  --munchee-dark-red: #a40e14;
  --munchee-crimson: #700609;
  --biscuit-amber: #d97706;
  --biscuit-light: #fffbeb;
  --text-dark: #1e293b;
  --text-light: #ffffff;
  --card-bg-back: linear-gradient(145deg, #ff6b1a 0%, #e61c24 50%, #a40e14 100%);
  --card-border: #fecb00;
  --glass-bg: rgba(20, 10, 5, 0.52);
  --glass-border: rgba(255, 255, 255, 0.28);
  --glass-highlight: rgba(255, 235, 59, 0.35);
  --shadow-main: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 8px 20px rgba(0, 0, 0, 0.3);
  --shadow-card-hover: 0 14px 28px rgba(230, 28, 36, 0.4), 0 0 20px rgba(254, 203, 0, 0.5);
  --radius-card: 16px;
  --radius-ui: 14px;
  --radius-pill: 9999px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Outfit', sans-serif;
  background-color: #fdb102;
}

/* App Container with background.png */
.app-container {
  width: 100vw;
  height: 100vh;
  background-image: url('../background.png?v=12.0');
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  position: relative;
  overflow: hidden;
  padding: 10px 20px 14px 20px;
}

/* Header & HUD Section: Positioned at TOP-RIGHT and enlarged */
.game-header {
  position: absolute;
  top: 16px;
  right: 24px;
  width: auto;
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  z-index: 20;
}

/* Modern Glass HUD Bar - Enlarged & Placed at Top-Right */
.hud-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  background: rgba(10, 5, 2, 0.45);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1.8px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.4);
  padding: 8px 20px;
  border-radius: var(--radius-pill);
  animation: slideDown 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-pill);
  color: var(--text-light);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.hud-pill:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: translateY(-1px);
}

.hud-icon {
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-gold);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.hud-icon svg {
  width: 22px;
  height: 22px;
}

.hud-content {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.hud-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 2px;
}

.hud-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

.hud-value.highlight {
  color: var(--primary-gold);
}

.timer-pill.urgent .hud-value {
  color: #ff3344;
  animation: pulseTimer 0.8s infinite alternate;
}

/* No spacer needed since header is positioned at top-right */
.branding-view-zone {
  display: none;
}

/* Main Playing Area - Positioned cleanly lower so top Tamil wording is fully visible */
.game-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  transform: translateY(38px);
  z-index: 10;
}

/* 12 Cards Deck Grid: 4 columns x 3 rows - Centered & Prominent */
.deck {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 16px;
  width: 86vw;
  max-width: 1200px;
  height: clamp(420px, 58vh, 540px);
  max-height: 540px;
  padding: 18px;
  background: rgba(10, 5, 2, 0.45);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 1px 2px rgba(255, 255, 255, 0.35);
  list-style: none;
  perspective: 1000px;
}

/* 3D Flip Card */
.card {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  perspective: 1000px;
  outline: none;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.card:hover .card-inner {
  transform: translateY(-4px) scale(1.025);
  box-shadow: var(--shadow-card-hover);
}

.card.open .card-inner,
.card.show .card-inner,
.card.match .card-inner {
  transform: rotateY(180deg) translateY(0);
}

/* Face Down Side (Card Back - NO LOGO) */
.card-front-face {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--radius-card);
  background: var(--card-bg-back);
  border: 3px solid var(--card-border);
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.45), inset 0 -4px 8px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Custom Embossed Biscuit/Mystery Pattern - NO LOGO */
.card-front-face::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  border: 2px dashed rgba(254, 203, 0, 0.65);
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.18) 0%, transparent 70%);
  pointer-events: none;
}

.card-front-face::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(45deg,
      rgba(255, 255, 255, 0.05) 0px,
      rgba(255, 255, 255, 0.05) 6px,
      transparent 6px,
      transparent 12px);
  pointer-events: none;
}

.card-mystery-badge {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7cc 0%, #fee700 60%, #e59e00 100%);
  border: 3px solid #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 2px 4px rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease;
}

.card:hover .card-mystery-badge {
  transform: scale(1.12) rotate(6deg);
}

.card-mystery-badge span {
  font-family: 'Fredoka', cursive, sans-serif;
  font-size: 36px;
  font-weight: 700;
  color: var(--munchee-red);
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8), 0 2px 4px rgba(164, 14, 20, 0.4);
  line-height: 1;
}

/* Face Up Side (Card Face with revealed Item) */
.card-back-face {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  border-radius: var(--radius-card);
  background: radial-gradient(circle at 50% 50%, #ffffff 0%, #fff7ed 70%, #fef3c7 100%);
  border: 3px solid #fecb00;
  box-shadow: inset 0 2px 8px rgba(255, 255, 255, 0.95), inset 0 -2px 6px rgba(0, 0, 0, 0.12);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  overflow: hidden;
}

.card-back-face img {
  max-width: 92%;
  max-height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.25));
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.card.show .card-back-face img {
  transform: scale(1.06);
}

/* Matched Card Style */
.card.match .card-inner {
  animation: matchBounce 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.card.match .card-back-face {
  border: 3px solid #22c55e;
  background: radial-gradient(circle at 50% 50%, #ffffff 0%, #f0fdf4 70%, #dcfce7 100%);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.7), inset 0 0 10px rgba(34, 197, 94, 0.25);
}

.card.match .card-back-face::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 8px;
  background: #22c55e;
  color: #fff;
  font-family: 'Fredoka', sans-serif;
  font-size: 14px;
  font-weight: bold;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Unmatched Shake */
.card.unmatch .card-inner {
  animation: shakeCard 0.5s ease-in-out;
}

.card.unmatch .card-back-face {
  border: 3px solid #ef4444;
}

/* Footer / Controls Bar: Positioned at BOTTOM-LEFT */
.game-footer {
  position: absolute;
  bottom: 20px;
  left: 24px;
  width: auto;
  max-width: none;
  padding: 0;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 14px;
  z-index: 20;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 28px;
  font-family: 'Fredoka', sans-serif;
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
  background: linear-gradient(135deg, #e61c24 0%, #a40e14 100%);
  border: 2.5px solid var(--primary-gold);
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(164, 14, 20, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.5);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  outline: none;
}

.action-btn:hover {
  background: linear-gradient(135deg, #fecb00 0%, #f59e0b 100%);
  color: var(--munchee-dark-red);
  border-color: #ffffff;
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 28px rgba(254, 203, 0, 0.55), 0 0 18px rgba(254, 203, 0, 0.45);
}

.action-btn:active {
  transform: translateY(1px) scale(0.98);
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(10, 5, 2, 0.45);
  backdrop-filter: blur(14px);
  border: 2px solid var(--glass-border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-main);
  transition: all 0.2s ease;
  outline: none;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  color: var(--primary-gold);
  transform: scale(1.08);
}

/* =========================================================
   OVERLAYS & MODALS (Victory & Timeout)
   ========================================================= */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 4, 2, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.4s ease;
}

.overlay-modal {
  background: linear-gradient(165deg, #b91c1c 0%, #7f1d1d 60%, #450a0a 100%);
  border: 3px solid var(--primary-gold);
  border-radius: 28px;
  padding: 36px 44px;
  text-align: center;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(254, 203, 0, 0.35);
  color: #ffffff;
  position: relative;
  overflow: hidden;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay-modal::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(254, 203, 0, 0.15) 0%, transparent 60%);
  pointer-events: none;
  animation: rotateGlow 20s linear infinite;
}

.overlay-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 38px;
  font-weight: 700;
  color: var(--primary-gold);
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), 0 0 20px rgba(254, 203, 0, 0.4);
  margin-bottom: 8px;
  line-height: 1.1;
}

.overlay-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 20px 0 26px 0;
}

.stat-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.8);
}

.stat-number {
  font-family: 'Fredoka', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  margin-top: 2px;
}

.stat-number.gold {
  color: var(--primary-gold);
}

.tryAgain {
  width: 100%;
  padding: 14px;
  font-family: 'Fredoka', sans-serif;
  font-size: 22px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--munchee-dark-red);
  background: linear-gradient(135deg, #fff7cc 0%, #fecb00 50%, #f59e0b 100%);
  border: 2px solid #ffffff;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4), 0 0 20px rgba(254, 203, 0, 0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
  outline: none;
}

.tryAgain:hover {
  transform: scale(1.04);
  box-shadow: 0 14px 32px rgba(254, 203, 0, 0.7);
  background: #ffffff;
}

/* =========================================================
   START SCREEN OVERLAY
   ========================================================= */

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url('../background.png?v=16.0');
  background-size: 100% 100%;
  background-position: center center;
  background-repeat: no-repeat;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-card {
  background: rgba(10, 5, 2, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2.5px solid rgba(254, 203, 0, 0.45);
  border-radius: 30px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 35px rgba(254, 203, 0, 0.25);
  padding: 40px 48px;
  text-align: center;
  max-width: 520px;
  width: 90%;
  transform: translateY(40px);
  animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.start-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 22px;
  border-radius: var(--radius-pill);
  background: rgba(254, 203, 0, 0.16);
  border: 1.8px solid var(--primary-gold);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  margin-bottom: 20px;
}

.start-badge-icon {
  font-size: 22px;
}

.start-badge-text {
  font-family: 'Fredoka', sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.03em;
}

.start-badge-text strong {
  color: var(--primary-gold);
  font-size: 24px;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(254, 203, 0, 0.6);
}

.start-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 38px;
  font-weight: 700;
  color: var(--primary-gold);
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.6), 0 0 25px rgba(254, 203, 0, 0.4);
  line-height: 1.1;
  margin-bottom: 12px;
}

.start-subtitle {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 28px;
  line-height: 1.45;
}

.start-btn {
  font-size: 22px;
  padding: 14px 44px;
  letter-spacing: 0.06em;
  animation: pulseStart 2s infinite alternate;
}

@keyframes pulseStart {
  0% {
    box-shadow: 0 8px 22px rgba(164, 14, 20, 0.5), 0 0 10px rgba(254, 203, 0, 0.3);
    transform: scale(1);
  }
  100% {
    box-shadow: 0 14px 34px rgba(254, 203, 0, 0.65), 0 0 25px rgba(254, 203, 0, 0.5);
    transform: scale(1.04);
  }
}

/* Settings Modal (F2) */
.settings-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.settings-content {
  background: #1e1b18;
  border: 2px solid var(--primary-gold);
  border-radius: 20px;
  padding: 24px 28px;
  width: 100%;
  max-width: 400px;
  color: #ffffff;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  position: relative;
}

.settings-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 26px;
  color: #aaa;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s ease;
}

.settings-close:hover {
  color: #fff;
}

.settings-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 22px;
  color: var(--primary-gold);
  margin-bottom: 14px;
}

.settings-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px;
  font-family: 'Outfit', sans-serif;
  font-weight: bold;
  border-radius: 8px;
  border: 1.5px solid #444;
  background: #2a2724;
  color: #fff;
  margin: 10px 0 18px 0;
  outline: none;
}

.settings-input:focus {
  border-color: var(--primary-gold);
  box-shadow: 0 0 10px rgba(254, 203, 0, 0.4);
}

.settings-save-btn {
  width: 100%;
  padding: 10px;
  font-family: 'Fredoka', sans-serif;
  font-size: 16px;
  font-weight: 600;
  background: var(--primary-gold);
  color: var(--munchee-dark-red);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.settings-save-btn:hover {
  background: #ffffff;
  transform: translateY(-2px);
}

/* =========================================================
   ANIMATIONS & KEYFRAMES
   ========================================================= */

@keyframes matchBounce {
  0% {
    transform: rotateY(180deg) scale(1);
  }

  40% {
    transform: rotateY(180deg) scale(1.15);
  }

  100% {
    transform: rotateY(180deg) scale(1);
  }
}

@keyframes shakeCard {

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

  20%,
  60% {
    transform: rotateY(180deg) translateX(-6px);
  }

  40%,
  80% {
    transform: rotateY(180deg) translateX(6px);
  }
}

@keyframes popIn {
  0% {
    transform: scale(0.7) translateY(40px);
    opacity: 0;
  }

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

@keyframes slideDown {
  0% {
    transform: translateY(-30px);
    opacity: 0;
  }

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

@keyframes fadeIn {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

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

  60% {
    transform: scale(1.3);
  }

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

@keyframes pulseTimer {
  0% {
    transform: scale(1);
  }

  100% {
    transform: scale(1.1);
  }
}

@keyframes rotateGlow {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* =========================================================
   RESPONSIVE LAYOUT
   ========================================================= */

@media screen and (max-height: 800px) {
  .deck {
    height: clamp(400px, 66vh, 520px);
    max-height: 520px;
    padding: 14px;
    gap: 12px;
  }

  .card-mystery-badge {
    width: 48px;
    height: 48px;
  }

  .card-mystery-badge span {
    font-size: 28px;
  }

  .hud-bar {
    padding: 6px 14px;
    gap: 10px;
  }

  .hud-pill {
    padding: 4px 10px;
  }

  .hud-value {
    font-size: 20px;
  }
}

@media screen and (max-width: 900px) {
  .game-header {
    position: relative;
    top: 0;
    right: 0;
    align-items: center;
    margin-bottom: 10px;
  }

  .hud-bar {
    justify-content: center;
  }

  .game-footer {
    position: relative;
    bottom: 0;
    left: 0;
    justify-content: center;
    margin-top: 10px;
  }

  .deck {
    width: 96vw;
    max-width: 600px;
    height: auto;
    max-height: none;
    gap: 10px;
    padding: 12px;
  }
}