/* ===========================================
   COLOR VARIABLES — Free Press / Zanagrams palette
   =========================================== */
:root {
  /* CTAs — FP blue; snake path uses --color-snake-stroke */
  --snake-green: #4169f1;
  --snake-green-dark: #2f50d8;
  --snake-green-darker: #2744b8;
  --color-snake-stroke: #E56B4A;
  --green: #2e9e5b;
  --green-dark: #278a4f;

  /* Pills & Buttons */
  --pill-bg: #f6f4ef;

  /* Letter Tiles */
  --tile-bg: #d9d5c8;

  /* Text Colors */
  --text-dark: #1c1c1e;
  --text-medium: #616162;
  --text-light: #b8b8b4;
  --text-white: white;

  /* Status Colors */
  --color-bonus: #f59e0b;
  --color-error: #e0524a;
  --color-badge: #e0524a;
  --hint-bg: #F5D0C4;
  --blue: #4169f1;
  --orange: #f59e0b;

  /* Backgrounds */
  --bg-white: #f6f4ef;
  --bg-light: #f0efe9;
  --bg-gray: #e8e6dd;
  --bg-green-light: #e6ecff;
  --bg-green-highlight: #eef2ff;
  --bg-modal: #f6f4ef;

  /* Borders */
  --border-light: #ece9e0;
  --border-medium: #d8d5c9;

  /* Puzzle Status */
  --status-solved: #dff3e6;
  --status-solved-text: #2e9e5b;
  --status-partial: #fdebcf;
  --status-partial-text: #c47d10;
  --status-unsolved: #b8b8b4;

  /* Letter Backgrounds */
  --letter-bg: #e8e6dd;
  --letter-light: #e8e6dd;
  --current-puzzle: #e6ecff;

  /* Rainbow Animation */
  --rainbow-1: #B84451;
  --rainbow-2: #D5713E;
  --rainbow-3: #E9AF34;
  --rainbow-4: #9FAD44;
  --rainbow-5: #8D4B86;

  /* Gray Shades */
  --gray-light: #f0efe9;
  --gray-medium: #b8b8b4;
  --gray-dark: #616162;
  --gray-darker: #444;
  --gray-darkest: #1c1c1e;

  /* Completed tiles use success green (not the blue snake) */
  --tile-complete: #2e9e5b;
}

/* ===========================================
   BASE RESET
   =========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Baloo 2", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
  height: 100%;
}

body {
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  position: fixed;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
  background: var(--bg-white);
  touch-action: none;
  opacity: 1;
  transition: opacity 0.3s ease-in;
  overscroll-behavior: none;
}

body.loading {
  opacity: 0;
}

/* ===========================================
   LAYOUT
   =========================================== */
.container {
  height: 100dvh;
  width: 100%;
  max-width: 440px;
  padding: calc(env(safe-area-inset-top) + 16px) 20px 0px 20px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow: hidden;
}

.container.loaded {
  opacity: 1;
  visibility: visible;
}

/* ===========================================
   HEADER BUTTONS (Menu + Rotate)
   =========================================== */
.rotate-btn,
.help-btn,
.hint-btn,
.menu-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dark);
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
  width: 38px;
  height: 38px;
  box-shadow: none;
  transition: color 0.15s ease;
  flex-shrink: 0;
  text-decoration: none;
}

.rotate-btn:hover,
.help-btn:hover,
.hint-btn:hover,
.menu-btn:hover {
  color: var(--snake-green);
  opacity: 1;
}

.rotate-btn svg,
.help-btn svg,
.hint-btn svg,
.menu-btn svg {
  width: 30px;
  height: 30px;
  display: block;
}

.hint-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: 11px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  pointer-events: none;
}

.hint-btn.shake {
  animation: iconShake .35s ease;
}

@keyframes iconShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.top-right-actions {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
  pointer-events: auto;
}

.rotate-btn svg {
  transition: transform 0.3s ease;
}

.rotate-btn.rotating svg {
  animation: spin 0.6s ease-in-out;
}

.menu-btn:active {
  transform: scale(0.95);
}

/* ===========================================
   GAME LAYOUT
   =========================================== */
.game-content {
  display: flex;
  flex-direction: column;
  overflow: visible;
  margin-top: 24px;
}

