/* =========================
   Cookie Jar Math - Main Stylesheet
   ========================= */

/* ========== Base Styles ========== */
body {
  font-family: sans-serif;
  text-align: center;
  background: #fef6e4;
}

h1 {
  margin-bottom: 0.5em;
}

#goalText {
  font-size: 1.25em;
  color: #8B4513;
  margin-bottom: 2em;
  line-height: 1.25;
}

/* ========== Question & Answer ========== */
#question {
  font-size: 1.4em !important;
  font-weight: bold;
  color: #8B4513;
  margin-top: 0.75em;
  margin-bottom: 0.75em;
}

.answer-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

#answer {
  font-size: 1.25em;
  text-align: center;
  padding: 0.5em;
  margin: 0;
  background: white;
  border: 2px solid #8B4513;
  border-radius: 8px;
  min-height: 1.2em;
  max-width: 175px;
  color: #8B4513;
  font-weight: bold;
  box-sizing: border-box;
  height: 48px;
  line-height: 1.25em;
}

#submitBtn {
  font-size: 1.25em;
  text-align: center;
  padding: 0.5em 1.2em;
  margin: 0;
  min-height: 1.2em;
  background: #8B4513;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  height: 48px;
  line-height: 1.25em;
  font-weight: bold;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}
#submitBtn:hover {
  background: #A0522D;
}

/* ========== Game End Buttons ========== */
.play-again-btn {
  font-size: 1.25em;
  text-align: center;
  padding: 0.5em 1.2em;
  height: 48px;
  background: #8B4513;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-sizing: border-box;
  margin: 1.5em auto 0 auto;
}
.play-again-btn:hover {
  background: #A0522D;
}

.eat-button {
  font-size: 0.75em;
  text-align: center;
  padding: 0.25em 0.25em;
  background: #8B4513;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.3s;
  display: block;
  width: fit-content;
  margin: 1em auto 0 auto;
  font-weight: bold;
}
.eat-button:hover {
  background: #A0522D;
}

/* ========== Cookie Jar Display ========== */
#cookieJarContainer {
  margin-top: 1.5em;
  margin-bottom: 1.5em;
  position: relative;
  height: 250px;
}

#cookieJar {
  width: 200px;
  height: 250px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0.10) 80%, rgba(200,200,200,0.08) 100%);
  border-left: 4px solid #8B4513;
  border-right: 4px solid #8B4513;
  border-bottom: 4px solid #8B4513;
  border-top: none;
  border-radius: 0 0 60px 60px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 10px 20px rgba(0,0,0,0.05),
    0 0 10px rgba(139, 69, 19, 0.1),
    inset 0 -18px 24px 0 rgba(120, 80, 40, 0.13);
}

#cookieJar::before {
  content: "";
  position: absolute;
  left: 30px;
  top: 10px;
  width: 50px;
  height: 30px;
  background: linear-gradient(120deg, rgba(255,255,255,0.45) 60%, rgba(255,255,255,0));
  border-radius: 30px 30px 20px 20px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.7;
}

#cookieJar::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 30px;
  background: linear-gradient(to top, rgba(120,80,40,0.10) 70%, rgba(255,255,255,0) 100%);
  border-radius: 0 0 60px 60px;
  z-index: 2;
  pointer-events: none;
}

#cookiesInJar {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ========== Cookie Animations ========== */
.fallingCookie {
  position: absolute;
  width: 45px;
  height: 45px;
  background: #D2691E;
  border-radius: 50%;
  border: 2px solid #8B4513;
  animation: fallIntoJar 1s ease-in forwards;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.fallingCookie::after {
  content: "🍪";
  font-size: 36px;
}
@keyframes fallIntoJar {
  0% { top: -50px; left: 50%; transform: translateX(-50%); }
  100% { top: 200px; left: 50%; transform: translateX(-50%); }
}

.cookieInJar {
  position: absolute;
  width: 52px;
  height: 52px;
  background: #D2691E;
  border-radius: 50%;
  border: 2px solid #8B4513;
  animation: stackInJar 0.5s ease-out forwards;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.cookieInJar::after {
  content: "🍪";
  font-size: 42px;
}
@keyframes stackInJar {
  0% { opacity: 0; transform: scale(0.5); }
  100% { opacity: 1; transform: scale(1); }
}

/* ========== Cookie Monster & Crumbs ========== */
#cookieMonster {
  position: fixed;
  top: 50%;
  left: -200px;
  width: 100px;
  height: 100px;
  background: #FFE4B5;
  border-radius: 50%;
  border: 4px solid #DEB887;
  z-index: 100;
  transition: left 2s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
}
#cookieMonster::after {
  content: "🤤";
  font-size: 75px;
}
#cookieMonster.eating {
  animation: eatCookies 3s ease-in-out;
}
@keyframes eatCookies {
  0% { transform: translateY(0) scale(1); }
  25% { transform: translateY(-20px) scale(1.1); }
  50% { transform: translateY(0) scale(1.2); }
  75% { transform: translateY(-10px) scale(1.1); }
  100% { transform: translateY(0) scale(1); }
}

