@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+KR:wght@100;200;300;400;500;600;700&display=swap');

:root {
    --primary-color: #d2691e;
    --secondary-color: #8b4513;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --dark-bg: #1f2937;
    --light-bg: #f9fafb;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'IBM Plex Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #ededed;
    min-height: 100vh;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }
}

.container {
    max-width: 400px;
    margin: 0 auto;
    background: white;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 1;
}

@media (max-width: 768px) {
    .container {
        max-width: 100vw;
        width: 100vw;
        min-height: 100vh;
        margin: 0;
    }
}

header {
    text-align: center;
    padding: 30px 20px 20px;
    color: #8b4513;
    background: white;
    border-radius: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Header visibility states */
header.hidden {
    display: none !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

header.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 8px;
    text-shadow: none;
    font-weight: 700;
}

header p {
    font-size: 1rem;
    opacity: 0.8;
    color: #8b4513;
}

main {
    background: white;
    padding: 20px 20px 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
    z-index: 5;
}

/* Adjust main positioning when header is hidden */
header.hidden ~ main {
    padding-top: 20px;
    justify-content: flex-start;
}

/* 손금선 소개 섹션 */
.palmline-intro-section {
    display: block;
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 320px;
    width: 100%;
    padding: 0 20px;
    z-index: 12;
}

.palmline-intro-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    justify-items: center;
}

.palmline-intro-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    opacity: 0.85;
    transition: opacity 0.3s ease;
}

.palmline-intro-item:hover {
    opacity: 1;
}

.palmline-icon {
    font-size: 1.8rem;
    margin-bottom: 2px;
}

.palmline-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: #8b4513;
    text-align: center;
    line-height: 1.2;
}

.upload-section {
    margin-bottom: 40px;
    display: flex;
    justify-content: center;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    width: 280px;
    height: 280px;
}

.upload-area {
    border: 2px dashed #d2691e;
    border-radius: 15px;
    padding: 30px 15px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: #fafafa;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    margin: 0 auto;
    box-sizing: border-box;
}

.hand-guide-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.5;
    pointer-events: none;
    border-radius: 15px;
    z-index: 1;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.upload-icon {
    color: var(--primary-color);
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

.upload-area h2 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 1.2rem;
    position: relative;
    z-index: 2;
    font-weight: 600;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 15px;
    position: relative;
    z-index: 2;
    font-size: 0.9rem;
}

.upload-btn, .analyze-btn, .reset-btn, .retry-btn, .share-btn {
    padding: 12px 30px;
    font-size: 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.upload-btn {
    background: var(--primary-color);
    color: white;
    position: relative;
    z-index: 2;
}

.upload-btn:hover {
    background: #5558e3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(99, 102, 241, 0.3);
}

.preview-section {
    text-align: center;
    animation: fadeIn 0.5s ease;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 21;
    box-sizing: border-box;
}

.preview-section img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 15px;
    box-shadow: var(--shadow);
}

.analyze-btn {
    background: var(--success-color);
    color: white;
    margin-right: 10px;
}

.analyze-btn:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.3);
}

.reset-btn {
    background: var(--text-secondary);
    color: white;
}

.reset-btn:hover {
    background: #4b5563;
}

.loading-section {
    text-align: center;
    padding: 30px;
    animation: fadeInCentered 0.5s ease forwards;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    z-index: 30;
    width: 420px;
    height: 460px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.analyzing-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
    animation: pulse 1.5s ease-in-out infinite;
    white-space: nowrap;
    margin-top: 10px;
    text-align: center;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.countdown-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 25px;
    width: 100%;
    height: 100%;
    overflow: visible;
    min-height: 400px;
}

.countdown-circle {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 15px;
    flex-shrink: 0;
}

.countdown-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
    overflow: visible;
}

.countdown-bg {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 8;
}

.countdown-progress {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 565.48;
    stroke-dashoffset: 0;
    animation: countdown 5s linear forwards;
}

@keyframes countdown {
    to {
        stroke-dashoffset: 565.48;
    }
}

