:root {
    /* Colors */
    --primary: #0064FF;
    --primary-dark: #0050CC;
    --background: #F2F4F6;
    --surface: #FFFFFF;
    --text-main: #191F28;
    --text-sub: #8B95A1;
    --border: #E5E8EB;
    --error: #F04452;
    --success: #34C759;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    /* Animation */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--background);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
    /* Center vertical on Large Screens */
    align-items: flex-start;
}

@media (min-width: 481px) {
    body {
        align-items: center;
        background-color: #E0E2E5;
        /* Darker background for outside area */
    }

    #app {
        height: 95vh;
        min-height: 600px;
        max-height: 900px;
        border-radius: 24px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
        overflow: hidden;
    }
}

/* App Container (Mobile First) */
#app {
    width: 100%;
    max-width: 480px;
    /* Mobile Max Width */
    background-color: var(--surface);
    height: 100vh;
    /* Default Mobile Full Height */
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

/* View Management */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--surface);
    transition: transform var(--transition-medium), opacity var(--transition-medium);
    z-index: 10;
}

.view.hidden {
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.view.active {
    transform: translateY(0);
    opacity: 1;
    z-index: 20;
}

/* Typography Helpers */
h1,
h2,
h3 {
    line-height: 1.35;
    font-weight: 700;
}

.highlight {
    color: var(--primary);
}

.subtitle {
    color: var(--text-sub);
    font-size: 16px;
    margin-top: 8px;
    font-weight: 500;
}

/* Header */
.main-header,
.result-header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-lg);
    background-color: var(--surface);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 20px;
    color: var(--primary);
}

/* Landing Content */
.landing-content {
    flex: 1;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.hero-text {
    margin-bottom: 40px;
}

.hero-text h2 {
    font-size: 28px;
}

/* Form */
.form-group {
    margin-bottom: 32px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 8px;
}

select,
input {
    width: 100%;
    border: none;
    border-bottom: 2px solid var(--border);
    font-size: 24px;
    padding: 8px 0;
    font-weight: 600;
    color: var(--text-main);
    border-radius: 0;
    background: transparent;
    transition: border-color var(--transition-fast);
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-wrapper {
    display: flex;
    align-items: center;
}

.unit {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-main);
    margin-left: 4px;
    white-space: nowrap;
    /* Prevent line break */
    flex-shrink: 0;
}

/* Footer Buttons */
.landing-footer,
.result-footer {
    padding: var(--spacing-lg);
    padding-bottom: max(var(--spacing-lg), env(safe-area-inset-bottom));
}

.cta-button {
    width: 100%;
    height: 56px;
    background-color: var(--primary);
    color: white;
    font-size: 17px;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--transition-fast), transform 0.1s;
}

.cta-button:disabled {
    background-color: var(--border);
    color: var(--text-sub);
    cursor: not-allowed;
}

.cta-button:active:not(:disabled) {
    transform: scale(0.98);
    background-color: var(--primary-dark);
}

/* Result View Styles */
.result-content {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
    background-color: var(--background);
    /* Light gray bg for cards */
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
}

.sub-card {
    background: transparent;
    border: 1px solid var(--border);
    padding: 16px;
    text-align: center;
    box-shadow: none;
}

.sub-text {
    font-size: 15px;
    color: var(--text-sub);
}

.sub-text strong {
    color: var(--text-main);
    font-weight: 700;
}

.sub-card {
    background: transparent;
    border: 1px solid var(--border);
    padding: 16px;
    text-align: center;
    box-shadow: none;
}

.sub-text {
    font-size: 15px;
    color: var(--text-sub);
}

.sub-text strong {
    color: var(--text-main);
    font-weight: 700;
}

.rank-card {
    text-align: center;
}

.rank-badge {
    display: inline-block;
    background: rgba(0, 100, 255, 0.1);
    color: var(--primary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 16px;
}

/* Overall Row inside Detail Card */
.overall-row {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.overall-label {
    font-size: 14px;
    color: var(--text-sub);
}

.overall-value {
    font-size: 16px;
    color: var(--text-main);
}

/* Chart Container Control */
.chart-container {
    position: relative;
    width: 100%;
    /* Keep a nice aspect ratio to prevent stretching */
    height: 220px;
    margin: 16px 0;
}

canvas {
    width: 100% !important;
    height: 100% !important;
}

.rank-description {
    font-size: 18px;
}

/* Detail Card */
.card-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.card-header h3 {
    margin-bottom: 0;
    /* Remove default margin from h3 inside header */
}

.stats-row {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Help Buttons */
.form-group .label-with-icon {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-wrap: nowrap;
}

.help-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-sub);
    font-size: 18px;
    display: inline-flex;
    /* Changed from flex to inline-flex */
    align-items: center;
    transition: color 0.2s;
}

.help-btn:hover {
    color: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background: var(--surface);
    width: 100%;
    max-width: 320px;
    border-radius: 20px;
    padding: 24px;
    position: relative;
    z-index: 1001;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    transform: translateY(0);
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.modal.hidden .modal-content {
    transform: translateY(20px);
}

.modal-content h3 {
    margin-bottom: 12px;
    font-size: 18px;
}

.modal-content p {
    font-size: 15px;
    color: var(--text-sub);
    line-height: 1.5;
    margin-bottom: 24px;
    white-space: pre-line;
    /* Allow newlines */
}

.modal-close-btn {
    width: 100%;
    height: 48px;
    background-color: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item .label {
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 4px;
}

.stat-item .value {
    font-size: 16px;
    font-weight: 600;
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--error);
}

/* Buttons */
.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    margin-left: -8px;
}

.share-btn {
    width: 100%;
    height: 52px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    border: none;
    cursor: pointer;
}

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

.share-btn.link {
    background-color: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
}

/* Ad Slot */
.ad-slot {
    margin: 24px 0;
    text-align: center;
}

.ad-placeholder {
    background: #e9e9e9;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    border-radius: 8px;
    font-size: 12px;
}