/* ========== 모바일 최우선 설계 ========== */

/* 전역 설정 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* 모바일 탭 하이라이트 제거 */
}

:root {
    /* 안전 영역 (iPhone 노치 대응) */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
    --safe-area-right: env(safe-area-inset-right);
}

html {
    /* 부드러운 스크롤 */
    scroll-behavior: smooth;
    /* iOS 오버스크롤 방지 */
    overscroll-behavior: none;
    /* 폰트 크기 자동 조절 방지 (iOS) */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
    position: relative;
    
    /* Safe Area 적용 */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* ========== 언어 선택 드롭다운 (에고그램 스타일) ========== */
.language-dropdown {
    position: fixed;
    top: calc(15px + var(--safe-area-top));
    right: 15px;
    z-index: 1000;
}

.dropdown-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #e0e7ff;
    padding: 10px 16px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    color: #667eea;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: all 0.3s;
    backdrop-filter: blur(5px);
}

.dropdown-btn:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.arrow-down {
    font-size: 10px;
    transition: transform 0.3s;
}

.language-dropdown.active .arrow-down {
    transform: rotate(180deg);
}

.dropdown-content {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: white;
    min-width: 140px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: dropdownFadeIn 0.3s ease-out;
}

.language-dropdown.active .dropdown-content {
    display: flex;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.lang-option {
    background: none;
    border: none;
    padding: 12px 20px;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    color: #444;
    cursor: pointer;
    transition: background 0.2s;
}

.lang-option:hover {
    background: #f0f4ff;
    color: #667eea;
}

.lang-option:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
}

/* 기존 .language-selector 및 .lang-btn 관련 스타일 삭제/수정 */
.lang-btn { display: none; } /* 기존 코드 호환을 위해 숨김 처리 */

/* ========== 컨테이너 (모바일 우선) ========== */
.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 15px;
    /* 언어 버튼 영역 확보 */
    padding-top: calc(60px + var(--safe-area-top));
}

/* ========== 화면 전환 애니메이션 ========== */
.screen {
    display: none;
    animation: fadeInUp 0.5s ease-out;
}

.screen.active {
    display: block;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== 홈 화면 (모바일 최적화) ========== */
.home-content {
    background: white;
    border-radius: 20px;
    padding: 40px 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    margin-top: 20px;
    /* 부드러운 터치 스크롤 */
    -webkit-overflow-scrolling: touch;
}

.sparkle {
    font-size: 50px;
    animation: sparkle 2s infinite;
}

@keyframes sparkle {
    0%, 100% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(1.15) rotate(180deg);
    }
}

.main-title {
    font-size: clamp(28px, 8vw, 48px); /* 반응형 폰트 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 15px 0;
    font-weight: 800;
    line-height: 1.2;
    word-break: break-word; /* 일본어 등 띄어쓰기 없는 언어 대응 */
    overflow-wrap: break-word;
}

.subtitle {
    font-size: clamp(14px, 4vw, 18px);
    color: #666;
    margin-bottom: 25px;
    line-height: 1.6;
    padding: 0 10px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.start-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 18px 50px;
    font-size: clamp(16px, 4.5vw, 20px);
    border-radius: 50px;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
    margin-top: 20px;
    width: 100%;
    max-width: 320px;
    
    /* 터치 최적화 */
    touch-action: manipulation;
    user-select: none;
    min-height: 56px; /* 충분한 터치 영역 */
}

.start-btn:active {
    transform: scale(0.98);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.6);
}

.info-box {
    margin-top: 25px;
    padding: 15px;
    background: #f8f9ff;
    border-radius: 15px;
    color: #555;
    font-size: clamp(13px, 3.5vw, 15px);
}

/* ========== 진행률 바 (모바일 최적화) ========== */
.progress-container {
    background: white;
    border-radius: 15px;
    padding: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    position: sticky;
    top: calc(10px + var(--safe-area-top));
    z-index: 100;
    backdrop-filter: blur(10px);
}

.progress-bar {
    height: 6px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}

