/* ===========================================================
   Sar Yee's 62nd Birthday Memory Match
   Bright & fun palette tuned to harmonize with the burgundy /
   gold / blush tones in happycarol.png & sadcarol.png.
   Mobile-portrait first.
=========================================================== */

:root {
  --cream: #FFF7EC;
  --pink-soft: #FFD6E6;
  --pink: #FF5C93;
  --gold: #FFB627;
  --gold-deep: #E8960C;
  --coral: #FF7A59;
  --plum: #6E1E3A;
  --plum-deep: #4A1226;
  --urgent: #FF3B3B;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  background: linear-gradient(160deg, #FFEDD8 0%, #FFD9E8 55%, #FFE3B0 100%);
  color: var(--plum);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  gap: 8px;
  overflow: hidden;
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.carol-frame {
  flex: 0 0 auto;
  width: 25vw;
  max-width: 108px;
  min-width: 76px;
  height: 34vw;
  max-height: 148px;
  min-height: 104px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 10px rgba(110, 30, 58, 0.25);
  background: var(--pink-soft);
}

.carol-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: opacity .15s ease;
}

.carol-img.pulse { animation: carolPulse .6s ease; }
.carol-img.shake { animation: carolShake .5s ease; }

@keyframes carolPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes carolShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px) rotate(-1deg); }
  40% { transform: translateX(4px) rotate(1deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(3px) rotate(1deg); }
}

.title-block {
  flex: 1 1 auto;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--pink);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.15rem, 5.6vw, 1.55rem);
  font-weight: 800;
  line-height: 1.05;
  color: var(--plum);
  text-shadow: 0 2px 0 rgba(255,255,255,.5);
}

.timer-pill {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold), var(--gold-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--plum-deep);
  box-shadow: 0 4px 10px rgba(232, 150, 12, .45), inset 0 -3px 0 rgba(0,0,0,.08);
  border: 2px solid #fff;
}

.timer-pill.urgent {
  background: radial-gradient(circle at 35% 30%, #FF6B6B, var(--urgent));
  color: #fff;
  animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ---------- Info bar ---------- */

.info-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
}

.pairs-badge {
  background: #fff;
  color: var(--plum);
  font-weight: 700;
  font-size: .85rem;
  padding: 5px 14px;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(110,30,58,.15);
}

.pairs-badge strong {
  color: var(--pink);
  font-size: .95rem;
}

/* ---------- Board ---------- */

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: clamp(4px, 1.6vw, 8px);
  margin: auto;
}

.card {
  position: relative;
  perspective: 700px;
  touch-action: manipulation;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .45s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}

.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  backface-visibility: hidden;
  font-size: clamp(1.15rem, 6.2vw, 1.8rem);
}

.card-back {
  background: linear-gradient(135deg, var(--gold), var(--coral));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 2px 4px rgba(110,30,58,.2);
}

.card-front {
  background: var(--cream);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 2px rgba(110,30,58,.08);
}

.card.matched .card-front {
  background: linear-gradient(135deg, #FFE8B0, #FFD68A);
  box-shadow: inset 0 0 0 2px var(--gold-deep), 0 0 10px rgba(255,182,39,.6);
}

.card.matched { cursor: default; }

.card.wrong .card-front {
  box-shadow: inset 0 0 0 2px var(--urgent);
}

/* Bonus center tile */
.card.bonus {
  cursor: default;
  border-radius: var(--radius-sm);
  background: radial-gradient(circle, #8A2E52, var(--plum-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(255,182,39,.7);
  animation: bonusGlow 2.4s ease-in-out infinite;
}

.bonus-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: clamp(1rem, 5.6vw, 1.6rem);
  color: var(--gold);
}

.bonus-num {
  font-size: .55em;
  font-weight: 800;
  color: #fff;
  margin-top: 2px;
}

@keyframes bonusGlow {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 10px rgba(255,182,39,.5); }
  50% { box-shadow: 0 0 0 2px var(--gold), 0 0 20px rgba(255,182,39,.95); }
}

/* ---------- Overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 18, 38, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
  transition: opacity .25s ease;
}

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

.overlay-card {
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: 22px 22px 26px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  border: 4px solid var(--gold);
}

.overlay-img {
  width: 150px;
  height: 200px;
  object-fit: cover;
  object-position: top center;
  border-radius: var(--radius-md);
  border: 3px solid var(--gold);
  box-shadow: 0 4px 10px rgba(110,30,58,.3);
  margin-bottom: 14px;
}

.overlay-message {
  white-space: pre-line;
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.35;
  color: var(--plum);
  margin: 0 0 18px;
}

.play-again-btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--plum-deep);
  background: linear-gradient(135deg, var(--gold), var(--coral));
  border: none;
  padding: 12px 28px;
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--gold-deep), 0 8px 16px rgba(0,0,0,.2);
  cursor: pointer;
}

.play-again-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--gold-deep), 0 4px 8px rgba(0,0,0,.2);
}

/* ---------- Confetti ---------- */

.confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 25;
}

.confetti-piece {
  position: absolute;
  top: -40px;
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: .9; }
}

/* ---------- Small screens ---------- */

@media (max-width: 340px) {
  h1 { font-size: 1.05rem; }
  .timer-pill { width: 50px; height: 50px; font-size: 1.2rem; }
}
