/**
 * Game Detail Modal Styles
 * Modal overlay + responsive bottom sheet for game detail panels
 * Enqueued on state hub pages alongside state-hub-styles.css
 *
 * Requirements: 3.1, 3.2, 3.3, 8.8
 */

/* ============================================
   SCOPED GAME DETAIL VARIABLES
   Only apply inside the modal overlay —
   prevents :root color leaks onto the hub page.
   ============================================ */

.sp-modal-overlay {
  --color-primary: #3b82f6;
  --color-primary-contrast: #ffffff;
  --color-success: #319B42;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-highlight: #004986;
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f8f9fa;
  --color-bg-tertiary: #e9ecef;
  --color-border-light: #e0e0e0;
  --color-border-medium: #d1d5db;
}

/* ============================================
   HIDDEN PANELS — Zero Paint Cost
   ============================================ */

.game-detail-panel[hidden] {
  display: none !important;
}

/* ============================================
   OVERLAY — Covers viewport
   ============================================ */

.sp-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.sp-modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   CONTAINER — Desktop centered dialog
   ============================================ */

.sp-modal-container {
  background: #fff;
  border-radius: 12px;
  max-width: 800px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  opacity: 0;
  transition: transform 300ms ease, opacity 300ms ease;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.sp-modal-overlay.is-open .sp-modal-container {
  transform: translateY(0);
  opacity: 1;
}

/* ============================================
   DRAG HANDLE — Mobile pill indicator
   ============================================ */

.sp-modal-drag-handle {
  display: none;
  width: 36px;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  margin: 8px auto 0;
  flex-shrink: 0;
}

/* ============================================
   HEADER — Sticky with close button
   ============================================ */

.sp-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
  gap: 1rem;
}

/* Modal title */
#sp-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Close button */
.sp-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 150ms ease, color 150ms ease;
}

.sp-modal-close:hover {
  background: #e5e7eb;
  color: #1a1a1a;
}

.sp-modal-close:focus-visible {
  outline: 2px solid #319B42;
  outline-offset: 2px;
}

/* ============================================
   BODY — Scrollable content area
   ============================================ */

.sp-modal-body {
  overflow-y: auto;
  padding: 1.5rem;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
   INSTANT CONTENT — Pre-rendered panel content
   ============================================ */

.sp-modal-instant-content {
  margin-bottom: 1.5rem;
}

/* ============================================
   KEY STATS GRID
   ============================================ */

.gdp-key-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.gdp-stat {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: center;
}

.gdp-stat::before {
  content: attr(data-label);
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

/* The stat value itself */
.gdp-stat {
  font-size: 1.125rem;
  font-weight: 700;
  color: #1a1a1a;
}

/* ============================================
   WARNING BANNER (all top prizes claimed)
   ============================================ */

.gdp-warning-banner {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  color: #856404;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.gdp-warning-banner .warning-icon {
  flex-shrink: 0;
}

/* ============================================
   GAME HEADER (image + meta)
   ============================================ */

.gdp-game-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.gdp-game-image {
  flex-shrink: 0;
}

.gdp-game-image img {
  border-radius: 8px;
  width: 120px;
  height: auto;
  object-fit: contain;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.gdp-game-meta {
  flex: 1;
}

.gdp-game-number {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0;
}

@media (max-width: 768px) {
  .gdp-game-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .gdp-game-image img {
    width: 100px;
  }
}

/* ============================================
   AI ANALYSIS SECTION
   ============================================ */

.gdp-analysis {
  margin-bottom: 1.5rem;
}

.gdp-analysis h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0 0 0.75rem 0;
}

.gdp-analysis-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #374151;
}

.gdp-analysis-text p {
  margin: 0 0 0.75rem 0;
}

.gdp-analysis-text p:last-child {
  margin-bottom: 0;
}

/* ============================================
   AJAX CONTENT — Prize tables loaded via AJAX
   ============================================ */

.sp-modal-ajax-content {
  border-top: 1px solid #e9ecef;
  padding-top: 1.5rem;
}

/* aria-live region — visually integrated, screen reader announced */
.sp-modal-ajax-content[aria-live] {
  position: relative;
}

/* ============================================
   LOADING STATE — Spinner animation
   ============================================ */

.sp-modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: #6b7280;
  font-size: 0.9rem;
}

.sp-modal-loading::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid #e9ecef;
  border-top-color: #319B42;
  border-radius: 50%;
  animation: sp-spin 0.6s linear infinite;
  margin-right: 0.75rem;
  flex-shrink: 0;
}

