/* ============================================
   TOUCH GRASS TIMER — Children's Book Aesthetic
   ============================================ */

:root {
  --grass-dark: #4CAF50;
  --grass-light: #8BC34A;
  --sky-blue: #87CEEB;
  --sun-yellow: #FFD54F;
  --dirt-brown: #8D6E63;
  --flower-pink: #F48FB1;
  --cream: #FFF8E1;
  --white: #FFFDE7;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Patrick Hand', cursive;
  background: linear-gradient(180deg, var(--sky-blue) 0%, #B2EBF2 40%, #C8E6C9 100%);
  color: #3E2723;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  transition: background 2s ease;
  /* Paper texture */
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(255,255,255,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 40%);
}

body.state-running {
  background: linear-gradient(180deg, #81D4FA 0%, #A5D6A7 60%, #66BB6A 100%);
}

body.state-expired {
  background: linear-gradient(180deg, #66BB6A 0%, #4CAF50 50%, #388E3C 100%);
}

/* ---- Flash Overlay ---- */
.flash-overlay {
  position: fixed;
  inset: 0;
  background: #69F0AE;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
}

.flash-overlay.active {
  animation: flash-green 0.6s ease-out forwards;
}

@keyframes flash-green {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---- Clouds ---- */
.clouds {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255,255,255,0.8);
  border-radius: 58% 42% 55% 45% / 60% 55% 45% 40%;
  filter: blur(1px);
}

.cloud::before,
.cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.cloud-1 {
  width: 200px;
  height: 70px;
  top: 8%;
  left: -200px;
  animation: cloud-drift 35s linear infinite;
}
.cloud-1::before {
  width: 80px; height: 60px;
  top: -30px; left: 40px;
}
.cloud-1::after {
  width: 100px; height: 50px;
  top: -20px; left: 90px;
}

.cloud-2 {
  width: 160px;
  height: 55px;
  top: 18%;
  left: -160px;
  animation: cloud-drift 45s linear infinite 10s;
  opacity: 0.7;
}
.cloud-2::before {
  width: 60px; height: 45px;
  top: -25px; left: 30px;
}
.cloud-2::after {
  width: 80px; height: 40px;
  top: -15px; left: 70px;
}

.cloud-3 {
  width: 180px;
  height: 60px;
  top: 12%;
  left: -180px;
  animation: cloud-drift 55s linear infinite 22s;
  opacity: 0.6;
}
.cloud-3::before {
  width: 70px; height: 50px;
  top: -28px; left: 35px;
}
.cloud-3::after {
  width: 90px; height: 45px;
  top: -18px; left: 80px;
}

@keyframes cloud-drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 300px)); }
}

/* ---- Container ---- */
.container {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
}

/* ---- Screens ---- */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.state-idle .screen-idle,
.state-running .screen-running,
.state-expired .screen-expired {
  display: flex;
}

/* ---- Title (IDLE) ---- */
.title {
  font-family: 'Bubblegum Sans', cursive;
  font-size: clamp(2.5rem, 8vw, 4rem);
  color: var(--grass-dark);
  text-shadow: 3px 3px 0 var(--dirt-brown), 4px 4px 0 rgba(0,0,0,0.1);
  display: flex;
  gap: 0.4em;
  flex-wrap: nowrap;
  justify-content: center;
  white-space: nowrap;
}

.title-word {
  display: inline-block;
  animation: title-bounce 2s ease-in-out infinite;
  transform: rotate(-2deg);
}
.title-word:nth-child(2) {
  animation-delay: 0.2s;
  transform: rotate(1deg);
  color: var(--grass-light);
}
.title-word:nth-child(3) {
  animation-delay: 0.4s;
  transform: rotate(-1deg);
}

@keyframes title-bounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(1deg); }
}

/* ---- Timer Display ---- */
.timer-display {
  font-family: 'Bubblegum Sans', cursive;
  font-size: clamp(3.5rem, 14vw, 6rem);
  color: #3E2723;
  background: rgba(255,255,255,0.6);
  border-radius: 42% 58% 45% 55% / 55% 45% 55% 45%;
  padding: 0.2em 0.6em;
  box-shadow: 4px 6px 0 rgba(141,110,99,0.3);
  min-width: 260px;
  transform: rotate(-1deg);
}

