/* ===== CSS RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== CSS VARIABLES (Dark Mode First) ===== */
:root {
    --primary: #10b981;
    --primary-light: #34d399;
    --primary-dark: #059669;
    --primary-glow: rgba(16, 185, 129, 0.4);
    --bg: #0a0f0d;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-glass: rgba(255, 255, 255, 0.08);
    --text: #f0f5f3;
    --text-secondary: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 10px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Score colors */
    --score-red: #ef4444;
    --score-orange: #f97316;
    --score-yellow: #eab308;
    --score-lime: #84cc16;
    --score-green: #22c55e;
}

/* ===== LIGHT MODE ===== */
[data-theme="light"] {
    --bg: #f0fdf4;
    --bg-card: rgba(16, 185, 129, 0.06);
    --bg-glass: rgba(16, 185, 129, 0.08);
    --text: #0f1f18;
    --text-secondary: #6b7280;
    --border: rgba(16, 185, 129, 0.15);
    --shadow: 0 8px 32px rgba(16, 185, 129, 0.12);
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== APP LOADER ===== */
.app-loader {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.4s ease;
}
.app-loader.hidden { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; }
.loader-emoji { font-size: 48px; margin-bottom: 16px; animation: loaderPulse 1.5s ease-in-out infinite; }
.loader-spinner {
    width: 40px; height: 40px; margin: 0 auto 12px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loader-text { color: var(--text-secondary); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes loaderPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ===== SKIP LINK ===== */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    z-index: 10001;
    font-size: 14px;
    text-decoration: none;
    transition: top 0.2s;
}
.skip-link:focus { top: 8px; }

/* ===== BODY & LAYOUT ===== */
html { scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(16, 185, 129, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(52, 211, 153, 0.08) 0%, transparent 50%);
    z-index: -1;
    pointer-events: none;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    position: relative;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    position: fixed;
    top: 16px; right: 16px;
    width: 44px; height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.theme-toggle:hover { background: rgba(16, 185, 129, 0.2); transform: scale(1.08); }

/* ===== LANGUAGE SELECTOR ===== */
.language-selector { position: fixed; top: 16px; left: 16px; z-index: 100; }
.lang-toggle {
    width: 44px; height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.lang-toggle:hover { background: rgba(16, 185, 129, 0.2); }
.lang-menu {
    position: absolute;
    top: 52px; left: 0;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    min-width: 260px;
    box-shadow: var(--shadow);
    opacity: 1;
    transform: translateY(0);
    transition: var(--transition);
}
.lang-menu.hidden { opacity: 0; pointer-events: none; transform: translateY(-8px); }
.lang-option {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: var(--transition);
    min-height: 44px;
    display: flex;
    align-items: center;
}
.lang-option:hover, .lang-option.active { background: rgba(16, 185, 129, 0.2); }

/* ===== HEADER ===== */
.app-header {
    text-align: center;
    padding: 60px 0 24px;
}
.clover-icon {
    font-size: 56px;
    margin-bottom: 12px;
    animation: cloverFloat 3s ease-in-out infinite;
}
@keyframes cloverFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-8px) rotate(5deg); }
}
.app-title {
    font-size: 32px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}
.app-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
}

/* ===== MEASURE BUTTON ===== */
.measure-section {
    display: flex;
    justify-content: center;
    padding: 40px 0;
}
.measure-btn {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 3px solid var(--primary);
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    box-shadow: 0 0 40px var(--primary-glow), 0 8px 32px rgba(0, 0, 0, 0.3);
    min-height: 44px;
    min-width: 44px;
    letter-spacing: 0.02em;
}
.measure-btn::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 60%);
    animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { transform: translate(-30%, -30%); }
    50% { transform: translate(30%, 30%); }
}
.measure-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 60px var(--primary-glow), 0 12px 40px rgba(0, 0, 0, 0.4);
}
.measure-btn:active {
    transform: scale(0.95);
}
.measure-btn.spinning {
    pointer-events: none;
    animation: btnPulse 0.5s ease-in-out infinite;
}
@keyframes btnPulse {
    0%, 100% { box-shadow: 0 0 40px var(--primary-glow); }
    50% { box-shadow: 0 0 80px var(--primary-glow); }
}

