.overlay-modal {
  position: fixed;
  inset: 0;
  background-color: rgba(22, 47, 78, 0.92);
  backdrop-filter: blur(6px);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 50;
  border-radius: 0;
  text-align: center;
  padding: 20px 20px 28px;
  box-sizing: border-box;
  overflow-y: auto;
}

.overlay-modal.active {
  display: flex;
}

#topup-opening-modal {
  padding: 16px 20px;
  justify-content: center;
  align-items: center;
  gap: 0;
  max-width: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

#topup-opening-modal .topup-opening-content,
#topup-opening-modal > .overlay-actions {
  width: 100%;
  margin: 0;
  max-width: min(90vw, 480px);
}

#topup-opening-modal .topup-opening-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#topup-opening-modal .topup-opening-content > * {
  padding: 0;
}

#topup-opening-modal h2 {
  margin-bottom: 12px;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.3;
}

#topup-opening-modal p {
  font-size: clamp(12px, 3.5vw, 14px);
  line-height: 1.6;
  margin-bottom: 10px;
}

#topup-opening-modal .overlay-actions {
  margin-top: 12px;
}

#go-gate-modal {
  justify-content: center;
  align-items: center;
  gap: 12px;
  z-index: 45;
}

.go-octagon-btn {
  width: clamp(120px, calc(var(--game-size) * 0.42), 200px);
  height: clamp(120px, calc(var(--game-size) * 0.42), 200px);
  border: none;
  cursor: pointer;
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  background: linear-gradient(180deg, #78dc7f 0%, #2e9d44 58%, #1f7b33 100%);
  color: #ffffff;
  font-family: Arial, sans-serif;
  font-size: clamp(30px, calc(var(--game-size) * 0.12), 56px);
  font-weight: 900;
  letter-spacing: 0.06em;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.28),
    inset 0 -6px 12px rgba(0,0,0,0.24),
    0 16px 28px rgba(0,0,0,0.35);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.go-octagon-btn:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.go-octagon-btn:active {
  filter: brightness(0.95);
  transform: translateY(1px);
}

.go-gate-hint {
  color: #dbeafe;
  font-family: Arial, sans-serif;
  font-size: clamp(12px, calc(var(--game-size) * 0.04), 18px);
  letter-spacing: 0.02em;
}

#highscore-entry-modal {
  justify-content: center;
}

#leaderboard-modal {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 680px);
  height: min(620px, 88vh);
  height: min(620px, 88dvh);
  max-height: 88vh;
  max-height: 88dvh;
  border-radius: 16px;
  padding: 20px 24px 24px;
  justify-content: flex-start;
  align-items: flex-start;
  text-align: left;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

#leaderboard-modal .leaderboard-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

#leaderboard-modal > h3,
#leaderboard-modal > .audit-link-container,
#leaderboard-modal > .overlay-actions {
  flex: 0 0 auto;
}

#best-board-modal {
  justify-content: flex-start;
  padding-top: 10px;
  padding-bottom: 10px;
}

.initials-wrapper {
  position: relative;
  display: inline-flex;
  gap: 10px;
  margin: 15px 0;
}

.hidden-initials-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  z-index: 10;
  cursor: pointer;
  font-size: 16px;
}

.initial-tile {
  width: clamp(40px, calc(var(--game-size) * 0.15), 70px);
  height: clamp(40px, calc(var(--game-size) * 0.15), 70px);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(24px, calc(var(--game-size) * 0.1), 48px);
  font-family: Arial, sans-serif;
  font-weight: bold;
  background-color: #fdf6e3;
  color: #1a1a1a;
  border-radius: 6px;
  box-shadow:
    inset 3px 3px 5px rgba(255, 255, 255, 1),
    inset -3px -3px 5px rgba(0, 0, 0, 0.15),
    2px 3px 5px rgba(0, 0, 0, 0.4);
  position: relative;
}

.initial-tile.empty::after {
  content: '';
  position: absolute;
  inset: 0;
}

.initial-tile.active::after {
  content: '|';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(26, 26, 26, 0.75);
  animation: blink-caret 1.2s steps(1) infinite;
}

.initials-wrapper.focused .initial-tile.empty.active {
  background-color: #fff9d6;
}

@keyframes blink-caret {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* NEW WINNER OVERLAY STYLES */
.winner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 35, 60, 0.9);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.winner-overlay.active {
  opacity: 1;
}

.winner-title {
  color: var(--highlight);
  margin-bottom: 12px;
  font-size: 36px;
  text-align: center;
  line-height: 1.2;
  padding: 0 20px;
}

.winner-initials {
  font-size: 72px;
  font-weight: bold;
  color: #FFD700;
  text-shadow: 0 0 16px #ffaa00;
  text-align: center;
}

.help-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 120;
  width: auto;
  min-width: 82px;
}

#help-modal {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 760px);
  max-height: 88vh;
  border-radius: 16px;
  padding: 20px 24px 24px;
  justify-content: flex-start;
  align-items: flex-start;
  text-align: left;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.help-content {
  width: 100%;
  color: #eaf1ff;
  font-size: 15px;
  line-height: 1.5;
}

.help-content h3 {
  margin: 14px 0 8px;
  color: var(--highlight);
  font-size: 18px;
}

.help-content p {
  margin: 6px 0;
}

.help-content ul {
  margin: 6px 0 10px 20px;
  padding: 0;
}

.help-content li {
  margin: 4px 0;
}

.help-content .help-subtle {
  color: #cbd5e1;
  font-size: 13px;
}

.help-content a {
  color: var(--highlight);
}

@media (max-width: 700px) {
  .help-fab {
    right: 12px;
    bottom: 12px;
    min-width: 74px;
  }

  #help-modal {
    width: min(94vw, 760px);
    padding: 16px 18px 18px;
  }

  .help-content {
    font-size: 14px;
  }

  #topup-opening-modal {
    padding: 12px 16px;
  }

  #topup-opening-modal h2 {
    margin-bottom: 10px;
    font-size: clamp(16px, 4.5vw, 22px);
  }

  #topup-opening-modal p {
    font-size: clamp(11px, 3vw, 13px);
    margin-bottom: 8px;
  }

  #topup-opening-modal .overlay-actions {
    margin-top: 10px;
  }
}

@media (max-height: 800px) {
  #topup-opening-modal {
    padding: 10px 16px;
    overflow: hidden;
    max-height: 100vh;
    max-height: 100dvh;
  }

  #topup-opening-modal h2 {
    margin-bottom: 8px;
    font-size: clamp(14px, 4vw, 20px);
  }

  #topup-opening-modal p {
    font-size: clamp(10px, 2.8vw, 12px);
    margin-bottom: 6px;
  }

  #topup-opening-modal .overlay-actions {
    margin-top: 8px;
  }
}