@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');
@import url(icons.css);
@import url(variables.css);

@-webkit-keyframes fadeIn {
    0% { opacity: 0; }
    to { opacity: 1; }
}
@keyframes fadeIn {
    0% { opacity: 0; }
    to { opacity: 1; }
}

@-webkit-keyframes scaleUp {
    0% {
        -webkit-transform: scale(0.8);
        opacity: 0;
    }
    100% {
        -webkit-transform: scale(1);
        opacity: 1;
    }
}
@keyframes scaleUp {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@-webkit-keyframes discord-spin {
    0% { -webkit-transform: rotate(0deg); }
    50% { -webkit-transform: rotate(360deg); } /* Пауза-подобный скачок (на деле плавное замедление) */
    100% { -webkit-transform: rotate(720deg); } /* Полный второй круг для завершения */
}
@keyframes discord-spin {
    0% { transform: rotate(0deg); }
    50% { transform: rotate(360deg); }
    100% { transform: rotate(720deg); }
}

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

html {
    scroll-behavior: smooth;
}

body {
    /* Keep DOM background static. Animated background lives in #bg-canvas for 60+ FPS. */
    background-color: var(--bg-color);
    -webkit-animation-name: fadeIn;
    animation-name: fadeIn;
    animation-duration: 1s;
    font-family: 'JetBrains Mono', monospace;
    height: 100%;
    overflow: hidden;

    /* IMPORTANT:
       The theme is updated frequently while the avatar video plays.
       Animating background-color on every update forces continuous repaints on mobile
       (seen as flicker + huge jank during pinch-zoom). */
    transition: background-color 0.5s ease;

    opacity: 1;
    color: var(--text-color);

}

/* Once the site is entered, disable the background-color transition to avoid
   permanent repaint/animation while CSS variables are updated by theme-sync.js. */
body.is-entered {
    transition: none;
}

/* During interactive resize: keep blur (user request) */
body.is-resizing .card { }

/* Pinch-zoom: keep blur (user request). We only pause background animation in JS. */
body.is-zooming .card { }


#overlay {
    position: fixed;
    inset: 0;
    /* Static overlay background; animated background is drawn on canvas */
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    cursor: pointer;
    transition: opacity 650ms ease, transform 650ms cubic-bezier(0.2, 0.9, 0.2, 1);
    transform: scale(1);

    /* Mobile tap flash fix (iOS/Android): prevents blue highlight/flash on click */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;

    /* Avoid scrolling/pinch gestures being interpreted as tap highlight */
    touch-action: manipulation;
}

#overlay.is-leaving {
    opacity: 0;
    transform: scale(1.03);
}

#overlay h1 {
    color: var(--text-color);
    font-size: clamp(20px, 10vw, 40px);
    text-align: center;
    opacity: 1;
    letter-spacing: 0.08em;
    text-transform: uppercase;

    /* Prevent iOS text selection / callout flash on tap */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

#overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(800px 500px at 50% 45%, rgb(var(--ui-accent-rgb) / 18%), transparent 60%);
}

#bg-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    opacity: 1;
    transform: none;
}

/* Moved to canvas for perf: CSS fixed blend layers can flicker on mobile during color updates */
body::before { content: none; }


/* Telegram in-app browser: legacy rule (body::before disabled above) */
.tg-webview body::before,
body.tg-webview::before { content: none; }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .card {
        /* Hint compositor to keep the blur layer stable */
        will-change: backdrop-filter;
    }
}

/* Telegram WebView often flashes when viewport height changes (URL bar).
   Disable vh-driven relayout and heavy effects were already reduced above. */
.tg-webview main { min-height: 100vh; }

