/* style.css */

:root {
    /* 파스텔톤 컬러 시스템 */
    --color-bg-start: #ffeef2;
    --color-bg-mid: #f3e9ff;
    --color-bg-end: #e8f0fe;
    
    --color-primary: #ff7597;      /* 딸기 핑크 */
    --color-primary-hover: #ff547d;
    --color-secondary: #8aaaff;    /* 하늘색 */
    --color-secondary-hover: #668cff;
    --color-accent: #ffd15c;       /* 바나나 노랑 */
    
    --color-board-bg: rgba(255, 255, 255, 0.4);
    --color-grid-line: rgba(255, 117, 151, 0.08);
    
    --font-korean: 'Jua', sans-serif;
    --font-latin: 'Outfit', sans-serif;
    
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(138, 92, 246, 0.08), 0 4px 6px -2px rgba(138, 92, 246, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(255, 117, 151, 0.12), 0 10px 10px -5px rgba(255, 117, 151, 0.06);
    
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.5);
}

/* 초기화 및 공통 스타일 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    font-family: var(--font-korean);
    background: linear-gradient(135deg, var(--color-bg-start), var(--color-bg-mid), var(--color-bg-end));
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: #4a4a4a;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* 귀여운 동물 SVG 반복 패턴 배경 */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.15;
    pointer-events: none;
    z-index: 0;
    /* 고양이, 토끼, 발바닥, 별 등의 귀여운 인라인 SVG 패턴 */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='%23ff7597'%3E%3Cpath d='M20,15 C22,10 28,10 30,15 C31,17 31,23 29,25 C26,27 24,27 21,25 C19,23 19,17 20,15 Z' /%3E%3Cpath d='M35,15 C37,10 43,10 45,15 C46,17 46,23 44,25 C41,27 39,27 36,25 C34,23 34,17 35,15 Z' /%3E%3Ccircle cx='32.5' cy='28' r='10' /%3E%3Cpath d='M30,28 L35,28' stroke='%23ffffff' stroke-width='1.5' /%3E%3C/g%3E%3Cg fill='%238aaaff'%3E%3Ccircle cx='85' cy='30' r='8' /%3E%3Cpath d='M75,20 L80,27 M95,20 L90,27' stroke='%238aaaff' stroke-width='3.5' stroke-linecap='round' /%3E%3Ccircle cx='82' cy='29' r='1' fill='%23fff'/%3E%3Ccircle cx='88' cy='29' r='1' fill='%23fff'/%3E%3C/g%3E%3Cg fill='%23ffd15c'%3E%3Ccircle cx='30' cy='85' r='5' /%3E%3Ccircle cx='23' cy='80' r='3.5' /%3E%3Ccircle cx='37' cy='80' r='3.5' /%3E%3Ccircle cx='30' cy='74' r='3.5' /%3E%3C/g%3E%3Cpath d='M90,85 L85,90 L80,85 L85,80 Z' fill='%23ffafcc' /%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* 배경 그라데이션 애니메이션 */
@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 둥둥 떠다니는 배경 오브젝트 */
.bg-bubble {
    position: absolute;
    font-size: 2.2rem;
    z-index: 0;
    opacity: 0.7;
    animation: floatAround 20s ease-in-out infinite;
    pointer-events: none;
}

.b1 { top: 10%; left: 10%; animation-duration: 25s; }
.b2 { top: 75%; left: 15%; animation-duration: 18s; animation-delay: -2s; }
.b3 { top: 20%; right: 12%; animation-duration: 22s; animation-delay: -5s; }
.b4 { top: 80%; right: 20%; animation-duration: 28s; animation-delay: -10s; }
.b5 { top: 45%; left: 5%; animation-duration: 30s; animation-delay: -4s; }
.b6 { top: 50%; right: 5%; animation-duration: 24s; animation-delay: -8s; }

@keyframes floatAround {
    0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
    33% { transform: translateY(-30px) translateX(20px) rotate(15deg) scale(1.1); }
    66% { transform: translateY(15px) translateX(-15px) rotate(-10deg) scale(0.9); }
}

/* 메인 컨테이너 */
.app-container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
    z-index: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 글래스모피즘 공통 카드 스타일 */
.glassmorphism {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 3px solid var(--glass-border);
    border-radius: 32px;
    box-shadow: var(--shadow-lg);
}

