@font-face {
  font-family: 'TheClouds';
  src: url('Fonts/Theclouds.otf') format('opentype');
}

@font-face {
  font-family: 'LittleDreams';
  src: url('Fonts/Littledreams-Regular.otf') format('opentype');
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #fdf8ee;
  color: #3d2b00;
  font-family: Arial, sans-serif;
  text-align: center;
  overflow-x: hidden;
}

/* ===== INTRO ===== */
#intro-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 40px 40px 40px 160px;
  animation: introFadeOut 0.6s ease 2.8s forwards;
}

#intro-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: floatBob 2.5s ease-in-out 1s infinite;
}

#intro-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 70px;
}

#intro-left {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  animation: slideInLeft 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.2s forwards;
}

#intro-char {
  height: 300px;
  width: 300px;
  object-fit: contain;
}

#intro-right {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  animation: slideInRight 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.4s forwards;
}

#intro-title {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 4.5rem;
  color: #fdf8ee;
  -webkit-text-stroke: 2px #3d2b00;
  line-height: 1.1;
  max-width: 420px;
  text-align: left;
}

#intro-click-hint {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 3.2rem;
  color: #3d2b00;
  opacity: 0;
  text-align: center;
  margin-left: -80px;
  animation: slideInLeft 0.7s cubic-bezier(0.22, 1, 0.36, 1) 0.6s forwards;
}

/* ===== GAME ===== */
#game {
  padding: 12px 20px;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#game.hidden {
  display: none;
}

#game.visible {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

h1 {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 3.5rem;
  margin-bottom: 6px;
  letter-spacing: 2px;
  color: #fdf8ee;
  -webkit-text-stroke: 0.8px #3d2b00;
}

#status {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 3.5rem;
  margin-bottom: 2px;
  color: #3d2b00;
  min-height: 1.5em;
}

#level-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 2px;
  min-height: 28px;
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: #c8bfa8;
  transition: background-color 0.3s ease;
}

.dot.active {
  background-color: #3d2b00;
}

.dot.complete {
  background-color: #4ecca3;
}

#stats {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 3.5rem;
  margin-bottom: 16px;
  color: #3d2b00;
  display: flex;
  justify-content: center;
  gap: 40px;
}

#countdown {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 4rem;
  color: #fdf8ee;
  height: 80px;
  line-height: 88px;
  margin-top: -8px;
  margin-bottom: 8px;
  -webkit-text-stroke: 1.5px #3d2b00;
}

#countdown.pulse {
  animation: countdownPulse 0.6s ease forwards;
}

#level-splash {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 3.5rem;
  color: #fdf8ee;
  -webkit-text-stroke: 2px #3d2b00;
  letter-spacing: 2px;
  height: 60px;
  line-height: 60px;
  margin: 2px 0;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  display: none;
}

#level-splash.show {
  opacity: 1;
  transform: scale(1);
}

#level-splash.hide {
  opacity: 0;
  transform: scale(1.2);
}

/* ===== SCORECARD ===== */
#scorecard-wrap {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
}

#scorecard {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  background-color: #fdf8ee;
  border: 3px solid #3d2b00;
  border-radius: 16px;
  overflow: hidden;
  width: 420px;
  box-shadow: 6px 6px 0px #3d2b00;
}

#scorecard-img {
  width: 180px;
  height: 240px;
  object-fit: fill;
  object-position: center;
  flex-shrink: 0;
  border-right: 3px solid #3d2b00;
  image-rendering: auto;
}

#scorecard-info {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 16px;
  flex: 1;
  text-align: right;
}

#scorecard-top {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#scorecard-time {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 3.4rem;
  color: #fdf8ee;
  -webkit-text-stroke: 2px #3d2b00;
  line-height: 1;
}

#scorecard-message {
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 1.3rem;
  color: #3d2b00;
  line-height: 1.2;
}

