/* MODERN MINIMALISTIC DESIGN */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Color Palette - Clean & Modern */
    --primary: #3b82f6;
    --primary-light: #60a5fa;
    --primary-dark: #2563eb;
    --secondary: #8b5cf6;
    --accent: #06b6d4;
    
    /* Semantic Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    /* Neutrals - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f8fafc;
    
    /* Text - Light Mode */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;
    
    /* Borders */
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    /* Spacing Scale */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows - Subtle & Layered */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
body.dark-mode {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --surface: #1e293b;
    --surface-hover: #334155;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-inverse: #0f172a;
    
    --border-color: #334155;
    --border-light: #475569;
    
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #e0e7ff 0%, #e9d5ff 50%, #fce7f3 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-xl) var(--spacing-md) var(--spacing-md);
    gap: 0;
    position: relative;
}

/* Main content wrapper for game containers */
.content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xl);
    width: 100%;
    max-width: 1400px;
    flex: 1;
    padding-bottom: var(--spacing-xl);
}

body.dark-mode {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #1e1b4b 100%);
}

/* Dark Mode Toggle Button */
.dark-mode-toggle {
    position: fixed;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: all var(--transition-base);
    padding: 0;
    margin: 0;
}

.dark-mode-toggle:hover {
    transform: translateY(-2px) rotate(10deg);
    box-shadow: var(--shadow-lg);
}

.dark-mode-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

.dark-mode-toggle .sun-icon {
    display: block;
}

.dark-mode-toggle .moon-icon {
    display: none;
}

body.dark-mode .dark-mode-toggle .sun-icon {
    display: none;
}

body.dark-mode .dark-mode-toggle .moon-icon {
    display: block;
}

@media (min-width: 1024px) {
    .content-wrapper {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
    }
}

.hidden {
    display: none !important;
}

/* CONTAINER */
.game-container {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: var(--spacing-2xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 600px;
    transition: transform var(--transition-slow), box-shadow var(--transition-slow);
    animation: fadeInUp 0.5s ease-out;
}

.game-container:hover {
    transform: translateY(-4px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

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

/* TYPOGRAPHY */
h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xl);
    letter-spacing: -0.025em;
    line-height: 1.2;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
    letter-spacing: -0.025em;
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
}

p {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

/* FORM INPUTS */
select,
input[type="text"] {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    margin-bottom: var(--spacing-lg);
    transition: border-color var(--transition-base), background var(--transition-base), box-shadow var(--transition-base);
    appearance: none;
}

select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%233b82f6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 20px 20px;
    padding-right: 3rem;
}

/* Dark mode arrow color */
body.dark-mode select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%2360a5fa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

select:hover,
input[type="text"]:hover {
    border-color: var(--primary-light);
    background-color: var(--bg-primary);
}

select:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
    background-color: var(--bg-primary);
}

/* Dropdown option styling - limited browser support but we try */
select option {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    padding: var(--spacing-md);
    font-weight: 500;
}

select option:hover {
    background-color: var(--primary-light);
    color: var(--text-inverse);
}

select option:checked {
    background-color: var(--primary);
    color: var(--text-inverse);
    font-weight: 600;
}

body.dark-mode select option {
    background-color: var(--surface);
    color: var(--text-primary);
}

body.dark-mode select option:hover {
    background-color: var(--primary-light);
    color: var(--text-inverse);
}

body.dark-mode select option:checked {
    background-color: var(--primary);
    color: var(--text-inverse);
}

/* CUSTOM DROPDOWN COMPONENT */
.custom-select {
    position: relative;
    width: 100%;
    margin-bottom: var(--spacing-lg);
}

.custom-select select {
    display: none; /* Hide native select */
}

.select-styled {
    position: relative;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md) var(--spacing-xl);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.select-styled::after {
    content: '';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--primary);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.select-styled.active::after {
    transform: translateY(-50%) rotate(180deg);
}

.select-styled:hover {
    border-color: var(--primary-light);
    background: var(--bg-secondary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.select-styled.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.select-options {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 2px solid var(--primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.select-options.active {
    max-height: 300px;
    opacity: 1;
    transform: translateY(0);
    overflow-y: auto;
}

.select-options li {
    padding: var(--spacing-md) var(--spacing-xl);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: 500;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.select-options li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
    transform: scaleY(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.select-options li:hover {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
    color: var(--primary);
    padding-left: calc(var(--spacing-xl) + 0.5rem);
}

.select-options li:hover::before {
    transform: scaleY(1);
}

.select-options li.selected {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.15) 0%, rgba(59, 130, 246, 0.05) 100%);
    color: var(--primary);
    font-weight: 600;
}

.select-options li:active {
    transform: scale(0.98);
}

/* Staggered animation for dropdown items */
.select-options.active li {
    animation: slideInLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.select-options.active li:nth-child(1) { animation-delay: 0.05s; }
.select-options.active li:nth-child(2) { animation-delay: 0.1s; }
.select-options.active li:nth-child(3) { animation-delay: 0.15s; }
.select-options.active li:nth-child(4) { animation-delay: 0.2s; }
.select-options.active li:nth-child(5) { animation-delay: 0.25s; }

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Dark mode custom dropdown */
body.dark-mode .select-styled {
    background: var(--surface);
    border-color: var(--border-color);
}

body.dark-mode .select-styled::after {
    border-top-color: var(--primary-light);
}

body.dark-mode .select-options {
    background: var(--surface);
    border-color: var(--primary-light);
}

body.dark-mode .select-options li {
    color: var(--text-primary);
}

body.dark-mode .select-options li:hover {
    background: linear-gradient(90deg, rgba(96, 165, 250, 0.15) 0%, transparent 100%);
    color: var(--primary-light);
}

body.dark-mode .select-options li.selected {
    background: linear-gradient(90deg, rgba(96, 165, 250, 0.2) 0%, rgba(96, 165, 250, 0.08) 100%);
    color: var(--primary-light);
}

input[type="text"]::placeholder {
    color: var(--text-tertiary);
}

.correct {
    color: var(--success);
    font-weight: 600;
}

/* BUTTONS */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    padding: var(--spacing-md) var(--spacing-xl);
    margin: var(--spacing-xs);
    background: var(--primary);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

button:hover::before {
    width: 300px;
    height: 300px;
}

button:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Button Variants */
#cancel-button {
    background: var(--danger);
}

#cancel-button:hover {
    background: #dc2626;
}

#hint {
    background: var(--warning);
}

#hint:hover {
    background: #d97706;
}

#save,
#submit-button,
#difficulty-button,
#country-button {
    background: var(--success);
}