@media (min-width: 800px) {
  .game-content {
    flex-direction: column;
    flex-wrap: nowrap;
    row-gap: 20px;
    position: relative;
    align-items: center;
  }

  .letters-column {
    width: 100%;
    max-width: 440px;
  }
}

@media (max-width: 799px) {
  .game-content {
    flex: 1;
    min-height: 0;
  }
}

/* ===========================================
   WORDS COLUMN
   =========================================== */
.words-column {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  order: 0;
  transition: transform 0.4s ease;
}

@media (min-width: 800px) {
  .words-column {
    flex: 1;
    min-width: 0;
    order: 1;
  }

  .words-column.puzzle-completed {
    transform: translateY(-76px);
  }
}

@media (max-width: 799px) {
  .words-column {
    flex: none;
  }
}

.words-list {
  transition: height 0.4s ease, opacity 0.4s ease, margin-bottom 0.4s ease;
  overflow-x: visible;
  height: 185px;
  overflow: scroll;
  text-align: center;
  flex-shrink: 0;
  width: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin-bottom: 0;
  scroll-snap-type: y mandatory;
}

.words-list::-webkit-scrollbar {
  display: none;
}

@media (min-width: 800px) {
  .words-list {
    height: 330px;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
  }

  .words-column.collapsed .words-list {
    height: 0 !important;
    opacity: 0;
    margin-bottom: 0 !important;
    overflow: hidden;
  }
}

@media (max-width: 799px) {
  .words-list {
    height: 200px;
    margin: auto;
    margin-bottom: 60px;
    max-width: 320px;
  }
}

.words {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  width: 100%;
  justify-content: center;
}

.words::-webkit-scrollbar {
  display: none;
}

@media (min-width: 800px) {
  .words {
    justify-content: left;
  }
}

/* ===========================================
   WORD ITEMS
   =========================================== */
.word {
  display: block;
  margin: 0;
  padding: 10px;
  color: var(--letter-light);
  background: transparent;
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  cursor: default;
  position: relative;
  border-radius: 50px;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  box-sizing: border-box;
  transition: color 0.3s ease, background-color 0.3s ease;
  scroll-snap-align: start;
}

.word.bonus {
  display: none;
}

.word.found {
  color: var(--text-dark);
  background: transparent;
}

.word.found.already-found-shake {
  animation: error-shake 0.4s ease;
  color: var(--color-error);
}

.word.bonus.found {
  display: block;
  color: var(--color-bonus);
  background: transparent;
}

/* Found words in the list are not tappable */
#modal-words .word.found,
#modal-words .word.bonus.found {
  cursor: default;
  pointer-events: none;
}

.word-letter-slot {
  display: inline-flex;
  margin: 0;
  padding: 0;
}

.word-letter-dot {
  display: inline-block;
  color: var(--text-dark);
  margin: 0;
  padding: 0;
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: 38px;
  line-height: 1;
  vertical-align: baseline;
  position: relative;
  top: 5px;
  opacity: 1;
}

.word-letter-reveal {
  display: inline-block;
  margin: 0;
  padding: 0;
  color: var(--text-dark);
  opacity: 0;
  max-width: 0;
  overflow: hidden;
}

.word-letter-slot.revealed .word-letter-dot,
.word.found .word-letter-dot {
  opacity: 0;
  max-width: 0;
}

.word-letter-slot.revealed .word-letter-reveal,
.word.found .word-letter-reveal {
  opacity: 1;
  max-width: 1em;
  color: var(--text-dark);
}

.word.bonus.found .word-letter-reveal {
  color: var(--snake-green);
}

.word.animating-reveal .word-letter-reveal {
  animation: letterRevealPop 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--i) * 55ms);
}

/* ===========================================
   FEEDBACK BAR
   =========================================== */
.feedback-wrap {
  font-size: clamp(22px, 6.8vw, 32px);
  font-weight: 800;
  line-height: 1.2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  color: var(--text-dark);
  width: 100%;
  flex-shrink: 0;
  text-align: center;
  order: 1;
  transition: opacity 0.3s ease;
  position: relative;
  gap: 0;
}

.feedback-top {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  pointer-events: none;
}
.feedback-top .top-right-actions {
  pointer-events: auto;
}

@media (min-width: 800px) {
  .feedback-wrap {
    margin-bottom: 12px;
    min-height: 0;
    height: auto;
    order: 0;
    flex-basis: 100%;
  }
}