#scorecard-sub {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 1.2rem;
  color: #3d2b00;
  opacity: 0.8;
  line-height: 1.4;
}

#scorecard-brand {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

#scorecard-favicon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: auto;
}

#scorecard-game-title {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 1.1rem;
  color: #3d2b00;
  opacity: 0.5;
  margin-top: 2px;
}

#download-btn {
  display: block;
  margin: 0 auto;
  padding: 8px 30px;
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 1.5rem;
  color: #fdf8ee;
  background-color: #4ecca3;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 2px;
}

#download-btn:hover {
  background-color: #3ab88e;
}

#win-title {
  display: none;
}

#win-stats {
  display: none;
}

#board {
  display: grid;
  grid-template-columns: repeat(4, 160px);
  gap: 16px;
  justify-content: center;
  margin-top: 8px;
  transition: opacity 0.6s ease;
}

#board.fade-out {
  opacity: 0;
  pointer-events: none;
}

.card {
  width: 160px;
  height: 160px;
  perspective: 600px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.card:not(.flipped):not(.matched):hover {
  transform: translateY(-6px) scale(1.04);
}

.card.flipped,
.card.matched,
.card.wrong {
  transform: none !important;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.card.matched .card-inner {
  transform: rotateY(180deg) !important;
}

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

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-front {
  transform: rotateY(180deg);
  overflow: hidden;
  border-radius: 8px;
  background-color: #fdf8ee;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.card-front img {
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 8px;
  display: block;
  flex-shrink: 0;
}

.card-back {
  border: 3px solid #3d2b00;
  background-image: url('Images/CardBack.png');
  background-size: cover;
  background-position: center;
  border-radius: 8px;
}

.card.matched .card-back,
.card.matched .card-front {
  border: 3px solid #4ecca3;
  box-shadow: 0 0 12px #4ecca3;
  padding: 0;
  margin: 0;
}

.card.matched .card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 5px; /* Slightly smaller to account for border */
}

.card.matched {
  animation: matchBounce 0.4s ease forwards;
}

.card.matched .card-inner {
  transform: rotateY(180deg) !important;
}

.card.wrong .card-back,
.card.wrong .card-front {
  border: 3px solid #ff4444;
  box-shadow: 0 0 12px #ff4444;
  padding: 0;
  margin: 0;
}

.card.wrong .card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  border-radius: 5px; /* Slightly smaller to account for border */
}

button {
  display: block;
  margin: 4px auto 6px auto;
  padding: 8px 30px;
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 1.5rem;
  color: #fdf8ee;
  background-color: #3d2b00;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 2px;
}

button:hover {
  background-color: #5a3f00;
}

#audio-controls {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#audio-controls.visible {
  opacity: 1;
}

#radio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

#skip-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  margin-top: -22px;
  margin-left: 48px;
  width: auto;
}

#skip-prev,
#skip-next {
  background: none;
  border: none;
  color: #3d2b00;
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
  line-height: 1;
}

#play-pause-btn {
  background: none;
  border: none;
  color: #3d2b00;
  font-family: 'TheClouds', Arial, sans-serif;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s ease;
  line-height: 1;
  min-width: 1.1rem;
  min-height: 1.1rem;
}

#play-pause-btn.play-icon {
  font-size: 0.9rem;
}

#skip-prev:hover,
#skip-next:hover,
#play-pause-btn:hover {
  color: #5a3f00;
  transform: scale(1.15);
}

#skip-prev:active,
#skip-next:active,
#play-pause-btn:active {
  transform: scale(0.95);
}

#sfx-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#sfx-label {
  font-family: 'LittleDreams', Arial, sans-serif;
  font-size: 1.8rem;
  color: #3d2b00;
}

#sfx-toggle {
  position: relative;
  width: 50px;
  height: 26px;
  background-color: #c8bfa8;
  border: 2px solid #3d2b00;
  border-radius: 13px;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.3s ease;
  outline: none;
}

#sfx-toggle.sfx-on {
  background-color: #3d2b00;
}

