/* =========================================
   [싱글 게임] 디자인 스타일 및 그리드 최적화
   ========================================= */

:root {
    --table-felt: #0a5c36;
    --gold-accent: #d4af37;
    --ball-red: #d93025;
}

/* 1. 게임 뷰 컨테이너 (화면 정중앙 정렬) */
.game-view-container {
    width: 100%;
    height: 100%; /* 부모 높이 100% 채움 */
    display: flex;
    justify-content: center; /* 가로 중앙 */
    align-items: center;     /* 세로 중앙 */
    padding: 20px;           /* 여백 */
    box-sizing: border-box;
    overflow-y: auto;        /* 화면 작을 때 스크롤 허용 */
}

/* 2. 상단바 디자인 (뒤로가기 등) */
.game-top-bar {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; 
    background: linear-gradient(to bottom, #1e293b, #0f172a); 
    padding: 15px 25px;
    border-bottom: 2px solid var(--gold-accent);
    box-sizing: border-box; 
    /* 상단바는 game-view-container 밖, game-header에 위치함 */
}
.coin-info { display: flex; flex-direction: column; align-items: flex-start; }
.prize-info { display: flex; flex-direction: column; align-items: flex-end; }

/* 3. 게임 테이블 디자인 */
.game-room-border {
    background: 
        radial-gradient(circle at center, rgba(255,255,255,0.1) 0%, rgba(0,0,0,0.3) 100%),
        linear-gradient(135deg, #0a5c36 0%, #074d2e 100%);
    border: 6px solid var(--gold-accent);
    border-radius: 40px;
    padding: 30px;
    /* 마진 제거 (Flex 중앙 정렬 따름) */
    margin: 0; 
    width: 95%;
    max-width: 900px;
    /* 높이 고정보다는 내용에 따르되 최소 높이 확보 */
    min-height: 500px; 
    box-shadow: 
        inset 0 0 60px rgba(0,0,0,0.6),
        0 20px 50px rgba(0,0,0,0.5),
        0 0 0 3px #8c7853;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* 내부 내용 중앙 정렬 */
    position: relative;
    overflow: hidden;
}

/* 테이블 패턴 */
.game-room-border::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.6' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noiseFilter)' opacity='0.15'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

/* [NEW] 헤더 영역 높이 고정 (공 위치 흔들림 방지) */
.game-header-wrapper {
    width: 100%;
    min-height: 140px; /* 제목이나 점수판 높이를 커버할 만큼 확보 */
    display: flex;
    flex-direction: column;
    justify-content: center; /* 내용 수직 중앙 */
    align-items: center;
    margin-bottom: 20px;
    z-index: 1;
}

/* 제목 스타일 */
.game-title {
    font-family: 'Orbitron', sans-serif;
    color: var(--gold-accent);
    text-align: center;
    margin: 0; /* Wrapper가 정렬하므로 마진 제거 */
    font-size: 1.8rem;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.highlight { color: #fff; font-weight: bold; }

/* 타겟 공 */
.target-container { 
    display: flex; gap: 8px; justify-content: center; 
    margin-top: 10px; /* 위쪽 여백 */
    flex-wrap: wrap; 
}
.target-ball {
    width: 38px; height: 38px; border-radius: 50%;
    background: #1f2937; border: 2px solid #4b5563;
    color: #9ca3af; font-weight: bold; font-size: 0.9rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}
.target-ball.found {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    border-color: var(--gold-accent); color: #fff;
    box-shadow: 0 0 12px #ef4444;
}

/* 그리드 설정 */
.card-grid { 
    display: grid; 
    gap: 15px; 
    justify-content: center; 
    width: 100%; 
    z-index: 1; 
    /* 그리드 자체도 중앙 정렬 */
    margin: 0 auto;
}

/* EASY (Total 6) */
.grid-easy { grid-template-columns: repeat(2, 1fr); }
@media (orientation: landscape) { .grid-easy { grid-template-columns: repeat(3, 1fr); } }

/* NORMAL (Total 12) */
.grid-normal { grid-template-columns: repeat(3, 1fr); }
@media (orientation: landscape) { .grid-normal { grid-template-columns: repeat(4, 1fr); } }

/* HARD (Total 20) */
.grid-hard { grid-template-columns: repeat(4, 1fr); }
@media (orientation: landscape) { .grid-hard { grid-template-columns: repeat(5, 1fr); } }

/* 로또 공 디자인 */
.lotto-ball, .ball-wrapper {
    width: 100%; aspect-ratio: 1; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-family: 'Orbitron', sans-serif;
    cursor: pointer; position: relative;
    box-shadow: inset -4px -4px 10px rgba(0,0,0,0.7), 4px 4px 15px rgba(0,0,0,0.5);
    margin: 0 auto; /* 셀 내부 중앙 정렬 */
}
.ball-number-bg {
    position: absolute; width: 60%; height: 60%;
    background: #f3f4f6; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #111; font-weight: 900;
    box-shadow: inset 1px 1px 4px rgba(0,0,0,0.3);
}

/* 공 스타일 (기존 유지) */
.lotto-ball { background: linear-gradient(135deg, #7f1d1d, #450a0a); border: 2px solid #991b1b; transition: 0.2s; }
.lotto-ball .ball-number-bg { color: #6b7280; background: #e5e7eb; opacity: 0.8; }
.lotto-ball.selected { background: linear-gradient(135deg, #ef4444, #b91c1c); border-color: #fca5a5; transform: scale(1.1); box-shadow: 0 0 25px rgba(239, 68, 68, 0.6); }
.lotto-ball.selected .ball-number-bg { color: #000; background: #fff; opacity: 1; }

.ball-wrapper { perspective: 1000px; background: transparent; box-shadow: none; border: none; }
.ball-inner { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 0.6s; transform-style: preserve-3d; border-radius: 50%; box-shadow: 0 8px 20px rgba(0,0,0,0.4); }
.ball-wrapper.flipped .ball-inner { transform: rotateY(180deg); }
.ball-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: 3px solid; box-shadow: inset -4px -4px 10px rgba(0,0,0,0.6); }
.ball-front { background: linear-gradient(135deg, #b91c1c, #991b1b); border-color: #ef4444; }
.ball-front::after { content: '?'; font-size: 1.8rem; color: rgba(255,255,255,0.8); text-shadow: 2px 2px 4px rgba(0,0,0,0.5); }
.ball-back { background: linear-gradient(135deg, #ef4444, #b91c1c); border-color: var(--gold-accent); transform: rotateY(180deg); }

/* 난이도별 공 크기 제한 */
.easy-mode .lotto-ball, .easy-mode .ball-wrapper { max-width: 90px; max-height: 90px; }
.easy-mode .ball-number-bg { font-size: 1.8rem; }
.normal-mode .lotto-ball, .normal-mode .ball-wrapper { max-width: 75px; max-height: 75px; }
.normal-mode .ball-number-bg { font-size: 1.5rem; }
.hard-mode .lotto-ball, .hard-mode .ball-wrapper { max-width: 65px; max-height: 65px; }
.hard-mode .ball-number-bg { font-size: 1.3rem; }

/* 결과 박스 (게임 종료 후 위치 고정) */
.result-box {
    text-align: center; padding: 25px; border-radius: 20px;
    margin-top: 10px; margin-bottom: 10px; width: 85%; animation: popIn 0.5s;
    z-index: 10; border: 3px solid var(--gold-accent);
    background: rgba(0,0,0,0.85); backdrop-filter: blur(5px);
}
.win-gold { box-shadow: 0 0 40px var(--gold-accent); border-color: var(--gold-accent); }
.win-fail { box-shadow: 0 0 20px #ef4444; border-color: #ef4444; }
.result-msg { font-size: 2rem; font-weight: 900; color:#fff; margin-bottom: 5px; }
.final-prize { font-size: 1.4rem; color: #fde68a; font-weight: bold; }

@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 반응형 */
@media (max-width: 600px) {
    .game-room-border { width: 95%; padding: 20px; min-height: 380px; }
    .card-grid { gap: 10px; }
    .game-title { font-size: 1.5rem; }
    .easy-mode .lotto-ball, .easy-mode .ball-wrapper { width: 22vw; height: 22vw; }
    .normal-mode .lotto-ball, .normal-mode .ball-wrapper { width: 17vw; height: 17vw; }
    .hard-mode .lotto-ball, .hard-mode .ball-wrapper { width: 13vw; height: 13vw; }
    .game-top-bar { flex-direction: column; gap: 8px; text-align: center; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .game-room-border { min-height: 280px; padding: 10px; }
    .game-header-wrapper { min-height: 80px; margin-bottom: 10px; }
    .game-title { font-size: 1.2rem; }
    .target-ball { width: 30px; height: 30px; font-size: 0.8rem; }
}
/* 결과 박스 (화면 정중앙 팝업 스타일) */
.result-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* 정확한 중앙 정렬 */
    
    text-align: center; 
    padding: 30px; 
    border-radius: 20px;
    width: 90%; 
    max-width: 400px;
    z-index: 100; /* 공들보다 위에 뜨게 */
    
    background: rgba(15, 23, 42, 0.95); /* 배경 불투명도 높임 */
    border: 3px solid var(--gold-accent);
    box-shadow: 0 0 50px rgba(0,0,0,0.8); /* 그림자 진하게 */
    backdrop-filter: blur(10px);
    
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); /* 팝업 효과 */
}

/* 승리/패배 스타일 */
.win-gold { 
    box-shadow: 0 0 60px rgba(212, 175, 55, 0.4); 
    border-color: var(--gold-accent); 
}
.win-fail { 
    box-shadow: 0 0 40px rgba(239, 68, 68, 0.3); 
    border-color: #ef4444; 
}

.result-msg { 
    font-size: 1.8rem; 
    font-weight: 900; 
    color: #fff; 
    margin-bottom: 10px; 
}
.final-prize { 
    font-size: 2rem; 
    color: #fde68a; 
    font-weight: bold; 
    font-family: 'Orbitron';
    text-shadow: 0 0 10px rgba(253, 230, 138, 0.5);
}

@keyframes popIn { 
    from { transform: translate(-50%, -50%) scale(0.5); opacity: 0; } 
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; } 
}
