/* =====================================================
   Tile Explorer: Lost Relics — Full Stylesheet
   ===================================================== */

/* ===== 1. CSS 변수 설정 (색상 및 테마) ===== */
:root {
  --color-amber-200: #fde68a;
  --color-amber-400: #fbbf24;
  --color-amber-500: #f59e0b;
  --color-amber-600: #d97706;
  --color-amber-800: #92400e;
  --color-amber-900: #78350f;

  --color-emerald-400: #34d399;
  --color-emerald-500: #10b981;
  --color-emerald-600: #059669;

  --color-indigo-600: #4f46e5;
  --color-indigo-800: #3730a3;

  --color-red-400: #f87171;
  --color-red-500: #ef4444;

  --color-slate-400: #94a3b8;
  --color-slate-500: #64748b;
  --color-slate-950: #020617;

  --color-stone-200: #e7e5e4;
  --color-stone-500: #78716c;
  --color-stone-700: #44403c;
  --color-stone-800: #292524;
  --color-stone-900: #1c1917;
  --color-stone-950: #0c0a09;

  /* 타일 종류별 색상 */
  --color-blue-400: #60a5fa;
  --color-rose-400: #fb7185;
  --color-yellow-400: #facc15;
  --color-yellow-600: #ca8a04;
  --color-teal-500: #14b8a6;
  --color-orange-200: #fed7aa;
}

/* ===== 2. 기본 리셋 및 폰트 설정 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* 모바일 클릭 하이라이트 제거 */
}

body, html {
  font-family: 'Quicksand', sans-serif;
  background-color: var(--color-slate-950);
  color: #fff;
  width: 100%;
  height: 100%;
  overflow: hidden; /* 전체 페이지 스크롤 방지 */
}

/* ===== 3. 전체 레이아웃 컨테이너 ===== */
.app-container {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* 모바일 주소창 대응 높이 */
  background-color: var(--color-slate-950);
  overflow: hidden;
}

/* 배경 장식 */
.bg-decor {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}
.bg-orb-emerald {
  position: absolute;
  top: 10%; left: 10%;
  width: 300px; height: 300px;
  background: var(--color-emerald-600);
  filter: blur(100px);
  border-radius: 50%;
}
.bg-orb-amber {
  position: absolute;
  bottom: 10%; right: 10%;
  width: 350px; height: 350px;
  background: var(--color-amber-600);
  filter: blur(120px);
  border-radius: 50%;
}