#sfx-toggle.sfx-off {
  background-color: #c8bfa8;
}

#sfx-toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background-color: #fdf8ee;
  border-radius: 50%;
  transition: transform 0.3s ease;
  border: 1px solid #3d2b00;
}

#sfx-toggle.sfx-on #sfx-toggle-slider {
  transform: translateX(24px);
}

#sfx-toggle.sfx-off #sfx-toggle-slider {
  transform: translateX(0);
}

#radio-icon {
  width: 40px;
  height: 40px;
  display: block;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.2s ease;
}

#radio-icon:hover {
  transform: scale(1.1);
}

#volume-slider {
  width: 100px;
  height: 6px;
  border-radius: 3px;
  background: #c8bfa8;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3d2b00;
  cursor: pointer;
  border: 2px solid #fdf8ee;
}

#volume-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3d2b00;
  cursor: pointer;
  border: 2px solid #fdf8ee;
}

#play-again {
  display: block;
  margin-top: 0;
  opacity: 1;
}

/* Confetti */
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: confettiFall linear forwards;
  pointer-events: none;
  z-index: 999;
}

/* ===== KEYFRAMES ===== */
@keyframes floatBob {
  0%   { transform: translateY(0px); }
  50%  { transform: translateY(-18px); }
  100% { transform: translateY(0px); }
}

