:root {
    --gate-bg: #123c2a;
    --gate-card: #efe3c1;
    --gate-card-dark: #d7c69f;
    --gate-ink: #584d39;
    --gate-gold: #b99a61;
}

html,
body {
    min-height: 100%;
    background: radial-gradient(circle at 50% 12%, rgba(52, 105, 72, .6), transparent 310px), var(--gate-bg);
}

.gate-page {
    width: min(100%, 390px);
    min-height: 100svh;
    margin: 0 auto;
    /* overflow: hidden; */
    background: radial-gradient(circle at 50% 12%, rgba(52, 105, 72, .6), transparent 310px), var(--gate-bg);
    /* box-shadow: 0 0 60px rgba(0, 0, 0, .55); */
}

.gate-screen {
    min-height: 100svh;
    position: relative;
    padding: 18px 24px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.fish-stage {
    width: 100%;
    height: 382px;
    position: relative;
    margin: -6px 0 -16px;
    z-index: 3;
    pointer-events: none;
}

.fish-frame {
    position: absolute;
    left: 50%;
    top: 0;
    width: min(118%, 430px);
    height: auto;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity .08s linear, transform .25s ease;
    filter: drop-shadow(0 22px 24px rgba(0,0,0,.24));
}

.fish-frame.is-active {
    opacity: 1;
}

.fish-stage.is-chewing .fish-frame {
    animation: fish-bob .24s infinite alternate ease-in-out;
}

@keyframes fish-bob {
    from { transform: translateX(-50%) translateY(0) rotate(-.4deg) scale(1); }
    to { transform: translateX(-50%) translateY(5px) rotate(.5deg) scale(1.015); }
}

.gate-card {
    width: 100%;
    /* max-width: 314px; */
    position: relative;
    z-index: 2;
    padding: 24px 28px 29px;
    border-radius: 8px;
    background: var(--gate-card);
    color: var(--gate-ink);
    box-shadow: 0 20px 35px rgba(0,0,0,.16), inset 0 0 35px rgba(255,255,255,.25);
    transform-origin: 50% 12%;
    will-change: transform, opacity, filter;
}

.gate-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: #EEDAB9;
    /* background: url("assets/parchment.jpg") center/cover no-repeat; */
    opacity: .42;
    mix-blend-mode: multiply;
    pointer-events: none;
}

.gate-card > * {
    position: relative;
    z-index: 1;
}

.gate-title {
    margin: 0 0 22px;
    background: #514632;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-family: "Harry Potter Russian Version of Gfdtk", Georgia, serif;
    font-size: 38px;
    line-height: 1.2;
    font-style: normal;
    font-weight: 400;
    text-align: center;
    letter-spacing: .03em;
}

.gate-form {
    display: grid;
    gap: 16px;
}

.gate-field {
    display: block;
    font-size: 16px;
    line-height: 1.2;
    color: #5c513e;
    font-style: normal;
    font-weight: 700;
}

.gate-field span {
    display: block;
    margin-bottom: 7px;
}

.gate-field input {
    width: 100%;
    height: 38px;
    border: 1px solid rgba(91, 78, 54, .38);
    border-radius: 5px;
    padding: 0 13px;
    background: rgba(255,255,255,.68);
    color: #453a2a;
    font: 16px/1.2 "Futura PT Light Italic", Arial, sans-serif;
    font-style: italic;
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.12);
}

.gate-field input:focus {
    border-color: #9b7b43;
    box-shadow: 0 0 0 3px rgba(191, 146, 61, .22), inset 0 1px 3px rgba(0,0,0,.12);
}

.gate-button {
    height: 42px;
    border: 0;
    border-radius: 5px;
    margin-top: 0;
    background: #a09173;
    color: #fff;
    font: 700 14px/1 "Futura PT Light Italic", Arial, sans-serif;
    cursor: pointer;
    transition: transform .18s ease, background .18s ease, opacity .18s ease;
}

.gate-button:hover {
    background: #bf923d;
    transform: translateY(-1px);
}

.gate-error {
    min-height: 18px;
    margin: -3px 0 -4px;
    color: #7f1f1f;
    font-size: 12px;
    line-height: 1.25;
    font-style: normal;
    text-align: center;
}

.gate-hint {
    margin: 25px 0 0;
    color: rgba(242, 231, 200, .45);
    font-size: 12px;
    line-height: 1.3;
    text-align: center;
}

