/**
 * 포트폴리오 웹사이트 메인 스타일
 *
 * 구조:
 * 1. CSS 변수 및 기본 설정
 * 2. 레이아웃 및 그리드
 * 3. 3D 효과 및 애니메이션
 * 4. 반응형 스타일
 * 5. 모달 스타일
 * 6. 유틸리티
 */

/* ========================================
   1. CSS 변수 및 기본 설정
   ======================================== */

:root {
  /* 라인 별 대각선 왜곡 보정값 (PC 빈 모서리(좌상단, 우하단)를 완벽하게 채우기 위한 엇갈림 보정값) */
  --drift-comp: -3.5vw;

  /* 색상 */
  --color-bg: #000000;
  --color-bg-secondary: #0a0a0a;
  --color-surface: #1a1a1a;
  --color-border: #2a2a2a;
  --color-text: #ffffff;
  --color-text-secondary: #888888;

  /* 그리드 설정 */
  --grid-gap: 12px;
  --grid-cols-desktop: 7;
  --grid-cols-tablet: 5;
  --grid-cols-mobile: 3;
  --grid-rows: 4;

  /* 3D 효과 */
  --perspective: 1200px;
  --rotate-x: 32deg;
  --rotate-z: -15deg;

  /* 애니메이션 */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);

}

/* 기본 리셋 */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100vh;
  /* 내부 높이에 따라 자유롭게 늘어남 */
  overflow-x: hidden;
  /* 가로 스크롤만 완전 차단 */
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   2. 레이아웃 및 그리드
   ======================================== */

.main-container {
  width: 100%;
  position: relative;
  z-index: 2;
  /* 3D 배경 컨테이너 위에 논리적으로 배치 */
  pointer-events: none;
  /* 클릭은 뚫고 지나가 카드에 닿게 허용 됨 */
}

.perspective-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  perspective: var(--perspective);
  perspective-origin: 50% 50%;
  /* 시야의 중심 영역 고정 */
  pointer-events: none;
  /* 마우스 이벤트는 아이템으로 이관 (스크롤 덮음 방지) */
  z-index: 1;
  /* 최상단 윈도우 스크롤바와 겹치지 않게 하며 블랙스크린 방지 양수 설정 */
}

.grid-wrapper {
  position: absolute;
  top: 0;
  left: 50%;
  transform-origin: 50% 0%;
  /* 회전 축을 상단으로 올려 렌즈 왜곡 방지 */
  width: 140vw;
  /* 카드가 지나치게 커지지 않도록 적정 너비(140vw)로 축소 및 안정화 */
  margin-top: -10vh;
  /* 상단 여백 보정 값을 완화하여 자연스러운 3D 화각 유지 */
  display: flex;
  flex-direction: column;
  gap: var(--grid-gap);
  pointer-events: none;
  /* 투명한 영역이 우측 스크롤 바를 덮어 클릭을 막는 현상 방지. 아이템에서만 auto 적용 */
  /* 핵심 수학 공식:
     1. 수평 중앙 정렬 (-50%)
     2. 3D 공간 회전 (tilt, twist)
     3. *회전된 로컬 Y축을 따라* 위로(음수) 패닝 이동 */
  transform: translateX(-50%) rotateX(var(--rotate-x)) rotateZ(var(--rotate-z)) translateY(calc(var(--scroll-y, 0px) * -1));
  will-change: transform;
  transform-style: preserve-3d;
}

.grid-row {
  display: flex;
  justify-content: center;
  gap: var(--grid-gap);
  width: 100%;
  height: 100%;
}

/* 사용자의 엇갈림 배치 요구: 가장자리 카드가 너무 극단적으로 벗어나지 않도록 보폭 축소 */
.grid-row:nth-child(odd) {
  margin-left: -4vw;
}

.grid-row:nth-child(even) {
  margin-left: 4vw;
}

