body {
  background-color: rgb(15, 15, 35);
}

.gentium-book-plus {
  font-family: "Gentium Book Plus", serif;
  font-weight: 400;
  font-style: normal;
}

.dancing-script {
  font-family: "Dancing Script", cursive;
  font-optical-sizing: auto;
  font-weight: 500;
  font-style: normal;
}

.glow-text {
  color: #ffb347;
  text-shadow:
    0 0 5px #ffb347,
    0 0 10px #ff8c00,
    0 0 20px #ff8c00,
    0 0 40px #ff6600;
}

.no-glow {
  text-shadow: none;
}

.glow-text-green {
  color: #33ff33;
  text-shadow:
    0 0 5px #33ff33,
    0 0 10px #00ff00,
    0 0 20px #00ff00,
    0 0 40px #00cc00;
}

.glow-border {
  border-color: #ffb347;
  box-shadow:
    0 0 5px #ffb347,
    0 0 10px rgba(255, 179, 71, 0.5);
}

.tile-letter {
  background: linear-gradient(145deg, #1a1a3a, #0f0f23);
  border: 2px solid #ffb347;
  color: #ffb347;
  text-shadow:
    0 0 5px #ffb347,
    0 0 10px #ff8c00;
  box-shadow:
    0 0 5px rgba(255, 179, 71, 0.3),
    inset 0 0 10px rgba(255, 179, 71, 0.1);
  transform-style: preserve-3d;
  perspective: 1000px;
}

.tile-space {
  background: rgba(255, 179, 71, 0.15);
  border: 2px solid rgba(255, 179, 71, 0.3);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

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

@keyframes flash-red {
  0% { opacity: 0.5; }
  100% { opacity: 0; }
}

#flash-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 9999;
}

#flash-overlay.flash-green {
  background-color: #22c55e;
  animation: flash-green 0.3s ease-out;
}

#flash-overlay.flash-red {
  background-color: #ef4444;
  animation: flash-red 0.3s ease-out;
}

#fireworks-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
}

#freeze-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  transition: opacity 0.3s ease;
}

#freeze-overlay.active {
  opacity: 1;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 5px #ffb347, 0 0 10px rgba(255, 179, 71, 0.5);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 15px #ffb347, 0 0 30px rgba(255, 179, 71, 0.8), 0 0 45px rgba(255, 140, 0, 0.6);
  }
}

.pulse {
  animation: pulse 1s ease-in-out infinite;
  position: relative;
  z-index: 200;
}

@keyframes flip-tile {
  0% {
    transform: rotateX(0deg);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0deg);
  }
}

.flip-tile {
  animation: flip-tile 1s ease-in-out;
}

#prize-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#prize-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

#prize-overlay .prize-text {
  font-size: 8rem;
  font-weight: bold;
  color: #ffb347;
  text-shadow:
    0 0 10px #ffb347,
    0 0 20px #ff8c00,
    0 0 40px #ff8c00,
    0 0 80px #ff6600;
  text-align: center;
}

#prize-overlay .prize-calculation {
  font-size: 3rem;
  color: #ffb347;
  text-shadow:
    0 0 5px #ffb347,
    0 0 10px #ff8c00;
  margin-bottom: 1rem;
}

@keyframes prize-pop {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

#prize-overlay.active .prize-text {
  animation: prize-pop 0.5s ease-out;
}

/* ---------- responsive layout ---------- */

html, body {
  height: 100dvh;
  overscroll-behavior: none;
}

body {
  margin: 0;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

#delta-bar {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: max(var(--v-space), env(safe-area-inset-top)) clamp(0.5rem, 2vw, 1rem) 0;
  z-index: 50;
}

#jolly-display {
  font-size: clamp(1.2rem, 4vw, 2rem);
  line-height: 1;
  text-shadow: 0 0 10px #ffb347, 0 0 20px #ff8c00;
}

