/* 변수 설정 (파스텔 톤의 귀여운 색상) */
:root {
    --bg-color: #f6f8fd;
    --card-bg: #ffffff;
    --text-main: #333333;
    --primary: #ff7eb3;
    --secondary: #7afcff;
    --btn-hover: #ffedf4;
}

/* 기본 초기화 및 폰트 적용 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* 모바일 터치 하이라이트 제거 */
}

body {
    font-family: 'Jua', sans-serif; /* 한글은 Jua 폰트 기본 */
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* 모바일 스와이프 시 새로고침/스크롤 방지 */
    overscroll-behavior-y: contain;
}

/* 배경 장식 애니메이션 (떠다니는 물방울 모양) */
.decorative-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.7;
    animation: float 8s infinite ease-in-out alternate;
}

.blob-1 {
    width: 300px;
    height: 300px;
    background: #ffb8d2;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: #a1c4fd;
    bottom: -150px;
    right: -100px;
    animation-delay: 2s;
}

.blob-3 {
    width: 250px;
    height: 250px;
    background: #fdfbfb;
    top: 40%;
    left: 50%;
    animation-delay: 4s;
}

@keyframes float {
    0% { transform: translateY(0px) scale(1); }
    100% { transform: translateY(-30px) scale(1.05); }
}

/* 메인 앱 컨테이너 */
.app-container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* 헤더 영역 */
.header {
    text-align: center;
    margin-top: 3vh;
    margin-bottom: 2vh;
    position: relative;
    z-index: 20;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    position: relative;
    z-index: 20;
}

.control-btn {
    padding: 8px 16px;
    background: #ffb8d2;
    color: var(--text-main);
    border: 3px solid #fff;
    border-radius: 20px;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.active {
    background: var(--secondary);
    color: #2f3542;
}

/* 확대된 이미지 모달 */
.image-zoom-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.image-zoom-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.image-zoom-overlay img {
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.image-zoom-overlay.active img {
    transform: scale(1);
}

.grid-view-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.grid-view-container.hidden {
    display: none;
}

.grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #ffffff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    z-index: 101;
}

.grid-title {
    font-size: 1.5rem;
    color: var(--primary);
    margin: 0;
}

.btn-close-grid {
    background: #ff4757;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(255, 71, 87, 0.3);
}

.grid-view {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    overflow-y: auto;
    width: 100%;
    flex: 1;
    padding: 20px;
    scrollbar-width: none;
    align-content: start;
    max-width: 600px;
    margin: 0 auto;
}
.grid-view::-webkit-scrollbar {
    display: none;
}

.grid-card {
    background: var(--bg-color);
    border-radius: 15px;
    padding: 15px 10px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.grid-card:active {
    transform: scale(0.95);
}

.grid-letter {
    font-family: 'Fredoka One', cursive;
    font-size: 3rem;
    color: #3742fa;
    line-height: 1;
    word-break: break-all;
}

.grid-sound {
    font-size: 1.3rem;
    color: #ff4757;
    background: #ffeaa7;
    padding: 3px 15px;
    border-radius: 10px;
    margin-top: 10px;
    word-break: keep-all;
}

.logo-title {
    font-family: 'Fredoka One', cursive; /* 영문 타이틀 */
    font-size: 2.8rem;
    color: #ff6b81;
    letter-spacing: 1px;
    text-shadow: 3px 3px 0px #fff;
}

.subtitle {
    font-size: 1.3rem;
    color: #57606f;
    margin-top: 5px;
}

/* 카드 스테이지 (중앙 영역) */
.card-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    position: relative;
    width: 100%;
}

/* 네비게이션 버튼 */
.nav-button {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 20;
    color: #ff6b81;
    transition: all 0.2s ease;
    position: absolute;
}
.prev-button { left: -5px; }
.next-button { right: -5px; }

.nav-button:active {
    transform: scale(0.9);
    background: var(--btn-hover);
}

.nav-button svg {
    width: 32px;
    height: 32px;
}

/* 카드 뷰포트 (카드가 보여지는 영역) */
.card-viewport {
    width: 100%;
    height: 65vh;
    max-height: none; /* 크기 제한 해제하여 화면 활용도 극대화 */
    position: relative;
    margin: 0 20px;
    perspective: 1200px;
}

/* 파닉스 카드 본체 */
.phonics-card {
    width: 100%;
    height: 100%;
    background: var(--card-bg);
    border-radius: 30px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    position: absolute;
    top: 0;
    left: 0;
    border: 6px solid #fff;
    will-change: transform, opacity;
}

.phonics-card.word-mode {
    align-items: flex-start;
    padding: 25px; /* 상단, 좌우 여백을 25px로 동일하게 설정 */
}

.card-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.phonics-card.word-mode .card-inner {
    justify-content: flex-start;
}

.phonics-card.word-mode.no-image .card-inner {
    justify-content: center;
}

/* 이미지 켜기/끄기 토글 버튼 */
.toggle-image-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: #a1c4fd;
    border: 3px solid #fff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    z-index: 30;
    color: white;
    transition: transform 0.2s, background 0.2s;
}

