:root {
    color-scheme: light;
}

* {
    user-select: none;
    touch-action: manipulation;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 28%),
        radial-gradient(circle at top right, rgba(255, 210, 235, 0.9), transparent 22%),
        linear-gradient(180deg, #ffe6f2 0%, #ffd7eb 38%, #fff8fb 100%);
    color: #6d214b;
}

body.modal-open {
    overflow: hidden;
}

.game-app {
    width: 100%;
}

.game-top-bar {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 244, 250, 0.98));
}

.pixel-border {
    border: 4px solid #ff8cc6;
    box-shadow:
        0 0 0 4px rgba(255, 255, 255, 0.75) inset,
        0 10px 0 rgba(229, 73, 152, 0.16),
        0 22px 42px rgba(194, 53, 120, 0.18);
}

.panel-shell {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 244, 250, 0.98));
}

.pixel-button {
    transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
    box-shadow: 0 8px 0 rgba(177, 49, 106, 0.32), 0 18px 36px rgba(208, 74, 138, 0.16);
}

.pixel-button:hover {
    transform: translateY(-2px) scale(1.01);
    filter: saturate(1.05);
}

.pixel-button:active {
    transform: translateY(5px) scale(0.99);
    box-shadow: 0 3px 0 rgba(177, 49, 106, 0.25), 0 10px 22px rgba(208, 74, 138, 0.14);
}

.pixel-art {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.unicorn-pen {
    background-image:
        linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02)),
        url('./img/unicorn-enclosure.png');
    background-size: cover;
    background-position: center;
}

.grain-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px);
    background-size: 10px 10px;
    opacity: 0.4;
    mix-blend-mode: soft-light;
    pointer-events: none;
}

.modal-hidden {
    display: none !important;
}

.iphone-only {
    display: none !important;
}

.floating-badge {
    position: absolute;
    pointer-events: none;
    font-weight: 800;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.75);
    animation: floatUp 1s ease-out forwards;
}

.floating-badge-poop {
    animation-name: floatUpPoop;
}

.achievement-progress-bar {
    width: 0%;
    transition: width 260ms ease;
}

.tier-five-unicorn {
    filter: drop-shadow(0 0 8px rgba(255, 197, 82, 0.85));
    animation: tierFivePulse 2.2s ease-in-out infinite;
}

@keyframes tierFivePulse {
    0%,
    100% {
        transform: translateZ(0) scale(1);
    }
    50% {
        transform: translateZ(0) scale(1.05);
    }
}

.gardener-actor {
    filter: drop-shadow(0 4px 4px rgba(60, 130, 60, 0.32));
}

.event-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
    pointer-events: none;
}

body.event-rainbow .unicorn-pen {
    filter: saturate(1.25) hue-rotate(12deg);
}

body.event-moon .unicorn-pen {
    filter: saturate(1.1) hue-rotate(258deg) brightness(1.04);
}

body.event-starfall .unicorn-pen {
    filter: saturate(1.38) brightness(1.08);
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(0.9);
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    100% {
        transform: translateY(-42px) scale(1.08);
        opacity: 0;
    }
}

@keyframes floatUpPoop {
    0% {
        transform: translateY(0) scale(0.92);
        opacity: 0;
    }
    12% {
        opacity: 1;
    }
    100% {
        transform: translateY(-72px) scale(1.06);
        opacity: 0;
    }
}

@media (max-width: 640px) {
    .mobile-stack {
        grid-template-columns: 1fr;
    }

    .mobile-hide {
        display: none;
    }
}

@media (max-width: 900px) {
    .desktop-current-balance {
        display: none !important;
    }

    .profile-desktop-button {
        display: none !important;
    }
}

