:root {
    --primary: #2ed573;
    --primary-dark: #27ae60;
    --primary-light: #5dd98f;
    --bg-dark: #0f0f0f;
    --bg-surface: #1a1a1a;
    --bg-surface-2: #242424;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #333333;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
}

/* Light Theme */
[data-theme="light"] {
    --primary: #2ed573;
    --primary-dark: #27ae60;
    --primary-light: #5dd98f;
    --bg-dark: #f5f5fa;
    --bg-surface: #ffffff;
    --bg-surface-2: rgba(0, 0, 0, 0.03);
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a70;
    --border-color: rgba(46, 213, 115, 0.2);
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(46, 213, 115, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* 터치 최적화 */
button, a, input, [role="button"], [role="link"] {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

input[type="text"], textarea {
    -webkit-user-select: text;
    user-select: text;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* App Loader */
.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.app-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.loader-emoji {
    font-size: 48px;
    animation: loader-bounce 1s ease-in-out infinite;
}
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: loader-spin 0.8s linear infinite;
}
.loader-text {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 1px;
    font-weight: 500;
}
@keyframes loader-spin {
    to { transform: rotate(360deg); }
}
@keyframes loader-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Advertisement Areas */
.ad-container {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 10px;
    text-align: center;
}

.ad-placeholder {
    background: linear-gradient(135deg, #333333, #1a1a1a);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-top {
    position: sticky;
    top: 0;
    z-index: 50;
}

.ad-bottom {
    margin-top: auto;
}

/* App Container */
.app-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 24px;
    margin-top: 8px;
}

.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}

.category-tabs::-webkit-scrollbar {
    height: 4px;
}

.category-tabs::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 2px;
}

.tab-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn:active {
    transform: scale(0.98);
}

.tab-btn.active {
    background: var(--primary);
    color: var(--bg-dark);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(46, 213, 115, 0.3);
}

.tab-btn:not(.active):hover {
    background: var(--bg-surface-2);
    border-color: var(--primary);
}

/* Main Converter */
.converter-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.category-content {
    display: none;
    gap: 16px;
    animation: fadeIn 0.3s ease;
}

.category-content.active {
    display: flex;
}

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

/* Unit Rows */
.unit-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Nested unit rows fallback - CSS :has() not supported in older browsers */
.unit-row.nested {
    grid-template-columns: 1fr;
    gap: 12px;
}

/* Input Group */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.unit-input {
    padding: 12px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface-2);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.2s ease;
    appearance: none;
}

.unit-input::-webkit-outer-spin-button,
.unit-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.unit-input[type=number] {
    -moz-appearance: textfield;
}

.unit-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-surface-2);
    box-shadow: 0 0 0 3px rgba(46, 213, 115, 0.1);
    transform: translateY(-2px);
}

.unit-input::placeholder {
    color: #555555;
}

.unit-label {
    position: absolute;
    bottom: 12px;
    right: 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
}

.input-group {
    position: relative;
}

/* Swap Button (Glassmorphism) */
.swap-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--primary);
    padding: 0;
    margin-bottom: 0;
}

.swap-btn:active {
    transform: scale(0.95) rotate(180deg);
}

.swap-btn:hover {
    background: rgba(46, 213, 115, 0.1);
    border-color: var(--primary);
}

/* Separator Text */
.separator-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 0;
    grid-column: 1 / -1;
}

/* Quick Conversions Section */
.quick-conversions-section {
    margin-top: 24px;
    padding: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.quick-conversions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.quick-conversion-item {
    padding: 12px;
    background: var(--bg-surface-2);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.quick-conversion-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.quick-conversion-item:active {
    transform: scale(0.98);
}

.quick-conversion-copy-btn {
    background: rgba(46, 213, 115, 0.2);
    border: none;
    color: var(--primary);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.quick-conversion-copy-btn:active {
    background: rgba(46, 213, 115, 0.3);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: var(--bg-dark);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Favorites Section */
.favorites-section,
.history-section {
    margin-top: 24px;
    padding: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    cursor: pointer;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px;
}

.toggle-btn:active {
    transform: scale(0.9);
}

.favorites-list,
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.favorites-list::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 4px;
}

.favorites-list::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 2px;
}

.favorite-item,
.history-item {
    padding: 12px;
    background: var(--bg-surface-2);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.favorite-item:active,
.history-item:active {
    transform: scale(0.98);
}

.favorite-item:hover,
.history-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.favorite-remove-btn,
.history-remove-btn {
    background: rgba(255, 0, 0, 0.2);
    border: none;
    color: #ff6b6b;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.favorite-remove-btn:active,
.history-remove-btn:active {
    background: rgba(255, 0, 0, 0.3);
}

.add-favorite-btn,
.clear-history-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-surface-2);
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

.add-favorite-btn:active,
.clear-history-btn:active {
    transform: scale(0.98);
}

.add-favorite-btn:hover,
.clear-history-btn:hover {
    background: rgba(46, 213, 115, 0.1);
}

/* Premium Button */
.premium-btn {
    width: 100%;
    padding: 14px;
    margin-top: 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    color: var(--bg-dark);
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(46, 213, 115, 0.3);
}

.premium-icon {
    font-size: 18px;
    animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.premium-btn:active {
    transform: scale(0.98);
}

.premium-btn:hover {
    box-shadow: 0 6px 16px rgba(46, 213, 115, 0.4);
}

/* Premium Modal */
.premium-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.3s ease;
}

.premium-modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s ease;
}

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

.premium-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.premium-close-btn:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.premium-modal-content h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--primary);
}