@media (max-width: 799px) {
  .feedback-wrap {
    height: auto;
    min-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    /* Keep below the shell back button so it stays clickable */
    z-index: 5;
  }
}

.game-content.puzzle-completed .feedback-wrap #feedback-message {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  animation: none !important;
}

/* Word list modal: only show found words (no missing slots) */
#modal-words .word:not(.found) {
  display: none !important;
}

.words-empty {
  margin: 12px 0 0;
  text-align: center;
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 700;
  font-size: 18px;
  color: #616162;
}

.words-empty[hidden],
.words-empty[style*="display: none"] {
  display: none !important;
}

#feedback-message {
  line-height: 1;
  font-size: clamp(22px, 6.8vw, 32px);
  font-weight: 800;
  font-family: "Baloo 2", system-ui, sans-serif;
  color: var(--text-dark);
  white-space: nowrap;
  word-wrap: break-word;
  position: relative;
  z-index: 1;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 32px 0;
  letter-spacing: 0.5px;
  user-select: none;
}

/* Idle state — same slot as forming word (like Zanagrams) */
#feedback-message.words-left {
  color: var(--text-dark);
  font-size: clamp(22px, 6.8vw, 32px);
  cursor: pointer;
  background: none;
  padding: 0;
  box-shadow: none;
}

@media (hover: hover) {
  #feedback-message.words-left:hover {
    color: var(--snake-green, #2e9e5b);
  }
}

#feedback-message.words-left.completed {
  color: var(--green, #2e9e5b);
}

#feedback-message.forming {
  color: var(--color-snake-stroke);
  display: flex;
  background: none;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: clamp(30px, 8vw, 36px);
  font-weight: 800;
  cursor: default;
  letter-spacing: 0;
}

#feedback-message.forming.tap-mode {
  cursor: pointer;
}

#feedback-message.forming.tap-mode:hover {
  transform: scale(1.05);
  opacity: 1;
}

#feedback-message.forming.tap-mode:active {
  transform: scale(0.95);
}

/* Match Zanagrams .forming.res-good wordPop */
#feedback-message.success,
#feedback-message.forming.success {
  color: var(--green);
  letter-spacing: normal;
  animation: wordPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transform-origin: center;
}

#feedback-message.bonus,
#feedback-message.forming.bonus {
  color: var(--orange);
  letter-spacing: normal;
  animation: wordPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transform-origin: center;
}

@keyframes wordPop {
  0%   { transform: scale(0.6); opacity: 0; }
  55%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

#feedback-message.error {
  color: var(--color-error);
  animation: error-shake 0.4s ease;
}

#feedback-message.perfect {
  background: linear-gradient(90deg, #f7c948, #f97316, #e74c9a, #8b5cf6, #3b82f6, #22c55e, #f7c948);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: feedback-pop-in 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), rainbow-scroll 1.5s linear infinite;
  transform-origin: center;
  font-weight: 800;
}

/* ===========================================
   LETTERS COLUMN
   =========================================== */
.letters-column {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  align-items: center;
  transition: transform 0.4s ease;
  order: 2;
}

@media (min-width: 800px) {
  .letters-column {
    flex: 1;
    align-items: stretch;
  }

  .letters-column.puzzle-completed {
    transform: translateY(-76px);
  }
}

@media (max-width: 799px) {
  .letters-column {
    flex: 0 0 auto;
  }

  .letters-column.puzzle-completed {
    transform: translateY(-78px);
  }

  .completion-section.show {
    margin-top: -48px;
  }
}

.letters-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 0;
  width: 100%;
  max-width: 320px;
  padding: 10px;
  align-self: center;
  padding-bottom: 50px;
}

@media (max-width: 799px) {
  .letters-wrap {
    width: 90%;
    max-width: 320px;
  }
}

.letters-grid-wrap {
  flex: 1;
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 800px) {
  .letters-grid-wrap {
    align-items: flex-start;
  }
}

/* ===========================================
   SNAKE SVG
   =========================================== */
.snake-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.snake-svg #snake-head {
  display: none;
}

#snake-poly {
  transition: stroke 0.12s ease-out;
}

