@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0a1a0a;
  overflow: hidden;
  font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  color: #fff;
}

/* 로딩 화면 */
#loading-screen {
  position: fixed; inset: 0;
  background-image: url('https://d2xsxph8kpxj0f.cloudfront.net/310519663631751248/c3nNmMywJRRFezd9NtDDQ8/casino_lobby_bg-WF82ErrgH8TED2hqXHjfjd.webp');
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#loading-screen::before {
  content: '';
  position: absolute; inset: 0;
  background: rgba(5, 3, 15, 0.70);
}
.loading-inner {
  position: relative; z-index: 1;
  text-align: center;
  padding: 48px 56px;
  background: rgba(8, 6, 18, 0.78);
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 40px rgba(201,168,76,0.08);
  min-width: 400px;
}
.loading-emblem {
  font-size: 52px;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 16px rgba(201,168,76,0.5));
}
.loading-title {
  font-family: 'Cinzel', serif;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #f0d080;
  margin-bottom: 0;
  text-shadow: 0 0 24px rgba(201,168,76,0.4);
}
.loading-title span {
  display: block;
  font-family: 'Malgun Gothic', sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 8px;
  color: #a89060;
  margin-top: 6px;
  margin-bottom: 28px;
}
/* 트럼프 카드 애니메이션 */
.loading-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 40px;
  perspective: 800px;
}
.lcard {
  width: 80px;
  height: 112px;
  perspective: 600px;
}
.lcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: cardFlip 1.6s ease-in-out infinite;
}
.lcard-1 .lcard-inner { animation-delay: 0s; }
.lcard-2 .lcard-inner { animation-delay: 0.2s; }
.lcard-3 .lcard-inner { animation-delay: 0.4s; }
.lcard-4 .lcard-inner { animation-delay: 0.6s; }
.lcard-5 .lcard-inner { animation-delay: 0.8s; }
.lcard-front, .lcard-back {
  position: absolute;
  width: 100%; height: 100%;
  backface-visibility: hidden;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: bold;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}
