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

:root {
    /* Background */
    --bg-mint: #7dd4c4;
    --dot-color: rgba(255, 255, 255, 0.6);

    /* Display */
    --display-text: #5fffcc;
    --display-glow: #3affaa;
}

body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', monospace;
    overflow: hidden;
}

/* Polka dot background */
.background {
    position: fixed;
    inset: 0;
    background-color: var(--bg-mint);
    background-image: radial-gradient(var(--dot-color) 3px, transparent 3px);
    background-size: 24px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Calculator wrapper - positions image and overlay */
.calculator-wrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
}

/* The calculator image */
.calculator-image {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 25px 50px rgba(40, 100, 120, 0.5));
}

/* Overlay container - sits exactly on top of image */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* Display overlay - positioned over the image's LCD screen */
.display-overlay {
    position: absolute;
    /* Adjust these values to match the LCD position in your image */
    top: 10%;
    left: 12%;
    right: 12%;
    height: 11%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 4%;
    /* Debug: uncomment to see position */
    /* background: rgba(255, 0, 0, 0.3); */
}

.display-overlay span {
    color: var(--display-text);
    font-size: clamp(1.5rem, 6vw, 2.8rem);
    font-weight: 700;
    letter-spacing: 3px;
    text-shadow:
        0 0 10px var(--display-glow),
        0 0 20px var(--display-glow),
        0 0 30px rgba(58, 255, 170, 0.3);
    font-family: 'Orbitron', monospace;
}

/* Buttons overlay grid - positioned over the button area */
.buttons-overlay {
    position: absolute;
    /* Adjust these values to match button positions in your image */
    top: 32%;
    left: 10%;
    right: 10%;
    bottom: 4%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2.5%;
    /* Debug: uncomment to see position */
    /* background: rgba(0, 255, 0, 0.2); */
}

/* Invisible buttons with visible text */
.btn {
    background: transparent;
    border: none;
    font-family: 'Orbitron', monospace;
    font-size: clamp(0.9rem, 3.5vw, 1.4rem);
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    text-shadow:
        0 2px 3px rgba(0, 0, 0, 0.4),
        0 0 1px rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    /* Debug: uncomment to see button positions */
    /* background: rgba(255, 0, 0, 0.3); */
    /* border: 1px solid red; */
}

/* Number buttons - darker text for cream buttons */
.btn[data-value="0"],
.btn[data-value="1"],
.btn[data-value="2"],
.btn[data-value="3"],
.btn[data-value="4"],
.btn[data-value="5"],
.btn[data-value="6"],
.btn[data-value="7"],
.btn[data-value="8"],
.btn[data-value="9"],
.btn[data-value="."] {
    color: #555;
    text-shadow:
        0 1px 2px rgba(255, 255, 255, 0.5),
        0 -1px 1px rgba(0, 0, 0, 0.1);
}

/* Plus button spans 2 rows */
.btn-plus {
    grid-row: span 2;
    border-radius: 35%;
}

/* Hover effect - subtle highlight */
.btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn:active {
    background: rgba(0, 0, 0, 0.15);
    transform: scale(0.92);
}

/* Responsive adjustments */
@media (max-width: 360px) {
    .buttons-overlay {
        gap: 2%;
    }

    .btn {
        font-size: 0.85rem;
    }
}

@media (min-width: 500px) {
    .calculator-wrapper {
        max-width: 450px;
    }

    .btn {
        font-size: 1.5rem;
    }

    .display-overlay span {
        font-size: 3rem;
    }
}


/* ═══════════════════════════════════════════════════════════════
   EASTER EGG ANIMATIONS
   ═══════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────
   1729: RAMANUJAN'S TAXI
   ───────────────────────────────────────────────────────────── */
.easter-egg-taxi {
    position: fixed;
    top: 50%;
    left: -300px;
    transform: translateY(-50%);
    z-index: 1000;
    pointer-events: none;
    transition: none;
}