/* Success / extra-word snake — keep path visible, recolour, pulse with found word */
#snake-poly.res-good {
  stroke: var(--green) !important;
}
#snake-poly.res-bonus {
  stroke: var(--orange) !important;
}
/* Match Zanagrams tile/path pop timing (.62s) */
.snake-svg.snake-success-pulse {
  transform-origin: center center;
  animation: snakeSuccessPulse var(--snake-pop-ms, 0.62s) cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes snakeSuccessPulse {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.letter.res-good::before {
  background: var(--green);
}
.letter.res-good .letter-text {
  color: #fff;
}
.letter.res-bonus::before {
  background: var(--orange);
}
.letter.res-bonus .letter-text {
  color: #fff;
}
.letter.letter-success-pop {
  animation: letterSuccessPop 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 55ms);
  z-index: 4;
}
@keyframes letterSuccessPop {
  0%   { transform: scale(1); }
  65%  { transform: scale(1.16); }
  100% { transform: scale(1); }
}

/* ===========================================
   LETTER TILES
   =========================================== */
.letters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.letters.grid-4x4 {
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.letter {
  width: 100% !important;
  height: 0 !important;
  padding-bottom: 100%;
  font-size: 40px;
  position: relative;
  display: block !important;
  font-weight: 700;
  border-radius: 10px;
  transition: all 0.15s ease-out;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  color: var(--text-dark);
}

.letters.grid-4x4 .letter {
  font-size: 36px;
}

.letter::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--tile-bg);
  border-radius: 10px;
  z-index: 2;
  box-shadow: none;
}

.letter-text {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  z-index: 2;
  color: inherit;
  pointer-events: none;
}

.letter-counter {
  position: absolute;
  bottom: 7px;
  right: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-dark);
  z-index: 3;
  pointer-events: none;
}

.letters.grid-4x4 .letter-counter {
  font-size: 14px;
  bottom: 4px;
  right: 6px;
}

.letter.selected .letter-text {
  color: var(--text-white);
}

.letter.hint-letter::before {
  background: var(--hint-bg);
}
.letter.hint-letter .letter-text {
  color: #8B3F2C;
}

@keyframes hintPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes hintTint {
  0% { background: var(--letter-bg); }
  35% { background: var(--color-snake-stroke); }
  100% { background: var(--hint-bg); }
}
@keyframes hintTintLit {
  0% { background: var(--hint-bg); }
  35% { background: var(--color-snake-stroke); }
  100% { background: var(--hint-bg); }
}
.letter.hint-pulse {
  animation: hintPop .85s cubic-bezier(.34, 1.56, .64, 1) both;
  z-index: 3;
}
.letter.hint-pulse::before {
  animation: hintTint .85s ease both;
}
.letter.hint-pulse-lit {
  animation: hintPop .85s cubic-bezier(.34, 1.56, .64, 1) both;
  z-index: 3;
}
.letter.hint-pulse-lit::before {
  animation: hintTintLit .85s ease both;
}
.letter.hint-pulse .letter-text,
.letter.hint-pulse-lit .letter-text {
  color: #1e2a55;
}

.letter.completed-green::before {
  background: var(--tile-complete, var(--snake-green));
}

.letter.completed-green .letter-text {
  color: var(--text-white);
}

.letter.anticipation-pulse {
  animation: anticipationPulse 0.4s ease-out;
}

.letter.green-sweep::before {
  animation: greenSweep 0.3s ease-out forwards;
}