.cookieCrumb {
  position: absolute;
  font-size: 8px;
  animation: crumbFall 0.5s ease-in forwards;
  z-index: 5;
}
.cookieCrumb.bouncing {
  animation: crumbBounceAndFall 1.5s ease-out forwards;
}
@keyframes crumbFall {
  0% { opacity: 0; transform: scale(0.1); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes crumbBounceAndFall {
  0% { opacity: 0; transform: scale(0.1) translateY(0); }
  20% { opacity: 1; transform: scale(1) translateY(0); }
  40% { transform: scale(1.1) translateY(-20px); }
  60% { transform: scale(1) translateY(-10px); }
  80% { transform: scale(0.9) translateY(-5px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ========== Utility ========== */
.hidden { display: none; }
#endMessage {
  font-size: 1.75em;
  color: green;
  margin-top: 0.5em;
}

/* ========== Modal Styles ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-content {
  background: #fffbe8;
  border-radius: 16px;
  padding: 2em 2.5em;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  text-align: center;
  min-width: 300px;
}
#settingsForm label {
  font-size: 1.1em;
  color: #8B4513;
}
#settingsForm input[type="number"] {
  width: 3em;
  font-size: 1.1em;
  margin-left: 0.5em;
  margin-right: 0.5em;
  text-align: center;
}
#startGameBtn {
  margin-top: 1em;
  padding: 0.5em 1.5em;
  font-size: 1.1em;
  background: #8B4513;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
#startGameBtn:hover {
  background: #A0522D;
}

/* ========== Mobile Keypad & Answer Display ========== */
/* --- Keypad base styles --- */
.keypad-container {
  display: none; /* Hidden by default on desktop */
  margin-top: 0.5em;
  padding: 0.5em;
  background: #f8f4e8;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}
.keypad-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.keypad-row:last-child {
  margin-bottom: 0;
}
.keypad-btn {
  width: 60px;
  height: 60px;
  font-size: 1.5em;
  font-weight: bold;
  border: 2px solid #8B4513;
  border-radius: 12px;
  background: #fff;
  color: #8B4513;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.keypad-btn:hover {
  background: #f0e6d2;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.keypad-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.backspace-btn {
  width: 120px;
  font-size: 1.5em;
}
.submit-keypad-btn {
  width: 120px;
  background: #8B4513;
  color: white;
}
.submit-keypad-btn:hover {
  background: #A0522D;
}

/* --- Answer Display for Mobile Keypad --- */
/* Remove all CSS for #answerDisplay, both global and in the mobile media query */

/* ========== Mobile Overrides ========== */
@media (max-width: 600px) {
  /* Show keypad and answer display only on mobile */
  .keypad-container { display: block; }
  #answer {
    display: block;
  }
  #submitBtn {
    display: block;
    background: #8B4513;
    color: #fff;
    border-radius: 8px;
  }
  /* Show the answer container on mobile, but hide individual elements */
  .answer-container { display: flex; }
  #question {
    font-size: 1.25em;
    margin-top: 0.75em !important;
    margin-bottom: 0.75em !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }
  #cookieJarContainer {
    margin-top: 0.7em;
    margin-bottom: 0.3em;
  }
  .keypad-row-with-backspace {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
  }
  .keypad-row {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 6px;
  }
  .keypad-col {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    margin-left: 8px;
    width: 48px;
  }
  .backspace-btn {
    height: 104px; /* 2x 48px + gap */
    width: 100%;
    font-size: 1.2em;
    margin: 0;
    box-sizing: border-box;
    align-self: stretch;
  }
  #mobileKeypad { margin-top: 0.2em; }
  .keypad-grid-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(2, 48px);
    gap: 8px;
    margin: 10px auto 0 auto;
    max-width: 320px;
    background: #f8f4e8;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 0.5em 0.5em 0.7em 0.5em;
  }
  .keypad-grid-container .keypad-btn {
    width: 100%;
    height: 100%;
    font-size: 1.2em;
    border: 2px solid #8B4513;
    border-radius: 12px;
    background: #fff;
    color: #8B4513;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    touch-action: manipulation;
  }
  .keypad-grid-container .keypad-btn:active {
    background: #f0e6d2;
    color: #A0522D;
  }
  .keypad-grid-container .backspace-btn {
    grid-column: 6;
    grid-row: 1 / span 2;
    height: 100%;
    background: #8B4513;
    color: #fff;
    font-size: 1.5em;
    border-radius: 12px;
    border: 2px solid #8B4513;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .keypad-grid-container .backspace-btn:active {
    background: #A0522D;
    color: #fff;
  }
}

.keypad-grid-container {
  display: none;
}

@media (max-width: 600px) {
  .keypad-grid-container {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(2, 48px);
    gap: 8px;
    margin: 10px auto 0 auto;
    max-width: 320px;
    background: #f8f4e8;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 0.5em 0.5em 0.7em 0.5em;
  }
  .keypad-grid-container .keypad-btn {
    width: 100%;
    height: 100%;
    font-size: 1.2em;
    border: 2px solid #8B4513;
    border-radius: 12px;
    background: #fff;
    color: #8B4513;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    touch-action: manipulation;
  }
  .keypad-grid-container .keypad-btn:active {
    background: #f0e6d2;
    color: #A0522D;
  }
  .keypad-grid-container .backspace-btn {
    grid-column: 6;
    grid-row: 1 / span 2;
    height: 100%;
    background: #8B4513;
    color: #fff;
    font-size: 1.5em;
    border-radius: 12px;
    border: 2px solid #8B4513;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .keypad-grid-container .backspace-btn:active {
    background: #A0522D;
    color: #fff;
  }
}

@keyframes blink-infinite {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

#answer.correct {
  color: #228B22 !important; /* green */
  font-weight: bold;
  animation: none;
}
#answer.incorrect {
  color: #DC143C !important; /* red */
  font-weight: bold;
  animation: none;
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  margin: 1.2em 0 1em 0;
}
.range-btn {
  font-size: 1.3em;
  padding: 0.7em 0;
  background: #8B4513;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.2s;
}
.range-btn:hover, .range-btn:focus {
  background: #A0522D;
}