.paper-ball {
    position: absolute;
    left: 50%;
    top: 505px;
    width: 48px;
    height: 38px;
    z-index: 4;
    border-radius: 50% 45% 52% 40%;
    background: #efe3c1 url("assets/parchment.jpg") center/cover no-repeat;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 9px 16px rgba(0,0,0,.22), inset 8px 0 8px rgba(96,73,44,.18);
}

.paper-ball::before,
.paper-ball::after {
    content: "";
    position: absolute;
    background: rgba(89,72,46,.32);
    border-radius: 50%;
}

.paper-ball::before {
    width: 21px;
    height: 2px;
    left: 13px;
    top: 16px;
    transform: rotate(24deg);
}

.paper-ball::after {
    width: 17px;
    height: 2px;
    left: 18px;
    top: 23px;
    transform: rotate(-18deg);
}

.magic-note {
    position: absolute;
    left: 34px;
    right: 34px;
    top: 430px;
    z-index: 5;
    padding: 14px 16px;
    border: 1px solid rgba(244, 230, 131, .28);
    border-radius: 8px;
    background: rgba(0, 18, 13, .88);
    color: var(--gold-light);
    font-size: 14px;
    line-height: 1.25;
    text-align: center;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

.gate-screen.is-processing .magic-note {
    animation: note-in .35s ease forwards .9s;
}

@keyframes note-in {
    to { opacity: 1; transform: translateY(0); }
}

.gate-screen.is-processing .gate-card {
    animation: card-crumple 1.05s ease-in forwards;
}

.gate-screen.is-processing .paper-ball {
    animation: paper-fly 1.2s cubic-bezier(.62,-.01,.27,1.02) forwards .4s;
}

@keyframes card-crumple {
    0% { transform: translateY(0) scale(1) rotate(0); opacity: 1; filter: blur(0); }
    38% { transform: translateY(4px) scale(.75, .42) rotate(-4deg); opacity: .95; filter: blur(.1px); border-radius: 28px; }
    70% { transform: translateY(-72px) scale(.19) rotate(22deg); opacity: 0; filter: blur(1px); border-radius: 50%; }
    100% { transform: translateY(-110px) scale(.05) rotate(52deg); opacity: 0; filter: blur(2px); border-radius: 50%; }
}

@keyframes paper-fly {
    0% { opacity: 0; transform: translate(-50%, 0) scale(.7) rotate(0); }
    8% { opacity: 1; }
    62% { opacity: 1; transform: translate(-50%, -285px) scale(.55) rotate(360deg); }
    100% { opacity: 0; transform: translate(-50%, -330px) scale(.2) rotate(520deg); }
}

@media (max-width: 360px) {
    .gate-screen { padding-left: 18px; padding-right: 18px; }
    .fish-stage { height: 440px; }
    .gate-title { font-size: 29px; }
    .gate-card { padding-left: 24px; padding-right: 24px; }
}

.gate-form.shake {
    animation: gate-shake .28s ease;
}

@keyframes gate-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* v8 fixes: fish is placed above the form, not over it */
.fish-stage {
    height: 420px;
    margin: 0 0 18px;
    z-index: 1;
}

.fish-frame {
    top: 0;
    width: min(108%, 400px);
    transition: none;
    backface-visibility: hidden;
    transform: translate3d(-50%, 0, 0);
}

.fish-frame.is-active {
    opacity: 1;
    visibility: visible;
}

.fish-frame:not(.is-active) {
    opacity: 0;
    visibility: hidden;
}

.fish-stage.is-chewing {
    animation: fish-stage-bob .22s infinite alternate ease-in-out;
}

.fish-stage.is-chewing .fish-frame {
    animation: none;
}

@keyframes fish-stage-bob {
    from { transform: translateY(0) rotate(-.25deg) scale(1); }
    to { transform: translateY(4px) rotate(.25deg) scale(1.01); }
}

.gate-card {
    z-index: 3;
}

.paper-ball {
    top: 610px;
}

@keyframes paper-fly {
    0% { opacity: 0; transform: translate(-50%, 0) scale(.7) rotate(0); }
    8% { opacity: 1; }
    62% { opacity: 1; transform: translate(-50%, -345px) scale(.55) rotate(360deg); }
    100% { opacity: 0; transform: translate(-50%, -390px) scale(.2) rotate(520deg); }
}

/* Green magical puff for guests outside the list */
.stink-cloud {
    position: absolute;
    left: 50%;
    top: 374px;
    z-index: 8;
    width: 255px;
    min-height: 74px;
    padding: 17px 20px 15px;
    border-radius: 999px;
    background:
        radial-gradient(circle at 18% 42%, rgba(121, 198, 88, .98) 0 28px, transparent 29px),
        radial-gradient(circle at 39% 27%, rgba(77, 160, 70, .98) 0 34px, transparent 35px),
        radial-gradient(circle at 63% 39%, rgba(112, 202, 94, .97) 0 35px, transparent 36px),
        radial-gradient(circle at 82% 52%, rgba(59, 132, 62, .96) 0 29px, transparent 30px),
        rgba(78, 165, 71, .95);
    color: #f5efc5;
    font: 700 20px/1.2 "Futura PT Light Italic", Arial, sans-serif;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0,0,0,.45);
    box-shadow: 0 12px 28px rgba(10, 42, 18, .45), inset 0 0 20px rgba(244, 230, 131, .08);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 15px) scale(.45) rotate(-4deg);
    filter: blur(.2px);
}