.progress-text {
    text-align: center;
    margin-top: 8px;
    font-weight: 700;
    color: #667eea;
    font-size: clamp(15px, 4vw, 18px);
}

/* ========== 질문 카드 (모바일 최적화) ========== */
.question-card {
    background: white;
    border-radius: 20px;
    padding: 25px 18px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    margin-bottom: 20px;
}

.question-title {
    font-size: clamp(18px, 5vw, 24px);
    color: #333;
    margin-bottom: 25px;
    text-align: center;
    line-height: 1.5;
    font-weight: 700;
    word-break: break-word;
    overflow-wrap: break-word;
    padding: 0 5px;
}

.answers-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.answer-btn {
    background: #f8f9ff;
    border: 2px solid #e0e7ff;
    padding: 18px 16px;
    border-radius: 12px;
    cursor: pointer;
    font-size: clamp(14px, 3.8vw, 16px);
    text-align: left;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #333;
    font-weight: 600;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
    
    /* 터치 최적화 */
    touch-action: manipulation;
    user-select: none;
    min-height: 60px; /* 충분한 터치 영역 */
    
    /* 터치 피드백 개선 */
    position: relative;
    overflow: hidden;
}

/* 터치 시 물결 효과 */
.answer-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(102, 126, 234, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.answer-btn:active::before {
    width: 300px;
    height: 300px;
}

.answer-btn:active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
    transform: scale(0.98);
}

.back-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
    text-decoration: underline;
    width: 100%;
    text-align: center;
    padding: 10px;
    transition: color 0.3s;
}

.back-btn:active {
    color: #667eea;
}

/* ========== 로딩 화면 (모바일 최적화) ========== */
.loading-content {
    background: white;
    border-radius: 20px;
    padding: 60px 25px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    margin-top: 40px;
}

.spinner {
    width: 70px;
    height: 70px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 25px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-title {
    font-size: clamp(22px, 6vw, 28px);
    color: #667eea;
    margin-bottom: 12px;
    font-weight: 700;
}

.loading-step {
    font-size: clamp(14px, 4vw, 16px);
    color: #666;
    line-height: 1.6;
    word-break: keep-all;
}

/* ========== 결과 화면 (모바일 최적화) ========== */
.result-content {
    background: white;
    border-radius: 20px;
    padding: 40px 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    margin-top: 20px;
    margin-bottom: 30px;
    text-align: center;
}

.result-color-display {
    width: clamp(220px, 65vw, 300px); /* 선명하게 보이도록 크기 유지 및 약간 확대 */
    height: clamp(220px, 65vw, 300px);
    border-radius: 50%;
    margin: 0 auto 35px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); /* 부드러운 기본 그림자만 유지 */
    animation: auraAppear 1.2s ease-out forwards;
    background-size: cover;
    background-position: center;
    position: relative;
    border: 4px solid white; /* 이미지를 강조하는 깔끔한 흰색 테두리 */
}