/* ===== 4. 헤더 (점수 및 시간) ===== */
.game-header {
  position: relative;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.game-title {
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  color: var(--color-amber-400);
  letter-spacing: 0.1em;
}
.game-subtitle {
  font-size: 0.7rem;
  color: var(--color-slate-500);
}
.header-stats {
  display: flex;
  gap: 20px;
}
.stat-box { text-align: center; }
.stat-label { font-size: 9px; color: var(--color-slate-500); text-transform: uppercase; font-weight: 700; }
.stat-value { font-size: 1.2rem; font-weight: 700; }
.time-value.time-low { color: var(--color-red-500); animation: pulse 1s infinite; }

/* ===== 5. 익스플로러 팁 및 파워업 버튼 ===== */
.explorer-section {
  position: relative;
  z-index: 20;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.explorer-dialogue {
  width: 100%;
  max-width: 600px;
  background: rgba(28,25,23,0.9);
  border: 1px solid var(--color-stone-700);
  border-radius: 50px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.explorer-avatar { font-size: 1.5rem; }
.explorer-text { font-size: 0.85rem; font-style: italic; color: var(--color-stone-200); }

.powerups-row { display: flex; gap: 20px; }
.powerup-btn { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; transition: 0.2s; }
.powerup-btn:hover:not(.disabled) { transform: scale(1.1); }
.powerup-btn.disabled { opacity: 0.3; filter: grayscale(1); cursor: not-allowed; }
.powerup-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; border-bottom: 3px solid rgba(0,0,0,0.3);
}
.powerup-icon.shuffle { background: var(--color-indigo-600); }
.powerup-icon.time { background: var(--color-emerald-600); }
.powerup-icon.undo { background: var(--color-amber-600); }
.powerup-label { font-size: 9px; font-weight: 700; text-transform: uppercase; color: var(--color-slate-400); }

/* ===== 6. 게임 보드 (중앙 퍼즐판) ===== */
.game-board-container {
  position: relative;
  flex: 1; /* 남은 중앙 공간 다 차지 */
  display: flex;
  align-items: center;
 justify-content: flex-start; /* 스크롤 시작점 맞춤 */
  overflow-x: auto;            /* 가로 스크롤 활성화 */
  overflow-y: hidden;          /* 세로 스크롤은 방지 */
  padding: 20px;
  -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
}

/* ===== 2. 고대 유적 테마 커스텀 스크롤바 ===== */
/* 스크롤바 전체 */
.game-board-container::-webkit-scrollbar {
  height: 10px;
}
/* 스크롤바 트랙 (바탕) */
.game-board-container::-webkit-scrollbar-track {
  background: var(--color-stone-950);
  border-radius: 10px;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}
/* 스크롤바 핸들 (움직이는 부분) */
.game-board-container::-webkit-scrollbar-thumb {
  background: linear-gradient(to right, var(--color-amber-800), var(--color-amber-600));
  border-radius: 10px;
  border: 2px solid var(--color-stone-950);
}
.game-board-container::-webkit-scrollbar-thumb:hover {
  background: var(--color-amber-500);
}

.game-board-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.game-board {
  position: relative;
  width: 500px;
  height: 500px;
  flex-shrink: 0;
}

/* 오버레이 (시작/승리/패배 화면) - 중앙 정렬 핵심 */
#game-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3); /* 배경 살짝 어둡게 */
  pointer-events: auto;
}
.overlay-screen {
  text-align: center;
  padding: 40px;
  border-radius: 24px;
  backdrop-filter: blur(15px);
  background: rgba(15,23,42,0.8);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeInZoom 0.4s ease-out;
}
.overlay-emoji { font-size: 3.5rem; margin-bottom: 10px; }
.overlay-title { font-family: 'Cinzel', serif; font-size: 2rem; margin-bottom: 10px; color: var(--color-amber-400); }
.overlay-desc { font-size: 0.9rem; color: var(--color-slate-400); margin-bottom: 25px; max-width: 280px; }
.overlay-btn {
  padding: 14px 32px; border-radius: 50px; border: none; cursor: pointer;
  font-weight: 700; font-family: inherit; transition: 0.2s; background: var(--color-amber-600); color: #fff;
}
.overlay-btn:hover { background: var(--color-amber-500); transform: scale(1.05); }

/* ===== 7. 타일 스타일 ===== */
.tile {
  position: absolute;
  width: 64px;
  height: 80px;
  border-radius: 10px;
  border-bottom: 4px solid rgba(0,0,0,0.3);
  border-right: 4px solid rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.tile-icon { font-size: 1.8rem; pointer-events: none; }
.tile-label { font-size: 9px; font-weight: 700; text-transform: uppercase; color: rgba(0,0,0,0.3); pointer-events: none; }
.tile-blocked { filter: brightness(0.4) grayscale(1); cursor: not-allowed; }
.tile:hover:not(.tile-blocked) { transform: translateY(-5px); filter: brightness(1.1); }

/* 타일 개별 색상 */
.tile-color-blue-400 { background: var(--color-blue-400); }
.tile-color-amber-600 { background: var(--color-amber-600); }
.tile-color-stone-500 { background: var(--color-stone-500); }
.tile-color-rose-400 { background: var(--color-rose-400); }
.tile-color-yellow-400 { background: var(--color-yellow-400); }
.tile-color-slate-400 { background: var(--color-slate-400); }
.tile-color-indigo-500 { background: var(--color-indigo-600); }
.tile-color-emerald-400 { background: var(--color-emerald-500); }
.tile-color-orange-200 { background: var(--color-orange-200); }
.tile-color-yellow-600 { background: var(--color-yellow-600); }
.tile-color-teal-500 { background: var(--color-teal-500); }
.tile-color-amber-200 { background: var(--color-amber-200); }

/* ===== 8. 하단 트레이 (Explorer's Satchel) ===== */
.tray-footer {
  position: relative;
  z-index: 20;
  padding: 15px 20px 25px;
  background: var(--color-stone-900);
  border-top: 2px solid var(--color-amber-800);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tray-label-row { margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.tray-label { font-size: 10px; color: var(--color-stone-500); text-transform: uppercase; font-weight: 700; letter-spacing: 0.1em; }
.tray-count { font-size: 10px; color: var(--color-amber-600); }

.tray-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  height: 85px;
  background: var(--color-stone-950);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--color-stone-800);
}
.tray-slot { width: 55px; height: 70px; background: rgba(255,255,255,0.03); border-radius: 8px; flex-shrink: 0; }
.tray-tiles { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; }
.tray-tile {
  width: 55px; height: 70px; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-bottom: 3px solid rgba(0,0,0,0.3); animation: zoomIn 0.2s ease-out;
}
.tray-tile-icon { font-size: 1.4rem; }
.tray-tile-label { font-size: 7px; font-weight: 700; text-transform: uppercase; color: rgba(0,0,0,0.3); }

/* ===== 9. 리더보드 및 모달 ===== */
.leaderboard-btn {
  position: absolute; top: 15px; right: 15px; z-index: 30;
  width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1); color: var(--color-amber-400); cursor: pointer;
}
.leaderboard-modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
}
.leaderboard-modal {
  background: linear-gradient(145deg, var(--color-stone-900), #000);
  border: 2px solid var(--color-amber-600);
  border-radius: 24px;
  padding: 15px;
  width: 95%;
  max-width: 420px;
  box-shadow: 0 0 30px rgba(217, 119, 6, 0.3), inset 0 0 15px rgba(0,0,0,0.5);
  position: relative;
  animation: modalSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.leaderboard-header {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 15px;
  position: relative;
}

.leaderboard-title {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  color: var(--color-amber-400);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  letter-spacing: 2px;
}

.leaderboard-close {
  position: absolute;
  top: -10px;
  right: -10px;
  background: var(--color-stone-800);
  border: 1px solid var(--color-amber-600);
  color: var(--color-amber-400);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}

.leaderboard-close:hover {
  background: var(--color-amber-600);
  color: white;
}

/* 점수 제출 성공 메시지 */
.score-submitted {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--color-emerald-500);
  color: var(--color-emerald-400);
  padding: 12px;
  border-radius: 12px;
  text-align: center;
  font-size: 0.9rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* 리더보드 테이블 */
.leaderboard-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}

.leaderboard-table th {
  font-size: 0.75rem;
  color: var(--color-stone-500);
  text-transform: uppercase;
  padding: 0 6px 6px;
  border-bottom: 1px solid var(--color-stone-800);
}

.leaderboard-table td {
  padding: 8px 6px;
  background: rgba(255,255,255,0.03);
  font-weight: 600;
}

.leaderboard-table tr td:first-child { border-radius: 8px 0 0 8px; text-align: center; }
.leaderboard-table tr td:last-child { border-radius: 0 8px 8px 0; text-align: right; }

.rank-medal {
  font-size: 1.2rem;
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 30px;
  border-radius: 50%;
}

/* 순위별 강조색 */
.rank-1 { color: #ffd700; text-shadow: 0 0 10px rgba(255,215,0,0.5); }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.player-name { color: #fff; font-size: 1rem; }
.player-score { color: var(--color-amber-400); font-family: 'Cinzel', serif; }
.player-level { color: var(--color-slate-400); font-size: 0.8rem; }

/* 점수 입력 폼 */
.score-form {
  background: rgba(0,0,0,0.3);
  padding: 15px;
  border-radius: 15px;
  margin-bottom: 20px;
}
.score-input {
  width: 100%;
  padding: 10px 15px;
  background: var(--color-stone-950);
  border: 1px solid var(--color-stone-700);
  border-radius: 8px;
  color: #fff;
  margin-bottom: 10px;
}
.score-submit-btn {
  width: 100%;
  padding: 8px;
  background: var(--color-amber-600);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

/* ===== 10. 모바일 최적화 (Mobile Fixes) ===== */
@media (max-width: 768px) {
    .game-board-wrapper {
    /* 타일이 밖으로 나갈 수 있도록 보드의 최소 너비를 확보 */
    min-width: 550px; 
    padding: 40px;
    display: flex;
    justify-content: center;
  }

  /* 헤더 축소 */
  .game-header { padding: 8px 15px; }
  .game-title { font-size: 1rem; }
  .stat-value { font-size: 0.9rem; }

  /* 익스플로러 영역 축소 */
.explorer-section {
    padding: 2px 10px;
    gap: 4px;
  }
  .explorer-dialogue {
    padding: 4px 12px;
    border-radius: 20px;
  }
  .explorer-text { font-size: 0.7rem; }
  .powerup-icon { width: 34px; height: 34px; font-size: 1rem; }
  .powerup-label { font-size: 7px; }

  /* 게임 보드 자동 스케일링 (좌우 여백 확보) */
  .game-board {
     /* 너무 작게 줄이지 않고, 적당한 크기 유지 (스크롤 유도) */
    transform: scale(0.85); 
    transform-origin: center center;
    flex-shrink: 0; /* 크기 유지 */
  }

  .game-board-container {
    justify-content: flex-start; 
  }
}

  /* 하단 트레이 (Satchel) 최적화 - 짤림 방지 */
  .tray-footer { padding: 10px 10px 20px; }
  .tray-container { height: 60px; gap: 4px; padding: 0 5px; }
  .tray-slot, .tray-tile {
    width: calc((100vw - 40px) / 7);
    max-width: 45px; height: 48px;
  }
  .tray-tile-icon { font-size: 1rem; }
  .tray-tile-label { display: none; } /* 모바일은 텍스트 숨김 */
}

/* 애니메이션 */
@keyframes fadeInZoom { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes zoomIn { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* 유틸리티 */
.hidden { display: none !important; }