:root {
    --primary-color: #ff4757;
    --secondary-color: #2ed573;
    --tertiary-color: #1e90ff;
    --accent-color: #ffa502;
    --bg-color: #f1f2f6;
    --text-color: #2f3542;
    --card-bg: #ffffff;
    --font-family: 'Comic Sans MS', 'Fredoka One', 'Varela Round', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.back-btn {
    color: white;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1rem;
}

.game-title {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.2);
}

.level-display {
    background: rgba(255,255,255,0.2);
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
}

/* Game Container */
#game-container {
    max-width: 800px;
    margin: 20px auto;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    min-height: 500px;
    position: relative;
    overflow: hidden;
    padding-bottom: 70px; /* Space for bottom ad */
}

.screen {
    display: none;
    padding: 20px;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: flex;
}

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

/* Main Menu */
#main-menu {
    text-align: center;
}

.character-mascot {
    font-size: 8rem;
    margin-top: 30px;
    animation: bounce 2s infinite ease-in-out;
}

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

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

.menu-btn {
    background: linear-gradient(135deg, var(--tertiary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 20px 40px;
    font-size: 1.5rem;
    font-family: inherit;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0,0,0,0.15);
    transition: all 0.2s;
    font-weight: bold;
}

.menu-btn:active {
    transform: translateY(6px);
    box-shadow: none;
}

/* Grids */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
}

.word-grid-container {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.grid-item {
    background: #f8f9fa;
    border: 3px solid #e9ecef;
    border-radius: 15px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--tertiary-color);
}

.grid-item:hover {
    transform: scale(1.1);
    border-color: var(--tertiary-color);
    background: white;
    box-shadow: 0 5px 15px rgba(30, 144, 255, 0.2);
}

.word-item {
    aspect-ratio: auto;
    padding: 15px 10px;
    font-size: 1.2rem;
}

.back-to-menu {
    background: #ccc;
    color: #333;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-family: inherit;
    margin-top: auto;
}

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

.icon-btn {
    background: #eee;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
}

#current-letter-display {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.mode-tabs {
    display: flex;
    gap: 5px;
    background: #eee;
    padding: 5px;
    border-radius: 20px;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 8px 15px;
    border-radius: 15px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    font-family: inherit;
    transition: 0.3s;
}

.tab-btn.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.canvas-container {
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 31%,
        #e9ecef 31%,
        #e9ecef 33%,
        transparent 33%,
        transparent 65%,
        #e9ecef 65%,
        #e9ecef 67%,
        transparent 67%,
        transparent 100%
    );
    border: 4px solid var(--accent-color);
    border-radius: 20px;
    position: relative;
    margin-bottom: 20px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}

canvas {
    width: 100%;
    height: 100%;
    border-radius: 15px;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    touch-action: none; /* Crucial for drawing */
}

#guidance-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.word-association {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--tertiary-color);
    margin-bottom: 20px;
    height: 30px;
}

.controls {
    display: flex;
    gap: 15px;
}

.control-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-weight: bold;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    background: #eee;
    color: #333;
}

.control-btn.primary {
    background: var(--secondary-color);
    color: white;
}

/* Success Screen */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.overlay-screen.hidden {
    display: none;
}

.screen-content {
    text-align: center;
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    border: 2px solid var(--primary-color);
}

.game-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    margin: 5px;
    font-family: inherit;
}

.game-btn.secondary {
    background: #ccc;
    color: #333;
}

/* Responsive */
@media (max-width: 600px) {
    #game-container {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
        padding-bottom: 70px; /* Space for bottom ad */
    }
    .menu-buttons {
        flex-direction: column;
    }
}

@keyframes pulse-dot {
    from { transform: translate(-50%, -50%) scale(1); }
    to { transform: translate(-50%, -50%) scale(1.2); }
}

@keyframes pulse-btn {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

#bottom-ad.pmg-bottom-ad {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 50px;
    z-index: 9999;
    display: block;
    background: transparent;
}
