/* Bloomer - Sunny Orchard / Fruit Clash theme */

/* Fredoka 500/600/700 and Nunito 500/700/800 are loaded by the host page, not
   by an @import here: the Rails view links Google Fonts, and the portal builds
   swap in a self-hosted fonts.css because a portal build may not talk to any
   external host. Keeping the reference out of this file is what lets
   bin/build-portal copy it verbatim. */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Nunito', sans-serif;
}

html, body {
  height: 100%;
  width: 100%;
  touch-action: manipulation;
}

body {
  background: linear-gradient(180deg, #3db4ff 0%, #fff3b0 55%, #ffd56a 100%);
  color: #5a2e12;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.small-header {
  flex-shrink: 0;
}

/* Peach candy mute — sits in the header row, clear of the butterfly HUD */
.sound-btn {
  position: fixed;
  top: 8px;
  right: 12px;
  z-index: 1002;
  width: 40px;
  height: 40px;
  padding: 8px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #ffd56a 0%, #ff9e62 100%);
  border: 3px solid #5a2e12;
  border-radius: 50%;
  color: #5a2e12;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 0 #5a2e12, 0 8px 14px rgba(90, 46, 18, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.sound-btn:hover {
  background: linear-gradient(180deg, #ffe08a 0%, #ffb070 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #5a2e12, 0 10px 16px rgba(90, 46, 18, 0.2);
}

.sound-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #5a2e12;
}

.sound-btn svg {
  width: 100%;
  height: 100%;
}

.sound-btn .sound-slash {
  display: none;
}

.sound-btn.muted {
  filter: saturate(0.55) brightness(0.95);
  color: rgba(90, 46, 18, 0.55);
}

.sound-btn.muted .sound-waves {
  display: none;
}

.sound-btn.muted .sound-slash {
  display: block;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.game-container {
  background: transparent;
  border-radius: 12px;
  box-shadow: none;
  padding: 10px;
  width: 100%;
  height: 100%;
  text-align: center;
  border: none;
  display: flex;
  flex-direction: column;
  position: relative;
}

.game-info {
  margin: 0 auto 10px auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  width: 100%;
  max-width: 700px;
  gap: 15px;
}

.score-section,
.level-section,
.best-section {
  font-size: 1rem;
  color: #7a4a22;
}

.score-section span:last-child {
  color: #e24a4a;
  font-weight: 800;
}

.level-section span:last-child {
  color: #3aaa28;
  font-weight: 800;
}

.best-section span:last-child {
  color: #e08a00;
  font-weight: 800;
}

.game-area {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  border-radius: 8px;
  transition: filter 0.5s ease;
}

/* Dead effect when game is over */
canvas.dead {
  filter: grayscale(70%) sepia(20%) brightness(0.85);
}

/* Text colors for instructions */
.red-text {
  color: #e02424;
}

.green-text {
  color: #3aaa28;
}

.yellow-text {
  color: #e08a00;
}

/* Candy fruit button */
button {
  background: linear-gradient(180deg, #ff8a4a 0%, #ef5a20 100%);
  border: 3px solid #5a2e12;
  color: #fffdf5;
  padding: 12px 24px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  font-weight: 800;
  font-family: 'Fredoka', sans-serif;
  margin: 10px 2px;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 25px;
  transition: all 0.2s ease;
  box-shadow: 0 5px 0 #5a2e12, 0 8px 16px rgba(90, 46, 18, 0.2);
  text-shadow: none;
}

button:hover {
  background: linear-gradient(180deg, #ff9e62 0%, #ff6a30 100%);
  border-color: #5a2e12;
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #5a2e12, 0 10px 18px rgba(90, 46, 18, 0.22);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #5a2e12;
}

/* Modal styles - Garden themed */
.modal {
  display: none;
  position: fixed;
  z-index: 10;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: radial-gradient(ellipse at center, rgba(255, 244, 180, 0.75) 0%, rgba(140, 200, 255, 0.88) 100%);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.modal-content {
  background: linear-gradient(180deg, #fffdf2 0%, #ffe9a8 100%);
  margin: auto;
  padding: 30px;
  border-radius: 22px;
  width: 85%;
  max-width: 420px;
  text-align: left;
  color: #5a2e12;
  border: 4px solid #5a2e12;
  box-shadow: 0 10px 0 #5a2e12, 0 18px 40px rgba(90, 46, 18, 0.18);

  .start-btn {
    display: block;
    width: 100%;
    padding: 15px 32px;
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 14px;
    letter-spacing: 0.5px;
  }

  .story-section {
    text-align: center;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(90, 46, 18, 0.15);
    margin-bottom: 10px;

    h1 {
      font-family: 'Fredoka', sans-serif;
      font-size: 3.2rem;
      font-weight: 700;
      color: #ef5a20;
      margin-bottom: 0;
      text-shadow: 3px 3px 0 #5a2e12;
      letter-spacing: 1px;
    }

    .story-text {
      font-size: 1.05rem;
      color: #7a4a22;
      margin: 10px 0;
      line-height: 1.5;
      font-weight: 700;
    }
  }

  .instructions {
    padding: 8px 0;

    h3 {
      font-size: 0.85rem;
      color: #c07020;
      margin-bottom: 10px;
      text-transform: uppercase;
      letter-spacing: 2px;
      font-weight: 800;
    }

    h4 {
      font-size: 0.75rem;
      color: #c07020;
      margin: 10px 0 8px;
      text-transform: uppercase;
      letter-spacing: 1px;
      font-weight: 800;
    }

    p {
      margin: 8px 0;
      font-size: 0.95rem;
      color: #5a2e12;
      line-height: 1.4;
    }

    strong {
      color: #5a2e12;
    }
  }

  .controls-section {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(90, 46, 18, 0.15);
  }

  .control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 8px;
  }

  .control-icon {
    width: 24px;
    height: 24px;
    color: #ef5a20;
    flex-shrink: 0;
  }

  .control-label {
    font-size: 0.9rem;
    color: #5a2e12;
    flex: 1;
  }

  .control-or {
    font-size: 0.9rem;
  }

  .control-key-text {
    font-size: 0.8rem;
    color: #5a2e12;
    background: rgba(255, 180, 70, 0.35);
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 800;
  }

  .inline-icon {
    vertical-align: middle;
    margin-right: 8px;
  }

  .inline-icon.petal-icon {
    width: 32px;
    height: 18px;
    color: #ffcc00;
  }

  .inline-icon.leaf-icon {
    width: 24px;
    height: 32px;
    color: #4ade80;
  }

  .inline-icon.worm-icon {
    width: 36px;
    height: 18px;
  }

  .inline-icon.snake-icon {
    width: 36px;
    height: 18px;
  }
}

/* Game Over Modal - Transparent */
.game-over-modal {
  background: transparent !important;
  backdrop-filter: none !important;
}

.game-over-modal.show {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
}

.game-over-content {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  width: auto !important;
  margin: 0 !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.game-over-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.6rem;
  font-weight: 700;
  color: #ef5a20;
  letter-spacing: 0.06em;
  text-shadow: 3px 3px 0 #5a2e12;
  margin: 0;
}

.game-over-modal.won .game-over-title {
  color: #3aaa28;
  text-shadow: 3px 3px 0 #5a2e12;
  animation: bloom-title-pop 0.7s cubic-bezier(0.2, 1.4, 0.3, 1) both;
}

.petal-medal {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px 0 8px;
}

.petal-medal-core {
  position: relative;
  z-index: 2;
  width: 118px;
  height: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 38% 32%, #fffdf6 0%, #ffe9a8 72%, #ffd56a 100%);
  border: 4px solid #5a2e12;
  border-radius: 50%;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.55),
    0 6px 0 #5a2e12;
}

.petal-count-num {
  font-family: 'Fredoka', sans-serif;
  font-size: 3.1rem;
  font-weight: 700;
  line-height: 0.9;
  color: #ef5a20;
  text-shadow: 2px 2px 0 #5a2e12;
}

.petal-count-label {
  margin-top: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #7a4a22;
}

.game-over-modal:not(.won) .petal-medal-core {
  background: radial-gradient(circle at 38% 32%, #fff8ee 0%, #e8d2a8 100%);
}

.best-ribbon {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 8px 20px 8px 18px;
  background: #fffdf2;
  border: 3px solid #5a2e12;
  border-radius: 999px;
  box-shadow: 0 4px 0 #5a2e12;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a4a22;
}

.best-ribbon #gameOverBest {
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #ef5a20;
  text-shadow: 2px 2px 0 #5a2e12;
  line-height: 1;
}

.best-ribbon.new-record {
  background: linear-gradient(180deg, #fff6c8 0%, #ffe08a 100%);
}

.best-ribbon.new-record #gameOverBest {
  color: #3aaa28;
}

@keyframes bloom-title-pop {
  0% { transform: scale(0.72) rotate(-4deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .game-over-modal.won .game-over-title {
    animation: none;
  }
}

#playAgainButton {
  display: block;
  padding: 18px 44px;
  font-size: 1.25rem;
  font-weight: 800;
  margin: 4px 0 0;
  background: linear-gradient(180deg, #ff8a4a 0%, #ef5a20 100%);
  border: 3px solid #5a2e12;
  color: #fffdf5;
  border-radius: 28px;
  box-shadow: 0 6px 0 #5a2e12;
}

#playAgainButton:hover {
  background: linear-gradient(180deg, #ff9e62 0%, #ff6a30 100%);
  border-color: #5a2e12;
  transform: translateY(-2px);
}

/* Controls hint at bottom - Garden themed */
.controls-hint {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 12px 16px;
  color: #7a4a22;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.45);
  border-radius: 20px;
  margin: 8px auto;
  border: 2px solid #5a2e12;
}

.hint-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

kbd {
  background: #fff8dc;
  border: 2px solid #5a2e12;
  border-radius: 6px;
  padding: 4px 8px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  color: #5a2e12;
  box-shadow: 0 2px 0 #5a2e12;
}

/* Floating help tip (petal / leaf tutorial) — positioned in JS near the target */
.help-tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(240px, calc(100vw - 24px));
  padding: 10px 14px;
  border-radius: 12px;
  background: #fffdf2;
  color: #5a2e12;
  border: 3px solid #5a2e12;
  touch-action: manipulation;
  box-shadow: 0 5px 0 #5a2e12;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  box-sizing: border-box;
  transform: none;
}

.help-tip.show {
  opacity: 1;
  visibility: visible;
  cursor: pointer;
}

.help-tip-text {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
}

.help-tip-btn {
  margin: 0;
  padding: 8px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 20px;
  background: linear-gradient(180deg, #ff8a4a 0%, #ef5a20 100%);
  border: 3px solid #5a2e12;
  color: #fffdf5;
  box-shadow: 0 3px 0 #5a2e12;
  pointer-events: none;
}

.help-tip-btn:hover {
  background: linear-gradient(180deg, #ff9e62 0%, #ff6a30 100%);
  border-color: #5a2e12;
  transform: none;
}

.help-tip::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 12px;
  height: 12px;
  background: #fffdf2;
  border-right: 3px solid #5a2e12;
  border-bottom: 3px solid #5a2e12;
  transform: translateX(-50%) rotate(45deg);
}

.help-tip.help-tip-below::after {
  top: -8px;
  bottom: auto;
  border-right: none;
  border-bottom: none;
  border-left: 3px solid #5a2e12;
  border-top: 3px solid #5a2e12;
}

.help-tip.help-tip-right::after {
  left: -8px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%) rotate(135deg);
}

.help-tip.help-tip-left::after {
  left: auto;
  right: -8px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%) rotate(-45deg);
}

@media (max-width: 600px) {
  .help-tip {
    width: min(260px, calc(100vw - 24px));
    padding: 10px 12px;
  }

  .help-tip-text {
    font-size: 0.75rem;
  }

  .help-tip-btn {
    padding: 7px 16px;
    font-size: 0.8rem;
  }
}

/* Game Control Buttons */
.game-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin: 8px auto;
  width: 90%;
  max-width: 400px;
  touch-action: manipulation;
}

.control-btn {
  --btn-edge: #1f7a18;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: none;
  background: linear-gradient(180deg, #7ee05a 0%, #3aaa28 100%);
  color: #fffdf5;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  box-shadow: 0 4px 0 var(--btn-edge);
  border: 3px solid var(--btn-edge);
}

.control-btn:hover {
  background: linear-gradient(180deg, #96f070 0%, #4cbe32 100%);
  color: #fffdf5;
}

.control-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 0 var(--btn-edge);
}

/* Jump button - 80% of container */
.jump-btn {
  --btn-edge: #c44a12;
  flex: 4;
  height: 70px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ff9a3c 0%, #ef5a20 100%);
}

.jump-btn:active {
  background: linear-gradient(180deg, #ef5a20 0%, #d04818 100%);
}

.jump-btn svg {
  width: 40px;
  height: 40px;
}

.spacebar-icon {
  width: 120px;
  height: 40px;
}

/* Button tooltips */
.control-btn {
  position: relative;
}

@keyframes tooltip-auto-hide {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

.btn-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #fffdf2;
  color: #5a2e12;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: normal;
  max-width: min(200px, calc(100vw - 24px));
  text-align: center;
  line-height: 1.4;
  border: 3px solid #5a2e12;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  box-shadow: 0 4px 0 #5a2e12;
  box-sizing: border-box;
}

/* Keep tooltips inside the viewport: left btn grows right, right btn grows left */
.jump-btn .btn-tooltip {
  left: 8px;
  right: auto;
  transform: none;
}

.direction-btn .btn-tooltip {
  left: auto;
  right: 8px;
  transform: none;
}

.btn-tooltip::after {
  content: '';
  position: absolute;
  right: 14px;
  bottom: -10px;
  width: 12px;
  height: 12px;
  background: #fffdf2;
  border-right: 3px solid #5a2e12;
  border-bottom: 3px solid #5a2e12;
  transform: rotate(45deg);
}

.game-controls.tooltips-active .btn-tooltip {
  animation: tooltip-auto-hide 7s ease forwards;
}

/* Tutorial: freeze-and-teach highlight on first play */
@keyframes tutorial-btn-pulse {
  0%, 100% {
    box-shadow: 0 4px 0 var(--btn-edge),
                0 0 0 0 rgba(255, 154, 60, 0.55);
  }
  50% {
    box-shadow: 0 4px 0 var(--btn-edge),
                0 0 0 12px rgba(255, 154, 60, 0);
  }
}

@keyframes tutorial-tooltip-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.control-btn.tutorial-highlight {
  animation: tutorial-btn-pulse 1.2s ease-out infinite;
  color: #fffdf5;
}

.control-btn.tutorial-highlight .btn-tooltip {
  opacity: 1;
  animation: tutorial-tooltip-bob 1.2s ease-in-out infinite;
  max-width: min(220px, calc(100vw - 24px));
  width: max-content;
}

/* Keyboard hint line inside tutorial tooltips (desktop only) */
.btn-tooltip .tooltip-key {
  display: block;
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid rgba(90, 46, 18, 0.25);
  font-size: 0.68rem;
  font-weight: 700;
  color: #c07020;
}

/* Spacebar button highlight when flower is reachable */
@keyframes flower-reachable-pulse {
  0%, 100% { color: #fffdf5; }
  50% { color: #ffe566; }
}

.jump-btn.btn-flower-reachable {
  animation: flower-reachable-pulse 0.7s ease-in-out infinite;
}

/* Direction toggle button - 20% of container */
.direction-btn {
  --btn-edge: #1f7a18;
  flex: 1;
  height: 70px;
  border-radius: 16px;
}

.direction-btn svg {
  width: 36px;
  height: 36px;
  color: #fffdf5;
}

/* Show/hide based on device */
.mobile-only {
  display: none;
}

.desktop-only {
  display: flex;
}

.hidden {
  display: none !important;
}

/* Mobile styles */
@media (max-width: 600px) {
  .game-container {
    padding: 8px;
  }

  .game-info {
    font-size: 0.85rem;
  }

  button {
    padding: 10px 20px;
    font-size: 15px;
  }

  .modal-content {
    padding: 24px;
    width: 90%;

    .story-section h1 {
      font-size: 1.8rem;
    }

    .story-section .story-text {
      font-size: 1rem;
    }
  }

  .controls-hint {
    gap: 16px;
    padding: 10px 14px;
    font-size: 0.8rem;
  }

  /* Full height control buttons on mobile */
  .game-controls {
    padding: 0;
    margin: 0;
    gap: 8px;
    width: 100%;
    max-width: none;
    flex: 0 0 auto;
  }

  .control-btn {
    border-radius: 0;
  }

  .jump-btn,
  .direction-btn {
    height: 80px;
    border-radius: 0;
  }

  .sound-btn {
    top: 6px;
    right: 8px;
    width: 36px;
    height: 36px;
    padding: 7px;
  }

  .btn-tooltip,
  .control-btn.tutorial-highlight .btn-tooltip {
    font-size: 0.7rem;
    padding: 5px 10px;
    max-width: min(180px, calc(100vw - 16px));
  }

  .jump-btn .btn-tooltip {
    left: 4px;
  }

  .direction-btn .btn-tooltip {
    right: 4px;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block;
  }

  .mobile-only.hidden {
    display: none !important;
  }
}

/* Subtle animations */
@keyframes gentle-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.modal-content .story-section h1 {
  animation: gentle-pulse 3s ease-in-out infinite;
}

/* Floral modal decorations */
.modal-content.floral-modal {
  position: relative;
  padding: 45px 25px;
  overflow: hidden;
}

.floral-decoration {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: auto;
  pointer-events: none;
  z-index: 1;
}

.floral-top {
  top: -50px;
  transform: scaleY(-1);
}

.floral-bottom {
  bottom: -50px;
}

.modal-inner {
  position: relative;
  z-index: 2;
}