.stink-cloud::before,
.stink-cloud::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: rgba(105, 194, 83, .82);
    filter: none;
}

.stink-cloud::before {
    width: 42px;
    height: 28px;
    left: 12px;
    bottom: -8px;
    transform: rotate(-18deg);
}

.stink-cloud::after {
    width: 34px;
    height: 22px;
    right: 20px;
    top: -8px;
    background: rgba(154, 225, 99, .65);
}

.gate-screen.is-denied .stink-cloud {
    animation: stink-puff 2.15s ease-out both;
}

@keyframes stink-puff {
    0% {
        opacity: 0;
        transform: translate(-50%, 18px) scale(.36) rotate(-7deg);
        filter: blur(0);
    }
    14% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1) rotate(1deg);
        filter: blur(0);
    }
    58% {
        opacity: .9;
        transform: translate(-50%, -10px) scale(1.06) rotate(-1deg);
        filter: blur(.4px);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -34px) scale(1.45) rotate(2deg);
        filter: blur(7px);
    }
}

@media (max-width: 360px) {
    .fish-stage { height: 318px; margin-bottom: 14px; }
    .fish-frame { width: min(110%, 382px); }
    .stink-cloud { top: 350px; width: 232px; }
    .paper-ball { top: 580px; }
}


/* v9: larger and longer magical puff */
.stink-cloud {
    top: 360px;
    width: 318px;
    min-height: 92px;
    padding: 23px 26px 20px;
    color: #fff8d8;
    font: 700 16px/1.24 "Trebuchet MS", Arial, sans-serif;
    font-style: normal;
    letter-spacing: .01em;
    text-align: center;
    text-shadow: 0 1px 1px rgba(0,0,0,.28);
    background:
        radial-gradient(circle at 14% 45%, rgba(121, 198, 88, .98) 0 36px, transparent 37px),
        radial-gradient(circle at 34% 25%, rgba(77, 160, 70, .98) 0 43px, transparent 44px),
        radial-gradient(circle at 61% 38%, rgba(112, 202, 94, .97) 0 45px, transparent 46px),
        radial-gradient(circle at 86% 54%, rgba(59, 132, 62, .96) 0 39px, transparent 40px),
        rgba(78, 165, 71, .97);
    box-shadow: 0 12px 28px rgba(10, 42, 18, .45), inset 0 0 20px rgba(244, 230, 131, .08);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 15px) scale(.45) rotate(-4deg);
    filter: none;
}

.stink-cloud::before {
    width: 58px;
    height: 35px;
    left: 16px;
    bottom: -12px;
}

.stink-cloud::after {
    width: 48px;
    height: 30px;
    right: 25px;
    top: -12px;
}

.gate-screen.is-denied .stink-cloud {
    animation: stink-puff-long 3.8s ease-out both;
}

@keyframes stink-puff-long {
    0% {
        opacity: 0;
        transform: translate(-50%, 22px) scale(.34) rotate(-7deg);
        filter: none;
    }
    12% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1) rotate(1deg);
        filter: none;
    }
    62% {
        opacity: .96;
        transform: translate(-50%, -7px) scale(1.04) rotate(-1deg);
        filter: none;
    }
    78% {
        opacity: .72;
        transform: translate(-50%, -14px) scale(1.14) rotate(1deg);
        filter: none;
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -46px) scale(1.55) rotate(2deg);
        filter: none;
    }
}