.timer-countdown {
  font-size: clamp(4rem, 16vw, 7rem);
  transform: rotate(0.5deg);
}

/* ---- Slider ---- */
.slider-container {
  width: 100%;
  max-width: 340px;
}

.slider-label {
  font-size: 1.4rem;
  color: var(--dirt-brown);
  font-weight: bold;
}

#sliderValue {
  font-family: 'Bubblegum Sans', cursive;
  font-size: 1.6rem;
  color: var(--grass-dark);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: var(--cream);
  border-radius: 30% 70% 50% 50% / 60% 40% 60% 40%;
  outline: none;
  margin: 0.8rem 0 0.4rem;
  box-shadow: 2px 3px 0 rgba(141,110,99,0.2);
  border: 3px solid var(--dirt-brown);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  background: var(--grass-light);
  border: 3px solid var(--grass-dark);
  border-radius: 55% 45% 50% 50% / 45% 55% 45% 55%;
  cursor: pointer;
  box-shadow: 2px 3px 0 rgba(141,110,99,0.3);
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15) rotate(5deg);
}

input[type="range"]::-moz-range-thumb {
  width: 36px;
  height: 36px;
  background: var(--grass-light);
  border: 3px solid var(--grass-dark);
  border-radius: 55% 45% 50% 50% / 45% 55% 45% 55%;
  cursor: pointer;
  box-shadow: 2px 3px 0 rgba(141,110,99,0.3);
}

.slider-range {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--dirt-brown);
  opacity: 0.7;
}

/* ---- Buttons ---- */
.btn {
  font-family: 'Bubblegum Sans', cursive;
  font-size: 1.8rem;
  border: 4px solid;
  padding: 0.5em 2em;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}

.btn:hover {
  transform: translateY(-3px) rotate(1deg);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: none !important;
}

.btn-start {
  background: var(--grass-light);
  border-color: var(--grass-dark);
  color: white;
  border-radius: 55% 45% 52% 48% / 48% 52% 48% 52%;
  box-shadow: 4px 6px 0 rgba(76,175,80,0.4);
  text-shadow: 2px 2px 0 var(--grass-dark);
}

.btn-cancel {
  background: var(--sun-yellow);
  border-color: #F9A825;
  color: #5D4037;
  border-radius: 48% 52% 46% 54% / 52% 48% 52% 48%;
  box-shadow: 4px 6px 0 rgba(249,168,37,0.4);
  font-size: 1.3rem;
}

.btn-reset {
  background: var(--flower-pink);
  border-color: #EC407A;
  color: white;
  border-radius: 50% 50% 48% 52% / 45% 55% 45% 55%;
  box-shadow: 4px 6px 0 rgba(236,64,122,0.4);
  text-shadow: 2px 2px 0 #EC407A;
  z-index: 10;
}

/* ---- Running State Label ---- */
.running-label {
  font-size: 1.3rem;
  color: var(--dirt-brown);
  opacity: 0.8;
  transform: rotate(-1deg);
}

/* ---- Grass ---- */
.grass-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.grass-blade {
  position: absolute;
  bottom: 0;
  width: 12px;
  background: var(--grass-dark);
  border-radius: 80% 80% 0 0;
  transform-origin: bottom center;
  transform: scaleY(0);
}

.state-idle .grass-blade {
  transform: scaleY(0.3);
  transition: transform 0.5s ease;
}

.state-running .grass-blade {
  animation: grass-grow var(--grow-duration, 3s) ease forwards;
  animation-delay: var(--delay, 0s);
}