@keyframes slideInLeft {
  0%   { opacity: 0; transform: translateX(-60px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  0%   { opacity: 0; transform: translateX(60px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes introFadeOut {
  0%   { opacity: 1; pointer-events: all; }
  100% { opacity: 0; pointer-events: none; }
}

@keyframes popIn {
  0%   { opacity: 0; transform: scale(0.8) translateY(10px); }
  60%  { opacity: 1; transform: scale(1.08) translateY(-4px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes matchBounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.12); }
  60%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes countdownPulse {
  0%   { transform: scale(1);    opacity: 1; }
  40%  { transform: scale(1.3);  opacity: 1; }
  100% { transform: scale(0.85); opacity: 0; }
}

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

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
  /* Intro Screen */
  #intro-screen {
    padding: 20px;
  }

  #intro-top {
    flex-direction: column;
    gap: 20px;
  }

  #intro-char {
    height: 150px;
    width: 150px;
  }

  #intro-title {
    font-size: 2.5rem;
    text-align: center;
    max-width: 100%;
    -webkit-text-stroke: 2px #3d2b00;
  }

  #intro-click-hint {
    font-size: 2rem;
    margin-left: 0;
  }

  /* Game Title and Text */
  h1 {
    font-size: 2.2rem;
    margin-top: 0;
    -webkit-text-stroke: 1.2px #3d2b00 !important;
  }

  #status {
    font-size: 2rem;
  }

  #stats {
    font-size: 1.8rem;
    gap: 20px;
    flex-wrap: wrap;
  }

  #countdown {
    font-size: 2.5rem;
    height: 60px;
    line-height: 60px;
  }

  #level-splash {
    font-size: 2.2rem;
    height: 50px;
    line-height: 50px;
    -webkit-text-stroke: 2px #3d2b00;
  }

  /* Cards - Scale down for mobile */
  .card {
    width: 100px;
    height: 100px;
  }

  /* Disable hover animation on mobile */
  .card:not(.flipped):not(.matched):hover {
    transform: none !important;
  }

  /* Ensure ALL flipped cards fill properly on mobile (flipped, matched, wrong) */
  .card.flipped .card-back,
  .card.flipped .card-front,
  .card.matched .card-back,
  .card.matched .card-front,
  .card.wrong .card-back,
  .card.wrong .card-front {
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }

  .card.flipped .card-front,
  .card.matched .card-front,
  .card.wrong .card-front {
    overflow: hidden !important;
    background-color: transparent !important;
    border-radius: 8px !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    align-items: unset !important;
    justify-content: unset !important;
  }

  .card.flipped .card-front img,
  .card.matched .card-front img,
  .card.wrong .card-front img {
    position: absolute !important;
    top: -1px !important;
    left: -1px !important;
    right: -1px !important;
    bottom: -1px !important;
    width: calc(100% + 2px) !important;
    height: calc(100% + 2px) !important;
    min-width: calc(100% + 2px) !important;
    min-height: calc(100% + 2px) !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: cover !important;
    object-position: center !important;
    border-radius: 8px !important;
    display: block !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  .card.matched .card-inner {
    transform: rotateY(180deg) !important;
  }

  #board {
    gap: 10px;
    margin-bottom: 120px;
  }

  /* Audio Controls - Reposition for mobile ONLY - Fixed at very bottom of viewport */
  /* Now outside #game container, so truly fixed to viewport */
  #audio-controls {
    position: fixed !important;
    top: auto !important;
    bottom: 5px !important;
    right: 15px !important;
    left: auto !important;
    width: auto !important;
    height: auto !important;
    gap: 10px;
    align-items: flex-end;
    transform: none !important;
    z-index: 10000 !important;
    margin: 0 !important;
    padding: 0 !important;
    transition: opacity 0.6s ease !important;
    animation: none !important;
  }
  
  #audio-controls.visible {
    opacity: 1 !important;
  }

  #radio-controls {
    gap: 6px;
  }

  #radio-icon {
    width: 32px;
    height: 32px;
  }

  #volume-slider {
    width: 90px;
  }

  #skip-prev,
  #skip-next {
    font-size: 0.65rem;
  }

  #play-pause-btn {
    font-size: 0.95rem;
    min-width: 0.95rem;
    min-height: 0.95rem;
  }

  #play-pause-btn.play-icon {
    font-size: 0.8rem;
  }

  #skip-controls {
    margin-left: 38px;
    margin-top: -10px;
    gap: 2px;
  }

  #sfx-controls {
    gap: 6px;
  }

  #sfx-label {
    font-size: 1.5rem;
  }

  #sfx-toggle {
    width: 42px;
    height: 22px;
  }

  #sfx-toggle-slider {
    width: 16px;
    height: 16px;
    top: 1px;
    left: 1px;
  }

  #sfx-toggle.sfx-on #sfx-toggle-slider {
    transform: translateX(22px);
  }

  /* Scorecard */
  /* Scorecard - Keep desktop layout on mobile for consistent downloads */
  /* Scale down visually but keep actual size for downloads */
  #scorecard {
    width: 420px;
    max-width: 90vw;
    flex-direction: row;
    transform: scale(0.85);
    transform-origin: center;
  }

  #scorecard-img {
    width: 180px;
    height: 240px;
    border-right: 3px solid #3d2b00;
    border-bottom: none;
  }

  #scorecard-info {
    padding: 16px 16px;
    align-items: flex-end;
    text-align: right;
    justify-content: space-between;
  }

  #scorecard-top {
    align-items: flex-end;
    text-align: right;
  }

  #scorecard-time {
    font-size: 3.4rem;
    text-align: right;
    width: auto;
  }

  #scorecard-message {
    font-size: 1.3rem;
  }

  #scorecard-sub {
    font-size: 1.2rem;
  }

  /* Buttons */
  button {
    font-size: 1.2rem;
    padding: 6px 20px;
  }

  #download-btn {
    font-size: 1.2rem;
    padding: 6px 20px;
  }
}

/* Extra small phones */
@media (max-width: 480px) {
  h1 {
    font-size: 1.8rem;
  }

  #status {
    font-size: 1.6rem;
  }

  #stats {
    font-size: 1.4rem;
    gap: 12px;
  }

  .card {
    width: 80px;
    height: 80px;
  }

  #board {
    gap: 8px;
  }

  #countdown {
    font-size: 2rem;
  }

  #level-splash {
    font-size: 1.8rem;
  }
}