/* v9: fish spits the invitation before redirect */
.spit-invitation {
    position: absolute;
    left: 50%;
    top: 205px;
    z-index: 7;
    width: 178px;
    height: 112px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 0) scale(.12) rotate(-11deg);
    transform-origin: 50% 45%;
    filter: drop-shadow(0 18px 18px rgba(0,0,0,.25));
}

.spit-paper {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    border-radius: 5px;
    background: #efe3c1 url("assets/parchment.jpg") center/cover no-repeat;
    box-shadow: inset 0 0 22px rgba(77, 53, 26, .18);
    color: #6f5a31;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.spit-paper::before {
    content: "";
    position: absolute;
    inset: 12px;
    border: 1px solid rgba(111, 90, 49, .38);
    border-radius: 3px;
}

.spit-paper span,
.spit-paper strong {
    position: relative;
    z-index: 1;
    font-family: "Harry Potter Russian Version of Gfdtk", Georgia, serif;
    font-weight: 400;
    font-style: normal;
    background: linear-gradient(135deg, #856220 0%, #565020 27.5%, #98783b 50%, #724b25 75%, #36341b 100% 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.spit-paper span {
    font-size: 24px;
    line-height: .9;
}

.spit-paper strong {
    font-size: 22px;
    line-height: 1;
}

.gate-screen.is-spitting .spit-invitation {
    animation: spit-page 1.25s cubic-bezier(.16, .9, .28, 1.05) forwards;
}

@keyframes spit-page {
    0% {
        opacity: 0;
        transform: translate(-50%, 0) scale(.1) rotate(-14deg);
        filter: blur(2px) drop-shadow(0 10px 9px rgba(0,0,0,.18));
    }
    12% {
        opacity: 1;
        transform: translate(-50%, 22px) scale(.34) rotate(8deg);
        filter: blur(.2px) drop-shadow(0 12px 12px rgba(0,0,0,.22));
    }
    62% {
        opacity: 1;
        transform: translate(-50%, 255px) scale(1.05) rotate(-3deg);
        filter: blur(0) drop-shadow(0 20px 18px rgba(0,0,0,.26));
    }
    100% {
        opacity: 1;
        transform: translate(-50%, 330px) scale(1.18) rotate(0deg);
        filter: blur(0) drop-shadow(0 24px 22px rgba(0,0,0,.28));
    }
}

@media (max-width: 360px) {
    .stink-cloud {
        top: 336px;
        width: 282px;
        min-height: 86px;
        font-size: 15px;
        line-height: 1.22;
        padding: 21px 22px 18px;
    }
    .spit-invitation {
        top: 190px;
        width: 162px;
        height: 104px;
    }
}


/* Easter egg for Сергей Ваулин: access only on the 5th attempt */
.meme-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, .88);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.meme-overlay__image {
    display: block;
    max-width: min(92vw, 720px);
    max-height: 92vh;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 24px 45px rgba(0, 0, 0, .42));
    transform-origin: 50% 50%;
}

.meme-overlay.is-active {
    visibility: visible;
    opacity: 1;
    animation: meme-overlay-fade 3.6s ease-in-out both;
}

.meme-overlay.is-active .meme-overlay__image {
    animation: meme-overlay-image 3.6s ease-in-out both;
}

