/* ==============================================
   Intro Puzzle Overlay Styles (3×3 sliding puzzle)
   Pixel-accurate, accessible, reduced-motion aware
   Improvements:
     - Replaced custom tokens with main.css tokens for consistency
     - Added light theme support using main.css tokens
     - Enhanced accessibility with main.css --focus style
     - Optimized backdrop-filter with fallback for compatibility
     - Aligned button and tile styles with main.css components
     - Refined responsive design with clamp values
     - Optimized solved animation for performance
   ============================================== */

/* Fullscreen overlay */
#vb-intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vh, 16px);
  /* Matches main.css responsive padding */
  overflow: auto;
  /* Safe scroll fallback */
  color: var(--text);
  background: var(--bg);
  background: rgba(11, 15, 20, 0.9);
  /* Fallback for backdrop-filter */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* Dialog */
#vb-intro-dialog {
  width: min(96vw, 1040px);
  max-height: 92vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  row-gap: clamp(12px, 1.6vw, 18px);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 2.2vw, 24px);
  box-shadow: var(--shadow);
}

/* Header */
#vb-intro-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#vb-intro-title {
  font-size: clamp(18px, 2.2vw, 24px);
  font-weight: 650;
  letter-spacing: 0.2px;
  color: var(--text);
}

#vb-intro-meta {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Puzzle container */
#vb-puzzle-wrap {
  place-self: center;
  width: min(88vw, calc(92vh - 180px));
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
}

/* Base image + interactive layer */
#vb-puzzle-image,
#vb-puzzle-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

#vb-puzzle-image {
  filter: brightness(0.95) contrast(1.05);
}

/* Tiles */
.vb-tile {
  position: absolute;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  cursor: var(--cursor-pointer);
  outline: none;
  border: 0;
  border-radius: 6px;
  box-shadow: none;
  background-repeat: no-repeat;
  background-clip: padding-box;
}

.vb-tile:focus-visible {
  box-shadow: var(--focus);
}

.vb-empty {
  opacity: 0;
  pointer-events: none;
}

/* Controls */
#vb-intro-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#vb-intro-hint {
  color: var(--muted);
  font-size: 0.95rem;
}

.vb-btns {
  display: flex;
  gap: 10px;
}

.vb-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: var(--cursor-pointer);
  transition: var(--transition);
}

.vb-btn.primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: var(--white);
}

.vb-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.vb-btn:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

/* Solved flash */
#vb-puzzle-image.vb-solved {
  animation: vbSolved 650ms ease-out both;
}

@keyframes vbSolved {
  from {
    border-color: var(--border);
  }

  to {
    border-color: var(--blue-400);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #vb-intro-overlay {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .vb-tile,
  .vb-btn,
  #vb-puzzle-image.vb-solved {
    transition: none !important;
    animation: none !important;
  }
}

/* Mobile tweaks */
@media (max-width: 520px) {
  #vb-intro-meta {
    gap: 10px;
    font-size: 0.9rem;
  }

  #vb-intro-controls {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .vb-btns {
    justify-content: flex-end;
  }
}