@keyframes auraAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.result-title {
    font-size: clamp(32px, 9vw, 42px);
    text-align: center;
    margin-bottom: 8px;
    font-weight: 800;
    line-height: 1.2;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-subtitle {
    text-align: center;
    font-size: clamp(16px, 4.5vw, 20px);
    color: #666;
    margin-bottom: 25px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.keywords {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 30px;
    padding: 0 10px;
}

.keyword-tag {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    font-size: clamp(12px, 3.5vw, 14px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    word-break: break-word;
}

.result-details {
    text-align: left;
    margin-top: 30px;
    padding: 0 5px;
}

.result-details h3 {
    color: #333;
    margin: 40px 0 15px 0;
    font-size: clamp(17px, 5.5vw, 20px);
    font-weight: 800;
    border-bottom: 1.5px solid #eee;
    padding-bottom: 10px;
}

.result-details p {
    line-height: 1.8;
    color: #444;
    margin-bottom: 25px;
    font-size: clamp(15px, 4.2vw, 17px);
    padding: 5px 0;
    word-break: break-word;
    overflow-wrap: break-word;
}

.result-details ul {
    list-style: none;
    padding-left: 0;
}

.result-details li {
    padding: 14px 0;
    color: #333;
    line-height: 1.7;
    font-size: clamp(14px, 4vw, 16px);
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    word-break: break-word;
    overflow-wrap: break-word;
    border-bottom: 1px solid #f8f8f8;
}

.result-details li:last-child {
    border-bottom: none;
}

.result-details li::before {
    content: "✦";
    color: #667eea;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ========== 버튼들 (모바일 최적화) ========== */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 30px 0;
    padding: 0 5px;
}

.download-btn {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    padding: 16px 30px;
    border-radius: 30px;
    cursor: pointer;
    font-size: clamp(15px, 4vw, 16px);
    font-weight: 700;
    transition: all 0.3s;
    touch-action: manipulation;
    user-select: none;
    width: 100%;
    min-height: 52px;
}

.share-btn {
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    color: white;
    border: none;
    padding: 16px 30px;
    border-radius: 30px;
    cursor: pointer;
    font-size: clamp(16px, 4.5vw, 18px);
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(253, 160, 133, 0.4);
    transition: all 0.3s;
    touch-action: manipulation;
    user-select: none;
    width: 100%;
    min-height: 56px;
    animation: pulse-orange 2s infinite;
}

@keyframes pulse-orange {
    0% {
        transform: scale(1);
        box-shadow: 0 10px 25px rgba(253, 160, 133, 0.4);
    }
    50% {
        transform: scale(1.03);
        box-shadow: 0 15px 35px rgba(253, 160, 133, 0.6);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 10px 25px rgba(253, 160, 133, 0.4);
    }
}

.download-btn:active {
    background: #e2e8f0;
    transform: scale(0.98);
}

.share-btn:active {
    transform: scale(0.96);
    box-shadow: 0 5px 15px rgba(253, 160, 133, 0.4);
}

.retry-btn {
    background: #f8f9ff;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 16px 35px;
    border-radius: 30px;
    cursor: pointer;
    font-size: clamp(15px, 4vw, 16px);
    font-weight: 700;
    margin-top: 15px;
    transition: all 0.3s;
    display: block;
    width: 100%;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
    
    /* 터치 최적화 */
    touch-action: manipulation;
    user-select: none;
    min-height: 52px;
}

.retry-btn:active {
    background: #667eea;
    color: white;
    transform: scale(0.98);
}

/* ========== 모든 아우라 둘러보기 ========== */
.explore-auras {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px dashed #e0e7ff;
    text-align: center;
}

.explore-auras h3 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: clamp(18px, 5vw, 22px);
    font-weight: 700;
}

.aura-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    justify-items: center;
    max-width: 240px;
    margin: 0 auto 25px auto;
}

.aura-tab-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid white;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: all 0.3s;
    background-size: cover;
    background-position: center;
}

.aura-tab-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.aura-tab-btn.active {
    border-color: #667eea;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

.aura-explorer-detail {
    background: #f8f9ff;
    border-radius: 15px;
    padding: 20px;
    text-align: left;
    animation: fadeIn 0.5s ease-out;
}

.aura-explorer-detail h4 {
    font-size: 20px;
    color: #333;
    margin-bottom: 5px;
}

.aura-explorer-detail p#explorer-subtitle {
    font-weight: 700;
    color: #667eea;
    font-size: 14px;
    margin-bottom: 12px;
}

.aura-explorer-detail p#explorer-description {
    font-size: 14px;
    color: #555;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== Footer (모바일 최적화) ========== */
footer {
    text-align: center;
    padding: 25px 15px;
    padding-bottom: calc(25px + var(--safe-area-bottom));
    color: white;
    margin-top: 40px;
    font-size: clamp(12px, 3.5vw, 14px);
}

footer p {
    line-height: 1.8;
    word-break: keep-all;
}