/* 행별 교차 애니메이션 (원본 HTML 기준) */
.grid-row:nth-child(odd) {
  animation: floatRight 8s ease-in-out infinite;
}

.grid-row:nth-child(even) {
  animation: floatLeft 9s ease-in-out infinite;
}

@keyframes floatRight {

  0%,
  100% {
    transform: translateX(50px);
  }

  50% {
    transform: translateX(-50px);
  }
}

@keyframes floatLeft {

  0%,
  100% {
    transform: translateX(-50px);
  }

  50% {
    transform: translateX(50px);
  }
}

/* ========================================
   3. 그리드 아이템
   ======================================== */

.grid-item {
  position: relative;
  /* JS에서 주입하는 --columns 변수에 따라 동적으로 너비를 계산 */
  flex: 0 0 calc((100% - (var(--grid-gap) * (var(--columns, 7) - 1))) / var(--columns, 7));
  height: 100%;
  aspect-ratio: 16 / 9;
  cursor: pointer;
  pointer-events: auto;
  /* 실제 카드만 클릭/호버 감지 */
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  transition: transform 0.4s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.4s cubic-bezier(0.2, 0, 0, 1);
}

.phantom-item {
  /* 외곽 순환용 팬텀 데이터: 진짜 데이터와 완전히 동일하게 취급 (클릭 및 호버 허용) */
  opacity: 0.85;
}

.grid-item:hover {
  transform: scale(1.05) !important;
  z-index: 50;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}

.grid-item.expanded {
  transform: scale(1.1) !important;
  z-index: 100;
}

/* 썸네일 이미지 */
.portfolio-thumbnail {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* 핵심: 이미지가 늘어나지 않고 16:9 꽉 차게 잘라줌 */
  border-radius: 4px;
  pointer-events: none;
  /* 하위 이미지에서 마우스 이벤트를 강탈하여 커서가 깜빡이는 것 방지 */
}

/* 클릭 오버레이 */
.click-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: transparent;
  transition: background var(--transition-fast);
  cursor: pointer;
  /* 강제로 손가락 커서 유지 */
}

.grid-item:hover .click-overlay {
  background: rgba(0, 0, 0, 0.1);
}

/* ========================================
   4. 스켈레톤 로딩
   ======================================== */

.skeleton {
  position: absolute;
  inset: 0;
  background: var(--color-surface);
  overflow: hidden;
}

.skeleton.hidden {
  opacity: 0;
  pointer-events: none;
}

.skeleton-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.05),
      transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

.load-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-secondary);
  font-size: 12px;
}

/* ========================================
   5. 모달
   ======================================== */

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.95);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.preview-modal.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  position: relative;
  width: 90vw;
  height: 85vh;
  max-width: 1600px;
  background: var(--color-bg);
  border-radius: 16px;
  overflow: hidden;
  transform: scale(0.9);
  transition: transform var(--transition-slow);
}

.preview-modal.active .modal-content {
  transform: scale(1);
}

.modal-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
  z-index: 10;
}

.modal-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--color-text);
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-btn-primary {
  background: var(--color-text);
  color: var(--color-bg);
}

.modal-btn-primary:hover {
  transform: scale(1.05);
}

.modal-btn-close {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
}

.modal-btn-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.modal-iframe-container {
  width: 100%;
  height: 100%;
}

.modal-iframe-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ========================================
   6. 반응형
   ======================================== */

/* 태블릿 */
@media (max-width: 1024px) {
  :root {
    --grid-gap: 10px;
    --rotate-x: 22deg;
    --rotate-z: -10deg;
  }

  .grid-item {
    flex: 0 0 calc((100% - (var(--grid-gap) * 3)) / 4);
    aspect-ratio: 16 / 9;
  }
}

