/* Generic Popup System */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999999;
  opacity: 0;
  transition: opacity 0.2s ease;
  padding: 0;
  box-sizing: border-box;
}

.popup-overlay.visible {
  opacity: 1;
}

.popup-content {
  background: var(--bg-primary);
  border-radius: 12px;
  max-height: calc(100vh - 40px);
  position: relative;
  transform: scale(0.95);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}

.popup-overlay.visible .popup-content {
  transform: scale(1);
}

/* Mobile: Full screen */
@media (max-width: 768px) {
  .popup-content {
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    max-width: none;
    max-height: none;
    border-radius: 0;
    padding-top: 40px;
  }
}

/* Desktop: Full screen popup with centered content */
@media (min-width: 769px) {
  .popup-content {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .popup-header,
  .popup-body,
  .popup-footer {
    width: 100%;
    max-width: 500px; /* Constrain content to gameboard width */
  }
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 20px 24px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.popup-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.popup-close {
  background: none;
  border: none;
  font-size: 40px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.popup-overlay.end-game .popup-close {
  margin-right: 24px;
}

.popup-close:hover {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.popup-body {
  padding: 24px;
  color: var(--text-primary);
  line-height: 1.6;
  overflow-y: auto;
  flex: 1;
}

/* Minimal scrollbar styling */
.popup-body::-webkit-scrollbar {
  width: 6px;
}

.popup-body::-webkit-scrollbar-track {
  background: transparent;
}

.popup-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

[data-theme="dark"] .popup-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

.popup-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .popup-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Firefox */
.popup-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

[data-theme="dark"] .popup-body {
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.popup-footer {
  padding: 0 24px 24px 24px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Popup type variations - End game popup with proper centering */
.popup-overlay.end-game .popup-content {
  width: 100%;
  max-width: 500px;
  height: auto !important; /* Override the 100vh from desktop styles */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  margin: auto 0;
}

.popup-overlay.end-game .popup-header {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 20px 24px 0 24px;
  margin-bottom: 0;
}

.popup-overlay.end-game .popup-title {
  display: none;
}

.popup-overlay.end-game .popup-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

.popup-overlay.end-game .popup-footer {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* End-game popup weight block colors - override all weight classes */
.popup-overlay.end-game .weight-block.target.win,
.popup-overlay.end-game .weight-block.guess.win {
  color: #45AE26 !important;
  border-color: #45AE26 !important;
  background-color: var(--bg-primary) !important;
  box-shadow: none !important;
}

.popup-overlay.end-game .weight-block.target.loss,
.popup-overlay.end-game .weight-block.guess.loss {
  color: #C2331F !important;
  border-color: #C2331F !important;
  background-color: var(--bg-primary) !important;
  box-shadow: none !important;
}

/* Dark theme: lighter colors for better readability */
[data-theme="dark"] .popup-overlay.end-game .weight-block.target.win,
[data-theme="dark"] .popup-overlay.end-game .weight-block.guess.win {
  color: #5ED63F !important;
  border-color: #5ED63F !important;
  background-color: var(--bg-primary) !important;
}

[data-theme="dark"] .popup-overlay.end-game .weight-block.target.loss,
[data-theme="dark"] .popup-overlay.end-game .weight-block.guess.loss {
  color: #D23B26 !important;
  border-color: #D23B26 !important;
  background-color: var(--bg-primary) !important;
}

/* Mobile: larger X and share button */
@media (max-width: 768px) {
  .popup-overlay.end-game .popup-close {
    font-size: 45px;
  }

  .share-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    font-size: 3rem;
    padding: 20px 40px;
    flex: none !important;
  }

  .share-button::before {
    width: 40px;
    height: 40px;
  }
}

/* Button styles for popup footer */
.popup-footer button {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.popup-footer .btn-primary,
.popup-body .btn-primary {
  background-color: #45AE26;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.popup-footer .btn-primary:hover,
.popup-body .btn-primary:hover {
  background-color: #45AE26;
  opacity: 0.9;
  transform: translateY(-1px);
}

.popup-footer .btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.popup-footer .btn-secondary:hover {
  background-color: var(--bg-primary);
  transform: translateY(-1px);
}

/* Share button specific styling */
.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px auto 0 auto;
  padding: 12px 20px;
  background-color: #45AE26;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
  width: fit-content;
}

.share-button:hover {
  transform: translateY(-1px);
}

.share-button::before {
  content: "";
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='white' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.367 2.684 3 3 0 00-5.367-2.684z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Game statistics styling for end-game popup */
.game-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  margin: 20px 0;
  text-align: center;
}

.stat-item {
  background: var(--bg-tertiary);
  padding: 16px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--success-color);
  display: block;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* Results pattern display */
.results-pattern {
  font-family: monospace;
  font-size: 1.5rem;
  line-height: 1.8;
  margin: 16px 0;
  text-align: center;
  letter-spacing: 2px;
}

@media (max-width: 480px) {
  .popup-header {
    padding: 16px 20px 0 20px;
  }

  .popup-body {
    padding: 20px;
  }

  .popup-footer {
    padding: 0 20px 20px 20px;
  }

  .popup-footer button {
    flex: 1;
    min-width: auto;
  }

  .game-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .stat-item {
    padding: 12px 8px;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .results-pattern {
    font-size: 1.2rem;
    letter-spacing: 1px;
  }
}

/* How to Play popup specific styling */
.popup-body h3 {
  margin-top: 20px;
  margin-bottom: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.popup-body h3:first-child {
  margin-top: 0;
}

.popup-body ul {
  margin: 8px 0;
  padding-left: 24px;
}

.popup-body li {
  margin-bottom: 8px;
  line-height: 1.6;
}

.popup-body ul ul {
  margin-top: 4px;
  margin-bottom: 4px;
}

.popup-body p {
  margin: 8px 0;
}

/* Sample components in How to Play */
.sample-balance-scale {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.sample-balance-scale .balance-scale {
  transform: scale(0.8);
  transform-origin: center;
}

.sample-weight-board {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.sample-weight-board .weight-breakdown-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
  justify-content: center;
}

.sample-weight-board .weight-breakdown-row:last-child {
  margin-bottom: 0;
}

@media (max-width: 480px) {
  .sample-balance-scale .balance-scale {
    transform: scale(0.7);
  }

  .sample-weight-board .weight-breakdown-row {
    gap: 2px;
  }
}

/* Bug report and feedback popup vertical centering */
#bug-report-popup .popup-content,
#feedback-popup .popup-content {
  height: auto !important; /* Override the 100vh from desktop styles */
  margin: auto 0;
}

/* Feedback form styling */
.feedback-form {
  width: 100%;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: #45AE26;
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-actions {
  text-align: center;
  margin-top: 24px;
}

.form-message {
  text-align: center;
  padding: 12px;
  border-radius: 6px;
  font-weight: 600;
}

.form-message.success {
  background: rgba(69, 174, 38, 0.1);
  color: #45AE26;
  border: 1px solid #45AE26;
}

.form-message.error {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid #ef4444;
}