:root {
    --bg-gradient: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --card-shadow: 0 25px 60px rgba(0, 0, 0, 0.4);
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.5);
    --text-muted: rgba(255, 255, 255, 0.35);
    --text-faint: rgba(255, 255, 255, 0.25);
    --text-divider: rgba(255, 255, 255, 0.3);
    --history-bg: rgba(255, 255, 255, 0.03);
    --history-border: rgba(255, 255, 255, 0.05);
    --scrollbar-color: rgba(255, 255, 255, 0.15);
    --ball-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    --ball-text: #fff;
}

body.light-mode {
    --bg-gradient: linear-gradient(135deg, #e8eaf6, #c5cae9, #e3f2fd);
    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border: rgba(0, 0, 0, 0.08);
    --card-shadow: 0 25px 60px rgba(0, 0, 0, 0.1);
    --text-primary: #1a1a2e;
    --text-secondary: rgba(26, 26, 46, 0.55);
    --text-muted: rgba(26, 26, 46, 0.4);
    --text-faint: rgba(26, 26, 46, 0.3);
    --text-divider: rgba(26, 26, 46, 0.25);
    --history-bg: rgba(0, 0, 0, 0.03);
    --history-border: rgba(0, 0, 0, 0.06);
    --scrollbar-color: rgba(0, 0, 0, 0.12);
    --ball-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    --ball-text: #fff;
}

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

body {
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-gradient);
    overflow-x: hidden;
    position: relative;
    transition: background 0.5s ease;
}

/* Animated background particles */
.bg-particles {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
}
.bg-particles span {
    position: absolute;
    border-radius: 50%;
    animation: float-up linear infinite;
    opacity: 0;
}
@keyframes float-up {
    0%   { transform: translateY(100vh) scale(0); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

.container {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 30px 15px;
    max-width: 680px;
    width: 95%;
}

/* Glassmorphism card */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 40px 30px;
    box-shadow: var(--card-shadow);
    transition: background 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}

h1 {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    transition: color 0.5s ease;
}
h1 .emoji {
    font-size: 2.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
    margin-bottom: 30px;
    transition: color 0.5s ease;
}

/* 5 sets container */
.sets-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 30px;
}

.set-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    opacity: 0;
    transform: translateY(15px);
    transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.set-row.show {
    opacity: 1;
    transform: translateY(0);
}

.set-label {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-muted);
    min-width: 28px;
    text-align: right;
    margin-right: 4px;
    letter-spacing: 1px;
    transition: color 0.5s ease;
}

/* Number balls */
.ball {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--ball-text);
    position: relative;
    opacity: 0;
    transform: scale(0) rotate(-180deg);
    transition: all 0.45s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: var(--ball-shadow),
                inset 0 -3px 6px rgba(0, 0, 0, 0.2),
                inset 0 3px 6px rgba(255, 255, 255, 0.2);
    cursor: default;
    flex-shrink: 0;
}
.ball.show {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}
.ball:hover {
    transform: scale(1.15) rotate(5deg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4),
                inset 0 -3px 6px rgba(0, 0, 0, 0.2),
                inset 0 3px 6px rgba(255, 255, 255, 0.3);
}

/* Ball color ranges - Korean Lotto style */
.ball.range-1 { background: linear-gradient(145deg, #ffc843, #f5a623); }
.ball.range-2 { background: linear-gradient(145deg, #5ba8ff, #3d7ce0); }
.ball.range-3 { background: linear-gradient(145deg, #ff6b6b, #e04848); }
.ball.range-4 { background: linear-gradient(145deg, #a78bfa, #7c3aed); }
.ball.range-5 { background: linear-gradient(145deg, #34d399, #059669); }

/* Plus sign divider */
.plus-sign {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-divider);
    margin: 0 2px;
    flex-shrink: 0;
    transition: color 0.5s ease;
}

/* Bonus ball */
.ball.bonus {
    border: 2.5px solid rgba(255, 255, 255, 0.6);
}

/* Draw button */
.draw-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 16px 48px;
    font-size: 1.15rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    color: #fff;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    border-radius: 60px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
    position: relative;
    overflow: hidden;
}
.draw-btn::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}
.draw-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(102, 126, 234, 0.6);
}
.draw-btn:hover::before {
    left: 100%;
}
.draw-btn:active {
    transform: translateY(0);
}
.draw-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.draw-btn.spinning .btn-icon {
    animation: spin 0.6s ease-in-out;
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* History section */
.history {
    margin-top: 30px;
    text-align: left;
}
.history-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
    transition: color 0.5s ease;
}
.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-color) transparent;
}
.history-list::-webkit-scrollbar { width: 5px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-color);
    border-radius: 10px;
}

.history-group {
    background: var(--history-bg);
    border-radius: 12px;
    border: 1px solid var(--history-border);
    padding: 10px 12px;
    animation: slideIn 0.3s ease-out;
    transition: background 0.5s ease, border-color 0.5s ease;
}
.history-group-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-faint);
    margin-bottom: 6px;
    letter-spacing: 1px;
    transition: color 0.5s ease;
}
.history-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 0;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(-15px); }
    to   { opacity: 1; transform: translateX(0); }
}
.history-row .set-tag {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-faint);
    min-width: 18px;
    transition: color 0.5s ease;
}
.history-row .mini-ball {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--ball-text);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2),
                inset 0 -2px 3px rgba(0,0,0,0.15),
                inset 0 2px 3px rgba(255,255,255,0.15);
}
.history-row .mini-plus {
    font-size: 0.65rem;
    color: var(--text-faint);
    font-weight: 700;
    transition: color 0.5s ease;
}
.history-row .mini-ball.bonus {
    border: 1.5px solid rgba(255,255,255,0.5);
}

/* Confetti */
.confetti-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
    animation: confetti-fall 2s ease-out forwards;
}
@keyframes confetti-fall {
    0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Dark mode toggle button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid var(--card-border);
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: all 0.4s ease;
    outline: none;
}
.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.3);
}
.theme-toggle:active {
    transform: scale(0.95);
}
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.4s ease, transform 0.4s ease;
}
.theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}
.theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}
body.light-mode .theme-toggle .icon-sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}
body.light-mode .theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

/* Responsive */
@media (max-width: 500px) {
    .card { padding: 30px 15px; }
    h1 { font-size: 1.7rem; }
    .ball { width: 42px; height: 42px; font-size: 1rem; }
    .draw-btn { padding: 14px 36px; font-size: 1rem; }
    .set-row { gap: 5px; }
    .set-label { font-size: 0.75rem; min-width: 22px; }
    .theme-toggle { width: 44px; height: 44px; font-size: 1.2rem; top: 14px; right: 14px; }
}