@keyframes sp-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   ERROR STATE — With retry button
   ============================================ */

.sp-modal-error {
  text-align: center;
  padding: 2rem 1rem;
  color: #6b7280;
}

.sp-modal-error p {
  margin: 0 0 1rem 0;
  font-size: 0.9rem;
}

.sp-modal-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background: #319B42;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.sp-modal-retry-btn:hover {
  background: #277a34;
}

.sp-modal-retry-btn:focus-visible {
  outline: 2px solid #319B42;
  outline-offset: 2px;
}

/* ============================================
   HISTORY CHART MOUNT
   ============================================ */

.sp-modal-chart-mount {
  margin-top: 1.5rem;
  border-top: 1px solid #e9ecef;
  padding-top: 1.5rem;
  min-height: 200px;
}

.sp-modal-chart-mount p {
  color: #6b7280;
  font-size: 0.9rem;
  font-style: italic;
  text-align: center;
  padding: 2rem 1rem;
}

/* ============================================
   HISTORY CHART — In-modal mount (Task 7.1)
   Styles for the .gdp-history-mount element
   inside .sp-modal-instant-content
   ============================================ */

.sp-modal-instant-content .gdp-history-mount {
  margin-top: 1.5rem;
  border-top: 1px solid #e9ecef;
  padding-top: 1.5rem;
  min-height: 180px;
}

.sp-modal-instant-content .gdp-history-mount > p {
  color: #6b7280;
  font-size: 0.9rem;
  font-style: italic;
  text-align: center;
  padding: 1.5rem 1rem;
  margin: 0;
}

/* Chart error state */
.sp-chart-error {
  text-align: center;
  padding: 2rem 1rem;
  color: #6b7280;
}

.sp-chart-error p {
  margin: 0 0 1rem 0;
  font-size: 0.9rem;
}

.sp-chart-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  background: #319B42;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 150ms ease;
}

.sp-chart-retry-btn:hover {
  background: #277a34;
}

.sp-chart-retry-btn:focus-visible {
  outline: 2px solid #319B42;
  outline-offset: 2px;
}

/* Chart insufficient data state */
.sp-chart-insufficient {
  text-align: center;
  padding: 2rem 1rem;
  color: #6b7280;
}

.sp-chart-insufficient p {
  margin: 0;
  font-size: 0.9rem;
  font-style: italic;
}

/* ============================================
   MODAL CONTENT LAYOUT — Mobile App Style
   Translates the React Native GameDetailScreen
   design into CSS for the web modal content.
   
   Colors:
   - primary: #004986 (deep blue)
   - success: #319B42 (green)
   - textPrimary: #1A1A1A
   - textSecondary: #5B6770
   - background: #F5F5F5 (section gaps)
   - surface: #FFFFFF (card bg)
   - border: #E0E0E0
   ============================================ */

/* Override the game detail container inside modal */
.sp-modal-body .scratcher-game-detail-container {
  max-width: 100%;
  padding: 0;
  background-color: #F5F5F5;
  border-radius: 0;
  border: none;
}

/* Force single column flow */
.sp-modal-body .game-overview-layout {
  display: block;
}

.sp-modal-body .game-overview-left {
  position: static;
  margin-bottom: 0;
}

/* Image — full width, short, no border radius (like mobile) */
.sp-modal-body .game-image {
  margin-bottom: 0;
}

.sp-modal-body .game-image img {
  width: 100%;
  max-width: 100%;
  max-height: 200px;
  height: auto;
  object-fit: contain;
  border-radius: 0;
  box-shadow: none;
  display: block;
}

.sp-modal-body .image-placeholder {
  width: 100%;
  max-width: 100%;
  height: 160px;
  border-radius: 0;
}

/* Title section — white card below image */
.sp-modal-body .game-header {
  display: block;
}

.sp-modal-body .game-title-section {
  background: #FFFFFF;
  padding: 16px;
  margin-bottom: 8px;
  text-align: left;
}

.sp-modal-body .game-title-section h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #1A1A1A;
  margin: 0 0 4px 0;
  line-height: 1.2;
}

.sp-modal-body .game-meta {
  font-size: 0.8rem;
  color: #5B6770;
  margin: 0;
}

/* Sections — white cards with spacing and separator between */
.sp-modal-body .section {
  background-color: #FFFFFF;
  border: none;
  border-radius: 0;
  padding: 16px;
  margin-bottom: 0;
  border-bottom: 1px solid #E0E0E0;
}

.sp-modal-body .section:last-child {
  border-bottom: none;
}

