:root {
    /* Light Mode Colors */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --border-color: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.08);
    --shadow-lg: rgba(15, 23, 42, 0.15);
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-hover: #4f46e5;
    --success: #10b981;
    --error: #ef4444;
    --canvas-bg: #ffffff;
    --canvas-border: #e2e8f0;
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border-color: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.5);
    --accent-primary: #818cf8;
    --accent-secondary: #a78bfa;
    --accent-hover: #6366f1;
    --success: #34d399;
    --error: #f87171;
    --canvas-bg: #1e293b;
    --canvas-border: #475569;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    margin-bottom: 40px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.logo {
    text-align: left;
}

.logo h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.logo p {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Theme Toggle */
.theme-toggle {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.theme-toggle svg {
    position: absolute;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.theme-toggle .sun-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.8);
}

.theme-toggle .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="light"] .theme-toggle .sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

[data-theme="light"] .theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0.8);
}

/* Game Board */
.game-board {
    background: var(--bg-secondary);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 4px 6px -1px var(--shadow), 0 2px 4px -1px var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 40px;
}

/* Canvas */
.canvas-wrapper {
    margin-bottom: 30px;
}

.canvas-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    background: var(--canvas-bg);
    border: 3px solid var(--canvas-border);
    box-shadow: 0 10px 15px -3px var(--shadow), 0 4px 6px -2px var(--shadow);
}

#targetCanvas {
    display: block;
    width: 100%;
    height: auto;
}

/* Game Controls */
.game-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.attempts-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.attempt-badge {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.attempt-label {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.attempt-count {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--accent-primary);
    letter-spacing: -0.02em;
}

/* Input Section */
.input-section {
    display: flex;
    gap: 12px;
}

.input-wrapper {
    flex: 1;
}

#countryInput {
    width: 100%;
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    transition: all 0.2s ease;
}

#countryInput:focus {
    border-color: var(--accent-primary);
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#countryInput::placeholder {
    color: var(--text-tertiary);
}

/* Buttons */
.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 28px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    box-shadow: 0 4px 6px -1px var(--shadow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px var(--shadow-lg);
}

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

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* Previous Guesses */
.previous-guesses {
    margin-top: 40px;
}

.previous-guesses h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.guess-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}

.guess-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.guess-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.guess-flag {
    width: 64px;
    height: 42px;
    border-radius: 6px;
    object-fit: cover;
    box-shadow: 0 2px 4px var(--shadow);
    border: 1px solid var(--border-color);
}

.guess-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* Footer */
.footer {
    margin-top: auto;
    padding-top: 40px;
    padding-bottom: 20px;
}

.footer-content {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 4px var(--shadow);
}

.footer-copyright {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: var(--accent-primary);
}

.footer-separator {
    color: var(--text-tertiary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.hidden {
    display: none;
}

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

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    padding: 48px;
    border-radius: 24px;
    max-width: 700px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px var(--shadow-lg);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease;
}

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

.modal-content h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 24px;
    letter-spacing: -0.02em;
}

.result-canvas-wrapper {
    margin: 24px 0;
    border-radius: 16px;
    overflow: hidden;
    border: 3px solid var(--canvas-border);
    box-shadow: 0 10px 15px -3px var(--shadow);
}

#resultCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: var(--canvas-bg);
}

#resultText {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin: 24px 0;
    line-height: 1.6;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 16px;
    }

    .logo h1 {
        font-size: 2rem;
    }

    .logo p {
        font-size: 0.875rem;
    }

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

    .game-board {
        padding: 24px;
        border-radius: 16px;
    }

    .input-section {
        flex-direction: column;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
        padding: 14px 24px;
    }

    .attempts-info {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
        text-align: center;
    }

    .attempt-count {
        font-size: 1.5rem;
    }

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

    .modal-content {
        padding: 32px 24px;
    }

    .modal-content h2 {
        font-size: 1.5rem;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .footer-links {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .logo h1 {
        font-size: 1.75rem;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .logo {
        text-align: center;
    }

    .footer-copyright {
        font-size: 0.85rem;
    }

    .footer-links {
        font-size: 0.85rem;
    }
}