.toggle-image-btn:active {
    transform: scale(0.9);
}

.phonics-card.word-mode .toggle-image-btn {
    display: flex;
}

.toggle-image-btn svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* 단어 모드 전용 이미지 컨테이너 */
.card-image-container {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 4 / 3;
    margin: 0 auto 30px auto;
    border-radius: 30px;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: 6px solid var(--btn-hover);
    background: #f0f0f0;
    display: none;
    cursor: zoom-in;
}

.card-image-container.show {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.card-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 알파벳 (영어) */
.alphabet-display {
    font-family: 'Fredoka One', cursive;
    font-size: 8rem;
    color: #3742fa;
    line-height: 1;
    margin-bottom: 10px;
    text-shadow: 4px 4px 0px #dfe4ea;
    word-break: break-all;
    padding: 0 10px;
    transition: font-size 0.3s;
}

.alphabet-display.word-mode-text {
    font-size: clamp(3rem, 15vw, 6rem);
    width: 100%;
    text-align: center;
    margin-bottom: 5px;
}

/* 발음 (한국어) */
.phonics-display {
    font-size: 3.5rem;
    color: #ff4757;
    background: #ffeaa7;
    padding: 5px 30px;
    border-radius: 20px;
    margin-top: 15px;
    word-break: keep-all;
    text-align: center;
    transition: font-size 0.3s;
}

.phonics-display.word-mode-text {
    font-size: clamp(1.2rem, 6vw, 2.5rem);
    padding: 10px 20px;
    width: 100%;
    max-width: 320px;
    margin-top: 10px;
}

/* 하단 프로그레스 바 영역 */
.footer {
    text-align: center;
    padding-bottom: 3vh;
}

.progress-indicator {
    display: inline-block;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px 25px;
    border-radius: 30px;
    font-size: 1.4rem;
    color: #2f3542;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

/* =========================================
   카드 스와이프 애니메이션 (JS 타이머와 동기화)
   ========================================= */

/* 왼쪽으로 퇴장 (400ms) */
.slide-out-left {
    animation: slideOutLeft 0.4s forwards cubic-bezier(0.4, 0, 0.2, 1);
}
/* 오른쪽으로 퇴장 (400ms) */
.slide-out-right {
    animation: slideOutRight 0.4s forwards cubic-bezier(0.4, 0, 0.2, 1);
}
/* 오른쪽에서 입장 (600ms) */
.slide-in-right {
    animation: slideInRight 0.6s forwards cubic-bezier(0.4, 0, 0.2, 1);
}
/* 왼쪽에서 입장 (600ms) */
.slide-in-left {
    animation: slideInLeft 0.6s forwards cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideOutLeft {
    to { transform: translateX(-150%) rotate(-15deg); opacity: 0; }
}
@keyframes slideOutRight {
    to { transform: translateX(150%) rotate(15deg); opacity: 0; }
}
@keyframes slideInRight {
    from { transform: translateX(150%) rotate(15deg); opacity: 0; }
    to { transform: translateX(0) rotate(0); opacity: 1; }
}
@keyframes slideInLeft {
    from { transform: translateX(-150%) rotate(-15deg); opacity: 0; }
    to { transform: translateX(0) rotate(0); opacity: 1; }
}