/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Light Theme Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-tertiary: #adb5bd;
    --accent-primary: #007bff;
    --accent-secondary: #6c5ce7;
    --accent-tertiary: #00b894;
    --border-color: #dee2e6;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-teto: linear-gradient(135deg, #FF6B6B 0%, #FF8E8E 100%);
    --gradient-egen: linear-gradient(135deg, #4ECDC4 0%, #71EBE1 100%);
}

/* Dark Theme Colors */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-tertiary: #404040;
        --text-primary: #f8f9fa;
        --text-secondary: #adb5bd;
        --text-tertiary: #6c757d;
        --accent-primary: #0d6efd;
        --accent-secondary: #8b5cf6;
        --accent-tertiary: #06d6a0;
        --border-color: #495057;
        --shadow-light: rgba(0, 0, 0, 0.3);
        --shadow-medium: rgba(0, 0, 0, 0.4);
    }
}

/* Manual Dark Theme Override */
body.dark-theme {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    --text-primary: #f8f9fa;
    --text-secondary: #adb5bd;
    --text-tertiary: #6c757d;
    --accent-primary: #0d6efd;
    --accent-secondary: #8b5cf6;
    --accent-tertiary: #06d6a0;
    --border-color: #495057;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.4);
}

/* Base Typography */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    font-size: 16px;
    transition: all 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Layout and Container */
#app {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Screen Management */
.screen {
    display: none;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.screen.active {
    display: block;
    opacity: 1;
    transform: translateX(0);
}

/* Loading Screen */
#loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    color: white;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header Components */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    position: relative;
    z-index: 10;
}

.language-selector {
    display: flex;
    gap: 8px;
}

.lang-btn {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.lang-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
}

.lang-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-light);
}

/* Progress Components */
.progress-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 0;
}

.progress-info {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 14px;
    min-width: 40px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 4px;
    transition: width 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Welcome Screen */
.welcome-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 0;
}

/* Personality Preview Grid */
.personality-preview {
    margin: 0 auto 32px;
    width: 100%;
    max-width: min(95vw, 450px);
    padding: 0 8px;
}

.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(8px, 2vw, 12px);
    justify-items: center;
}

.preview-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
}

.preview-img {
    width: 100%;
    max-width: clamp(110px, 25vw, 160px);
    height: auto;
    aspect-ratio: 4 / 5;
    border-radius: 12px;
    object-fit: cover;
    object-position: center top;
    box-shadow: 0 4px 16px var(--shadow-light);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-bottom: 6px;
}

.preview-img:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px var(--shadow-medium);
}

.preview-label {
    font-size: clamp(12px, 2.8vw, 15px);
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 0.8;
    margin-top: 2px;
}



.welcome-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 16px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.3;
}

.welcome-content p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    line-height: 1.6;
}

.test-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 40px;
    width: 100%;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.info-item i {
    color: var(--accent-primary);
    width: 20px;
    height: 20px;
}

/* Button Styles */
.primary-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

/* Gender Selection */
.gender-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 0;
}

.gender-content h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.gender-content p {
    color: var(--text-secondary);
    margin-bottom: 40px;
    font-size: 16px;
}

.gender-options {
    display: flex;
    gap: 20px;
    width: 100%;
}

.gender-btn {
    flex: 1;
    padding: 32px 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.gender-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow-light);
}

.gender-btn.selected {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
}

.gender-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.gender-btn.selected .gender-icon {
    background: rgba(255, 255, 255, 0.2);
}

.gender-icon i {
    width: 32px;
    height: 32px;
}

/* Test Screen */
.question-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

.question-card {
    width: 100%;
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 32px 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px var(--shadow-light);
}

.question-card h3 {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.5;
    margin-bottom: 32px;
    text-align: center;
    color: var(--text-primary);
}

.answer-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.answer-btn {
    width: 100%;
    padding: 20px 24px;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.answer-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow-light);
}

.answer-btn:first-child {
    border-color: var(--accent-tertiary);
}

.answer-btn:first-child:hover {
    border-color: var(--accent-tertiary);
    background: rgba(6, 214, 160, 0.1);
}

.answer-btn:last-child {
    border-color: #ff6b6b;
}

