:root {
    --primary: #6366f1;
    --primary-raw: 99, 102, 241;
    --secondary: #ec4899;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-red: #ef4444;
    --accent-green: #22c55e;
}

[data-theme="emerald"] {
    --primary: #10b981;
    --primary-raw: 16, 185, 129;
    --secondary: #06b6d4;
    --bg-dark: #022c22;
    --card-bg: rgba(6, 78, 59, 0.7);
}

[data-theme="volcanic"] {
    --primary: #ef4444;
    --primary-raw: 239, 68, 68;
    --secondary: #f59e0b;
    --bg-dark: #450a0a;
    --card-bg: rgba(127, 29, 29, 0.7);
}

[data-theme="oceanic"] {
    --primary: #0ea5e9;
    --primary-raw: 14, 165, 233;
    --secondary: #2dd4bf;
    --bg-dark: #082f49;
    --card-bg: rgba(12, 74, 110, 0.7);
}

[data-theme="solar"] {
    --primary: #fbbf24;
    --primary-raw: 251, 191, 36;
    --secondary: #f59e0b;
    --bg-dark: #18181b;
    --card-bg: rgba(39, 39, 42, 0.7);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(236, 72, 153, 0.15) 0%, transparent 40%);
}

.app-container {
    width: 95vw;
    height: 92vh;
    min-height: 700px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(to right, #818cf8, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header h1 span {
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--accent-red);
    -webkit-text-fill-color: white;
    vertical-align: middle;
    margin-left: 10px;
    animation: blink 1.5s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

main {
    flex: 1;
    display: flex;
    gap: 20px;
    height: 100%;
    min-height: 0;
}

.game-view {
    flex: 1;
    position: relative;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

#gameCanvas {
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
}

.overlay-ui {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

#winnerNotification {
    background: rgba(15, 23, 42, 0.9);
    padding: 30px 60px;
    border-radius: 30px;
    border: 2px solid var(--primary);
    text-align: center;
    transform: scale(0);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#winnerNotification.show {
    transform: scale(1);
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

.sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    padding-right: 10px;
}

/* Custom Scrollbar for Sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    padding: 20px;
}

h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-dim);
    letter-spacing: 1px;
}

#leaderboardList {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.leader-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    transition: transform 0.2s;
}

.leader-item:hover {
    transform: translateX(5px);
    background: rgba(255, 255, 255, 0.1);
}

.leader-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    /* Important for ellipsis in flexbox */
}

.rank {
    font-weight: 800;
    width: 20px;
    color: var(--primary);
}

.flag-img-small {
    width: 24px;
    height: 16px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.country-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score {
    font-weight: 800;
    color: var(--accent-green);
    background: rgba(34, 197, 94, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.stat-item span:last-child {
    font-weight: 600;
    color: var(--text-main);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 5px;
}

.control-row span {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dim);
}

.theme-select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.theme-select option {
    background: var(--bg-dark);
}

/* Premium Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border: 1px solid var(--glass-border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding-bottom: 10px;
}