.easter-egg-taxi.animate {
    animation: taxi-drive 3.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.easter-egg-taxi.fade-out {
    opacity: 0;
    transition: opacity 0.5s ease;
}

@keyframes taxi-drive {
    0% {
        left: -300px;
    }
    15% {
        left: calc(50% - 150px);
    }
    70% {
        left: calc(50% - 150px);
    }
    100% {
        left: calc(100% + 50px);
    }
}

.taxi-wrapper {
    display: flex;
    align-items: center;
    gap: 20px;
}

.taxi-emoji {
    font-size: 4rem;
    animation: taxi-bounce 0.4s ease-in-out infinite;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

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

.taxi-trail {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.85);
    padding: 12px 20px;
    border-radius: 12px;
    border: 2px solid #ffd700;
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.3);
    opacity: 0;
    transform: translateX(-20px);
    animation: trail-appear 0.5s ease 0.4s forwards;
}

@keyframes trail-appear {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.trail-text {
    font-family: 'Orbitron', monospace;
    font-size: 1.4rem;
    color: #ffd700;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.trail-subtitle {
    font-family: 'Orbitron', monospace;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    letter-spacing: 1px;
}


/* ─────────────────────────────────────────────────────────────
   6174: KAPREKAR'S SPIRAL
   ───────────────────────────────────────────────────────────── */
.spiral-active {
    display: inline-flex !important;
    gap: 2px;
}

.spiral-digit {
    display: inline-block;
    animation: spiral-in 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    animation-delay: calc(var(--i) * 0.1s);
}

@keyframes spiral-in {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 1;
    }
    30% {
        transform: rotate(180deg) scale(0.5);
        opacity: 0.5;
    }
    60% {
        transform: rotate(360deg) scale(0.3);
        opacity: 0.3;
    }
    80% {
        transform: rotate(540deg) scale(0.8);
        opacity: 0.8;
    }
    100% {
        transform: rotate(720deg) scale(1);
        opacity: 1;
    }
}

.calculator-wrapper.kaprekar-glow {
    filter: drop-shadow(0 25px 50px rgba(40, 100, 120, 0.5))
            drop-shadow(0 0 30px rgba(138, 43, 226, 0.4));
}

.easter-egg-message {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-family: 'Orbitron', monospace;
    font-size: 0.8rem;
    letter-spacing: 1px;
    white-space: nowrap;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.easter-egg-message.kaprekar {
    border: 1px solid rgba(138, 43, 226, 0.5);
    box-shadow: 0 0 20px rgba(138, 43, 226, 0.3);
}

.easter-egg-message.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}


/* ─────────────────────────────────────────────────────────────
   0.7734: LCD HELLO MORPH
   ───────────────────────────────────────────────────────────── */
.display-overlay span.morphing {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.hello-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.hello-overlay.show {
    opacity: 1;
}

.lcd-hello {
    display: flex;
    gap: 4px;
}

.lcd-char {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.8rem, 7vw, 3.2rem);
    font-weight: 700;
    color: var(--display-text);
    text-shadow:
        0 0 10px var(--display-glow),
        0 0 20px var(--display-glow),
        0 0 30px rgba(58, 255, 170, 0.5);
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.lcd-char.wave {
    animation: lcd-wave 0.6s ease;
}

@keyframes lcd-wave {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-8px) rotate(-5deg); }
    75% { transform: translateY(4px) rotate(3deg); }
}


/* ─────────────────────────────────────────────────────────────
   5318008: FLIP & BLUR
   ───────────────────────────────────────────────────────────── */
.calculator-wrapper.flipping {
    animation: flip-rotate 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes flip-rotate {
    0% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(90deg) scale(0.9);
    }
    100% {
        transform: rotate(180deg) scale(1);
    }
}

.display-overlay span.blurred {
    filter: blur(8px);
    transition: filter 0.3s ease;
}

.flip-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 30px;
    opacity: 0;
    transform: rotate(180deg);
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.flip-overlay.show {
    opacity: 1;
}

.flip-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transform: rotate(180deg); /* Counter-rotate so text is readable */
}

.flip-emoji {
    font-size: 4rem;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.flip-emoji.shake {
    animation: emoji-shake 0.5s ease;
}

@keyframes emoji-shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-15deg); }
    75% { transform: rotate(15deg); }
}

.flip-text {
    font-family: 'Orbitron', monospace;
    font-size: 1.2rem;
    color: #fff;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}


/* ─────────────────────────────────────────────────────────────
   REDUCED MOTION SUPPORT
   ───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .easter-egg-taxi,
    .spiral-digit,
    .lcd-char,
    .calculator-wrapper.flipping,
    .taxi-emoji,
    .flip-emoji {
        animation: none !important;
    }
    
    .easter-egg-taxi {
        display: none;
    }
}