/* ===== SCORE DISPLAY ===== */
.result-section {
    animation: fadeSlideIn 0.6s ease-out;
}
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.score-circle-wrap {
    display: flex;
    justify-content: center;
    padding: 16px 0 12px;
}
.score-circle {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 4px solid var(--primary);
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 0 40px var(--primary-glow), inset 0 0 30px rgba(16, 185, 129, 0.1);
    transition: border-color 0.3s, box-shadow 0.3s;
}
.score-number {
    font-size: 56px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(135deg, var(--primary-light), #fff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Score color classes */
.score-circle.tier-1 { border-color: var(--score-red); box-shadow: 0 0 40px rgba(239, 68, 68, 0.3); }
.score-circle.tier-2 { border-color: var(--score-orange); box-shadow: 0 0 40px rgba(249, 115, 22, 0.3); }
.score-circle.tier-3 { border-color: var(--score-yellow); box-shadow: 0 0 40px rgba(234, 179, 8, 0.3); }
.score-circle.tier-4 { border-color: var(--score-lime); box-shadow: 0 0 40px rgba(132, 204, 22, 0.3); }
.score-circle.tier-5 { border-color: var(--score-green); box-shadow: 0 0 40px rgba(34, 197, 94, 0.4); }

.score-tier {
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    min-height: 30px;
}
.score-tier.tier-1 { color: var(--score-red); }
.score-tier.tier-2 { color: var(--score-orange); }
.score-tier.tier-3 { color: var(--score-yellow); }
.score-tier.tier-4 { color: var(--score-lime); }
.score-tier.tier-5 { color: var(--score-green); }

/* ===== CATEGORIES CARD (Glassmorphism) ===== */
.categories-card {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary-light);
    margin-bottom: 16px;
    text-align: center;
}
.category-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.category-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.category-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    min-width: 80px;
}
.category-stars {
    font-size: 20px;
    letter-spacing: 2px;
    line-height: 1;
}
.star-filled { color: #fbbf24; }
.star-empty { color: var(--border); opacity: 0.5; }

/* ===== LUCKY CARD ===== */
.lucky-card {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.lucky-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}
.lucky-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}
.lucky-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.lucky-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
.lucky-color-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

/* ===== ACTION BUTTONS ===== */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}
.share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    min-height: 48px;
    transition: var(--transition);
    width: 100%;
}
.share-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.twitter-btn { background: #1DA1F2; }
.copy-btn {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    color: var(--text);
}
.copy-btn:hover { background: rgba(16, 185, 129, 0.15); }
.retry-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    background: transparent;
    color: var(--primary-light);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    min-height: 48px;
    transition: var(--transition);
    width: 100%;
}
.retry-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    transform: translateY(-2px);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--primary);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    z-index: 1000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== AD ===== */
.ad-container { margin: 16px 0; min-height: 50px; text-align: center; }

/* ===== FOOTER ===== */
.app-footer {
    text-align: center;
    padding: 24px 16px 40px;
}
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    min-height: 44px;
}
.back-link:hover { color: var(--primary-light); }

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== SPINNING SCORE ANIMATION ===== */
@keyframes scoreReveal {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.score-circle.reveal {
    animation: scoreReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
    .app-title { font-size: 26px; }
    .measure-btn { width: 170px; height: 170px; font-size: 16px; }
    .score-number { font-size: 48px; }
    .score-circle { width: 140px; height: 140px; }
    .category-name { font-size: 14px; }
}
@media (min-width: 520px) {
    .app-container { padding: 24px; }
    .app-header { padding: 80px 0 32px; }
}