footer a {
    color: white;
    text-decoration: none;
    margin: 0 8px;
    opacity: 0.9;
    transition: opacity 0.3s;
    display: inline-block;
    padding: 5px;
    /* 터치 영역 확보 */
    min-width: 44px;
    min-height: 44px;
    line-height: 34px;
}

footer a:active {
    opacity: 1;
    transform: scale(0.95);
}

/* ========== 태블릿 최적화 (세로 모드) ========== */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        max-width: 600px;
        padding: 20px 25px;
    }
    
    .home-content,
    .question-card,
    .loading-content,
    .result-content {
        padding: 50px 35px;
    }
    
    .action-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .download-btn,
    .share-btn {
        width: auto;
        min-width: 200px;
    }
}

/* ========== 태블릿 가로 모드 / 데스크탑 ========== */
@media (min-width: 769px) {
    .container {
        max-width: 800px;
        padding: 20px 30px;
    }
    
    .home-content {
        padding: 60px 50px;
        margin-top: 60px;
    }
    
    .question-card {
        padding: 40px 45px;
    }
    
    .result-content {
        padding: 50px 45px;
        margin-top: 60px;
    }
    
    .action-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .download-btn,
    .share-btn {
        width: auto;
        min-width: 220px;
    }
    
    /* 데스크탑에서 호버 효과 활성화 */
    .answer-btn:hover {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border-color: #667eea;
        transform: translateX(8px);
        box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
    }
    
    .start-btn:hover,
    .download-btn:hover,
    .share-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 30px rgba(102, 126, 234, 0.5);
    }
    
    .lang-btn:hover {
        background: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }
    
    .retry-btn:hover {
        background: #667eea;
        color: white;
    }
}

/* ========== 대형 데스크탑 (1920px+) ========== */
@media (min-width: 1200px) {
    .container {
        max-width: 900px;
    }
    
    .main-title {
        font-size: 52px;
    }
    
    .question-title {
        font-size: 26px;
    }
    
    .result-title {
        font-size: 46px;
    }
}

/* ========== 작은 모바일 (iPhone SE 등) ========== */
@media (max-width: 375px) {
    .container {
        padding: 12px;
    }
    
    .home-content,
    .question-card,
    .loading-content,
    .result-content {
        padding: 30px 18px;
        border-radius: 18px;
    }
    
    .sparkle {
        font-size: 40px;
    }
    
    .keywords {
        gap: 8px;
    }
    
    .keyword-tag {
        padding: 8px 16px;
    }
    
    .language-selector {
        top: calc(8px + var(--safe-area-top));
        right: 8px;
        gap: 5px;
    }
    
    .lang-btn {
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* ========== 가로 모드 (모바일) ========== */
@media (max-height: 600px) and (orientation: landscape) {
    .home-content,
    .loading-content {
        margin-top: 15px;
        padding: 30px 20px;
    }
    
    .sparkle {
        font-size: 35px;
    }
    
    .result-color-display {
        width: 100px;
        height: 100px;
    }
    
    .result-content {
        margin-top: 15px;
        padding: 30px 20px;
    }
}

/* ========== iOS 특수 처리 ========== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari에서 입력 줌 방지 */
    input, select, textarea {
        font-size: 16px !important;
    }
    
    /* iOS 바운스 스크롤 제거 */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .container {
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========== 접근성 개선 ========== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== 다크 모드 지원 (선택사항) ========== */
@media (prefers-color-scheme: dark) {
    /* 필요시 다크 모드 스타일 추가 */
}

/* ========== 프린트 최적화 ========== */
@media print {
    body {
        background: white;
    }
    
    .language-selector,
    .action-buttons,
    .ad-space,
    footer {
        display: none;
    }
}

/* ========== 터치 디바이스 최적화 ========== */
@media (hover: none) and (pointer: coarse) {
    /* 모든 호버 효과 제거 (터치 디바이스) */
    .answer-btn:hover,
    .start-btn:hover,
    .download-btn:hover,
    .share-btn:hover,
    .retry-btn:hover,
    .lang-btn:hover {
        transform: none;
    }
}
