:root {
    --primary-color: #FF9800;
    --secondary-color: #4FC3F7;
    --accent-color: #FF4081;
    --background-color: #FFF3E0;
    --panel-bg: #FFFFFF;
    --text-color: #333;
    --border-radius: 20px;
    --font-main: 'Comic Neue', 'ZCOOL KuaiLe', cursive, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    font-family: var(--font-main);
    background-color: #B3E5FC;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    width: 100vw;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 0;
}

/* Main App Container */
.app-container {
    width: 90vw;
    min-height: 75vh;
    aspect-ratio: 16 / 9;
    background-color: var(--background-color);
    border-radius: var(--border-radius);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    position: relative;
    border: 8px solid #FFB74D;
    margin: 0 auto;
}

/* Flex Layout for Main Content and Nav */
.main-content {
    display: flex;
    flex: 1;
    gap: 20px;
    overflow: hidden;
    min-height: 0;
}

.navigation {
    flex: 0 0 auto;
    height: auto;
    min-height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px 0 20px;
}

/* Left Panel */
.left-panel {
    flex: 1;
    background-color: var(--panel-bg);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border: 4px dashed var(--secondary-color);
    overflow-y: auto;
}

.letter-display {
    font-size: 8rem;
    font-weight: bold;
    color: var(--accent-color);
    text-shadow: 3px 3px 0px #F8BBD0;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

#letter-icon {
    font-size: 4rem;
    margin-top: -10px;
}

.word-list {
    margin-top: 20px;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.word-item {
    font-size: 2rem;
    font-weight: bold;
    color: #0277BD;
    background: #E1F5FE;
    padding: 10px 20px;
    border-radius: 50px;
    display: inline-block;
    box-shadow: 0 4px 0 #B3E5FC;
    font-family: 'Comic Neue', cursive;
    letter-spacing: 1px;
    transition: transform 0.1s;
}

.word-item:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Right Panel */
.right-panel {
    flex: 1.5;
    background-color: var(--panel-bg);
    border-radius: var(--border-radius);
    padding: 15px;
    display: flex;
    flex-direction: column;
    border: 4px solid var(--primary-color);
    position: relative;
}

.canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
    background-image: radial-gradient(#E0E0E0 1px, transparent 1px);
    background-size: 20px 20px;
    border-radius: 15px;
    overflow: hidden;
    cursor: crosshair;
}

canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.canvas-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.9);
    padding: 5px;
    border-radius: 50px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.control-btn {
    background: #FF5252;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    font-family: var(--font-main);
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
}

.colors {
    display: flex;
    gap: 5px;
    align-items: center;
}

.color-btn {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
}

.color-btn.active {
    transform: scale(1.2);
    border-color: #333;
}

.nav-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.5rem;
    border-radius: 50px;
    font-family: var(--font-main);
    cursor: pointer;
    box-shadow: 0 5px 0 #E65100;
    transition: transform 0.1s;
}

.nav-btn:active {
    transform: translateY(5px);
    box-shadow: none;
}

.progress-indicator {
    font-size: 2rem;
    color: var(--text-color);
    font-weight: bold;
}

/* Start Screen */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #B3E5FC;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background-image: radial-gradient(#FFF 20%, transparent 20%), radial-gradient(#FFF 20%, transparent 20%);
    background-color: #81D4FA;
    background-position: 0 0, 50px 50px;
    background-size: 100px 100px;
}

.start-content {
    text-align: center;
    background: white;
    padding: 40px 60px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 8px solid #FF9800;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.start-content h1 {
    font-size: 4rem;
    color: #FF4081;
    margin-bottom: 30px;
    text-shadow: 3px 3px 0 #F8BBD0;
}

/* Shared Home Button Styles */
.home-btn {
    color: white;
    border: none;
    padding: 20px 40px;
    font-size: 2rem;
    border-radius: 50px;
    font-family: var(--font-main);
    cursor: pointer;
    transition: transform 0.1s;
    margin: 10px;
    display: inline-block;
}

.home-btn:active {
    transform: translateY(6px);
    box-shadow: none !important;
}

