:root {
    --primary: #4361ee;
    --primary-light: #4cc9f0;
    --primary-dark: #3a0ca3;
    --success: #4caf50;
    --error: #f44336;
    --bg-light: #f0f2ff;
    --bg-card: #ffffff;
    --text: #333;
    --border: #ddd;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-light) 0%, #e6f0ff 100%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--bg-card);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 3px solid var(--primary);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
}

.logo h1 {
    font-size: 1.5rem;
    color: var(--primary-dark);
}

nav ul {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

nav a {
    text-decoration: none;
    color: var(--text);
    padding: 0.6rem 1rem;
    border-radius: 30px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

nav a::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    z-index: -1;
    border-radius: 30px;
    transform: translateY(100%);
    transition: transform 0.3s;
}

nav a:hover::before, nav a.active::before {
    transform: translateY(0);
}

nav a:hover, nav a.active {
    color: white;
}

.badge {
    font-size: 0.7em;
    background: var(--primary);
    color: white;
    padding: 2px 5px;
    border-radius: 4px;
    margin-left: 2px;
}

main {
    flex: 1;
    padding: 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.page-section {
    display: none;
}

.page-section.active {
    display: block;
}

.typing-container {
    max-width: 900px;
    margin: 0 auto;
}

.daily-challenge {
    background: linear-gradient(135deg, #f8f9ff, #eef2ff);
    border-radius: 16px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.challenge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.challenge-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.challenge-progress {
    height: 10px;
    background: #e0e7ff;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    width: 0%;
    transition: width 0.5s;
}

.stats-container {
    display: flex;
    justify-content: space-around;
    background: linear-gradient(135deg, #f8f9ff, #eef2ff);
    padding: 1.2rem;
    border-radius: 16px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.stat-box {
    text-align: center;
    min-width: 100px;
    flex: 1;
}

.stat-box .icon {
    font-size: 1.5em;
    display: block;
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.difficulty-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 1.5rem;
}

.diff-btn {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.diff-btn:hover {
    background: rgba(67, 97, 238, 0.1);
}

.diff-btn.active {
    background: var(--primary);
    color: white;
}

.word-display {
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    font-size: 1.4rem;
    line-height: 1.6;
    min-height: 120px;
    margin-bottom: 1.5rem;
    background: #fafbff;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.05);
}

.word {
    display: inline-block;
    margin-right: 5px;
}

.current-word {
    background: rgba(76, 201, 240, 0.2);
    border-radius: 4px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 201, 240, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(76, 201, 240, 0); }
}

.correct { color: var(--success); font-weight: 600; }
.incorrect { color: var(--error); text-decoration: underline; }

.text-input {
    width: 100%;
    padding: 1rem;
    font-size: 1.2rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    outline: none;
    transition: all 0.3s;
    resize: none;
    height: 60px;
    background: #fafbff;
}

.text-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.button-container {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    font-size: 1rem;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(67, 97, 238, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d, #868e96);
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    box-shadow: none;
}

.full-width { width: 100%; }

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.game-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--primary);
    transition: all 0.3s;
    text-align: center;
    cursor: pointer;
}

.game-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(67, 97, 238, 0.2);
}

.game-card-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.game-card h3 {
    margin-bottom: 0.5rem;
    color: var(--primary-dark);
}

.game-card p {
    color: #666;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.game-canvas-container {
    display: none;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    min-height: 400px;
    max-height: 600px;
    background: #2b2b2b;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 3px solid var(--primary-dark);
}

.game-canvas-container.active {
    display: block;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.game-ui-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    padding: 20px;
}

.game-hud {
    display: flex;
    justify-content: space-between;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

.game-back-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(0,0,0,0.5);
    color: white;
    border: 1px solid white;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    z-index: 20;
    pointer-events: auto;
}

.game-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    pointer-events: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 90%;
    width: 400px;
}

.game-screen.hidden {
    display: none;
}

.game-title {
    color: var(--primary-dark);
    font-size: 2rem;
    margin-bottom: 1rem;
}

#game-center-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.scramble-word {
    font-size: 3rem;
    color: white;
    letter-spacing: 10px;
    text-shadow: 0 0 10px rgba(67, 97, 238, 0.8);
}

.static-page-content {
    padding: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
}

.static-page-content h2 {
    color: var(--primary-dark);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    margin-bottom: 0.5rem;
    color: var(--primary-dark);
    font-size: 1rem;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.auth-container {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow);
    max-width: 500px;
    margin: 2rem auto;
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--primary-dark);
}

.form-control {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    transition: all 0.3s;
}

.logout-btn:hover {
    background: rgba(67, 97, 238, 0.1);
}

.welcome-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.welcome-content {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.welcome-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

footer {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
}

footer p {
    margin: 0.5rem 0;
}

@media (max-width: 768px) {
    .logo h1 { font-size: 1.3rem; }
    .logo-icon { width: 35px; height: 35px; }
    nav a { padding: 0.5rem 0.8rem; font-size: 0.9rem; }
    .word-display { font-size: 1.2rem; padding: 1rem; }
    .text-input { font-size: 1.1rem; }
    .game-hud { font-size: 1rem; }
    .scramble-word { font-size: 2rem; letter-spacing: 5px; }
    .game-canvas-container { height: 50vh; }
}

@media (max-width: 480px) {
    .stats-container { flex-direction: column; }
    .word-display { font-size: 1rem; }
    .btn { padding: 0.7rem 1.5rem; font-size: 0.9rem; }
}