.lcard-front {
  background: #fff;
  color: #1a1a1a;
  transform: rotateY(180deg);
}
.lcard-front.lcard-red { color: #cc2222; }
.lcard-back {
  background: linear-gradient(135deg, #0d0820 0%, #1a1035 50%, #0d0820 100%);
  border: 2px solid rgba(201,168,76,0.55);
}
.lcard-back::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(201,168,76,0.25);
  border-radius: 4px;
  background: radial-gradient(ellipse at center, rgba(201,168,76,0.06) 0%, transparent 70%);
}
@keyframes cardFlip {
  0%   { transform: rotateY(0deg) translateY(0px); }
  30%  { transform: rotateY(90deg) translateY(-12px); }
  50%  { transform: rotateY(180deg) translateY(-18px); }
  70%  { transform: rotateY(270deg) translateY(-12px); }
  100% { transform: rotateY(360deg) translateY(0px); }
}
.loading-bar-wrap {
  width: 320px; height: 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px; overflow: hidden;
  margin: 0 auto 12px;
  border: 1px solid rgba(201,168,76,0.2);
}
.loading-bar {
  height: 100%;
  background: linear-gradient(90deg, #8a6a1e, #c9a84c, #f0d080, #c9a84c, #8a6a1e);
  background-size: 200% 100%;
  border-radius: 3px;
  transition: width 0.3s;
  animation: shimmer 1.5s linear infinite;
  box-shadow: 0 0 8px rgba(201,168,76,0.5);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.loading-pct { color: #c9a84c; font-size: 14px; letter-spacing: 3px; margin-top: 4px; }

/* 게임 화면 */
#game-screen {
  position: fixed; inset: 0;
  top: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  overflow: hidden;
}

#game-canvas {
  display: block;
  /* 16:9 비율 유지: 너비와 높이 중 작은 쪽에 맞춰 비율 유지 */
  width: 100vw;
  height: 56.25vw; /* 100vw * 9/16 */
  max-height: 100vh;
  max-width: 177.78vh; /* 100vh * 16/9 */
}

/* 상단 HUD - 캐맰버스 위에 절대 위치 오버레이 */
.top-hud {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  max-width: 177.78vh;
  height: 48px;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  pointer-events: auto;
}
.hud-logo { display: flex; align-items: baseline; gap: 6px; }
.logo-text { font-size: 22px; font-weight: bold; color: #FFD700; }
.logo-sub { font-size: 12px; color: #aaa; letter-spacing: 2px; }
.hud-notice {
  display: flex; align-items: center; gap: 8px;
  flex: 1; justify-content: center;
  max-width: 600px;
  overflow: hidden;
}
.notice-icon { font-size: 16px; flex-shrink: 0; }
#hud-notice-text {
  font-size: 14px; color: #FFE08A;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 500px;
}
.hud-actions { display: flex; gap: 8px; align-items: center; }
.btn-icon {
  padding: 6px 10px !important;
  font-size: 18px !important;
  line-height: 1;
}
.btn-hud {
  padding: 6px 14px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}
.btn-hud:hover { background: rgba(255,255,255,0.2); }

/* 메시지 */
.game-message {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px;
  background: rgba(0,0,0,0.85);
  border: 1px solid #FFD700;
  border-radius: 8px;
  font-size: 16px;
  z-index: 200;
  transition: opacity 0.3s;
}
.game-message.error { border-color: #ff4444; color: #ff4444; }

/* 결과 오버레이 */
.result-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
}
.result-inner {
  background: linear-gradient(135deg, #1a3a1a, #0a1a0a);
  border: 2px solid #FFD700;
  border-radius: 16px;
  padding: 40px 60px;
  text-align: center;
  min-width: 400px;
}
.result-round {
  font-size: 28px; font-weight: bold;
  color: #FFD700; margin-bottom: 20px;
}
.result-winner {
  display: flex; gap: 20px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.result-title { font-size: 28px; font-weight: bold; color: #FFD700; margin-bottom: 20px; }
.result-name { font-size: 20px; font-weight: bold; flex: 1; }
.result-hand { font-size: 16px; color: #aaa; flex: 1; }
.result-amount { font-size: 24px; font-weight: bold; color: #FFD700; }
.result-loser {
  display: flex; gap: 20px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
  opacity: 0.7;
}
.result-pot { font-size: 16px; color: #aaa; margin-top: 16px; }

/* 설정 팝업 */
.popup {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.popup-inner {
  background: #1a2a1a;
  border: 1px solid #FFD700;
  border-radius: 12px;
  padding: 30px;
  min-width: 300px;
}
.popup-inner h3 { font-size: 20px; color: #FFD700; margin-bottom: 20px; }
.toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.1);
  cursor: pointer; font-size: 16px;
}
.toggle-row input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.btn-primary {
  margin-top: 20px; width: 100%;
  padding: 12px;
  background: #FFD700; color: #000;
  border: none; border-radius: 8px;
  font-size: 16px; font-weight: bold;
  cursor: pointer;
}
.btn-primary:hover { background: #FFC000; }

.hidden { display: none !important; }

/* 접속불량 팝업 */
.disconnect-popup {
  text-align: center;
  border-color: #FF4444;
  background: #1a0a0a;
  min-width: 340px;
}
.disconnect-popup h3 { color: #FF4444; font-size: 22px; }
.disconnect-popup p { color: #ccc; font-size: 15px; line-height: 1.6; margin-bottom: 16px; }
.disconnect-icon { font-size: 48px; margin-bottom: 12px; }
.disconnect-countdown {
  font-size: 36px;
  font-weight: bold;
  color: #FF4444;
  width: 64px; height: 64px;
  line-height: 64px;
  border: 3px solid #FF4444;
  border-radius: 50%;
  margin: 0 auto;
  animation: countdown-pulse 1s ease-in-out infinite;
}
@keyframes countdown-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.7; }
}


/* ============================================================
   모바일 대응 (가로 전용)
   ============================================================ */

/* 세로 모드 안내 오버레이 */
#rotate-overlay {
  display: none;
  position: fixed; inset: 0;
  background: #0a1a0a;
  z-index: 99999;
  flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  padding: 40px;
}
#rotate-overlay .rotate-icon {
  font-size: 72px;
  margin-bottom: 24px;
  animation: rotate-hint 2s ease-in-out infinite;
}
#rotate-overlay .rotate-title {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 700;
  color: #FFD700;
  margin-bottom: 12px;
  letter-spacing: 2px;
}
#rotate-overlay .rotate-desc {
  font-size: 15px;
  color: #aaa;
  line-height: 1.6;
}
@keyframes rotate-hint {
  0%   { transform: rotate(0deg); }
  30%  { transform: rotate(90deg); }
  60%  { transform: rotate(90deg); }
  90%  { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}

/* 세로 모드일 때 오버레이 표시 */
@media screen and (orientation: portrait) {
  #rotate-overlay { display: flex; }
  #game-screen, #loading-screen { display: none !important; }
}

/* 로비/로그인 페이지도 세로 모드 차단 */
@media screen and (orientation: portrait) and (max-width: 768px) {
  body.lobby-page #rotate-overlay,
  body.login-page #rotate-overlay { display: flex; }
}

/* 모바일 가로 모드 HUD 최적화 */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .top-hud {
    height: 40px;
    padding: 0 12px;
  }
  .logo-text { font-size: 16px; }
  .logo-sub { display: none; }
  .hud-notice { max-width: 300px; }
  #hud-notice-text { font-size: 12px; max-width: 260px; }
  .btn-hud {
    padding: 5px 10px;
    font-size: 12px;
    min-height: 32px; /* 터치 최소 크기 */
  }
  .btn-icon { padding: 5px 8px !important; font-size: 16px !important; }
}

/* 모바일 팝업 최적화 */
@media screen and (max-width: 768px) and (orientation: landscape) {
  .popup-inner {
    padding: 20px;
    min-width: 260px;
    max-width: 90vw;
  }
  .popup-inner h3 { font-size: 17px; margin-bottom: 14px; }
  .toggle-row { font-size: 14px; padding: 8px 0; }
  .toggle-row input[type="checkbox"] { width: 22px; height: 22px; }
  .btn-primary { margin-top: 14px; padding: 12px; font-size: 15px; min-height: 44px; }

  .result-inner {
    padding: 20px 28px;
    min-width: 280px;
    max-width: 88vw;
  }
  .result-round { font-size: 20px; margin-bottom: 12px; }
  .result-title { font-size: 20px; margin-bottom: 12px; }
  .result-name { font-size: 16px; }
  .result-hand { font-size: 13px; }
  .result-amount { font-size: 18px; }
  .result-pot { font-size: 13px; }

  .disconnect-popup { min-width: 280px; max-width: 88vw; }
  .disconnect-popup h3 { font-size: 18px; }
  .disconnect-popup p { font-size: 13px; }
  .disconnect-icon { font-size: 36px; margin-bottom: 8px; }
  .disconnect-countdown { font-size: 28px; width: 52px; height: 52px; line-height: 52px; }

  /* 로딩 화면 모바일 최적화 */
  .loading-inner {
    min-width: unset;
    width: 90vw;
    padding: 28px 24px;
  }
  .loading-title { font-size: 22px; letter-spacing: 2px; }
  .lcard { width: 52px; height: 74px; }
  .lcard-front, .lcard-back { font-size: 28px; }
}

/* 터치 액션 최적화 - 캔버스 스크롤/줌 방지 */
#game-canvas {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