@keyframes jolly-pop {
  0% { transform: scale(0.4) rotate(-25deg); opacity: 0; }
  60% { transform: scale(1.35) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.jolly-pop { animation: jolly-pop 0.7s ease-out; }

#prev-delta-display { font-size: clamp(0.8rem, 2.6vw, 1.5rem); }
#delta-display { font-size: clamp(1rem, 3.4vw, 1.875rem); }

:root { --v-space: clamp(0.5rem, 2vh, 1rem); }

#container {
  padding: var(--v-space) clamp(0.4rem, 2vw, 2rem);
  gap: var(--v-space);
}

#grid {
  column-gap: calc(var(--tile-gap, 0.25rem) * 2.2);
  row-gap: calc(var(--tile-gap, 0.25rem) * 2);
  padding: 0.25rem;
  overflow: hidden;
}

.word-group { gap: var(--tile-gap, 0.25rem); }

/* word separators take less room than a full tile */
.space-tile { width: calc(var(--tile-size, 3rem) * 0.45); }

.tile {
  width: var(--tile-size, 3rem);
  height: var(--tile-h, calc(var(--tile-size, 3rem) * 1.17));
  font-size: var(--tile-font, calc(var(--tile-size, 3rem) * 0.55));
  line-height: 1;
}

#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, 3vw, 2rem);
  flex-wrap: wrap;
}

#hint {
  padding: clamp(0.3rem, 1.5vw, 1rem) clamp(0.6rem, 2.5vw, 1.5rem);
  font-size: clamp(1.5rem, 6vw, 3rem);
  text-align: center;
}

#outcome {
  padding: clamp(0.3rem, 1.5vw, 1rem) clamp(0.6rem, 2.5vw, 1.5rem);
  font-size: clamp(1.1rem, 4.5vw, 2.25rem);
  min-width: clamp(7rem, 32vw, 12rem);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#prize-overlay .prize-text { font-size: clamp(3rem, 18vw, 8rem); }
#prize-overlay .prize-calculation { font-size: clamp(1.25rem, 7vw, 3rem); }

/* ---------- on-screen keyboard (touch devices / small screens) ---------- */

#keyboard {
  --kb-gap: 0.35rem;
  display: none;
  flex-direction: column;
  gap: var(--kb-gap);
  padding: 0 clamp(0.3rem, 2vw, 1rem)
    calc(clamp(0.5rem, 2vh, 1rem) + env(safe-area-inset-bottom));
  background: transparent;
  z-index: 60;
  user-select: none;
}

#keyboard .kb-row {
  display: flex;
  justify-content: center;
  gap: var(--kb-gap);
}

#keyboard button {
  /* every key is the width of 1/10th of a row, like a phone keyboard */
  flex: 0 0 calc((100% - 9 * var(--kb-gap)) / 10);
  min-width: 0;
  height: 2.6rem;
  padding: 0;
  font-family: inherit;
  font-size: clamp(0.85rem, 4vw, 1.25rem);
  font-weight: 700;
  color: #ffb347;
  background: linear-gradient(145deg, #1a1a3a, #0f0f23);
  border: 1px solid rgba(255, 179, 71, 0.6);
  border-radius: 0.4rem;
  text-shadow: 0 0 4px #ff8c00;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#keyboard button.kb-vowel {
  color: #7fd4ff;
  border-color: rgba(127, 212, 255, 0.6);
  text-shadow: 0 0 4px #1e90ff;
}

#keyboard button:active { filter: brightness(1.8); transform: scale(0.95); }
#keyboard button[disabled] {
  opacity: 0.22;
  filter: grayscale(0.6);
  pointer-events: none;
}

body.has-keyboard #keyboard { display: flex; }

/* on wide screens keep the keyboard a comfortable, centered size */
@media (min-width: 820px) {
  #keyboard {
    --kb-gap: 0.4rem;
    width: min(44rem, 90vw);
    margin: 0 auto;
  }
  #keyboard button { height: 3rem; font-size: 1.1rem; }
}