.letter.wave-animate {
  animation: dramaticWave 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.letter.rainbow-animate::before {
  animation: rainbowBackgrounds 1.5s ease-in-out !important;
}

.letter.rainbow-animate .letter-text {
  color: var(--text-white);
}

.letter.settle-pop {
  animation: settlePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.letter.celebration-dance {
  animation: celebrationWiggle 0.9s ease-in-out both;
}

.letters.grid-success-pulse {
  animation: gridSuccessPulse 0.5s ease;
}

/* ===========================================
   PLAYERS SOLVED + SEE RESULTS
   =========================================== */
.players-solved-text {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-dark);
  text-align: center;
  margin-top: 80px;
  display: none;
}

.see-results-btn {
  background: var(--pill-bg);
  border: none;
  color: var(--text-dark);
  padding: 14px 24px;
  border-radius: 24px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  width: fit-content;
  align-self: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  margin-top: -62px;
  z-index: 999;
}

.see-results-btn:hover {
  opacity: 0.7;
}

.see-results-btn:active {
  opacity: 0.5;
}

/* ===========================================
   COMPLETION SECTION
   =========================================== */
.completion-section {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 30px;
  padding-top: 20px;
  flex-shrink: 0;
  opacity: 0;
  animation: celebrateIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.completion-section.show {
  display: flex;
}

.completion-time {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-dark);
  text-align: center;
  line-height: 1.3;
}

.completion-ranking {
  font-size: 26px;
  font-weight: 600;
  color: var(--snake-green);
  text-align: center;
  margin-top: 8px;
}

.more-puzzles-button {
  background: linear-gradient(135deg, var(--snake-green), var(--snake-green-dark));
  border: none;
  color: var(--text-white);
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  max-width: 260px;
  text-transform: none;
  margin-top: 24px;
}

.more-puzzles-button:hover {
  background: linear-gradient(135deg, var(--snake-green-dark), var(--snake-green-dark));
  transform: translateY(-2px);
}

.more-puzzles-button:active {
  transform: translateY(0);
}

/* ===========================================
   LOADER
   =========================================== */
.loader-overlay,
.loader-overlay.show {
  display: none !important;
}

.loader-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(26, 26, 26, 0.08);
  border-top-color: rgba(26, 26, 26, 0.28);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0;
}

.loader-text,
.loader-subtext {
  display: none;
}

/* ===========================================
   MODALS — BASE
   =========================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal-overlay::-webkit-scrollbar {
  display: none;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.show .modal {
  transform: scale(1);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 28px 24px 22px;
  max-width: 400px;
  width: 100%;
  border: 2px solid #2B2B2B;
  box-shadow: none;
  transform: scale(0.8);
  text-align: left;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
  max-height: min(58dvh, calc(100dvh - 96px));
  margin: auto 0;
  flex-shrink: 0;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body:has(.modal-overlay.show) {
  overflow: hidden !important;
  overscroll-behavior: none;
}

.modal::-webkit-scrollbar {
  display: none;
}

.modal-header {
  margin-bottom: 24px;
  text-align: center;
  position: relative;
}

.modal-word {
  font-size: 24px;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--gray-darkest);
}

.modal-close-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #2B2B2B;
  font-size: 26px;
  font-weight: 600;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  z-index: 3;
  padding: 0;
}

.modal-close-x:hover {
  background: rgba(0, 0, 0, .06);
  color: #2B2B2B;
}

.modal-close {
  background: #2B2B2B;
  border: 2px solid #2B2B2B;
  color: #fff;
  padding: 12px 24px;
  border-radius: 999px;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  box-shadow: none;
  width: 100%;
  margin-top: 16px;
}

.modal-close:hover {
  background: #3D3D3D;
  border-color: #3D3D3D;
  transform: none;
  box-shadow: none;
}

.modal-close:active {
  transform: translateY(0);
}

/* ===========================================
   INFO / ABOUT / HOW-TO-PLAY CONTENT
   =========================================== */
.info-title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  margin-bottom: 12px;
  text-align: center;
  padding: 0 28px;
}

.info-content {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--gray-darker);
  text-align: left;
}

.info-content h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-darkest);
  margin: 20px 0 10px 0;
}

.info-content p {
  margin-bottom: 12px;
}

.info-content ul {
  margin: 12px 0;
  padding-left: 20px;
}

.info-content li {
  margin-bottom: 8px;
}

.info-content a {
  color: var(--snake-green);
  text-decoration: none;
  font-weight: 600;
}

.info-content a:hover {
  text-decoration: underline;
}

.info-highlight {
  background: var(--bg-green-highlight);
  padding: 12px;
  border-radius: 8px;
  border-left: 4px solid var(--snake-green);
  margin: 16px 0;
  font-weight: 500;
}

.how-to-play-modal,
.privacy-terms-modal {
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.how-to-play-modal::-webkit-scrollbar,
.privacy-terms-modal::-webkit-scrollbar {
  display: none;
}

/* How to play — match Zanagrams / 18 Words numbered steps */
.how-to-play-modal .how-modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: static;
  margin-bottom: 12px;
  padding-bottom: 0;
}

.how-to-play-modal .how-modal-header .info-title {
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: 24px;
  font-weight: 800;
  margin: 0;
  text-align: center;
}