#start-btn {
    background-color: #4CAF50;
    box-shadow: 0 6px 0 #2E7D32;
    min-width: 300px;
}

#game-btn {
    background-color: #FF4081;
    box-shadow: 0 6px 0 #C2185B;
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Portrait Mode (9:16 or similar) */
@media (max-aspect-ratio: 1/1) {
    .app-container {
        aspect-ratio: 9 / 16;
        width: 95vw;
        height: auto;
        max-height: none;
        margin: 10px auto;
        padding-bottom: max(30px, env(safe-area-inset-bottom));
    }

    .main-content {
        flex-direction: column;
        gap: 10px;
        padding-bottom: 5px;
    }

    .left-panel {
        flex: 0 0 auto;
        max-height: 35%;
        padding: 10px;
    }

    .letter-display {
        font-size: 6rem;
        flex-direction: row;
        gap: 15px;
    }

    #letter-icon {
        font-size: 3rem;
        margin-top: 0;
    }

    .word-list {
        margin-top: 10px;
        gap: 5px;
    }

    .word-item {
        font-size: 1.2rem;
        padding: 5px 10px;
    }

    .right-panel {
        flex: 1;
    }

    .navigation {
        min-height: 60px;
        padding: 5px 10px 0 10px;
    }

    .nav-btn {
        padding: 8px 15px;
        font-size: 1rem;
    }

    .progress-indicator {
        font-size: 1.5rem;
    }
}

/* Small Landscape Screens */
@media (max-width: 800px) and (min-aspect-ratio: 1/1) {
    .letter-display {
        font-size: 6rem;
    }

    #letter-icon {
        font-size: 3rem;
    }

    .word-item {
        font-size: 1.5rem;
        padding: 8px 15px;
    }

    .nav-btn {
        padding: 10px 20px;
        font-size: 1.2rem;
    }
}

/* Back Button (Matching Game Page) */
.back-btn {
    text-decoration: none;
    background: #FF9800;
    color: white;
    padding: 8px 16px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 0 #E65100;
    border: none;
    cursor: pointer;
    display: inline-block;
    font-family: var(--font-main);
}

.back-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Donate Page Styles */
#donate-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #B3E5FC;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background-image: radial-gradient(#FFF 20%, transparent 20%), radial-gradient(#FFF 20%, transparent 20%);
    background-color: #F8BBD0;
    background-position: 0 0, 50px 50px;
    background-size: 100px 100px;
}

.donate-content {
    text-align: center;
    background: white;
    padding: 40px 60px;
    border-radius: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 8px solid #FF4081;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 90vw;
}

.donate-content h1 {
    font-size: 3rem;
    color: #FF4081;
    margin-bottom: 20px;
    text-shadow: 2px 2px 0 #F8BBD0;
}

.donate-msg {
    font-size: 1.5rem;
    color: #555;
    margin-bottom: 30px;
    line-height: 1.6;
    position: relative;
    overflow: hidden;
}

.qr-placeholder {
    width: 250px;
    height: 250px;
    background: #f0f0f0;
    border: 4px dashed #ccc;
    margin: 0 auto 30px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 15px;
    position: relative;
    overflow: hidden;
}

.qr-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.qr-fallback {
    color: #999;
    font-weight: bold;
    font-size: 1.2rem;
}

#donate-btn {
    background-color: #9C27B0;
    box-shadow: 0 6px 0 #7B1FA2;
}

/* Mobile Start Screen Styles */
@media (max-width: 600px) {
    .start-content {
        padding: 30px 20px;
        width: 85vw;
        border-width: 5px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    .start-content h1 {
        font-size: 2.5rem;
    }

    #start-btn,
    #game-btn,
    #donate-btn {
        min-width: unset;
        width: 100%;
        padding: 15px 20px;
        font-size: 1.5rem;
    }
}

/* Mobile Donate Page Styles */
@media (max-width: 600px) {
    .donate-content {
        padding: 20px;
        width: 85vw;
        max-height: 80vh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .donate-content h1 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }

    .donate-msg {
        font-size: 1rem;
        margin-bottom: 20px;
    }

    .qr-placeholder {
        width: 180px;
        height: 180px;
        margin-bottom: 20px;
    }
}