#premium-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.premium-item {
    padding: 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 14px;
    line-height: 1.6;
}

/* Ad Modal */
.ad-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
}

.ad-modal-content {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 20px;
    max-width: 90%;
    text-align: center;
}

.ad-countdown {
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

#countdown-num {
    color: var(--primary);
    font-size: 20px;
}

.ad-close-btn {
    margin-top: 16px;
    padding: 10px 16px;
    background: var(--primary);
    border: none;
    color: var(--bg-dark);
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-header h1 {
        font-size: 24px;
    }

    .category-tabs {
        gap: 6px;
    }

    .tab-btn {
        padding: 6px 14px;
        font-size: 12px;
    }

    .unit-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .unit-row.two-column {
        grid-template-columns: 1fr auto 1fr;
    }

    .swap-btn {
        grid-column: 2;
        margin-bottom: 0;
    }

    .unit-input {
        padding: 10px;
        font-size: 14px;
    }

    .premium-modal-content {
        max-width: 95%;
        max-height: 90vh;
    }
}

@media (max-width: 360px) {
    .app-container {
        padding: 12px;
    }

    .app-header {
        margin-bottom: 16px;
    }

    .app-header h1 {
        font-size: 20px;
    }

    .category-tabs {
        gap: 4px;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 11px;
    }

    .unit-row {
        padding: 12px;
        margin-bottom: 12px;
    }

    .input-group label {
        font-size: 11px;
    }

    .unit-input {
        padding: 10px;
        font-size: 13px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Print Styles */
@media print {
    .ad-container,
    .premium-btn,
    .favorites-section,
    .history-section {
        display: none;
    }
}

/* 빠른 변환 프리셋 */
.quick-presets {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg-surface);
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.presets-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    text-align: center;
}

.preset-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.preset-chip {
    padding: 8px 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.preset-chip:hover {
    background: rgba(46, 213, 115, 0.15);
    border-color: var(--primary);
    color: var(--primary-light);
    transform: translateY(-1px);
}

.preset-chip:active {
    transform: translateY(0);
}

.preset-chip.active {
    background: rgba(46, 213, 115, 0.2);
    border-color: var(--primary);
    color: var(--primary);
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 56px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

[data-theme="light"] .theme-toggle {
    background: rgba(46, 213, 115, 0.1);
    border-color: rgba(46, 213, 115, 0.2);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(46, 213, 115, 0.2);
}

/* Recommendations Section */
.recommendations-section { margin: 24px 0 0; padding: 0 16px; }
.rec-title { font-size: 15px; font-weight: 700; color: rgba(255,255,255,0.5); margin-bottom: 12px; text-align: center; letter-spacing: 0.5px; }
.rec-grid { display: flex; flex-direction: column; gap: 10px; }
.rec-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; text-decoration: none; color: #fff; transition: all 0.2s ease; }
.rec-card:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
.rec-icon { font-size: 28px; flex-shrink: 0; }
.rec-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rec-name { font-size: 14px; font-weight: 600; }
.rec-desc { font-size: 12px; color: rgba(255,255,255,0.5); }

[data-theme="light"] .rec-title { color: rgba(26, 26, 46, 0.5); }
[data-theme="light"] .rec-card { background: rgba(0, 0, 0, 0.03); border-color: rgba(46, 213, 115, 0.15); color: #1a1a2e; }
[data-theme="light"] .rec-card:hover { background: rgba(46, 213, 115, 0.1); }
[data-theme="light"] .rec-desc { color: #5a5a70; }

/* Game Footer & Back Link */
.game-footer {
    text-align: center;
    padding: 20px 0;
    margin-top: 20px;
}

.back-link, .home-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: rgba(255,255,255,0.4);
    text-decoration: none;
    font-size: 13px;
    padding: 12px 0;
    transition: color 0.2s;
}

.back-link:hover, .home-link:hover {
    color: rgba(255,255,255,0.7);
}
[data-theme="light"] .back-link,
[data-theme="light"] .home-link {
    color: rgba(26,26,46,0.4);
}
[data-theme="light"] .back-link:hover,
[data-theme="light"] .home-link:hover {
    color: rgba(26,26,46,0.7);
}

/* === Accessibility Improvements === */
button:focus-visible,a:focus-visible,input:focus-visible,[role="button"]:focus-visible{outline:3px solid #1abc9c;outline-offset:2px;}
button,a[href],input[type="button"],input[type="submit"],[role="button"]{min-width:44px;min-height:44px;display:inline-flex;align-items:center;justify-content:center;}
.skip-link{position:absolute;top:-40px;left:0;background:#1abc9c;color:white;padding:8px;text-decoration:none;z-index:100;}
.skip-link:focus{top:0;}
[role="dialog"]{z-index:1000;}
@media (prefers-reduced-motion: reduce){*{animation-duration:0.01ms !important;animation-iteration-count:1 !important;transition-duration:0.01ms !important;scroll-behavior:auto !important;}}
@media (prefers-contrast: more){button{border:2px solid #1abc9c;}}
.rec-card:focus-visible,.conversion-group:focus-visible{outline:3px solid #1abc9c;outline-offset:4px;}

/* Selection Color */
::selection {
    background: #1abc9c;
    color: white;
}

::-moz-selection {
    background: #1abc9c;
    color: white;
}
