:root {
    --bg-color: #f8fafc;
    --text-color: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.7);
    --glass-shadow: rgba(59, 130, 246, 0.06);
    --primary-color: #3b82f6; /* 희망찬 블루 */
    --primary-hover: #2563eb;
    --accent-color: #10b981; /* 성장의 그린 */
    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: #e2e8f0;
    --blob-1: #4f46e5;
    --blob-2: #ec4899;
}

body.dark-theme {
    --bg-color: #111827;
    --text-color: #f9fafb;
    --text-muted: #9ca3af;
    --glass-bg: rgba(31, 41, 55, 0.6);
    --glass-border: rgba(75, 85, 99, 0.4);
    --glass-shadow: rgba(0, 0, 0, 0.3);
    --primary-color: #6366f1;
    --primary-hover: #818cf8;
    --accent-color: #34d399;
    --input-bg: rgba(17, 24, 39, 0.8);
    --input-border: #374151;
    --blob-1: #312e81;
    --blob-2: #831843;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body {
    max-width: 100%;
    overflow-x: clip;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    position: relative;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 2.5rem 2rem 6rem;
}



/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem; /* 상단 여백과 대칭을 이루도록 조정 */
    position: relative;
}

/* 희망의 무드: 헤더 배경에 은은한 오로라 효과 (여백에 영향을 주지 않도록 절대 위치 조정) */
.header::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 60px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.08) 0%, rgba(16, 185, 129, 0.05) 100%);
    filter: blur(40px);
    z-index: -1;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.logo i {
    color: var(--primary-color);
}

.theme-toggle {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 44px;
    cursor: pointer;
    color: var(--text-color);
    transition: transform 0.2s ease, background-color 0.2s ease;
    transform: translateZ(0);
}

/* FAB (Fixed Action Button) Container */
.fab-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 9999;
    pointer-events: none;
}

.fab-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1.5px solid var(--glass-border);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12); /* 그림자 강화 */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    outline: none;
}

/* 다크 모드에서의 버튼 시인성 보강 */
body.dark-theme .fab-btn {
    background: rgba(45, 55, 72, 0.8);
    border-color: rgba(99, 102, 241, 0.3);
    color: white;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(99, 102, 241, 0.1);
}

body.dark-theme .fab-btn:hover,
body.dark-theme .fab-btn:focus {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-hover);
}

/* 라이트 모드에서의 버튼 시인성 보강 */
body:not(.dark-theme) .fab-btn {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(59, 130, 246, 0.2);
    color: var(--text-color);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.15);
}

body:not(.dark-theme) .fab-btn:hover,
body:not(.dark-theme) .fab-btn:focus {
    background: var(--primary-color);
    color: white !important; /* 명시적 확보 */
    border-color: var(--primary-hover);
}

.fab-btn:hover, .fab-btn:focus {
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}



.fab-btn.to-top {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
}

.fab-btn.to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.fab-btn i {
    width: 20px;
    height: 20px;
}

/* Scroll Guide Button (Seamlessly Integrated) */
.scroll-guide-wrapper {
    display: flex;
    justify-content: center;
    margin-top: -20px; /* 차트 컨테이너 하단 경계에 걸치도록 조정 */
    position: relative;
    z-index: 20;
}

.scroll-guide-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary-color);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0.6rem 1.2rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    animation: hintFloat 2s ease-in-out infinite;
    min-width: 210px;
}


.scroll-guide-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

@keyframes hintFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}






body.dark-theme .sun-icon { display: block; }
body.dark-theme .moon-icon { display: none; }
body:not(.dark-theme) .sun-icon { display: none; }
body:not(.dark-theme) .moon-icon { display: block; }

/* Main Grid */
.main-content {
    display: grid;
    grid-template-columns: 1fr 2.5fr;
    gap: 2rem;
    min-width: 0;
}

.main-content > * {
    min-width: 0;
}

.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 1.5rem;
    box-shadow: 0 4px 16px var(--glass-shadow);
    transition: transform 0.2s ease;
    /* 스크롤 성능 최적화 */
    transform: translateZ(0);
    backface-visibility: hidden;
    contain: paint;
}

/* Input Section */
.input-section {
    position: sticky;
    top: 2rem;
    height: fit-content;
    align-self: start;
}

.input-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

/* form-row 내부의 form-group은 중복 여백 방지를 위해 마진 제거 */
.form-row .form-group {
    margin-bottom: 0;
}

label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.input-wrapper, .select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 0.75rem;
    color: var(--text-color);
    font-size: 1rem;
    transition: all 0.2s ease;
    outline: none;
}

input:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.input-wrapper .unit {
    position: absolute;
    right: 1rem;
    color: var(--text-muted);
    pointer-events: none;
}

input[type="text"], input[type="number"] {
    padding-right: 3rem; /* Space for unit */
}

select {
    appearance: none;
    padding-right: 2.5rem;
}

.select-icon {
    position: absolute;
    right: 1rem;
    width: 1rem;
    height: 1rem;
    color: var(--text-muted);
    pointer-events: none;
}

.calc-btn {
    width: 100%;
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
}

.calc-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.calc-btn:active {
    transform: translateY(0);
}

/* Results Section */
.result-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    min-width: 0;
    scroll-margin-top: 110px;
}

.result-section > * {
    min-width: 0;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.card {
    padding: 1.5rem;
    text-align: center;
}

.card.highlight {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(16, 185, 129, 0.08));
    border: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.05);
}

