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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    background: linear-gradient(135deg, #186fae 0%, #222898 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1vh 2vw;
}

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

#game-card {
    background: white;
    border-radius: 1.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    max-height: 98vh;
}

#header {
    padding: 0.5rem 1rem 0.5rem;
    text-align: center;
    background: linear-gradient(135deg, #186fae 0%, #214ba5 50%, #222898 100%);
    color: white;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    z-index: 101;
}

#header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 50%);
    animation: headerShine 8s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes headerShine {
    0%, 100% { transform: translateX(-30%) translateY(-30%); }
    50% { transform: translateX(30%) translateY(30%); }
}

#game-title {
    font-size: 24pt;
    font-weight: 700;
    margin-bottom: 0.1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    letter-spacing: 1px;
}


#score-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-btn-group {
    display: flex;
    gap: 0.5rem;
    min-width: 90px;
}

.header-btn-group:last-child {
    justify-content: flex-end;
}

.header-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    font-size: 1.3rem;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.header-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1.2rem;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.score-label {
    font-size: 0.7rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.score-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ff8e00;
    text-shadow: 0 0 10px rgba(255, 142, 0, 0.5), 1px 1px 2px rgba(0, 0, 0, 0.3);
}

#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.3rem;
    min-height: 0;
    position: relative;
}

#next-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.3rem 0.8rem;
    background: linear-gradient(135deg, #ffffff 0%, #f0f6ff 100%);
    border-radius: 0.8rem;
    margin-bottom: 0.3rem;
    flex-shrink: 0;
    border: 2px solid rgba(33, 75, 165, 0.2);
    box-shadow: 0 2px 8px rgba(33, 75, 165, 0.1);
}

.preview-label {
    font-size: 0.85rem;
    color: #214ba5;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#next-item-display {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.75rem;
    color: white;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    animation: bobble 2s ease-in-out infinite;
}

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

#next-item-name {
    font-size: 0.8rem;
    color: #555;
    font-weight: 600;
}

#canvas-container {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: linear-gradient(180deg, #f0f6ff 0%, #e8f0fa 50%, #dce8f5 100%);
    border-radius: 1rem;
    overflow: hidden;
    border: none;
    min-height: 0;
    touch-action: none;
    cursor: pointer;
    width: 100%;
    position: relative;
    box-shadow: 
        inset 0 0 40px rgba(255, 255, 255, 0.5),
        0 4px 15px rgba(33, 75, 165, 0.15);
}

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

#footer {
    padding: 0.4rem 1rem;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    touch-action: none;
    cursor: pointer;
}

#footer-logo {
    height: 28px;
    width: auto;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(34, 40, 152, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: 1.5rem;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    color: white;
    padding: 2rem;
    max-width: 90%;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.overlay-content .instructions {
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 0.8rem;
    opacity: 0.9;
}

.overlay-content .keyboard-hint {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-bottom: 1.5rem;
}

.overlay-content .final-score,
.overlay-content .best-score-display {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.overlay-content .final-score span,
.overlay-content .best-score-display span {
    color: #ff8e00;
    font-weight: 700;
}

.overlay-btn {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-weight: 700;
    font-family: inherit;
    background: linear-gradient(135deg, #ff8e00 0%, #e67a00 100%);
    color: white;
    border: none;
    border-radius: 1rem;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 142, 0, 0.5);
    transition: transform 0.1s;
    min-width: 150px;
    min-height: 50px;
    margin-top: 1rem;
}

.overlay-btn:active {
    transform: scale(0.95);
}

@media (min-width: 768px) {
    #app-container {
        max-width: 450px;
    }
    
    #game-title {
        font-size: 1.8rem;
    }
}

@media (max-height: 600px) {
    #header {
        padding: 0.5rem 0.8rem;
    }
    
    #game-title {
        font-size: 1.3rem;
    }
    
    .score-value {
        font-size: 1.1rem;
    }
    
    #game-area {
        padding: 0.2rem;
    }
    
    #next-preview {
        padding: 0.3rem;
    }
}

.email-form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 1rem;
    width: 100%;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.email-prompt {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.email-input {
    padding: 0.8rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 0.8rem;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    outline: none;
    transition: all 0.2s ease;
}

.email-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.email-input:focus {
    border-color: #ff8e00;
    background: rgba(255, 255, 255, 0.2);
}

.email-input:invalid:not(:placeholder-shown) {
    border-color: #ff6b6b;
}

.victory-message,
.leaderboard-message {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    opacity: 0.95;
}

#victory-overlay {
    overflow: hidden;
}

#victory-overlay .overlay-content h2 {
    color: #ff8e00;
    font-size: 2.5rem;
}

.victory-title {
    animation: victoryPulse 0.5s ease-in-out infinite alternate;
    text-shadow: 0 0 20px rgba(255, 142, 0, 0.5);
}

@keyframes victoryPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.victory-content {
    z-index: 10;
    position: relative;
}

.victory-score-display {
    font-size: 1.3rem !important;
}

.victory-btn {
    animation: victoryBtnGlow 1s ease-in-out infinite alternate;
}

@keyframes victoryBtnGlow {
    from { box-shadow: 0 4px 20px rgba(255, 142, 0, 0.4); }
    to { box-shadow: 0 4px 30px rgba(255, 142, 0, 0.8); }
}

#confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 5;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -20px;
    animation: confettiFall linear forwards;
}

.confetti.circle {
    border-radius: 50%;
}

.confetti.square {
    border-radius: 2px;
}

.confetti.ribbon {
    width: 8px;
    height: 20px;
    border-radius: 2px;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg) scale(0.5);
        opacity: 0.3;
    }
}

.email-form .overlay-btn {
    margin-top: 0.5rem;
}

.analytics-content {
    min-width: 280px;
}

.analytics-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    justify-content: center;
}

.analytics-tab {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.6rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.analytics-tab:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.analytics-tab.active {
    background: rgba(255, 142, 0, 0.9);
    color: white;
    border-color: #ff8e00;
}

.analytics-tab-content {
    display: none;
}

.analytics-tab-content.active {
    display: block;
}

.analytics-stats {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin: 1rem 0;
}

.analytics-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.analytics-label {
    font-size: 0.9rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.analytics-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #ff8e00;
}

.leaderboard-list {
    max-height: 250px;
    overflow-y: auto;
    margin: 1rem 0;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
}

.leaderboard-rank {
    font-size: 1rem;
    font-weight: 700;
    color: #ff8e00;
    width: 30px;
    text-align: center;
}

.leaderboard-name {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
}

.leaderboard-score {
    font-size: 1rem;
    font-weight: 700;
    color: #ff8e00;
}

.leaderboard-empty {
    text-align: center;
    opacity: 0.7;
    padding: 2rem;
}
