:root {
    --background-light: #f3f4f6;
    --text-light: #1a1a1a;
    --background-dark: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --text-dark: #e4e4e7;
}

html,
body {
    min-height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    user-select: none;
}

body {
    font-family: "Inter", sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    min-height: 100dvh;
    transition:
        background-color 0.3s,
        color 0.3s;
}

body.light-mode {
    background-color: var(--background-light);
    color: var(--text-light);
}

body.dark-mode {
    background: var(--background-dark);
    color: var(--text-dark);
}

.content-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    padding:
        max(1rem, env(safe-area-inset-top))
        max(0.75rem, env(safe-area-inset-right))
        max(1rem, env(safe-area-inset-bottom))
        max(0.75rem, env(safe-area-inset-left));
    box-sizing: border-box;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Emoji row */

.emoji-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    font-size: clamp(2.5rem, 8vw, 5rem);
}

/* inline-flex keeps markup whitespace from padding the emoji */
.apple-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
    transition:
        transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.2s ease;
}

.geese {
    display: flex;
    align-items: center;
}

.goose-link {
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 1.15em;
    height: 1.15em;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition:
        filter 0.15s ease,
        transform 0.25s ease;
    touch-action: manipulation;
}

.goose-emoji {
    display: inline-block;
    transform-origin: center bottom;
    animation: bob 3.2s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * -0.5s);
}

.goose-name {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 50%;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
    opacity: 0;
    transform: translate(-50%, -0.35rem);
    pointer-events: none;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
}

.goose-link:hover {
    filter: brightness(1.15);
    transform: translateY(-2px);
}

.goose-link:focus-visible,
.apple-button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 4px;
    border-radius: 12px;
}

.goose-link:hover .goose-name,
.goose-link:focus-visible .goose-name {
    opacity: 0.75;
    transform: translate(-50%, 0);
}

.goose-link:hover .goose-emoji.wiggle-animation {
    animation: none;
}

/* Neighbours lean toward whichever goose you are pointing at */
.goose-link:has(+ .goose-link:hover) {
    transform: rotate(7deg);
}

.goose-link:hover + .goose-link {
    transform: rotate(-7deg);
}

/* Feeding time: the flock turns around and crowds the dropped apple */
.emoji-row.feeding .apple-button {
    transform: translateY(0.3em) rotate(-8deg);
    transition-timing-function: ease-in;
}

.apple-button.eaten {
    transform: translateY(0.3em) scale(0.1) rotate(-8deg);
    opacity: 0;
    transition-duration: 0.2s;
}

/* Staggered so the flock turns in a ripple instead of vanishing edge-on together */
.emoji-row.feeding .goose-link {
    transform: translateX(calc(-1em - var(--i, 0) * 0.35em)) scaleX(-1);
    transition-duration: 0.4s;
    transition-delay: calc(var(--i, 0) * 0.06s);
}

.emoji-row.feeding .goose-name {
    opacity: 0;
}

.goose-link.pecking .goose-emoji {
    animation: peck 0.26s ease-in-out;
}

/* Game nav */

.game-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    padding: 0 1rem;
    opacity: 0;
    transform: translateY(-10px);
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 0.6s ease,
        transform 0.6s ease;
}

.game-nav.visible {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
}

.game-nav-link {
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    letter-spacing: 0.03em;
    transition:
        background-color 0.2s,
        color 0.2s,
        transform 0.15s ease;
}

.game-nav-link:hover {
    transform: scale(1.05);
}

body.light-mode .game-nav-link {
    background-color: rgba(0, 0, 0, 0.07);
    color: var(--text-light);
}

body.light-mode .game-nav-link:hover {
    background-color: rgba(0, 0, 0, 0.13);
}

body.dark-mode .game-nav-link {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-dark);
}

body.dark-mode .game-nav-link:hover {
    background-color: rgba(255, 255, 255, 0.18);
}

@media (max-width: 420px) {
    .content-container {
        gap: 1rem;
        justify-content: center;
    }

    .emoji-row {
        width: 100%;
        gap: 0.1em;
        font-size: clamp(2.3rem, 13vw, 3.4rem);
    }

    .game-nav {
        gap: 0.35rem;
        padding: 0 0.5rem;
    }

    .game-nav-link {
        font-size: 0.75rem;
        min-height: 44px;
        padding: 0 0.75rem;
        display: inline-flex;
        align-items: center;
    }

    .goose-name {
        top: calc(100% + 0.2rem);
        opacity: 0.7;
        transform: translate(-50%, 0);
    }
}

@media (max-height: 480px) and (orientation: landscape) {
    .content-container {
        flex-direction: row;
        gap: 1rem;
    }

    .game-nav {
        max-width: 14rem;
    }

    .emoji-row {
        font-size: clamp(2rem, 9vh, 3rem);
    }
}

/* Animations */

.fade-in {
    opacity: 0;
    animation: fadeInBounce 1s forwards;
}

.fade-in.delay-1 {
    animation-delay: 0.5s;
}

.fade-in.delay-2 {
    animation-delay: 1s;
}

@keyframes fadeInBounce {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    60% {
        opacity: 1;
        transform: translateY(-10px) scale(1.05);
    }
    80% {
        transform: translateY(5px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes bob {
    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }
    25% {
        transform: translateY(-0.05em) rotate(-3deg);
    }
    75% {
        transform: translateY(-0.03em) rotate(3deg);
    }
}

@keyframes peck {
    0%,
    100% {
        transform: rotate(0deg) translateY(0);
    }
    50% {
        transform: rotate(24deg) translateY(0.06em);
    }
}

.goose-emoji.wiggle-animation {
    transform-origin: center center;
    animation: wiggle 0.6s ease-in-out 1;
}

@keyframes wiggle {
    0%,
    100% {
        transform: rotate(0deg) scale(1) translateY(0px);
    }
    10%,
    30%,
    50%,
    70%,
    90% {
        transform: rotate(-8deg) scale(1.05) translateY(-3px);
    }
    20%,
    40%,
    60%,
    80% {
        transform: rotate(8deg) scale(1.05) translateY(-2px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .fade-in {
        opacity: 1;
        animation: none;
    }

    .goose-emoji,
    .goose-emoji.wiggle-animation,
    .goose-link.pecking .goose-emoji {
        animation: none;
    }

    .emoji-row.feeding .apple-button,
    .emoji-row.feeding .goose-link,
    .apple-button.eaten {
        transform: none;
    }
}
