:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --accent-color: #ec4899;
    --text-color: #1f2937;
    --text-light: #f3f4f6;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --card-bg: rgba(255, 255, 255, 0.9);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.5);
}

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

body {
    font-family: 'Noto Sans SC', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    color: var(--text-color);
    background: #0f172a; /* Fallback */
}

/* Dynamic Background */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: linear-gradient(45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Main Container */
.main-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 3rem;
    width: 90%;
    max-width: 800px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    transition: transform 0.3s ease;
}

header {
    margin-bottom: 2.5rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #4f46e5, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

.subtitle {
    color: #6b7280;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

/* Control Panel */
.control-panel {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 2rem;
    margin-bottom: 3rem;
}

.selector-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #4b5563;
}

.custom-select {
    position: relative;
    width: 140px;
}

select {
    appearance: none;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 2px solid #e5e7eb;
    background: white;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.arrow {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: 0.75rem;
    color: #6b7280;
}

.btn-primary {
    padding: 0.75rem 2.5rem;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
    height: 50px; /* Match select height roughly */
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.5);
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.stop {
    background: linear-gradient(135deg, #ef4444, #f87171);
    box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.4);
}

.btn-primary.stop:hover {
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.5);
}

/* Display Area */
.display-area {
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cards-grid {
    display: grid;
    gap: 1.5rem;
    width: 100%;
    justify-items: center;
}

/* Grid Layouts based on count */
.cards-grid.mode-1 { grid-template-columns: 1fr; }
.cards-grid.mode-2 { grid-template-columns: repeat(2, 1fr); }
.cards-grid.mode-3 { grid-template-columns: repeat(3, 1fr); }
.cards-grid.mode-4 { grid-template-columns: repeat(2, 1fr); }
.cards-grid.mode-5 { grid-template-columns: repeat(3, 1fr); } /* 3 top, 2 bottom handled by flex centering if needed, but grid is easier */
.cards-grid.mode-6 { grid-template-columns: repeat(3, 1fr); }

/* Special handling for 5 items to look good */
.cards-grid.mode-5 {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}
.cards-grid.mode-5 .name-card {
    width: calc(33.33% - 1rem);
}

.name-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    width: 100%;
    max-width: 240px;
    aspect-ratio: 3/2;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.name-card span {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-color);
    z-index: 1;
}

.name-card.placeholder span {
    color: #9ca3af;
    font-size: 3rem;
}

/* Animation States */
.name-card.active {
    border-color: var(--primary-color);
    transform: scale(1.02);
    box-shadow: var(--shadow-glow);
}

.name-card.selected {
    background: white;
    border-color: var(--accent-color);
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(236, 72, 153, 0.4);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.name-card.selected span {
    background: linear-gradient(to right, #4f46e5, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 2rem;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1.05); opacity: 1; }
}

/* Responsive */
@media (max-width: 640px) {
    .main-container {
        padding: 1.5rem;
        width: 95%;
    }
    
    .control-panel {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .selector-group, .custom-select, .btn-primary {
        width: 100%;
    }

    .cards-grid.mode-3, .cards-grid.mode-4, .cards-grid.mode-5, .cards-grid.mode-6 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .cards-grid.mode-5 .name-card {
        width: 100%; /* Reset flex width for mobile grid */
    }
}