.state-expired .grass-blade {
  animation: grass-burst 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes grass-grow {
  0% { transform: scaleY(0.3) rotate(0deg); }
  70% { transform: scaleY(1.1) rotate(var(--sway, 3deg)); }
  100% { transform: scaleY(1) rotate(var(--sway, 2deg)); }
}

@keyframes grass-burst {
  0% { transform: scaleY(0.3) rotate(0deg); }
  60% { transform: scaleY(1.4) rotate(var(--sway, 5deg)); }
  80% { transform: scaleY(0.9) rotate(calc(var(--sway, 3deg) * -0.5)); }
  100% { transform: scaleY(1.2) rotate(var(--sway, 2deg)); }
}

/* Grass sway for idle */
.state-idle .grass-blade {
  animation: grass-idle-sway 3s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  transform: scaleY(0.3);
}

@keyframes grass-idle-sway {
  0%, 100% { transform: scaleY(0.3) rotate(0deg); }
  50% { transform: scaleY(0.3) rotate(var(--sway, 2deg)); }
}

/* ---- Character (EXPIRED) ---- */
.character {
  transform: translateY(100vh);
}

.state-expired .character {
  animation: character-pop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s forwards;
}

@keyframes character-pop {
  0% { transform: translateY(100vh); }
  100% { transform: translateY(0); }
}

.character-body {
  position: relative;
  width: 120px;
  height: 120px;
}

.character-face {
  width: 120px;
  height: 120px;
  background: var(--sun-yellow);
  border: 4px solid var(--dirt-brown);
  border-radius: 52% 48% 50% 50% / 48% 52% 48% 52%;
  position: relative;
  box-shadow: 4px 6px 0 rgba(141,110,99,0.3);
}

.eye {
  position: absolute;
  width: 16px;
  height: 20px;
  background: #3E2723;
  border-radius: 50%;
  top: 38px;
}
.eye-left { left: 30px; }
.eye-right { right: 30px; }

.eye::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
}

.mouth {
  position: absolute;
  width: 40px;
  height: 24px;
  background: #E64A19;
  border: 3px solid #3E2723;
  border-radius: 0 0 50% 50%;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
}

.leaf-hat {
  position: absolute;
  width: 50px;
  height: 30px;
  background: var(--grass-light);
  border: 3px solid var(--grass-dark);
  border-radius: 0 80% 0 80%;
  top: -18px;
  left: 50%;
  transform: translateX(-50%) rotate(-15deg);
}

.leaf-hat::after {
  content: '';
  position: absolute;
  width: 3px;
  height: 20px;
  background: var(--grass-dark);
  top: 8px;
  left: 18px;
  transform: rotate(30deg);
}

/* ---- Shout Text ---- */
.shout-text {
  font-family: 'Bubblegum Sans', cursive;
  font-size: clamp(2rem, 7vw, 3.5rem);
  color: var(--white);
  text-shadow: 3px 3px 0 var(--grass-dark), 5px 5px 0 rgba(0,0,0,0.15);
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 0;
  white-space: nowrap;
}

.shout-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(40px);
}

.state-expired .shout-letter {
  animation: bounce-letter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  animation-delay: calc(0.8s + var(--i) * 0.06s);
}

.shout-letter.space {
  width: 0.3em;
}

@keyframes bounce-letter {
  0% { opacity: 0; transform: translateY(40px) scale(0.5) rotate(-10deg); }
  60% { opacity: 1; transform: translateY(-10px) scale(1.1) rotate(3deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

/* Continuous bounce after appearing */
.state-expired .shout-letter {
  animation:
    bounce-letter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
    letter-wave 1.5s ease-in-out calc(2s + var(--i) * 0.08s) infinite;
}

@keyframes letter-wave {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

/* ---- Leaves ---- */
.leaves-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.leaf {
  position: absolute;
  width: 20px;
  height: 28px;
  background: var(--grass-light);
  border-radius: 0 80% 0 80%;
  border: 2px solid var(--grass-dark);
  top: -40px;
  opacity: 0;
}

.state-expired .leaf {
  animation: leaf-fall var(--fall-duration, 4s) ease-in var(--fall-delay, 0s) forwards;
}

@keyframes leaf-fall {
  0% {
    opacity: 0;
    transform: translateY(0) rotate(0deg) translateX(0);
  }
  10% { opacity: 0.9; }
  100% {
    opacity: 0;
    transform: translateY(110vh) rotate(720deg) translateX(var(--drift, 50px));
  }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
  .container {
    padding: 1rem;
  }

  .timer-display {
    min-width: 200px;
    padding: 0.1em 0.4em;
  }

  .character-body {
    width: 90px;
    height: 90px;
  }
  .character-face {
    width: 90px;
    height: 90px;
  }
  .eye { width: 12px; height: 16px; top: 28px; }
  .eye-left { left: 22px; }
  .eye-right { right: 22px; }
  .mouth { width: 30px; height: 18px; bottom: 16px; }
  .leaf-hat { width: 38px; height: 22px; top: -14px; }

  .btn {
    font-size: 1.4rem;
    padding: 0.4em 1.5em;
  }

  .grass-container {
    height: 80px;
  }
}