.how-to-play-modal .how-modal-header .modal-close-x {
  top: 10px;
  right: 10px;
  transform: none;
}

.how-body {
  font-size: 18px;
  line-height: 1.55;
  color: var(--text-dark);
  text-align: left;
}

.how-subhead {
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 800;
  font-size: 20px;
  color: var(--text-dark);
  margin: 26px 0 16px;
}

.how-steps {
  list-style: none;
  margin: 0;
  padding: 0;
}

.how-steps li {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 16px;
  font-size: 18px;
  line-height: 1.5;
  font-weight: 600;
  color: var(--text-dark);
}

.how-steps li:last-child {
  margin-bottom: 0;
}

.how-steps .num {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--snake-green);
  color: #fff;
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(65, 105, 241, 0.35);
}

.how-section.is-controls .how-steps .num {
  background: var(--tile-complete, #2e9e5b);
  box-shadow: 0 2px 6px rgba(46, 158, 91, 0.35);
}

/* ===========================================
   MENU MODAL
   =========================================== */
.menu-modal {
  text-align: left;
}

.menu-title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  margin: 0;
  padding: 0 28px;
  line-height: inherit;
  text-align: center;
}

.menu-links {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.menu-link {
  background: none;
  border: none;
  color: var(--gray-darkest);
  padding: 15px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

.menu-link:hover {
  background: var(--bg-gray);
  border-color: var(--border-medium);
  transform: translateY(-1px);
}

.menu-link:active {
  transform: translateY(0);
}

.menu-dark-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
}

.menu-dark-mode-row:hover {
  transform: none;
}

.dark-mode-toggle {
  position: relative;
  width: 44px;
  height: 26px;
  background: var(--bg-gray);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.25s ease;
  flex-shrink: 0;
  border: 2px solid var(--border-light);
}

.dark-mode-toggle.active {
  background: var(--snake-green);
  border-color: var(--snake-green);
}

.dark-mode-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  transition: transform 0.25s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.dark-mode-toggle.active .dark-mode-toggle-knob {
  transform: translateX(18px);
}

/* ===========================================
   RESULTS MODAL
   =========================================== */
#results-overlay {
  padding-top: 120px;
  align-items: flex-start;
}

#results-overlay .modal {
  margin: 0 20px;
}

.results-modal {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.results-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
  margin-top: -8px;
  margin-bottom: 0px;
  line-height: 40px;
}

.results-time {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 20px;
  text-align: center;
}

.results-ranking {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 25px;
  text-align: center;
}

.results-share-button {
  background: var(--snake-green);
  border: none;
  color: var(--text-white);
  padding: 12px 32px;
  border-radius: 50px;
  font-size: 19px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  width: fit-content;
  text-transform: none;
  margin-bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.results-share-button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.results-share-button:hover {
  background: var(--snake-green-darker);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(94, 141, 90, 0.3);
}

.results-share-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(94, 141, 90, 0.3);
}

.results-change-puzzle-button {
  gap: 0;
}

.results-streak {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-dark);
  text-align: center;
  margin-bottom: 20px;
}

.results-stats {
  margin-bottom: 12px;
  width: 100%;
}

.results-try-master {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-dark);
  text-align: center;
  margin-top: 10px;
  cursor: pointer;
}

.results-try-master-link {
  text-decoration: underline;
}

.stat-label {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-dark);
  text-align: center;
  line-height: 1.3;
  max-width: 80px;
}

/* ===========================================
   PUZZLE LIST MODAL
   =========================================== */
.puzzle-list-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.puzzle-tab {
  flex: 1;
  padding: 10px 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  background: var(--pill-bg);
  border-radius: 20px;
  text-decoration: none;
  transition: opacity 0.2s ease;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08), 0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

.puzzle-tab.active {
  background: var(--snake-green);
  color: var(--text-white);
}

.puzzle-list-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 16px;
}

.puzzle-list-note {
  font-size: 14px;
  color: var(--text-light);
  text-align: center;
  margin-bottom: 22px;
}

.puzzle-list {
  max-height: 270px;
  overflow-y: auto;
  margin-bottom: 20px;
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.puzzle-list::-webkit-scrollbar {
  display: none;
}

.puzzle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-white);
}

.puzzle-item.current {
  background: var(--current-puzzle);
  border-color: var(--snake-green);
  border-width: 1px;
}

