* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#back-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    font-size: 28px;
    text-decoration: none;
    color: #555;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#stars {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 100;
    font-size: 24px;
}

#equation-bar {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border-radius: 16px;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.addend-card {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: white;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}

#addend1 {
    background: #ef5350;
}

#addend2 {
    background: #42a5f5;
}

.sum-unknown {
    background: #e0e0e0;
    color: #999;
}

.operator {
    font-size: 22px;
    font-weight: bold;
    color: #666;
}

#speech-bubble {
    position: absolute;
    z-index: 80;
    background: white;
    border-radius: 18px;
    padding: 12px 18px;
    font-size: 16px;
    color: #333;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
    max-width: 280px;
    pointer-events: none;
}

.speech-arrow {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 12px solid white;
}

.hidden {
    display: none !important;
}

#game-area {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#bg-canvas, #anim-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    touch-action: none;
}

#bg-canvas {
    z-index: 1;
}

#anim-canvas {
    z-index: 30;
}

#number-line-container {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    z-index: 20;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 20px 10px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

#number-line-container::-webkit-scrollbar {
    display: none;
}

#number-line-container::before,
#number-line-container::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    z-index: 25;
    pointer-events: none;
}

#number-line-container::before {
    left: 0;
    background: linear-gradient(to right, rgba(200, 230, 201, 0.8), transparent);
}

#number-line-container::after {
    right: 0;
    background: linear-gradient(to left, rgba(200, 230, 201, 0.8), transparent);
}

#number-line {
    display: flex;
    gap: 6px;
    padding: 60px 20px 0;
    width: fit-content;
}

.block {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.3s;
    user-select: none;
    -webkit-user-select: none;
}

.block:active {
    transform: scale(0.95);
}

.block.predicted {
    border: 3px solid #ffd700;
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.6);
}

.block.landed {
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.5);
}

.block.wrong-highlight {
    background: #8d6e63 !important;
    transition: background 0.5s;
}

.block.sparkle {
    animation: sparkle 0.8s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% {
        box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
}

.flag {
    position: absolute;
    top: -52px;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}

.flag-pole {
    width: 4px;
    height: 40px;
    background: #5d4037;
    margin: 0 auto;
    border-radius: 2px;
}

.flag-pennant {
    width: 32px;
    height: 22px;
    background: linear-gradient(135deg, #ffd700, #ffab00);
    position: absolute;
    top: 0;
    left: 4px;
    border-radius: 2px 4px 4px 2px;
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

/* Floating interactive flag — visible before placement */
#floating-flag {
    position: absolute;
    z-index: 25;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.3s ease, filter 0.3s ease;
    animation: flag-bob 2s ease-in-out infinite;
}

#floating-flag.held {
    cursor: grabbing;
    animation: none;
    transform: translateX(-50%) scale(1.25);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.7));
}

#floating-flag.hidden {
    display: none !important;
}

@keyframes flag-bob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-8px); }
}

.block.drag-hover {
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.5);
    transform: scale(1.05);
}

.helper-line {
    position: absolute;
    display: flex;
    gap: 6px;
    z-index: 21;
    pointer-events: auto;
    animation: helper-slide-in 0.4s ease-out;
}

@keyframes helper-slide-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.helper-block {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(66, 165, 245, 0.3);
    border: 1.5px dashed rgba(66, 165, 245, 0.5);
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.15s, box-shadow 0.3s;
}

.helper-block:active {
    transform: scale(0.95);
}

.helper-block.drag-hover {
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.5);
    transform: scale(1.05);
}

.helper-block.sparkle {
    animation: sparkle 0.8s ease-in-out infinite;
}

.block.start-glow {
    box-shadow: 0 0 12px rgba(239, 83, 80, 0.6);
    border: 2px solid #ef5350;
}

.helper-block.wrong-highlight {
    background: rgba(141, 110, 99, 0.5) !important;
    transition: background 0.5s;
}

.helper-block.correct-highlight {
    background: rgba(102, 187, 106, 0.5) !important;
    border-color: #66bb6a !important;
    box-shadow: 0 0 10px rgba(102, 187, 106, 0.4);
}

#floating-flag.pulse {
    animation: flag-pulse 0.6s ease-in-out !important;
}

@keyframes flag-pulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.3); }
}

@media (max-width: 480px) {
    .helper-block {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }
}

#ground-line {
    position: absolute;
    bottom: 76px;
    left: 0;
    right: 0;
    height: 3px;
    background: #8d6e63;
    z-index: 15;
}

#break-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

#break-message {
    background: white;
    border-radius: 20px;
    padding: 30px 40px;
    text-align: center;
    font-size: 20px;
    color: #333;
    max-width: 360px;
}

@media (max-width: 480px) {
    .block {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    .addend-card {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    #equation-bar {
        padding: 8px 16px;
        gap: 8px;
    }

    #speech-bubble {
        font-size: 14px;
        max-width: 220px;
    }
}