main {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 20px 16px;
    position: relative;
    z-index: 1;

    /* Avoid animating opacity on the container: some mobile browsers apply backdrop-filter late */
    opacity: 1;
    visibility: hidden;
    transform: translateY(10px);
    transition: transform 1100ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

body.is-entered main {
    visibility: visible;
    transform: translateY(0);
}

/* Hard lock after entrance so resize/reflow can't cause transform/animation flicker */
body.entered-done main {
    transform: none;
}

@keyframes cardInTransform {
    0% {
        transform: translateY(18px) scale(0.985);
    }
    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes itemIn {
    0% {
        transform: translateY(10px);
    }
    100% {
        transform: translateY(0);
    }
}

.card {
    width: min(520px, 92vw);
    padding: 22px 20px;
    border-radius: 22px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    align-items: center;

    /* entrance: keep backdrop-filter active immediately (no opacity animation) */
    opacity: 1;
    visibility: hidden;
    transform: translateY(18px) scale(0.985);
    will-change: transform;

}
body.is-entered .card {
    visibility: visible;
}

body.is-entered:not(.entered-done) .card {
    animation: cardInTransform 900ms cubic-bezier(0.2, 0.9, 0.2, 1) 120ms both;
}

body.entered-done .card {
    animation: none !important;
    transform: none;
    will-change: auto;
}

/* Performance fallback for older phones */
body.low-end .card {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgb(var(--ui-bg-rgb) / 68%);
}

/* Telegram in-app browser/WebView: disable real blur to avoid micro-freezes/black flashes */
.tg-webview .card,
body.tg-webview .card {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgb(var(--ui-bg-rgb) / 72%);
}

body.low-end.is-entered .card {
    animation-duration: 700ms;
}

body.low-end #avatar-wrapper::after { opacity: 0.35; }
body.low-end button { box-shadow: 0 8px 20px rgb(0 0 0 / 22%); }

/* staggered items (run once; then lock-in so resize won't restart) */
body.is-entered:not(.entered-done) #avatar-wrapper { animation: itemIn 700ms cubic-bezier(0.2, 0.9, 0.2, 1) 220ms both; }
body.is-entered:not(.entered-done) #who { animation: itemIn 700ms cubic-bezier(0.2, 0.9, 0.2, 1) 320ms both; }
body.is-entered:not(.entered-done) #footer { animation: itemIn 700ms cubic-bezier(0.2, 0.9, 0.2, 1) 420ms both; }
body.is-entered:not(.entered-done) .flexbox a:nth-child(1) button { animation: itemIn 700ms cubic-bezier(0.2, 0.9, 0.2, 1) 540ms both; }
body.is-entered:not(.entered-done) .flexbox a:nth-child(2) button { animation: itemIn 700ms cubic-bezier(0.2, 0.9, 0.2, 1) 620ms both; }

body.entered-done #avatar-wrapper,
body.entered-done #who,
body.entered-done #footer,
body.entered-done .flexbox button {
    animation: none !important;
    transform: none;
}

@media (min-width: 520px) {
    .card { padding: 26px 24px; }
}

/* Обёртка для видео (исправление для мобильных) */
#avatar-wrapper {
    width: 156px;
    height: 156px;
    border-radius: 26px;
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid rgb(255 255 255 / 16%);
    opacity: 1;
    will-change: transform;
    transform: translateZ(0);
    transition: border-color 0.5s ease, box-shadow 0.5s ease;
    position: relative;
    box-shadow: 0 14px 45px rgb(0 0 0 / 35%);

    background: #000;
}

#avatar-wrapper::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(800px 380px at 20% 10%, rgb(var(--ui-accent-rgb) / 18%), transparent 55%);
    opacity: 0.6;
}

/* spinning removed */

/* Видео внутри обёртки */
#avatar-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background-color: #000;

    /* Avoid tap/zoom highlight flashes and keep video isolated */
    -webkit-tap-highlight-color: transparent;

    /* Put video on its own compositor layer to avoid edge flicker during background updates */
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#who {
    color: var(--text-color);
    -webkit-user-select: none;
    user-select: none;
    font-size: clamp(24px, 5.8vw, 34px);
    letter-spacing: 0.02em;
    margin-bottom: 8px;
    opacity: 1;
    transition: color 0.5s ease;
    text-shadow: 0 10px 40px rgb(0 0 0 / 40%);
}

#footer {
    color: var(--text-color-light);
    font-size: clamp(12px, 3.8vw, 18px);
    margin-bottom: 18px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    text-align: center;
    hyphens: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: color 0.5s ease;
    line-height: 1.35;
}

#footer::before {
    content: "";
    width: 74px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(var(--ui-accent-rgb) / 55%), transparent);
    margin-bottom: 12px;
    border-radius: 999px;
}

#footer::after {
    content: "";
    width: 74px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(var(--ui-accent-rgb) / 35%), transparent);
    margin-top: 12px;
    border-radius: 999px;
}

@media (max-width: 420px) {
    #footer::before, #footer::after { width: 58px; }
}

button {
    background: linear-gradient(
        180deg,
        rgb(255 255 255 / 10%),
        rgb(0 0 0 / 0%)
    ),
    var(--btn-bg);
    border: var(--btn-border);
    border-radius: 16px;
    padding: 11px 14px;
    font-size: clamp(14px, 2vw, 17px);
    color: var(--btn-color);
    cursor: pointer;
    font-family: 'JetBrains Mono', monospace;
    margin: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 170px;
    max-width: 100%;
    box-sizing: border-box;
    text-align: center;
    opacity: 1;
    transition: transform 0.18s ease, background-color 0.35s ease, border-color 0.35s ease, color 0.35s ease;
    will-change: transform;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 10px 30px rgb(0 0 0 / 28%), 0 1px 0 rgb(255 255 255 / 7%) inset;
    position: relative;
    overflow: hidden;
}