.puzzle-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.puzzle-number {
  font-weight: 600;
  font-size: 16px;
  color: var(--gray-darkest);
}

.puzzle-details {
  font-size: 14px;
  color: var(--text-medium);
  margin-top: 2px;
}

.puzzle-status {
  font-weight: 600;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
}

.puzzle-status.solved {
  background: var(--status-solved);
  color: var(--status-solved-text);
}

.puzzle-status.partial {
  background: var(--status-partial);
  color: var(--status-partial-text);
}

.puzzle-status.unsolved {
  background: var(--bg-light);
  color: var(--status-unsolved);
}

/* ===========================================
   MILESTONE MODALS
   (first-letter-counter, two-thirds, first-drag, first-bonus)
   =========================================== */
.first-letter-counter-modal,
.two-thirds-modal,
.first-drag-modal,
.first-bonus-modal {
  text-align: center;
}

.first-letter-counter-title,
.two-thirds-title,
.first-drag-title,
.first-bonus-title,
.hint-title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--text-dark);
  padding: 0 28px;
}

.first-bonus-title.bonus-title {
  color: var(--orange);
}

.first-letter-counter-message,
.two-thirds-message,
.first-drag-message,
.first-bonus-message,
.hint-body {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-medium);
  margin-top: 12px;
}

.first-bonus-message.bonus-body {
  font-size: 19px;
  color: var(--text-dark);
  max-width: 300px;
  margin: 12px auto 0;
  text-align: center;
}
.first-bonus-message.bonus-body p {
  margin: 0 0 14px;
}
.first-bonus-message.bonus-body p:last-child {
  margin-bottom: 0;
}

.btn-bonus {
  background: var(--orange) !important;
  box-shadow: 0 8px 18px rgba(245, 158, 11, .38) !important;
}
.btn-bonus:hover {
  filter: brightness(.97);
  background: var(--orange) !important;
}

.modal-hint {
  text-align: center;
  max-width: 400px;
}
.hint-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.hint-actions .btn {
  flex: 1;
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: 17px;
  border-radius: 999px;
  cursor: pointer;
  border: none;
  padding: 14px 18px;
  touch-action: manipulation;
}
.hint-actions .btn-primary {
  background: var(--blue);
  color: #fff;
}
.hint-actions .btn-secondary {
  background: transparent;
  color: var(--text-dark);
  border: 3px solid var(--text-dark);
}

.first-drag-message-desktop {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .first-drag-message-mobile {
    display: none;
  }
  .first-drag-message-desktop {
    display: inline;
  }
}

.first-letter-counter-continue-button,
.two-thirds-continue-button,
.first-drag-continue-button,
.first-bonus-continue-button,
.continue-playing-button,
.feedback-button {
  background: linear-gradient(135deg, var(--snake-green), var(--snake-green-dark));
  border: none;
  color: var(--text-white);
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 3px 10px rgba(76, 175, 80, 0.3);
  width: 100%;
  margin-top: 20px;
  text-transform: none;
}

.feedback-button {
  display: block;
  font-size: 18px;
  text-decoration: none;
  text-align: center;
}

.first-letter-counter-continue-button:hover,
.two-thirds-continue-button:hover,
.first-drag-continue-button:hover,
.first-bonus-continue-button:hover,
.continue-playing-button:hover,
.feedback-button:hover {
  background: linear-gradient(135deg, var(--snake-green-dark), var(--snake-green-dark));
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

.first-letter-counter-continue-button:active,
.two-thirds-continue-button:active,
.first-drag-continue-button:active,
.first-bonus-continue-button:active,
.continue-playing-button:active,
.feedback-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.first-letter-counter-continue-button:disabled,
.two-thirds-continue-button:disabled,
.first-drag-continue-button:disabled,
.first-bonus-continue-button:disabled,
.continue-playing-button:disabled,
.feedback-button:disabled,
.first-letter-counter-continue-button.disabled,
.two-thirds-continue-button.disabled,
.first-drag-continue-button.disabled,
.first-bonus-continue-button.disabled,
.continue-playing-button.disabled,
.feedback-button.disabled {
  background: linear-gradient(135deg, #a5a5a5, #8c8c8c);
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  opacity: 0.7;
}

/* ===========================================
   WORD DEFINITION MODAL (single word)
   =========================================== */
.word-def-modal {
  text-align: left;
  padding-top: 20px;
}

.word-def-name {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-dark);
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  margin-top: 16px;
  line-height: 1;
}

.word-def-name.bonus {
  color: var(--snake-green);
}

.word-def-definition {
  font-size: 17px;
  color: var(--gray-darker);
  line-height: 1.55;
  margin: 0 0 8px 0;
}

.word-def-example {
  font-size: 16px;
  color: #999;
  font-style: italic;
  line-height: 1.45;
  margin: 0;
}

/* ===========================================
   WORD LIST MODAL (progress pill)
   =========================================== */
.definitions-modal {
  max-height: min(70vh, 560px);
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
}

.definitions-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-dark);
  text-align: center;
}

