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

:root {
    --bg-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #1e3c72;
    --text-secondary: #666;
    --text-tertiary: #888;
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.2);
    --province-bg: white;
    --stats-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --stats-text: white;
    --legend-bg: #f8f9fa;
    --legend-text: #555;
    --hover-border: #1e3c72;
}

body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --card-bg: rgba(30, 30, 46, 0.95);
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --border-color: #3f3f46;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --province-bg: rgba(51, 51, 61, 0.8);
    --stats-gradient: linear-gradient(135deg, #4c1d95 0%, #5b21b6 100%);
    --stats-text: white;
    --legend-bg: rgba(39, 39, 42, 0.8);
    --legend-text: #d4d4d8;
    --hover-border: #8b5cf6;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease;
}

* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

#app {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding: 30px;
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 8px 32px var(--shadow-color);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.header-top {
    position: absolute;
    top: 20px;
    right: 20px;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle-btn {
    position: relative;
    width: 50px;
    height: 26px;
    background: #ccc;
    border: none;
    border-radius: 13px;
    cursor: pointer;
    padding: 0;
    transition: background 0.3s ease;
}

body.dark-mode .theme-toggle-btn {
    background: #8b5cf6;
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

body.dark-mode .toggle-slider {
    transform: translateX(24px);
}

.theme-label {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    user-select: none;
}

h1 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 2.5em;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
    transition: color 0.3s ease;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 25px;
    font-size: 1.1em;
    transition: color 0.3s ease;
}

.language-switcher {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.lang-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 16px;
    font-weight: 500;
}

.lang-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.lang-btn.active {
    border-color: var(--hover-border);
    background: var(--bg-gradient);
    color: white;
    transform: scale(1.05);
}

.flag {
    font-size: 24px;
    line-height: 1;
}

.lang-name {
    text-transform: capitalize;
}

main {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 8px 32px var(--shadow-color);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.stats-banner {
    text-align: center;
    padding: 20px;
    background: var(--stats-gradient);
    border-radius: 10px;
    margin-bottom: 25px;
    color: var(--stats-text);
    font-size: 1.2em;
    font-weight: 600;
    transition: background 0.3s ease;
}

.provinces-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

.province-item {
    background: var(--province-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 20px 15px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.wikipedia-hint {
    display: none;
    color: var(--hover-border);
    font-size: 0.75em;
    margin-top: 8px;
    font-weight: 600;
    animation: pulse 1.5s ease-in-out infinite;
}

.province-item:hover .wikipedia-hint {
    display: block;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

.province-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.province-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow-color);
    border-color: var(--hover-border);
}

.province-item:hover::before {
    transform: scaleX(1);
}

.province-seal {
    width: 60px;
    height: 60px;
    object-fit: contain;
    margin: 10px 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: transform 0.3s ease;
}

.province-item:hover .province-seal {
    transform: scale(1.1);
}

.province-seal-fallback {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow-color);
    margin: 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.province-item:hover .province-seal-fallback {
    transform: scale(1.1);
}

.province-initials {
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.province-number {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--hover-border);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75em;
    font-weight: bold;
    z-index: 1;
    transition: background 0.3s ease;
}

.province-name {
    color: var(--text-primary);
    font-size: 1.1em;
    font-weight: 600;
    margin: 10px 0;
    line-height: 1.3;
    transition: color 0.3s ease;
}

.province-capital {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-top: 8px;
    transition: color 0.3s ease;
}

.province-capital .icon {
    font-size: 1em;
}

.province-area {
    color: var(--text-tertiary);
    font-size: 0.8em;
    margin-top: 5px;
    transition: color 0.3s ease;
}

/* Legend */
.provinces-legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 30px;
    padding: 20px;
    background: var(--legend-bg);
    border-radius: 10px;
    flex-wrap: wrap;
    transition: background 0.3s ease;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--legend-text);
    font-size: 0.9em;
    transition: color 0.3s ease;
}

.legend-icon {
    font-size: 1.2em;
}

footer {
    text-align: center;
    margin-top: 30px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: 0 8px 32px var(--shadow-color);
    color: var(--text-primary);
    font-size: 1.1em;
    transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* Responsive design */
@media (max-width: 1200px) {
    .provinces-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 900px) {
    .provinces-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.8em;
    }

    .subtitle {
        font-size: 1em;
    }

    .header-top {
        position: static;
        display: flex;
        justify-content: flex-end;
        margin-bottom: 15px;
    }

    .theme-toggle-btn {
        width: 44px;
        height: 24px;
    }

    .toggle-slider {
        width: 18px;
        height: 18px;
    }

    body.dark-mode .toggle-slider {
        transform: translateX(20px);
    }

    .language-switcher {
        flex-direction: column;
        align-items: stretch;
    }

    .lang-btn {
        justify-content: center;
    }

    .provinces-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .province-item {
        padding: 15px 10px;
    }

    .province-seal {
        width: 50px;
        height: 50px;
    }

    .province-seal-fallback {
        width: 50px;
        height: 50px;
    }

    .province-initials {
        font-size: 14px;
    }

    .province-name {
        font-size: 1em;
    }
}

@media (max-width: 576px) {
    .provinces-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .provinces-legend {
        flex-direction: column;
        gap: 10px;
    }
}

/* Thai language specific styles */
[lang="th"] .province-name {
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    font-size: 1em;
}

/* Animation for grid items */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.province-item {
    animation: fadeInUp 0.5s ease-out;
}

.province-item:nth-child(1) { animation-delay: 0.05s; }
.province-item:nth-child(2) { animation-delay: 0.1s; }
.province-item:nth-child(3) { animation-delay: 0.15s; }
.province-item:nth-child(4) { animation-delay: 0.2s; }
.province-item:nth-child(5) { animation-delay: 0.25s; }
.province-item:nth-child(6) { animation-delay: 0.3s; }
.province-item:nth-child(7) { animation-delay: 0.35s; }
.province-item:nth-child(8) { animation-delay: 0.4s; }
.province-item:nth-child(9) { animation-delay: 0.45s; }
.province-item:nth-child(10) { animation-delay: 0.5s; }
.province-item:nth-child(11) { animation-delay: 0.55s; }
.province-item:nth-child(12) { animation-delay: 0.6s; }
.province-item:nth-child(13) { animation-delay: 0.65s; }
.province-item:nth-child(14) { animation-delay: 0.7s; }