.answer-btn:last-child:hover {
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

/* Result Screen */
.result-content {
    flex: 1;
    padding: 40px 0;
    display: flex;
    flex-direction: column;
}

.result-header {
    text-align: center;
    margin-bottom: 32px;
}

.result-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.result-card {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 32px 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px var(--shadow-light);
    margin-bottom: 32px;
}

.result-type {
    text-align: center;
    margin-bottom: 24px;
}

.result-icon {
    width: 160px;
    height: 200px;
    margin: 0 auto 20px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 8px 24px var(--shadow-medium);
    background: var(--bg-tertiary);
}

.result-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: 20px;
    transition: transform 0.3s ease;
}

.result-icon img:hover {
    transform: scale(1.05);
}

.result-type h3 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.result-percentage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.result-percentage span {
    transition: all 0.3s ease;
}

.dominant-percentage {
    font-size: 24px !important;
    font-weight: 700 !important;
    color: var(--primary-color) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transform: scale(1.1);
}

.secondary-percentage {
    font-size: 16px !important;
    font-weight: 500 !important;
    color: var(--text-secondary) !important;
    opacity: 0.8;
}

.result-percentage .vs {
    color: var(--text-tertiary);
    font-size: 14px;
}

.result-description {
    margin-bottom: 24px;
}

.result-description p {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.result-traits h4 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.result-traits ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-traits li {
    font-size: 15px;
    color: var(--text-secondary);
    position: relative;
    padding-left: 20px;
}

.result-traits li::before {
    content: '•';
    color: var(--accent-primary);
    font-weight: bold;
    position: absolute;
    left: 0;
}

/* Romance Style Section */
.romance-section {
    margin-top: 32px;
    padding: 24px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    border-radius: 16px;
    color: white;
}

.romance-section h4 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    text-align: center;
    color: white;
}

.romance-content p {
    font-size: 15px;
    line-height: 1.6;
    text-align: center;
    opacity: 0.95;
}

/* Compatibility Section */
.compatibility-section {
    margin-top: 32px;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.compatibility-section h4 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    text-align: center;
}

.compatibility-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.match-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.best-match {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
    color: white;
}

.worst-match {
    background: linear-gradient(135deg, #8b5a3c, #6b4226);
    color: white;
}

.match-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.match-label {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
}

.match-type {
    font-size: 16px;
    font-weight: 600;
}

.compatibility-reason {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border-left: 4px solid var(--accent-primary);
}

.compatibility-reason h5 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.compatibility-reason p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Action Buttons */
.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.share-btn {
    width: 100%;
    padding: 16px 24px;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.share-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow-light);
}

.kakao-btn {
    background: #FEE500;
    color: #3C1E1E;
    border-color: #FEE500;
}

.kakao-btn:hover {
    background: #FFEB3B;
    border-color: #FFEB3B;
    color: #3C1E1E;
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 0 16px;
    }
    
    .welcome-content h1 {
        font-size: 24px;
    }
    
    .personality-preview {
        max-width: min(92vw, 380px);
        padding: 0 6px;
    }
    
    .preview-grid {
        gap: clamp(6px, 1.5vw, 10px);
    }
    
    .preview-img {
        max-width: clamp(100px, 22vw, 140px);
    }
    
    .preview-label {
        font-size: clamp(11px, 2.5vw, 14px);
    }
    
    .gender-options {
        flex-direction: column;
        gap: 16px;
    }
    
    .gender-btn {
        padding: 24px 16px;
    }
    
    .question-card {
        padding: 24px 20px;
    }
    
    .question-card h3 {
        font-size: 18px;
    }
    
    .result-icon {
        width: 140px;
        height: 175px;
    }
}

@media (max-width: 360px) {
    .container {
        padding: 0 12px;
    }
    
    .welcome-content h1 {
        font-size: 22px;
    }
    
    .test-info {
        gap: 12px;
    }
    
    .info-item {
        padding: 12px;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.question-card {
    animation: fadeInUp 0.4s ease-out;
}

/* Touch-friendly improvements */
@media (hover: none) {
    .primary-btn:hover,
    .share-btn:hover,
    .answer-btn:hover,
    .gender-btn:hover,
    .icon-btn:hover,
    .lang-btn:hover {
        transform: none;
    }
}

/* Focus states for accessibility */
button:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}

/* Utility classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
