/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Accessibility: Skip Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: bold;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Accessibility: Visually Hidden (for screen readers) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for accessibility */
:focus-visible {
    outline: 3px solid var(--theme-accent);
    outline-offset: 2px;
}

:root {
    /* Default theme (Light Blue) */
    --theme-primary: #60a5fa;
    --theme-secondary: #3b82f6;
    --theme-accent: #2563eb;
    --theme-gradient-start: #60a5fa;
    --theme-gradient-end: #3b82f6;
    --theme-text: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--theme-text);
    transition: background 0.5s ease;
}

/* Light Blue Theme (default) */
body.theme-light-blue {
    --theme-primary: #60a5fa;
    --theme-secondary: #3b82f6;
    --theme-accent: #2563eb;
    --theme-gradient-start: #60a5fa;
    --theme-gradient-end: #3b82f6;
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%);
}

/* Light Green Theme */
body.theme-light-green {
    --theme-primary: #34d399;
    --theme-secondary: #10b981;
    --theme-accent: #059669;
    --theme-gradient-start: #34d399;
    --theme-gradient-end: #10b981;
    background: linear-gradient(135deg, #34d399 0%, #10b981 50%, #059669 100%);
}

/* Pink Theme */
body.theme-pink {
    --theme-primary: #f472b6;
    --theme-secondary: #ec4899;
    --theme-accent: #db2777;
    --theme-gradient-start: #f472b6;
    --theme-gradient-end: #ec4899;
}

/* Rainbow Unicorn Theme */
body.theme-rainbow-unicorn {
    --theme-primary: #f472b6;
    --theme-secondary: #a78bfa;
    --theme-accent: #60a5fa;
    --theme-gradient-start: #f472b6;
    --theme-gradient-end: #a78bfa;
    background: linear-gradient(135deg, #f472b6 0%, #ec4899 25%, #a78bfa 50%, #60a5fa 75%, #34d399 100%);
    background-size: 200% 200%;
    animation: rainbowShift 8s ease infinite;
}

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

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
    position: relative;
}

.header-top {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 10px;
}

.btn-theme {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.btn-theme:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.btn-profile-header {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.btn-profile-header:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.logo {
    max-width: 150px;
    height: auto;
    margin-bottom: 10px;
}

h1 {
    font-size: 2.5em;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.tagline {
    font-size: 1.1em;
    opacity: 0.9;
}

/* Game Area */
.game-area {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

/* Level Selector */
.level-selector h2 {
    margin-bottom: 20px;
    color: var(--theme-primary);
    text-align: center;
}

/* Progress Overview */
.progress-overview {
    background: linear-gradient(135deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    color: white;
}

.progress-overview h2 {
    color: white;
    margin-bottom: 15px;
    font-size: 1.8em;
}

.overall-progress {
    margin-top: 15px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.progress-text {
    font-size: 1.1em;
    font-weight: 600;
}

.progress-percentage {
    font-size: 1.5em;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 20px;
}

.overall-progress-bar {
    width: 100%;
    height: 25px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    overflow: hidden;
    position: relative;
}

.overall-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4ade80 0%, #22c55e 100%);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.5);
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.level-card {
    background: linear-gradient(135deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 3px solid transparent;
}

.level-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.level-card.locked {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.level-card.completed {
    border-color: #4ade80;
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
}

.level-card-number {
    font-size: 2em;
    font-weight: bold;
    margin-bottom: 5px;
}

.level-card-title {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.level-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.level-badge {
    background: var(--theme-primary);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
}

.level-title {
    font-size: 1.2em;
    font-weight: 600;
    color: #333;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-back {
    background: #6b7280;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.2s;
}

.btn-back:hover {
    background: #4b5563;
}

.btn-debug {
    background: #f59e0b;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.2s;
    opacity: 0.8;
    border: 2px dashed rgba(255, 255, 255, 0.5);
}

.btn-debug:hover {
    background: #d97706;
    opacity: 1;
    transform: scale(1.05);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.stat {
    flex: 1;
    min-width: 120px;
}

.stat-label {
    display: block;
    font-size: 0.85em;
    color: #6b7280;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.8em;
    font-weight: bold;
    color: var(--theme-primary);
}

.stat-value.score {
    color: #f59e0b;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 5px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    width: 0%;
    transition: width 0.3s ease;
}

/* Typing Area */
.typing-area {
    margin-bottom: 30px;
}

.text-display {
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 30px;
    min-height: 180px;
    font-size: 2em;
    line-height: 2.2;
    margin-bottom: 20px;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

.text-display .char {
    display: inline-block;
}

.text-display .char.correct {
    color: #22c55e;
    background: #dcfce7;
}

.text-display .char.incorrect {
    color: #ef4444;
    background: #fee2e2;
    text-decoration: underline;
}

.text-display .char.current {
    background: #dbeafe;
    border-left: 3px solid #3b82f6;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { border-left-color: #3b82f6; }
    51%, 100% { border-left-color: transparent; }
}

.input-area {
    margin-top: 15px;
}

#typingInput {
    width: 100%;
    padding: 15px;
    font-size: 1.8em;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    text-align: center;
    transition: border-color 0.2s;
}

#typingInput:focus {
    outline: none;
    border-color: var(--theme-primary);
}

#typingInput:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Keyboard */
.keyboard-container {
    margin-top: 30px;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f3f4f6;
    padding: 15px;
    border-radius: 12px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.key {
    background: white;
    border: 2px solid #d1d5db;
    border-radius: 6px;
    padding: 12px 8px;
    min-width: 45px;
    text-align: center;
    font-size: 0.9em;
    font-weight: 600;
    color: #374151;
    transition: all 0.15s;
    position: relative;
    user-select: none;
}

.key.wide {
    min-width: 80px;
}

.key.space {
    min-width: 300px;
}

.key.active {
    background: var(--theme-primary);
    color: white;
    border-color: var(--theme-primary);
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.4);
}

.key.highlight {
    background: #fef3c7;
    border-color: #fbbf24;
    animation: pulse 1s infinite;
}

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

.key.locked {
    opacity: 0.3;
    background: #e5e7eb;
}

/* Game Message */
.game-message {
    text-align: center;
    margin-top: 20px;
    min-height: 30px;
    font-size: 1.1em;
    font-weight: 600;
}

.game-message.success {
    color: #22c55e;
}

.game-message.error {
    color: #ef4444;
}

.game-message.info {
    color: #3b82f6;
}

/* Level Complete */
.level-complete {
    text-align: center;
    padding: 40px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}

.level-complete h2 {
    font-size: 2.5em;
    color: var(--theme-primary);
    margin-bottom: 30px;
}

.completion-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.completion-stat {
    display: flex;
    flex-direction: column;
}

.completion-label {
    font-size: 0.9em;
    color: #6b7280;
    margin-bottom: 10px;
}

.completion-value {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--theme-primary);
}

.total-score {
    margin: 30px 0;
    padding: 20px;
    background: linear-gradient(135deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    border-radius: 15px;
    color: white;
}

.total-score-label {
    font-size: 1.2em;
    margin-right: 15px;
    opacity: 0.9;
}

.total-score-value {
    font-size: 2.5em;
    font-weight: bold;
}

.completion-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 30px;
}

.completion-actions .btn-primary,
.completion-actions .btn-secondary {
    min-width: 150px;
    padding: 15px 30px;
    font-size: 1.1em;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--theme-gradient-start) 0%, var(--theme-gradient-end) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.btn-secondary:hover {
    background: #d1d5db;
}

/* Profile Section */
.profile-section {
    /* Container for the profile modal only now */
}

.profile-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.profile-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.profile-content h3 {
    margin-bottom: 20px;
    color: var(--theme-primary);
}

.profile-form label {
    display: block;
    margin-bottom: 15px;
}

.profile-form input {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 1em;
}

.profile-form input:focus {
    outline: none;
    border-color: var(--theme-primary);
}

.profile-stats {
    margin: 20px 0;
    padding: 15px;
    background: #f9fafb;
    border-radius: 8px;
}

.profile-stats p {
    margin: 8px 0;
}

.profile-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Welcome Modal */
.welcome-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
}

.welcome-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
}

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

.welcome-content h2 {
    font-size: 2.5em;
    color: var(--theme-primary);
    margin-bottom: 15px;
}

.welcome-text {
    font-size: 1.2em;
    color: #374151;
    margin-bottom: 25px;
}

.welcome-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
}

.welcome-form input {
    padding: 15px;
    font-size: 1.2em;
    border: 3px solid #e5e7eb;
    border-radius: 10px;
    text-align: center;
    transition: border-color 0.2s;
}

.welcome-form input:focus {
    outline: none;
    border-color: var(--theme-primary);
}

.welcome-note {
    font-size: 0.9em;
    color: #6b7280;
    font-style: italic;
}

.completion-greeting {
    font-size: 1.5em;
    color: var(--theme-primary);
    font-weight: 600;
    margin: 10px 0 20px 0;
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Theme Selector Modal */
.theme-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(5px);
}

.theme-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
}

.theme-content h3 {
    font-size: 2em;
    color: var(--theme-primary);
    margin-bottom: 25px;
}

.themes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

@media (min-width: 600px) {
    .themes-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.theme-option {
    cursor: pointer;
    transition: transform 0.2s;
    padding: 10px;
    border-radius: 15px;
    border: 3px solid transparent;
}

.theme-option:hover {
    transform: translateY(-5px);
    background: #f9fafb;
}

.theme-option.active {
    border-color: var(--theme-primary);
    background: rgba(96, 165, 250, 0.1);
}

.theme-preview {
    width: 100%;
    height: 120px;
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-light-blue {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 50%, #2563eb 100%);
}

.theme-light-green {
    background: linear-gradient(135deg, #34d399 0%, #10b981 50%, #059669 100%);
}

.theme-pink {
    background: linear-gradient(135deg, #f472b6 0%, #ec4899 100%);
}

.theme-rainbow-unicorn {
    background: linear-gradient(135deg, #f472b6 0%, #ec4899 25%, #a78bfa 50%, #60a5fa 75%, #34d399 100%);
    background-size: 200% 200%;
    animation: rainbowShift 3s ease infinite;
}

.theme-name {
    display: block;
    font-weight: 600;
    color: #374151;
    font-size: 1em;
}

/* Responsive */
@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
    
    .game-area {
        padding: 20px;
    }
    
    .progress-overview {
        padding: 20px;
    }
    
    .progress-overview h2 {
        font-size: 1.5em;
    }
    
    .progress-info {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .progress-percentage {
        font-size: 1.3em;
    }
    
    .levels-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .stats-bar {
        flex-direction: column;
    }
    
    .keyboard-row {
        flex-wrap: wrap;
    }
    
    .key.space {
        min-width: 200px;
    }
    
    .completion-stats {
        flex-direction: column;
        gap: 20px;
    }
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    color: white;
    font-size: 0.95em;
    opacity: 0.9;
}

.site-footer p {
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.heart-icon {
    display: inline-block;
    cursor: pointer;
    transition: transform 0.2s;
}

.heart-icon:hover {
    animation: heartPulse 0.6s ease-in-out infinite;
}

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