.card {
    padding: 35px 25px;
    width: 100%;
    max-width: 440px;
    text-align: center;
    animation: fadeInScale 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* 화면 전환 관리 */
.screen {
    display: none;
    width: 100%;
    justify-content: center;
    align-items: center;
}

.screen.active {
    display: flex;
}

/* 로고 영역 */
.logo-container {
    margin-bottom: 20px;
}

.logo-emoji {
    font-size: 3.2rem;
    display: block;
    margin-bottom: 5px;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.logo-title {
    font-size: 2.8rem;
    line-height: 1.15;
    color: var(--color-primary);
    text-shadow: 2px 2px 0px #fff, 4px 4px 0px rgba(255, 117, 151, 0.15);
    letter-spacing: -1px;
}

.subtitle {
    font-size: 1.15rem;
    color: #6a6a6a;
    margin-bottom: 30px;
    line-height: 1.4;
    word-break: keep-all;
}

/* 폼 입력 그룹 */
.input-group {
    text-align: left;
    margin-bottom: 25px;
    width: 100%;
}

.input-group label {
    display: block;
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: #4a4a4a;
    padding-left: 5px;
}

.input-group input {
    width: 100%;
    padding: 15px 20px;
    border-radius: 20px;
    border: 3px solid rgba(255, 117, 151, 0.3);
    font-family: var(--font-korean);
    font-size: 1.3rem;
    color: #4a4a4a;
    background: rgba(255, 255, 255, 0.9);
    outline: none;
    transition: all 0.25s ease;
    text-align: center;
}

.input-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(255, 117, 151, 0.15);
    background: #ffffff;
}

/* 버튼 시스템 */
.btn {
    font-family: var(--font-korean);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.btn:active {
    transform: scale(0.96) translateY(1px);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-bottom: 5px solid #d64f70;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    color: #5a5a5a;
    border: 3px solid #dcdcdc;
    border-bottom: 6px solid #d0d0d0;
}

.btn-secondary:hover {
    background: #ffffff;
    color: #333333;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-large {
    padding: 16px 28px;
    font-size: 1.4rem;
    width: 100%;
}

.btn-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.btn-group-vertical .btn {
    padding: 14px 20px;
    font-size: 1.2rem;
}

.btn-group-horizontal {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 15px;
}

.btn-group-horizontal .btn {
    flex: 1;
    padding: 12px 10px;
    font-size: 1.15rem;
}

/* 파이어베이스 연결 배지 */
.firebase-status {
    margin-top: 25px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 30px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 0.85rem;
    color: #7a7a7a;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.green { background: #34d399; box-shadow: 0 0 6px #34d399; }
.status-dot.red { background: #ff8b8b; }

/* 2. 모달 스타일 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(43, 31, 53, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 30px 25px;
    position: relative;
    text-align: left;
    animation: modalSlideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.1) forwards;
}

@keyframes modalSlideUp {
    from { transform: translateY(40px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2.2rem;
    cursor: pointer;
    color: #8a8a8a;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--color-primary);
}

.modal-content h2 {
    font-size: 1.8rem;
    color: var(--color-primary);
    margin-bottom: 20px;
    border-bottom: 3px dashed rgba(255, 117, 151, 0.2);
    padding-bottom: 10px;
}

.instructions-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 25px;
}

.inst-section h3 {
    font-size: 1.15rem;
    color: var(--color-secondary-hover);
    margin-bottom: 6px;
}

.inst-section p {
    font-size: 0.95rem;
    line-height: 1.5;
    color: #5a5a5a;
    word-break: keep-all;
}

/* 키보드 레이아웃 설명 스타일 */
.control-grid {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 8px 12px;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.4);
    padding: 10px;
    border-radius: 12px;
}

.control-grid div {
    display: flex;
    gap: 3px;
    align-items: center;
}

.control-grid span {
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    color: #4a4a4a;
}

kbd {
    background: #ffffff;
    border: 2px solid #ccc;
    border-bottom: 4px solid #b5b5b5;
    border-radius: 6px;
    padding: 2px 6px;
    font-family: var(--font-latin);
    font-size: 0.75rem;
    font-weight: 800;
    box-shadow: 0 2px 0 rgba(0,0,0,0.05);
}

/* 3. 게임 영역 */
#screen-game {
    flex-direction: column;
    max-width: 580px;
    width: 100%;
}

.game-layout {
    display: flex;
    gap: 16px;
    width: 100%;
    justify-content: center;
    align-items: flex-start;
}

/* 게임판 테두리 및 캔버스 */
.board-area {
    padding: 12px;
    position: relative;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    background: rgba(255, 255, 255, 0.6);
    border: 4px solid #fff;
}

#game-canvas {
    background: var(--color-board-bg);
    border-radius: 14px;
    display: block;
    /* JS에서 반응형 크기로 캔버스 픽셀을 조절하므로 CSS에서는 비율만 정해줍니다 */
    aspect-ratio: 1 / 2;
    width: 280px;
    max-width: 100%;
}

/* 일시정지 / 카운트다운 오버레이 */
.overlay-screen {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    color: white;
    text-align: center;
}

#pause-overlay {
    background: rgba(43, 31, 53, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.overlay-content h2 {
    font-size: 2.2rem;
    margin-bottom: 12px;
    color: var(--color-accent);
}

.overlay-content p {
    font-size: 1.1rem;
    margin-bottom: 25px;
}

#countdown-overlay {
    background: rgba(255, 117, 151, 0.3);
    pointer-events: none;
}

.countdown-num {
    font-size: 6rem;
    color: white;
    text-shadow: 0 4px 10px rgba(0,0,0,0.2), 0 0 20px var(--color-primary);
    animation: pulseNum 1s ease infinite;
}

@keyframes pulseNum {
    0% { transform: scale(1.2); opacity: 0; }
    15% { transform: scale(1); opacity: 1; }
    85% { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(0.7); opacity: 0; }
}

.hidden {
    display: none !important;
}

/* 사이드 정보 패널 */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    min-width: 110px;
}