#save:hover,
#submit-button:hover,
#difficulty-button:hover,
#country-button:hover {
    background: #059669;
}

#share,
#restart-button {
    background: var(--secondary);
}

#share:hover,
#restart-button:hover {
    background: #7c3aed;
}

/* BUTTON GRID */
.button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
}

.button-grid button {
    margin: 0;
}

/* STATION LISTS */
.stop-list {
    list-style: none;
    padding: 0;
    margin: var(--spacing-lg) 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--spacing-md);
    max-height: 400px;
    overflow-y: auto;
}

.stop-list::-webkit-scrollbar {
    width: 8px;
}

.stop-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

.stop-list::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: var(--radius-full);
}

.stop-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

.stop-list li {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    border-left: 4px solid var(--primary);
    font-weight: 500;
    transition: all var(--transition-base);
    animation: slideIn 0.3s ease-out backwards;
}

.stop-list li:nth-child(1) { animation-delay: 0.05s; }
.stop-list li:nth-child(2) { animation-delay: 0.1s; }
.stop-list li:nth-child(3) { animation-delay: 0.15s; }
.stop-list li:nth-child(4) { animation-delay: 0.2s; }
.stop-list li:nth-child(5) { animation-delay: 0.25s; }
.stop-list li:nth-child(6) { animation-delay: 0.3s; }

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.stop-list li:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, #e0e7ff, #ddd6fe);
}

/* LEADERBOARD */
#leaderboard {
    grid-template-columns: 1fr;
    max-height: 500px;
}

#leaderboard li {
    border-left-color: var(--accent);
}

#leaderboard li a {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    padding: var(--spacing-xs);
    transition: color var(--transition-base);
}

#leaderboard li:hover a {
    color: var(--primary);
}

/* GAME OUTPUT */
#game-output {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    padding: var(--spacing-xl);
    border-radius: var(--radius-xl);
    margin-top: var(--spacing-lg);
    border: 1px solid var(--border-light);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* STATS GRID */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
    margin: var(--spacing-lg) 0;
}

.stats-grid p {
    background: var(--surface);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    text-align: center;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    position: relative;
}

/* Tooltip for time display */
#time {
    cursor: help;
}

#time::after {
    content: 'This timer may not show the exact time that will be saved due to latency';
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 400;
    white-space: normal;
    width: 200px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-base);
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

#time::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 0.125rem);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--text-primary);
    opacity: 0;
    transition: opacity var(--transition-base);
    z-index: 100;
}

#time:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

#time:hover::before {
    opacity: 1;
}

#result {
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    margin: var(--spacing-lg) 0;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

/* SORTABLE STATIONS */
.stations {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--spacing-md);
    margin: var(--spacing-lg) 0;
}

.stop {
    background: var(--surface);
    border: 2px solid var(--border-color);
    padding: var(--spacing-lg);
    text-align: center;
    font-weight: 500;
    border-radius: var(--radius-lg);
    transition: all var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.stop:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stop-moveable {
    cursor: move;
    border-style: dashed;
}

.stop-moveable:hover {
    background: var(--bg-secondary);
}

/* SHARED RESULTS */
#stop-div {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-xl);
    margin-top: var(--spacing-xl);
}

#stop-div > div {
    background: var(--bg-secondary);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
}

/* STS CONTAINER */
.sts-container {
    max-width: 800px;
}

.sts-title h2 {
    text-align: center;
}

.sts-desc {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.sts-desc p {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
    body {
        padding: var(--spacing-lg) var(--spacing-md);
    }

    .game-container {
        padding: var(--spacing-xl) var(--spacing-lg);
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .button-grid {
        grid-template-columns: 1fr;
    }

    .stop-list {
        grid-template-columns: 1fr;
        max-height: none;
    }

    .stations {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    #stop-div {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 769px) and (max-width: 1023px) {
    .stop-list {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* PRINT STYLES */
@media print {
    body {
        background: white;
    }

    .game-container {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }

    button {
        display: none;
    }
}

/* FOOTER */
.app-footer {
    width: 100%;
    max-width: 1400px;
    text-align: center;
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--text-tertiary);
    font-size: 0.875rem;
    opacity: 0.6;
    transition: opacity var(--transition-base);
    margin-top: 0;
}

.app-footer:hover {
    opacity: 1;
}

.app-footer p {
    margin: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-base);
    font-weight: 500;
}

/* .app-footer a:hover {
    color: var(--text-primary);
} */