@keyframes meme-overlay-fade {
    0% { opacity: 0; }
    8% { opacity: 1; }
    85% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes meme-overlay-image {
    0% {
        transform: scale(.55) scaleX(.7) scaleY(1.28) rotate(-7deg);
    }
    10% {
        transform: scale(1.02) scaleX(1.18) scaleY(.82) rotate(6deg) translate(0, -6px);
    }
    20% {
        transform: scale(1.08) scaleX(.84) scaleY(1.18) rotate(-5deg) translate(-10px, 6px);
    }
    30% {
        transform: scale(1) scaleX(1.2) scaleY(.8) rotate(4deg) translate(10px, -2px);
    }
    40% {
        transform: scale(1.06) scaleX(.88) scaleY(1.22) rotate(-4deg) translate(-12px, 3px);
    }
    52% {
        transform: scale(1.03) scaleX(1.14) scaleY(.86) rotate(3deg) translate(10px, -4px);
    }
    64% {
        transform: scale(1.04) scaleX(.9) scaleY(1.16) rotate(-3deg) translate(-8px, 5px);
    }
    76% {
        transform: scale(1.02) scaleX(1.08) scaleY(.92) rotate(2deg) translate(6px, -3px);
    }
    88% {
        transform: scale(1) scaleX(.97) scaleY(1.03) rotate(-1deg);
    }
    100% {
        transform: scale(.96) scaleX(1) scaleY(1) rotate(0deg);
    }
}

/* Desktop layout upgrade */
@media (min-width: 900px) {
    .gate-page {
        width: min(100% - 56px, 920px);
        min-height: auto;
        margin: 34px auto;
        border-radius: 28px;
        overflow: hidden;
        /* border: 1px solid rgba(244, 230, 131, .12);
        box-shadow: 0 30px 95px rgba(0, 0, 0, .44); */
    }

    .gate-screen {
        min-height: 760px;
        padding: 44px 70px 56px;
        justify-content: flex-start;
    }

    .fish-stage {
        width: min(100%, 560px);
        height: 500px;
        margin: 0 auto 18px;
    }

    .fish-frame {
        width: min(112%, 540px);
    }

    .gate-card {
        width: min(100%, 560px);
        padding: 36px 44px 40px;
        border-radius: 16px;
        box-shadow: 0 28px 80px rgba(0,0,0,.20), inset 0 0 42px rgba(255,255,255,.25);
    }

    .gate-title {
        font-size: 58px;
        margin-bottom: 28px;
    }

    .gate-form {
        gap: 20px;
    }

    .gate-field {
        font-size: 18px;
    }

    .gate-field input {
        height: 50px;
        font-size: 18px;
        padding: 0 16px;
    }

    .gate-button {
        height: 52px;
        font-size: 16px;
        border-radius: 8px;
    }

    .gate-error {
        min-height: 20px;
        font-size: 14px;
    }

    .gate-hint {
        max-width: 560px;
        margin-top: 28px;
        font-size: 14px;
    }

    .magic-note {
        left: 32%;
        right: auto;
        top: 520px;
        width: min(100% - 120px, 390px);
        transform: translate(-50%, 10px);
        font-size: 18px;
        padding: 16px 20px;
    }

    .stink-cloud {
        top: 448px;
        width: 370px;
        min-height: 104px;
        font-size: 18px;
    }

    .spit-invitation {
        top: 265px;
        width: 220px;
        height: 138px;
    }

    .spit-paper span {
        font-size: 30px;
    }

    .spit-paper strong {
        font-size: 28px;
    }

    .paper-ball {
        top: 815px;
    }

    @keyframes paper-fly {
        0% { opacity: 0; transform: translate(-50%, 0) scale(.7) rotate(0); }
        8% { opacity: 1; }
        62% { opacity: 1; transform: translate(-50%, -425px) scale(.55) rotate(360deg); }
        100% { opacity: 0; transform: translate(-50%, -480px) scale(.2) rotate(520deg); }
    }

    @keyframes spit-page {
        0% {
            opacity: 0;
            transform: translate(-50%, 0) scale(.1) rotate(-14deg);
            filter: blur(2px) drop-shadow(0 10px 9px rgba(0,0,0,.18));
        }
        12% {
            opacity: 1;
            transform: translate(-50%, 26px) scale(.34) rotate(8deg);
            filter: blur(.2px) drop-shadow(0 12px 12px rgba(0,0,0,.22));
        }
        62% {
            opacity: 1;
            transform: translate(-50%, 330px) scale(1.05) rotate(-3deg);
            filter: blur(0) drop-shadow(0 20px 18px rgba(0,0,0,.26));
        }
        100% {
            opacity: 1;
            transform: translate(-50%, 420px) scale(1.18) rotate(0deg);
            filter: blur(0) drop-shadow(0 24px 22px rgba(0,0,0,.28));
        }
    }
}

@media (min-width: 1280px) {
    .gate-page {
        width: min(100% - 80px, 1040px);
    }

    .gate-screen {
        padding-left: 96px;
        padding-right: 96px;
    }
}


/* Mobile fix: meme overlay must be above the gate screen and fit narrow phones */
@media (max-width: 899px) {
    .meme-overlay {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 2147483000;
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 16px;
        overflow: hidden;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }

    .meme-overlay__image {
        max-width: 94vw;
        max-height: 84vh;
        max-height: 84dvh;
        width: auto;
        height: auto;
        object-fit: contain;
    }
}