.card h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

.card .value.profit {
    color: var(--accent-color);
}

.card .unit {
    font-size: 1rem;
    font-weight: 500;
}

.card .yield {
    font-size: 0.875rem;
    color: var(--accent-color);
    margin-top: 0.25rem;
    font-weight: 600;
}

/* Chart */
.chart-container {
    height: 350px;
    padding: 1.5rem;
    position: relative;
}




/* Table */
.table-container {
    scroll-margin-top: 110px; /* 앵커 광고 시뮬레이션 결과 반영 보정 */
}


.table-container h3 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

th, td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}

/* 라이트 모드 테이블 경계선 보완 */
body:not(.dark-theme) th, 
body:not(.dark-theme) td {
    border-bottom-color: #e5e7eb;
}

th {
    text-align: right;
    font-weight: 700;
    color: var(--text-color);
    font-size: 0.875rem;
    background: rgba(255, 255, 255, 0.05);
}

/* 라이트 모드 헤더 배경 보완 */
body:not(.dark-theme) th {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-color);
}

th:first-child, td:first-child {
    text-align: center;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

body:not(.dark-theme) tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Share & SEO Sections */
.share-action {
    text-align: center;
}

.share-btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: var(--text-color);
    border-radius: 0.75rem;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px var(--glass-shadow);
    min-width: 210px;
}

.share-btn:hover {
    transform: translateY(-2px);
    background: var(--input-bg);
    border-color: var(--primary-color);
}

.seo-content {
    padding: 1.5rem;
    line-height: 1.7;
    text-align: left;
}

.seo-content h2 {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    color: var(--primary-color);
}

.seo-content h3 {
    font-size: 1.1rem;
    margin: 1.5rem 0 1rem;
    color: var(--text-color);
}

.seo-content p {
    color: var(--text-muted);
}

.seo-content details {
    margin-bottom: 0.75rem;
    border: 1px solid var(--glass-border);
    border-radius: 0.75rem;
    overflow: hidden;
    transition: all 0.2s ease;
}

.seo-content details:last-child {
    margin-bottom: 0;
}

/* 라이트 모드 가독성 보완 */
body:not(.dark-theme) .seo-content details {
    border-color: #e5e7eb;
    background: rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.seo-content summary {
    padding: 0.8rem;
    cursor: pointer;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.03);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

/* 라이트 모드 요약 영역 배경 보완 */
body:not(.dark-theme) .seo-content summary {
    background: rgba(0, 0, 0, 0.02);
}

.seo-content summary::after {
    content: '+';
    font-size: 1.2rem;
    transition: transform 0.3s ease;
    margin-top: -2px; /* 텍스트 라인 높이와 맞추기 위한 미세 조정 */
    flex-shrink: 0; /* 기호가 찌그러지지 않도록 보호 */
}

.seo-content details[open] summary::after {
    transform: rotate(45deg);
}

.seo-content details p {
    padding: 0 0.8rem 0.8rem;
    margin-top: 0.5rem;
    font-size: 0.95rem;
}

/* Ad Containers (CLS 방지) */
.ad-container-top {
    margin-top: 2.5rem; /* 입력 폼 하단과의 간격 확보 */
    min-height: 100px;
    display: block; /* flex 대신 block으로 변경하여 애드센스 너비 계산 안정화 */
    text-align: center;
}

.ad-container-bottom {
    margin: 0; /* 부모 .result-section의 gap(2rem)을 활용하므로 추가 마진 제거 */
    min-height: 100px; /* 280px -> 100px로 축소하여 광고 미출력 시 공백 최소화 */
    display: block; /* 애드센스 반응형 계산을 위해 block 권장 */
    text-align: center;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .input-section {
        position: static !important;
    }
    
    .glass-panel {
        box-shadow: 0 4px 12px var(--glass-shadow);
    }
    
    body.hide-principal-on-mobile #resultTable th:nth-child(2),
    body.hide-principal-on-mobile #resultTable td:nth-child(2) {
        display: none;
    }
}

.only-m-dp { display: none !important; }
@media (max-width: 600px) {
    .only-m-dp { display: inline !important; }
    .container {
        padding: 2.5rem 0.8rem 4rem; /* 모바일에서도 충분한 상단 여백 확보 */
        width: 100%;
        box-sizing: border-box;
    }

    .glass-panel {
        padding: 0.8rem;
    }
    .form-row {
        grid-template-columns: 1fr;
        gap: 1.25rem; /* 모바일 1열 나열 시 form-group 마진과 동일하게 설정 */
    }
    .header {
        flex-direction: row;
        gap: 0.5rem;
        justify-content: space-between;
    }
    .logo h1 {
        font-size: 1.1rem;
    }
    .theme-toggle {
        width: 36px;
        height: 36px;
    }
    .summary-cards {
        grid-template-columns: 1fr;
    }
    .chart-container {
        height: 300px; /* 차트 시인성 확보를 위해 높이 고정 */
        padding: 0.8rem;
    }


    .table-container {
        min-width: 0;
        width: 100%;
    }
    .table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    th, td {
        padding: 0.4rem;
        font-size: 0.75rem;
    }
    input[type="text"], input[type="number"], select {
        font-size: 16px; /* iOS 자동 확대 방지 */
        padding: 0.6rem;
    }
    .fab-container {
        bottom: 1.5rem;
        right: 1rem;
        gap: 0.5rem;
    }
    .fab-btn {
        width: 42px;
        height: 42px;
    }
}