@media screen and (max-width: 430px) and (min-width: 380px) {
    /* Header-Reihe für die Buttons */
    .mobile-header-actions {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 0.5rem !important; /* Verhindert große Spalten, hält Buttons nah beieinander */
    }

    /* Text-Buttons: Shop UND Balance werden jetzt beide angezeigt und teilen sich den Platz */
    .mobile-header-actions #openShopButton,
    .mobile-header-actions #openBalanceButton.iphone-only {
        display: inline-flex !important; /* Macht den Balance Button auf dem iPhone SICHTBAR */
        align-items: center !important;
        justify-content: center !important;
        flex: 1 1 0% !important; /* Teilt den Platz exakt 50/50 zwischen Shop und Balance auf */
        text-align: center !important;
        padding: 0.5rem 0.25rem !important; /* Kompaktes Padding gegen Textumbrüche */
        font-size: 0.65rem !important;
        letter-spacing: 0.08em !important; /* Leicht verringert, damit "Current Balance" sicher reinpasst */
        white-space: nowrap !important;
    }

    /* Profil-Button bleibt kompakt und quadratisch am Ende der Reihe */
    #openProfileButtonMobile.iphone-only {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin-left: 0 !important; /* Entfernt alten Abstandshalter */
        flex-shrink: 0 !important; /* Verhindert Stauchung */
        padding: 0.5rem !important;
        width: 2.25rem !important; /* Quadratische Box passend zur Höhe der anderen Buttons */
        height: 2.25rem !important;
    }

    .mobile-header-actions #openProfileButtonMobile.iphone-only img {
        width: 1.1rem !important;
        height: 1.1rem !important;
    }

    /* Profil-Label verstecken */
    .profile-button-label {
        display: none !important;
    }

    /* Mobile Klick-Leiste unten (Dock) */
    .mobile-click-dock.iphone-only {
        display: block !important;
        position: fixed !important;
        left: 0.75rem !important;
        right: 0.75rem !important;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 0.55rem) !important;
        z-index: 45 !important;
        border: 3px solid #ff9fcd !important;
        border-radius: 1rem !important;
        background: rgba(255, 243, 249, 0.95) !important;
        box-shadow: 0 10px 28px rgba(175, 60, 112, 0.2) !important;
        padding: 0.6rem !important;
        backdrop-filter: blur(3px) !important;
    }

    /* App-Container Anpassung für das untere Dock */
    #gameApp {
        padding: 0.55rem 0.55rem calc(8.4rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    #gameApp > div {
        gap: 0.5rem !important;
    }

    /* Top-Bar Design-Kompression */
    .game-top-bar {
        padding: 0.55rem 0.6rem !important;
        border-radius: 1.25rem !important;
    }

    /* Main Grid & Spielfeld-Anpassungen */
    main {
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
    }

    #playfieldShell {
        height: calc(100vh - 20rem) !important;
        min-height: 12.5rem !important;
        justify-content: center !important;
        padding: 0.4rem !important;
    }

    #unicornPen {
        width: 100% !important;
        max-height: 100% !important;
        background-size: contain !important;
        background-repeat: no-repeat !important;
        background-position: center !important;
    }

    /* Desktop-Elemente ausblenden */
    .desktop-click-wrap {
        display: none !important;
    }
}

@media (min-width: 820px) and (max-width: 1024px) and (orientation: portrait) {
    #gameApp {
        padding: 0.9rem 0.9rem calc(8.4rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    .mobile-header-actions {
        flex-wrap: nowrap !important;
        gap: 0.55rem !important;
        align-items: center;
    }

    #openShopButton,
    #openBalanceButton.iphone-only {
        padding: 0.55rem 0.85rem !important;
        font-size: 0.75rem !important;
        line-height: 1 !important;
        letter-spacing: 0.18em !important;
        white-space: nowrap;
    }

    #openProfileButtonMobile.iphone-only {
        padding: 0.55rem !important;
    }

    #openProfileButtonMobile.iphone-only img {
        width: 1.15rem;
        height: 1.15rem;
    }

    #openProfileButtonMobile.iphone-only {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        margin-left: 0;
    }

    #openBalanceButton.iphone-only {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    .mobile-click-dock.iphone-only {
        display: block !important;
        position: fixed;
        left: 0.9rem;
        right: 0.9rem;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
        z-index: 45;
        border: 3px solid #ff9fcd;
        border-radius: 1rem;
        background: rgba(255, 243, 249, 0.95);
        box-shadow: 0 10px 28px rgba(175, 60, 112, 0.2);
        padding: 0.75rem;
        backdrop-filter: blur(3px);
    }

    #playfieldShell {
        height: calc(100dvh - 13.25rem) !important;
        min-height: 32rem !important;
    }

    #unicornPen {
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }
}

@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    main {
        grid-template-columns: minmax(0, 1.75fr) minmax(300px, 0.75fr) !important;
    }

    #playfieldShell {
        height: calc(100dvh - 11.75rem) !important;
        min-height: 28rem !important;
    }

    #unicornPen {
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }
}

@media (min-width: 1600px) and (min-aspect-ratio: 16/9) {
    #unicornPen {
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }
}

@media screen and (min-width: 1024px) {
    .profile-layout-container {
        display: grid;
        grid-template-columns: 320px 1fr;
        gap: 1.5rem;
    }
    .profile-left-column {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
}

@media screen and (max-width: 1023px) {
    .profile-layout-container {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
    }
    .account-settings-panel {
        order: 99;
    }
}

.portrait-option-btn {
    transition: transform 0.1s ease, border-color 0.2s ease;
}

.portrait-option-btn:hover {
    transform: scale(1.03);
    border-color: #ff68ba;
}
