:root {
    --bg-gradient: linear-gradient(135deg, #189B85 0%, #0F6F5E 100%);
    --text-color: #ffffff;
    --item-bg: #ffffff;
    --item-text: #0F6F5E;
    --zone-bg: rgba(255, 255, 255, 0.2);
    --zone-border: rgba(255, 255, 255, 0.5);
    --zone-hover: rgba(255, 255, 255, 0.4);
    --success-color: #4CAF50;
    --error-color: #F44336;
    --streak-color: #FF9800;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

body {
    background: var(--bg-gradient);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 800px;
    height: 100vh;
    height: 100dvh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    font-size: 1.2rem;
    font-weight: 600;
    z-index: 50;
}

.stats-group {
    display: flex;
    gap: 10px;
}

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

.score-container, .timer-container, .streak-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.15);
    padding: 8px 14px;
    border-radius: 20px;
    transition: all 0.3s;
}

.streak-container {
    background: rgba(255, 152, 0, 0.2);
    color: var(--streak-color);
}

.streak-container.hidden {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
}

/* Difficulty Badge */
.difficulty-badge {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 12px;
    color: #fff;
    letter-spacing: 1px;
    transition: all 0.3s;
}

.difficulty-badge.hidden {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
}

.badge-pop {
    animation: badgePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes badgePop {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

/* Main Area */
#game-board {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0 20px 20px 20px;
}

#prompt-text {
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: absolute;
    top: 20px;
    width: 100%;
    padding: 0 20px;
}

/* Board Layout: Canvas Container */
#canvas-container {
    width: 100%;
    flex: 1;
    margin-top: 60px;
    max-height: 800px;
    position: relative;
}

#canvas-container canvas {
    width: 100%;
    height: 100%;
    display: block;
    outline: none;
    touch-action: none;
}

/* Overlay */
#overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

#overlay.hidden { display: none; }

.overlay-content {
    background: #fff;
    color: var(--item-text);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    max-width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.overlay-content h1 { font-size: 2.2rem; margin-bottom: 5px; }
.overlay-content p { font-size: 1.3rem; margin-bottom: 10px; font-weight: 600; }

/* High Score */
.high-score {
    font-size: 1rem !important;
    color: #666;
    margin-bottom: 15px !important;
}

.high-score.new-high {
    color: #FFD700;
    font-weight: 800 !important;
    font-size: 1.1rem !important;
    animation: badgePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
    padding: 15px;
    background: #f0f7f5;
    border-radius: 12px;
}

.stats-grid.hidden { display: none; }

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: #0F6F5E;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Wrong Answers */
.wrong-answers-container {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.wrong-answers-container.hidden {
    display: none;
}

.wrong-answers-container h3 {
    font-size: 1.1rem;
    color: var(--error-color);
    margin-bottom: 10px;
    border-bottom: 2px solid #eee;
    padding-bottom: 5px;
}

#wrong-answers-list {
    list-style: none;
}

#wrong-answers-list li {
    font-size: 0.9rem;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    color: #333;
}

#wrong-answers-list li:last-child {
    border-bottom: none;
}

#wrong-answers-list strong {
    color: #0F6F5E;
}

#restart-btn {
    background: var(--bg-gradient);
    color: #fff;
    border: none;
    padding: 15px 30px;
    font-size: 1.2rem;
    font-weight: 800;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: auto;
}

#restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
}

.end-buttons {
    display: flex;
    gap: 10px;
    margin-top: auto;
}

.end-buttons button {
    flex: 1;
}

.secondary-btn {
    background: #eef2f5;
    color: #0F6F5E;
    border: none;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: 800;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.secondary-btn:hover {
    transform: translateY(-2px);
    background: #e2e8f0;
}

/* Floating Bonus Text */
.floating-score {
    position: absolute;
    font-weight: 800;
    font-size: 1.5rem;
    color: #FFD700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 100;
    animation: floatUp 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(0.5); opacity: 1; }
    50% { transform: translateY(-30px) scale(1.2); opacity: 1; }
    100% { transform: translateY(-50px) scale(1); opacity: 0; }
}

/* Streak Pop Animation */
.streak-pop {
    animation: streakPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

/* Timer warning when low */
.timer-warning {
    background: rgba(244, 67, 54, 0.3) !important;
    animation: timerPulse 1s infinite;
}

@keyframes timerPulse {
    0%, 100% { transform: scale(1); }
}

/* Leaderboard Button */
.header-btn {
    background: rgba(0, 0, 0, 0.15);
    border: none;
    font-size: 1.2rem;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    color: white;
}

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

/* Leaderboard Overlay */
#leaderboard-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    backdrop-filter: blur(5px);
}

#leaderboard-overlay.hidden { display: none; }

.leaderboard-content {
    min-width: 320px;
    width: 90%;
    max-width: 500px;
    position: relative;
    padding: 20px 0 0 0 !important;
}

.leaderboard-content h1 {
    color: var(--item-text);
    margin-bottom: 20px;
    padding: 0 20px;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

.leaderboard-list-container {
    background: #f8f9fa;
    border-radius: 0 0 20px 20px;
    overflow: hidden;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
}

.leaderboard-header {
    display: grid;
    grid-template-columns: 50px 1fr 80px;
    padding: 12px 20px;
    background: #eef2f5;
    font-weight: 800;
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#leaderboard-list {
    overflow-y: auto;
    flex: 1;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 50px 1fr 80px;
    padding: 12px 20px;
    border-bottom: 1px solid #eee;
    align-items: center;
    text-align: left;
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item .rank {
    font-weight: 800;
    color: #999;
}

.leaderboard-item .rank.top-1 { color: #FFD700; font-size: 1.2rem; }
.leaderboard-item .rank.top-2 { color: #C0C0C0; font-size: 1.1rem; }
.leaderboard-item .rank.top-3 { color: #CD7F32; font-size: 1.1rem; }

.leaderboard-item .user {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-item .score {
    text-align: right;
    font-weight: 800;
    color: var(--item-text);
}

.loading-spinner {
    padding: 30px;
    color: #666;
    font-style: italic;
    text-align: center;
}

/* Mobile Responsive Adjustments */
@media (max-width: 450px) {
    header {
        padding: 10px;
        font-size: 1rem;
    }
    .stats-group, .header-right {
        gap: 5px;
    }
    .score-container, .timer-container, .streak-container {
        padding: 6px 8px;
        gap: 4px;
    }
    .difficulty-badge {
        padding: 4px 6px;
        font-size: 0.65rem;
    }
    .header-btn {
        padding: 6px 10px;
        font-size: 1rem;
    }
}