button::before {
    content: "";
    position: absolute;
    inset: -40%;
    background: radial-gradient(circle at 30% 30%, rgb(var(--ui-accent-rgb) / 25%), transparent 45%);
    opacity: 0;
    transition: opacity 0.25s ease;
}

button:hover {
    transform: translateY(-2px);
    border-color: rgb(var(--ui-accent-rgb) / 45%);
    background: linear-gradient(
        180deg,
        rgb(255 255 255 / 12%),
        rgb(0 0 0 / 0%)
    ),
    var(--btn-hover-bg);
}

button:hover::before { opacity: 1; }

button:active {
    transform: translateY(0);
}

:root[data-scheme="light"] button:active {
    box-shadow:
        0 8px 22px rgb(0 0 0 / 12%),
        0 1px 0 rgb(255 255 255 / 70%) inset;
}

button:focus-visible {
    outline: 2px solid rgb(var(--ui-accent-rgb) / 55%);
    outline-offset: 3px;
}

button i.icon {
    margin-right: 0;
    font-size: 1.1em;
    width: 36px;
    height: 36px;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

a {
    text-decoration: none;
    color: var(--ahref-color);
    font-family: 'JetBrains Mono', monospace;
    -webkit-tap-highlight-color: transparent;
}

.flexbox {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
}

.icon {
    padding: 0;
    font-style: normal;
    border: 1px solid rgb(255 255 255 / 14%);
    color: rgb(var(--ui-accent-rgb) / 95%);
    cursor: pointer;
    border-radius: 999px;
    background-color: rgb(255 255 255 / 10%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: color 0.35s ease, background-color 0.35s ease, border-color 0.35s ease;
}

button:hover .icon {
    border-color: rgb(var(--ui-accent-rgb) / 35%);
    background-color: rgb(var(--ui-accent-rgb) / 12%);
}

/* Light scheme tweaks: make controls visible and "glassy", not white-on-white */
:root[data-scheme="light"] button {
    background:
        linear-gradient(180deg, rgb(255 255 255 / 88%), rgb(255 255 255 / 62%)),
        radial-gradient(circle at 18% 18%, rgb(var(--ui-accent-rgb) / 18%), transparent 55%);
    border: 1px solid rgb(0 0 0 / 12%);
    box-shadow:
        0 10px 26px rgb(0 0 0 / 12%),
        0 1px 0 rgb(255 255 255 / 70%) inset;
}

:root[data-scheme="light"] button:hover {
    border-color: rgb(var(--ui-accent-rgb) / 55%);
    background:
        linear-gradient(180deg, rgb(255 255 255 / 92%), rgb(255 255 255 / 68%)),
        radial-gradient(circle at 18% 18%, rgb(var(--ui-accent-rgb) / 22%), transparent 58%);
}

:root[data-scheme="light"] .icon {
    border: 1px solid rgb(0 0 0 / 10%);
    background-color: rgb(var(--ui-accent-rgb) / 10%);
    color: rgb(var(--ui-accent-rgb) / 85%);
}

:root[data-scheme="light"] button:hover .icon {
    border-color: rgb(var(--ui-accent-rgb) / 35%);
    background-color: rgb(var(--ui-accent-rgb) / 16%);
}

::selection {
    background-color: var(--selection);
    transition: background-color 0.5s ease;
}

::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-button {
    display: none;
}

::-webkit-scrollbar-thumb {
    background-color: var(--scroll-bar);
    transition: background-color 0.5s ease;
}

/* Медиа-запросы для мобильных, мозги выебало */
@media (max-width: 870px) {
    .flexbox {
        position: static;
        padding: 6px 0 0;
        justify-content: center;
        align-items: center;
        z-index: 2;
        overflow-x: visible;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .flexbox::-webkit-scrollbar {
        display: none;
    }

    button {
        flex: 0 0 auto;
        min-width: 140px;
        font-size: clamp(12px, 2vw, 16px);
        padding: 10px 12px;
        margin: 6px;
        text-align: center;
        transform-origin: center;
        will-change: transform;
        touch-action: manipulation;
    }

    button i.icon {
        font-size: 1.3em;
    }

    #avatar-wrapper {
        width: 148px;
        height: 148px;
        border-radius: 24px;
    }

    #who {
        font-size: clamp(23px, 9vw, 29px);
    }

    #footer {
        font-size: clamp(12px, 9vw, 20px);
    }
}

/* Дополнительные фиксы которые я ебал */
@supports (-webkit-touch-callout: none) {
    #avatar-video {
        -webkit-mask-image: -webkit-radial-gradient(white, black);
    }
}

/* Фикс для хром дрочеров */
@media (-webkit-min-device-pixel-ratio:0) and (max-width: 870px) {
    #avatar-wrapper {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
}