.panel-card {
    padding: 10px;
    text-align: center;
    border-radius: 20px;
    border-width: 2px;
}

.nickname-badge {
    background: var(--color-primary);
    border-color: rgba(255,255,255,0.4);
    color: white;
    font-size: 1.15rem;
    padding: 8px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: var(--shadow-sm);
}

.next-card h3, .hold-card h3 {
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
    font-family: var(--font-latin);
    font-weight: 800;
}

#next-canvas, #hold-canvas {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    display: block;
    margin: 0 auto;
    width: 70px;
    height: 70px;
}

.stats-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.82rem;
    color: #7a7a7a;
    margin-bottom: 1px;
}

.stat-value {
    font-family: var(--font-latin);
    font-weight: 800;
    font-size: 1.2rem;
    color: #4a4a4a;
}

.stat-value.highlight {
    color: var(--color-primary);
    font-size: 1.35rem;
}

#btn-pause-toggle {
    padding: 10px;
    font-size: 1rem;
    border-radius: 14px;
    margin-top: auto;
}

/* 모바일용 터치 패널 */
.mobile-controls-panel {
    display: none; /* 데스크톱 기본 숨김 */
    width: 100%;
    margin-top: 15px;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.touch-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    width: 100%;
}

.ctrl-btn {
    background: rgba(255, 255, 255, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-bottom: 4px solid rgba(0, 0, 0, 0.15);
    color: #555555;
    font-weight: bold;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.05s active;
}

.ctrl-btn:active {
    transform: scale(0.9) translateY(2px);
    background: #ffffff;
    border-bottom-width: 2px;
}

.ctrl-btn.round {
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.95rem;
    flex: 1;
    max-width: 90px;
    height: 42px;
}

/* 모바일 가상 D-Pad */
.touch-dpad {
    display: grid;
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(3, 54px);
    gap: 8px;
}

.dpad-btn {
    border-radius: 50%;
    font-size: 1.3rem;
    width: 54px;
    height: 54px;
}

.dpad-btn.up { background: var(--color-accent); color: #7c5f0b; border-bottom-color: rgba(0,0,0,0.2); }
.dpad-btn.left, .dpad-btn.right { background: var(--color-secondary); color: white; border-bottom-color: rgba(0,0,0,0.2); }
.dpad-btn.down { background: var(--color-primary); color: white; border-bottom-color: rgba(0,0,0,0.2); }

.dpad-center {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    opacity: 0.5;
}

/* 4. 게임오버 및 랭킹 카드 */
.game-over-card {
    max-width: 440px;
}

.game-over-emoji {
    font-size: 3.5rem;
    display: inline-block;
    margin-bottom: 8px;
}

.game-over-title {
    font-size: 2.3rem;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.game-over-subtitle {
    font-size: 1.1rem;
    color: #7a7a7a;
    margin-bottom: 20px;
}

.final-score-box {
    background: rgba(255, 255, 255, 0.7);
    border: 3px solid rgba(255, 117, 151, 0.2);
    border-radius: 20px;
    padding: 14px;
    margin-bottom: 22px;
    box-shadow: var(--shadow-sm);
}

.final-score-title {
    font-size: 1rem;
    color: #8a8a8a;
    margin-bottom: 2px;
}

.final-score-val {
    font-family: var(--font-latin);
    font-size: 2.4rem;
    font-weight: 800;
    color: var(--color-primary);
}

/* 리더보드 테이블 */
.leaderboard-section {
    text-align: left;
    margin-bottom: 25px;
}

.leaderboard-section h3 {
    font-size: 1.2rem;
    color: #4a4a4a;
    margin-bottom: 8px;
    padding-left: 5px;
}

.leaderboard-container {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    border: 2px solid rgba(0, 0, 0, 0.05);
    overflow: hidden;
    max-height: 180px;
    overflow-y: auto;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-latin);
}

.leaderboard-table th, .leaderboard-table td {
    padding: 8px 12px;
    text-align: center;
}

.leaderboard-table th {
    background: rgba(255, 117, 151, 0.1);
    color: #ff547d;
    font-weight: bold;
    font-size: 0.85rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.leaderboard-table td {
    font-size: 0.95rem;
    color: #5a5a5a;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

/* 한글 이름은 다시 Jua 폰트로 */
.leaderboard-table td:nth-child(2) {
    font-family: var(--font-korean);
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.25);
}

.leaderboard-table tr:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* 1, 2, 3등 강조 */
.leaderboard-table tr:nth-child(1) td:first-child { color: gold; font-weight: 800; font-size: 1.2rem; }
.leaderboard-table tr:nth-child(2) td:first-child { color: silver; font-weight: 800; font-size: 1.1rem; }
.leaderboard-table tr:nth-child(3) td:first-child { color: #cd7f32; font-weight: 800; font-size: 1.05rem; }

.loading {
    text-align: center;
    padding: 20px !important;
    font-family: var(--font-korean) !important;
    color: #8a8a8a !important;
}

/* 음소거 컨트롤 버튼 */
#audio-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    border: 3px solid rgba(255,255,255,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    z-index: 99;
    transition: all 0.2s;
}

#audio-toggle:hover {
    transform: scale(1.1);
    background: #ffffff;
}

#audio-toggle.active {
    background: var(--color-primary);
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
}

/* 미디어 쿼리: 스마트폰 및 터치 스크린 기기 최적화 */
@media (max-width: 480px) {
    body {
        align-items: flex-start;
        padding-top: 10px;
    }
    
    .app-container {
        padding: 8px;
    }
    
    .card {
        padding: 24px 16px;
    }
    
    .logo-title {
        font-size: 2.2rem;
    }
    
    .logo-emoji {
        font-size: 2.6rem;
    }
    
    .game-layout {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    #game-canvas {
        width: 220px; /* 화면 폭에 맞춰 보드 크기 적절히 줄임 */
    }
    
    .side-panel {
        flex-direction: row;
        width: 100%;
        max-width: 250px;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .nickname-badge {
        width: 100%;
        order: 1;
    }
    
    .next-card, .hold-card {
        flex: 1;
        order: 2;
        padding: 6px;
        max-width: 110px;
    }
    
    #next-canvas, #hold-canvas {
        width: 56px;
        height: 56px;
    }
    
    .stats-card {
        width: 100%;
        order: 3;
        flex-direction: row;
        justify-content: space-around;
        padding: 8px;
    }
    
    .stat-item {
        flex-direction: row;
        gap: 4px;
    }
    
    .stat-label {
        font-size: 0.72rem;
    }
    
    .stat-value {
        font-size: 0.95rem;
    }
    
    .stat-value.highlight {
        font-size: 1rem;
    }
    
    #btn-pause-toggle {
        display: none !important; /* 모바일은 화면 상의 일시정지 대신 사이드바 숨김으로 모바일 공간 확보 */
    }
    
    .mobile-controls-panel {
        display: flex; /* 모바일 전용 버튼 노출 */
    }
}