.sp-modal-body .section h2 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5B6770;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px 0;
}

.sp-modal-body .section-compact {
  padding: 16px;
  margin-bottom: 0;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid #E0E0E0;
}

.sp-modal-body .section-compact h2 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5B6770;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px 0;
}

/* Stats grid — horizontal row with centered items, light gray bg */
.sp-modal-body .stats-grid,
.sp-modal-body .status-grid,
.sp-modal-body .analysis-grid,
.sp-modal-body .ticket-stats-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  background: #F5F5F5;
  border-radius: 12px;
  padding: 8px 0;
  gap: 0;
}

.sp-modal-body .stat-card,
.sp-modal-body .status-item,
.sp-modal-body .analysis-item,
.sp-modal-body .ticket-stat {
  flex: 1;
  min-width: 80px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 4px;
  text-align: center;
}

.sp-modal-body .stat-label,
.sp-modal-body .status-label,
.sp-modal-body .analysis-label,
.sp-modal-body .ticket-stat-label {
  font-size: 0.65rem;
  color: #5B6770;
  text-align: center;
  margin-bottom: 4px;
  text-transform: none;
  letter-spacing: 0;
}

.sp-modal-body .stat-value,
.sp-modal-body .status-value,
.sp-modal-body .analysis-value,
.sp-modal-body .ticket-stat-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1A1A1A;
  text-align: center;
}

.sp-modal-body .stat-value-highlight {
  color: #004986;
}

/* Status explanation */
.sp-modal-body .status-explanation {
  background: #F5F5F5;
  border-left: 4px solid #004986;
  padding: 8px 12px;
  border-radius: 4px;
  margin-top: 8px;
}

.sp-modal-body .status-explanation p {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: #5B6770;
}

/* Warning banner — compact */
.sp-modal-body .warning-banner {
  background: #FFEBEE;
  border: 2px solid #D32F2F;
  border-radius: 0;
  padding: 12px 16px;
  margin-bottom: 8px;
}

/* Game analysis section */
.sp-modal-body .game-analysis {
  background: #FFFFFF;
  margin-bottom: 8px;
}

.sp-modal-body .game-analysis .analysis-text {
  font-size: 0.85rem;
  color: #1A1A1A;
  line-height: 1.6;
}

/* Prize table — tighter for modal */
.sp-modal-body .prize-table {
  font-size: 0.75rem;
}

.sp-modal-body .prize-table th {
  font-size: 0.7rem;
  padding: 8px 4px;
  background: #F5F5F5;
}

.sp-modal-body .prize-table td {
  padding: 6px 4px;
}

/* Disclaimer */
.sp-modal-body .additional-info {
  background: transparent;
  border: none;
  padding: 12px 16px;
}

.sp-modal-body .disclaimer {
  background: transparent;
  border-left: none;
  padding: 0;
}

.sp-modal-body .disclaimer p {
  font-size: 0.75rem;
  color: #5B6770;
  line-height: 1.5;
}

/* Data freshness inside modal */
.sp-modal-body .sp-modal-freshness {
  background: #FFFFFF;
  padding: 10px 16px;
  margin-bottom: 0;
  font-size: 0.8rem;
  color: #5B6770;
  border-bottom: 1px solid #E0E0E0;
}

/* ============================================
   MOBILE — Bottom sheet (≤768px)
   ============================================ */

@media (max-width: 768px) {
  .sp-modal-overlay {
    align-items: flex-end;
  }

  .sp-modal-container {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    opacity: 1;
  }

  .sp-modal-overlay.is-open .sp-modal-container {
    transform: translateY(0);
  }

  .sp-modal-drag-handle {
    display: block;
  }

  .sp-modal-header {
    padding: 0.75rem 1.25rem 1rem;
  }

  #sp-modal-title {
    font-size: 1.1rem;
  }

  .sp-modal-body {
    padding: 1rem 1.25rem 1.5rem;
  }

  .gdp-key-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .gdp-stat {
    padding: 0.625rem 0.75rem;
  }

  .gdp-stat::before {
    font-size: 0.7rem;
  }

  .gdp-stat {
    font-size: 1rem;
  }
}

/* ============================================
   REDUCED MOTION — Respect user preferences
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .sp-modal-overlay {
    transition: none;
  }

  .sp-modal-container {
    transition: none;
  }

  .sp-modal-loading::before {
    animation-duration: 1.5s;
  }
}

/* ============================================
   SCREEN READER ONLY — Visually hidden announcements
   ============================================ */

.sp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