.definitions-modal .words-list {
  height: auto !important;
  max-height: none;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px 0 0;
  text-align: center;
  scroll-snap-type: none;
}

.definitions-modal .words {
  justify-content: center;
  padding-bottom: 8px;
}

/* ===========================================
   DARK MODE
   =========================================== */
body.dark-mode {
  --pill-bg: #2a2a2a;
  --tile-bg: #2e2e2e;

  --text-dark: #efefef;
  --text-medium: #aaa;
  --text-light: #777;

  --bg-white: #1a1a1a;
  --bg-light: #222;
  --bg-gray: #333;
  --bg-green-light: #1e2f1e;
  --bg-green-highlight: #1b281b;
  --bg-modal: #121212;

  --border-light: #383838;
  --border-medium: #444;

  --status-solved: #1e3d1e;
  --status-solved-text: #66bb6a;
  --status-partial: #3a2800;
  --status-partial-text: #ffb74d;
  --status-unsolved: #888;

  --letter-bg: #2e2e2e;
  --letter-light: #2a2a2a;
  --current-puzzle: #1e2f1e;

  --gray-light: #222;
  --gray-medium: #999;
  --gray-dark: #aaa;
  --gray-darker: #bbb;
  --gray-darkest: #dedede;
}

body.dark-mode .modal-close-x:hover {
  background: #333;
}

body.dark-mode .definitions-word-example {
  color: #777;
}

/* ===========================================
   KEYFRAME ANIMATIONS
   =========================================== */
@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes letterRevealPop {
  0%   { opacity: 0; transform: scale(0.3) translateY(6px); }
  65%  { opacity: 1; transform: scale(1.2) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes celebrateIn {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes rainbow-scroll {
  0%   { background-position: 0% center; }
  100% { background-position: 200% center; }
}

@keyframes success-pulse {
  0%, 100% { transform: scale(1); }
  30%       { transform: scale(1.15); }
  60%       { transform: scale(0.95); }
}

@keyframes feedback-pop-in {
  0%   { transform: scale(0.3) rotateZ(-10deg); opacity: 0; }
  50%  { transform: scale(1.2) rotateZ(5deg); }
  100% { transform: scale(1) rotateZ(0deg); opacity: 1; }
}

@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

@keyframes anticipationPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.05); }
}

@keyframes greenSweep {
  0%   { background: var(--letter-bg); }
  100% { background: var(--tile-complete, var(--snake-green)); }
}

@keyframes dramaticWave {
  0%, 100%  { transform: translateY(0) scale(1); }
  40%, 60%  { transform: translateY(-40px) scale(1.1); }
}

@keyframes rainbowBackgrounds {
  0%   { background: var(--rainbow-1); }
  20%  { background: var(--rainbow-2); }
  40%  { background: var(--rainbow-3); }
  60%  { background: var(--rainbow-4); }
  80%  { background: var(--rainbow-5); }
  100% { background: var(--tile-complete, var(--snake-green)); }
}

@keyframes settlePop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes celebrationWiggle {
  0%   { transform: rotate(0deg); }
  15%  { transform: rotate(-6deg); }
  35%  { transform: rotate(6deg); }
  55%  { transform: rotate(-4deg); }
  75%  { transform: rotate(4deg); }
  90%  { transform: rotate(-1deg); }
  100% { transform: rotate(0deg); }
}

@keyframes gridSuccessPulse {
  0%, 100% { transform: scale(1); }
  30%       { transform: scale(1.03); }
  60%       { transform: scale(0.98); }
}