.countdown-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: bold;
    color: var(--primary-color);
}

.loading-text {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin: 10px 0;
    text-align: center;
    line-height: 1.4;
    flex-shrink: 0;
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 320px;
    margin-top: 10px;
    flex-shrink: 0;
}

.loading-steps .step {
    padding: 10px 20px;
    background: var(--light-bg);
    border-radius: 8px;
    color: var(--text-secondary);
    opacity: 0.5;
    transition: all 0.3s ease;
}

.loading-steps .step.active {
    opacity: 1;
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.loader {
    width: 60px;
    height: 60px;
    border: 5px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

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

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

@keyframes fadeInCentered {
    from { 
        opacity: 0; 
        transform: translate(-50%, calc(-50% + 20px));
    }
    to { 
        opacity: 1; 
        transform: translate(-50%, -50%);
    }
}

/* Ensure animations maintain z-index hierarchy */
.fadeIn, .loading-section, .results-section, .preview-section {
    isolation: isolate;
}

/* Better content positioning when header is hidden - only for results-section */
header.hidden ~ main .results-section {
    margin-top: 0 !important;
    padding-top: 20px !important;
}

/* Ensure smooth content transitions - only for results-section */
.results-section {
    transition: margin-top 0.3s ease, padding-top 0.3s ease;
}

.results-section {
    animation: fadeIn 0.5s ease;
    position: relative;
    z-index: 25;
    margin-top: 100px;
    padding: 20px;
}

.results-section h2 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 2rem;
    color: var(--text-primary);
}

.result-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.result-card {
    background: var(--light-bg);
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.result-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.card-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.card-icon {
    font-size: 2rem;
    margin-right: 10px;
}

.card-header h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
}

.result-bars {
    margin-bottom: 15px;
}

.result-bar {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.result-label {
    width: 100px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-right: 10px;
}

.bar-container {
    flex: 1;
    height: 25px;
    background: var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 1s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

.heart-card .bar-fill { background: linear-gradient(90deg, #ef4444, #f87171); }
.love-card .bar-fill { background: linear-gradient(90deg, #ec4899, #f9a8d4); }
.life-card .bar-fill { background: linear-gradient(90deg, #10b981, #6ee7b7); }
.brain-card .bar-fill { background: linear-gradient(90deg, #3b82f6, #93c5fd); }

.result-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.summary-section {
    background: var(--light-bg);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
}

.summary-section h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

#summaryText {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
    font-size: 1.05rem;
}

.retry-btn, .share-btn {
    color: white;
    margin-bottom: 10px;
    padding: 12px 30px;
    font-size: 1rem;
    width: 100%;
    max-width: 200px;
    display: inline-block;
    text-align: center;
    box-sizing: border-box;
}

.retry-btn {
    background: #18db1f;
}

.share-btn {
    background: #e8db25;
}

.retry-btn:hover {
    background: #15c21c;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(24, 219, 31, 0.3);
}

.share-btn:hover {
    background: #d4c821;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(232, 219, 37, 0.3);
}

footer {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    text-align: center;
    color: #8b4513;
    padding: 10px 15px 15px;
    opacity: 0.7;
    font-size: 0.45rem;
    background: white;
    border-radius: 0;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 11;
}

/*
Z-INDEX HIERARCHY:
- Background/Base: z-index: 1-9
  - Container: 1
  - Hand guide overlay: 1
  - Upload elements (icons, text, buttons): 2
  - Main content: 5
  
- Fixed UI Elements: z-index: 10-19
  - Header: 10
  - Footer: 11
  - Palm line intro: 12
  
- Content Sections: z-index: 20-29
  - Upload section: 20
  - Preview section: 21
  - Results section: 25
  
- Interactive Overlays: z-index: 30-39
  - Loading section: 30
  
- System Messages: z-index: 40+
  - All message overlays: 40
*/

/* Message overlays - highest priority */
.message-overlay {
    z-index: 40 !important;
    position: fixed !important;
}

/* Ensure loading messages appear above everything */
#modelLoadingMessage,
#successMessage,
#errorMessage,
#warningMessage {
    z-index: 40 !important;
}

    
    header {
        padding: 25px 15px 15px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    header p {
        font-size: 0.9rem;
    }
    
    main {
        padding: 15px 15px 25px;
        justify-content: center;
        align-items: center;
        width: 100%;
    }
    
    .palmline-intro-section {
        top: 25%;
        max-width: 280px;
    }
    
    .palmline-intro-grid {
        gap: 10px;
    }
    
    .palmline-icon {
        font-size: 1.5rem;
    }
    
    .palmline-name {
        font-size: 0.7rem;
    }
    
    .upload-section {
        width: 240px;
        height: 240px;
    }
    
    .upload-area {
        padding: 25px 15px;
    }
    
    .loading-section {
        width: 380px;
        height: 440px;
        padding: 25px;
    }
    
    .countdown-container {
        gap: 22px;
    }
    
    .countdown-circle {
        width: 180px;
        height: 180px;
        margin: 12px;
    }
    
    
    .countdown-bg,
    .countdown-progress {
        cx: 90;
        cy: 90;
        r: 81;
    }
    
    .countdown-progress {
        stroke-dasharray: 508.94;
    }
    
    @keyframes countdown {
        to {
            stroke-dashoffset: 508.94;
        }
    }
    
    .countdown-number {
        font-size: 3.2rem;
    }
    
    .loading-steps {
        max-width: 330px;
    }
    
    .result-cards {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .results-section h2 {
        font-size: 1.4rem;
    }
    
    .summary-section {
        padding: 20px;
    }
    
    footer {
        padding: 8px 15px 12px;
    }
}

@media (max-width: 480px) {
    .container {
        max-width: 100vw;
        width: 100vw;
        min-height: 100vh;
        margin: 0;
        padding: 0 15px;
        border-radius: 0;
    }
    
    header {
        padding: 20px 15px 15px;
        border-radius: 0;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    main {
        padding: 15px 15px 20px;
        justify-content: center;
        align-items: center;
        width: 100%;
    }
    
    .palmline-intro-section {
        top: 25%;
        max-width: 250px;
        padding: 0 15px;
    }
    
    .palmline-intro-grid {
        gap: 8px;
    }
    
    .palmline-icon {
        font-size: 1.3rem;
    }
    
    .palmline-name {
        font-size: 0.65rem;
    }
    
    .upload-section {
        width: 200px;
        height: 200px;
    }
    
    .upload-area {
        padding: 20px 10px;
    }
    
    .upload-area h2 {
        font-size: 1.1rem;
    }
    
    .upload-area p {
        font-size: 0.85rem;
    }
    
    .upload-btn, .analyze-btn, .reset-btn, .retry-btn, .share-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .retry-btn, .share-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
        width: 100%;
        max-width: 180px;
    }
    
    .result-cards {
        gap: 12px;
    }
    
    .result-card {
        padding: 15px;
    }
    
    .result-label {
        width: 80px;
        font-size: 0.8rem;
    }
    
    .loading-section {
        width: 360px;
        height: 420px;
        padding: 20px;
    }
    
    .countdown-container {
        gap: 20px;
    }
    
    .countdown-circle {
        width: 160px;
        height: 160px;
        margin: 10px;
    }
    
    
    .countdown-bg,
    .countdown-progress {
        cx: 80;
        cy: 80;
        r: 72;
    }
    
    .countdown-progress {
        stroke-dasharray: 452.39;
    }
    
    @keyframes countdown {
        to {
            stroke-dashoffset: 452.39;
        }
    }
    
    .countdown-number {
        font-size: 2.8rem;
    }
    
    .loading-steps {
        max-width: 300px;
    }
    
    .summary-section {
        padding: 15px;
    }
    
    #summaryText {
        font-size: 0.95rem;
    }
    
    footer {
        padding: 6px 15px 10px;
        border-radius: 0;
    }
}