/* 모바일 */
@media (max-width: 768px) {
  :root {
    --grid-gap: 6px;
    --rotate-x: 23deg;
    --rotate-z: -8deg;
    --drift-comp: -4.5vw;
    /* 모바일 대각선으로 흘러가는 증상 절대 방어 */
  }

  /* 모바일 스크롤 및 3D 컨테이너 복구 */
  .grid-wrapper {
    width: 155vw;
    /* 모바일 추가 피드백: 아래쪽 카드가 더 보이도록 크기를 전반적으로 축소 (200vw -> 155vw) */
    margin-top: 5vh;
    transform: translateX(-50%) rotateX(var(--rotate-x)) rotateZ(var(--rotate-z)) translateY(calc(var(--scroll-y, 0px) * -1));
    display: flex;
    flex-direction: column;
    gap: var(--grid-gap);
  }

  .grid-row {
    display: flex;
    justify-content: center;
    gap: var(--grid-gap);
    width: 100%;
  }

  .grid-item {
    flex: 0 0 calc((100% - (var(--grid-gap) * (var(--grid-cols-mobile) - 1))) / var(--grid-cols-mobile));
    aspect-ratio: 16 / 9;
  }

  /* 모달 풀스크린 */
  .modal-content {
    width: 100vw;
    height: 100vh;
    max-width: none;
    border-radius: 0;
  }

  .modal-header {
    padding: 12px 16px;
  }

  .modal-title {
    font-size: 14px;
  }

  .modal-btn {
    padding: 8px 16px;
    font-size: 13px;
  }
}

/* =========================================================================
   Branding & Security (Splash Screen & Watermark)
   ========================================================================= */

/* 1. Splash Screen Intro */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #0a0a0a;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1), visibility 1s;
}

.splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  text-align: center;
  animation: splashFadeIn 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes splashFadeIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.splash-text {
  color: #888;
  font-size: 12px;
  letter-spacing: 3px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.splash-title {
  color: #eee;
  font-size: 26px;
  font-weight: 300;
  letter-spacing: 1.5px;
}

/* 2. Fixed Watermark Logo */
.watermark-logo {
  position: fixed;
  top: 30px;
  left: 40px;
  z-index: 100;
  color: rgba(255, 255, 255, 0.7);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 1.5px;
  pointer-events: none;
  /* 클릭 투과 (아래 UI 조작 방해 금지) */
  user-select: none;
  /* 텍스트 드래그 방지 */
  -webkit-user-select: none;
  font-family: 'Inter', sans-serif;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  /* 3D 배경 위에서 돋보이게 */
}

.watermark-logo span {
  color: rgba(255, 255, 255, 0.4);
  margin: 0 6px;
  font-weight: 300;
}

/* 3. 전역 텍스트 드래그(선택) 블락 */
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

@media (max-width: 768px) {
  .watermark-logo {
    top: 20px;
    left: 20px;
    font-size: 12px;
  }

  .splash-title {
    font-size: 18px;
  }

  .splash-text {
    font-size: 10px;
  }
}

/* 소형 모바일 */
@media (max-width: 480px) {
  :root {
    --grid-gap: 6px;
    --rotate-x: 13deg;
    --rotate-z: -5deg;
    --drift-comp: -5vw;
  }

  .perspective-container {
    perspective-origin: 50% 50%;
  }

  .grid-wrapper {
    width: 150vw;
  }

  .grid-row {
    display: flex;
    justify-content: center;
    gap: var(--grid-gap);
    width: 100%;
  }

  .grid-item {
    flex: 0 0 calc((100% - (var(--grid-gap) * 1)) / 2);
    /* 2열로 고정 */
  }
}

/* ========================================
   7. 유틸리티
   ======================================== */

/* 노이즈 오버레이 */
.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* 접근성: 포커스 표시 */
.grid-item:focus-visible,
.modal-btn:focus-visible {
  outline: 2px solid #4a9eff;
  outline-offset: 2px;
}

/* 모션 감소 설정 존중 */
@media (prefers-reduced-motion: reduce) {

  .row-1,
  .row-2,
  .row-3,
  .row-4 {
    animation: none;
  }

  .skeleton-shimmer {
    animation: none;
  }
}