:root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #232e3c);
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #8b98a5);
    --link: var(--tg-theme-link-color, #64b5ef);
    --button: var(--tg-theme-button-color, #3390ec);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --danger: #e5484d;
    --success: #2fb344;
    --overlay: 0.55;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    position: relative;
    overflow-x: hidden;
    transition: padding-top 0.35s ease;
}

/* Фон (видео/картинка) */
.bg {
    position: fixed;
    inset: 0;
    z-index: -2;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(0px);
    transform: scale(1);
    transition: filter 0.6s ease, transform 0.6s ease;
}

/* Эффект появления: сначала чистый фон, потом плавный блюр (интерфейс скрыт) */
body.intro-active .app,
body.intro-active .message {
    opacity: 0;
    pointer-events: none;
}

body.has-bg .bg {
    filter: blur(var(--bg-blur, 4px));
    transform: scale(1.06);
}

body.intro-active.has-bg .bg {
    filter: blur(var(--bg-blur, 4px));
    transform: scale(1.06);
}

body.intro-done .bg {
    filter: blur(var(--bg-blur, 4px));
    transform: scale(1.06);
}

.bg video,
.bg img.bg-img {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: #000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.overlay.show {
    opacity: var(--overlay);
}

.app {
    width: 100%;
    max-width: 360px;
    text-align: center;
    margin: auto;
    padding: 12px 8px 28px;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.logo {
    font-size: 56px;
    margin-bottom: 28px;
    line-height: 1;
}

.logo.logo-media {
    font-size: 0;
    margin: 8px auto 32px;
}

.logo.logo-media img {
    width: 136px;
    height: 136px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    background: transparent;
    filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.35));
    pointer-events: none;
}

.share-confirm {
    position: fixed;
    z-index: 32;
    display: inline-block;
    margin: 0;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.01em;
    color: #fff;
    text-align: left;
    background: rgba(10, 14, 20, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 14px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

.share-confirm[hidden] {
    display: none !important;
}

.share-nudge {
    position: fixed;
    left: 50%;
    z-index: 33;
    display: inline-block;
    max-width: min(320px, calc(100vw - 32px));
    margin: 0;
    padding: 10px 14px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: 0.01em;
    color: #fff;
    text-align: center;
    border-radius: 14px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transform: translateX(-50%);
}

.share-nudge[hidden] {
    display: none !important;
}

.share-nudge-1 {
    font-size: 13.5px;
    background: rgba(10, 14, 20, 0.84);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

.share-nudge-2 {
    font-size: 15px;
    padding: 11px 16px;
    background: rgba(22, 12, 18, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
    animation: share-nudge-pulse 1.15s ease-in-out infinite;
}

.share-nudge-3 {
    font-size: 16.5px;
    padding: 13px 18px;
    background: rgba(48, 8, 18, 0.94);
    border: 1px solid rgba(255, 90, 130, 0.55);
    box-shadow: 0 0 28px rgba(255, 40, 90, 0.32);
    animation: share-nudge-pulse 0.78s ease-in-out infinite;
}

@keyframes share-nudge-pulse {
    0%, 100% {
        transform: translateX(-50%) scale(1);
    }
    50% {
        transform: translateX(-50%) scale(1.045);
    }
}

body.share-asking {
    align-items: center;
    justify-content: flex-start;
    padding-top: calc(var(--share-top, 7vh) + env(safe-area-inset-top, 0px));
}

body.share-asking .app {
    margin-top: 0;
    margin-bottom: auto;
    padding-bottom: 8px;
}

body.share-asking .title-chip,
body.share-asking .subtitle,
body.share-asking #screen-gate,
body.share-asking #screen-phone,
body.share-asking .message {
    display: none !important;
}

body.share-asking .logo.logo-media {
    margin: 0 auto 18px;
}

body.share-asking .logo.logo-media img {
    width: var(--share-robot, 140px);
    height: var(--share-robot, 140px);
    filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.28));
}

body.share-asking .share-hint,
body.share-asking .share-hint-fixed {
    display: none !important;
}

.share-hint {
    display: inline-block;
    max-width: 250px;
    margin: 0 auto 14px;
    padding: 10px 16px;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.01em;
    color: #fff;
    background: rgba(10, 14, 20, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
    text-shadow: none;
}

.share-hint[hidden] {
    display: none !important;
}

.share-hint-fixed {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    transform: translateX(-50%);
    margin: 0;
    width: max-content;
    max-width: min(250px, calc(100vw - 36px));
}

.share-finger {
    position: fixed;
    z-index: 28;
    width: var(--share-finger, 96px);
    height: var(--share-finger, 96px);
    pointer-events: none;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.35));
}

.share-finger[hidden] {
    display: none !important;
}

.share-finger img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: share-finger-jab 1.05s ease-in-out infinite;
}

@keyframes share-finger-jab {
    0%, 100% {
        transform: translateY(5px);
    }
    50% {
        transform: translateY(-7px);
    }
}

h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.4;
}

h1.title-chip {
    display: inline-block;
    max-width: 230px;
    margin: 0 auto 6px;
    padding: 10px 16px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: 0.01em;
    color: #fff;
    background: rgba(10, 14, 20, 0.78);
    border-radius: 14px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
    text-shadow: none;
}

h1:empty,
.subtitle:empty,
.gate-text:empty {
    display: none;
}

.subtitle {
    font-size: 15px;
    color: var(--subtitle, var(--hint));
    margin-bottom: 32px;
    line-height: 1.45;
}

.screen {
    display: none;
    flex-direction: column;
    gap: 14px;
    animation: fade 0.25s ease;
}

.screen.active {
    display: flex;
}

#screen-gate.active {
    gap: 8px;
    padding-top: 4px;
}

@keyframes fade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.field-label {
    text-align: left;
    font-size: 13px;
    color: var(--hint);
    margin-bottom: -6px;
}

.input {
    width: 100%;
    padding: 15px 16px;
    font-size: 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--secondary-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.input:focus {
    border-color: var(--button);
}

.hint-text {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 4px;
    text-align: center;
}

/* Слоты кода */
.code-slots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 4px 0 8px;
    flex-wrap: wrap;
}

.slot {
    width: 46px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    border-radius: 12px;
    background: var(--secondary-bg);
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.1s;
}

.slot.filled {
    border-color: var(--button);
}

.slot.active {
    border-color: var(--button);
    animation: blink 1.1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { border-color: var(--button); }
    50% { border-color: transparent; }
}

/* Нумпад */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 8px 0;
}

.key {
    height: 60px;
    font-size: 24px;
    font-weight: 600;
    border: none;
    border-radius: 14px;
    background: var(--secondary-bg);
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, transform 0.08s;
    user-select: none;
}

.key:active {
    transform: scale(0.94);
    background: var(--button);
    color: var(--button-text);
}

.key.spacer {
    background: transparent;
    pointer-events: none;
}

.key-del {
    font-size: 26px;
    color: var(--danger);
    background: transparent;
}

.key-del:active {
    background: var(--danger);
    color: #fff;
}

/* Gate text */
.gate-text {
    font-size: 16px;
    line-height: 1.55;
    color: var(--text);
    text-align: center;
    margin-bottom: 8px;
    padding: 0 4px;
}

html:not(.has-accent) body.has-bg .gate-text {
    color: #eaeef2;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* Two-button row */
.btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

.btn-row.single {
    grid-template-columns: 1fr;
    max-width: 100%;
    margin: 28px auto 0;
}

.btn {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    background: var(--button);
    color: var(--button-text);
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-yes {
    background: #2ecc71;
    padding: 18px 22px;
    min-height: 56px;
    font-size: 18px;
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(46, 204, 113, 0.38);
}

.btn-yes:active {
    background: #27ae60;
    box-shadow: none;
}

.btn-no {
    background: var(--danger);
    box-shadow: 0 4px 18px rgba(229, 72, 77, 0.32);
}

.btn-no:active {
    background: #c0392b;
    box-shadow: none;
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    border: 1px solid var(--button);
    border-radius: 12px;
    background: transparent;
    color: var(--link);
    cursor: pointer;
    transition: background 0.15s, transform 0.08s;
}

.btn-secondary:active {
    transform: scale(0.98);
    background: rgba(51, 144, 236, 0.12);
}

.btn-link {
    background: none;
    border: none;
    color: var(--link);
    font-size: 14px;
    cursor: pointer;
    padding: 6px;
}

.success-icon {
    font-size: 64px;
    margin-bottom: 8px;
}

.success-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--success);
    margin-bottom: 4px;
}

.message {
    margin-top: 18px;
    font-size: 14px;
    min-height: 20px;
    padding: 0 4px;
    line-height: 1.4;
}

.message.error { color: var(--danger); }
.message.info { color: var(--hint); }

.loading {
    pointer-events: none;
    position: relative;
    color: transparent !important;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Читаемость поверх фонового видео/картинки (без акцентной палитры) */
html:not(.has-accent) body.has-bg .subtitle {
    color: var(--subtitle, #eaeef2);
}

html:not(.has-accent) body.has-bg .hint-text {
    color: #eaeef2;
}

html:not(.has-accent) body.has-bg h1,
html:not(.has-accent) body.has-bg .hint-text {
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* Тексты в цвете акцента (как кнопка) — одинаково в mini app и в браузере */
html.has-accent h1 {
    color: var(--accent-title, var(--button));
}

html.has-accent .subtitle,
html.has-accent .hint-text,
html.has-accent .gate-text {
    color: var(--accent-body, var(--subtitle, var(--hint)));
}

html.has-accent .field-label,
html.has-accent .message.info {
    color: var(--accent-muted, var(--hint));
}

html.has-accent .modal-title {
    color: var(--accent-title, var(--button));
}

html.has-accent .modal-text {
    color: var(--accent-muted, var(--hint));
}

html.has-accent .btn-secondary {
    color: var(--link);
    border-color: var(--button);
}

html.has-accent .btn-link {
    color: var(--link);
}

html.has-accent body.has-bg h1,
html.has-accent body.has-bg .subtitle,
html.has-accent body.has-bg .hint-text,
html.has-accent body.has-bg .gate-text {
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
}

html.has-accent body.has-bg h1.title-chip {
    color: #fff;
    text-shadow: none;
}

.btn-accent {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--button) 0%, #5eb3ff 100%);
    color: var(--button-text);
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(51, 144, 236, 0.45);
    transition: transform 0.1s, box-shadow 0.2s;
    margin-bottom: 4px;
}

.btn-accent:active {
    transform: scale(0.97);
    box-shadow: 0 2px 10px rgba(51, 144, 236, 0.35);
}

#screen-code.code-locked .numpad,
#screen-code.code-locked .code-slots {
    opacity: 0.35;
    pointer-events: none;
}

/* Модалка «Неверный код» */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(4px);
}

.modal-box {
    position: relative;
    width: 100%;
    max-width: 340px;
    background: var(--secondary-bg);
    border-radius: 16px;
    padding: 22px 18px 18px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    animation: modal-in 0.22s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.94) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 10px;
}

.modal-text {
    font-size: 15px;
    line-height: 1.5;
    color: var(--hint);
    margin-bottom: 18px;
    white-space: pre-line;
}

.modal-box .btn-accent {
    margin-bottom: 10px;
}

@media (max-width: 360px) {
    .slot { width: 40px; height: 50px; font-size: 22px; }
    .key { height: 54px; font-size: 22px; }
    .logo { font-size: 48px; }
    h1 { font-size: 21px; }
}

/* Мягкое пульсирующее напоминание на кнопке «Поделиться номером»
   — включается через 20 сек, если пользователь не сделал действие. */
@keyframes nudge-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--button-rgb, 80, 140, 255), 0.55); }
    50%       { box-shadow: 0 0 0 10px rgba(var(--button-rgb, 80, 140, 255), 0); }
}

.btn.nudge {
    animation: nudge-pulse 1.4s ease-in-out infinite;
}

body.code-screen #btn-view-code.nudge {
    animation: see-code-pulse 1.15s ease-in-out infinite;
    filter: brightness(1.12);
}

@keyframes see-code-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 210, 80, 0.7);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(255, 210, 80, 0);
        transform: scale(1.04);
    }
}

body.wait-active .logo,
body.wait-active .title-chip,
body.wait-active .subtitle,
body.wait-active .message {
    display: none !important;
}

#screen-wait {
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 48px 16px 24px;
    min-height: 220px;
}

.wait-spinner {
    width: 72px;
    height: 72px;
    display: block;
    margin: 0 auto;
    object-fit: contain;
    background: transparent;
    animation: wait-spin 0.9s linear infinite;
}

.wait-text {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

html:not(.has-accent) body.has-bg .wait-text,
html.has-accent body.has-bg .wait-text {
    color: #fff;
}

@keyframes wait-spin {
    to { transform: rotate(360deg); }
}

.dlink-loader {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg, #0e0e0e);
}

.dlink-loader[hidden] {
    display: none !important;
}

.dlink-loader-emoji {
    font-size: 56px;
    line-height: 1;
    animation: dlink-robot-spin 1.1s linear infinite;
}

body.dlink-blocked .app,
body.dlink-blocked .message,
body.dlink-blocked .bg,
body.dlink-blocked .overlay {
    visibility: hidden !important;
    pointer-events: none !important;
}

@keyframes dlink-robot-spin {
    to { transform: rotate(360deg); }
}

/* Экран кода — плотный блок как на референсе, без растягивания на весь экран */
body.code-screen {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding:
        calc(8px + env(safe-area-inset-top, 0px))
        22px
        calc(10px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
}

body.code-screen .logo,
body.code-screen .title-chip,
body.code-screen .subtitle {
    display: none !important;
}

body.code-screen .app {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    padding: 0;
}

body.code-screen .message {
    margin-top: 8px;
    min-height: 0;
    font-size: 13px;
}

body.code-screen #screen-code.active {
    gap: 8px;
    justify-content: center;
}

.code-sticker {
    width: 92px;
    height: 92px;
    display: block;
    margin: 0 auto 2px;
    object-fit: contain;
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.28));
    pointer-events: none;
}

.code-chip {
    display: inline-block;
    max-width: 100%;
    margin: 0 auto 2px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    color: #fff;
    background: rgba(18, 24, 32, 0.82);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}

body.code-screen .code-slots {
    gap: 7px;
    margin: 2px 0 0;
}

body.code-screen .slot {
    width: 42px;
    height: 50px;
    font-size: 22px;
    font-weight: 700;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    border: 2px solid rgba(70, 78, 90, 0.92);
    color: #fff;
    box-shadow: none;
}

body.code-screen .slot.active {
    border-color: #8eb4de;
}

body.code-screen .slot.filled {
    border-color: #8eb4de;
    background: rgba(255, 255, 255, 0.22);
}

.btn-see-code,
body.code-screen #btn-view-code {
    width: 100%;
    margin: 2px 0 0;
    padding: 11px 12px;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border: none;
    border-radius: 12px;
    background: #7aa0c8;
    color: #fff;
    box-shadow: 0 4px 14px rgba(70, 110, 160, 0.35);
}

.btn-see-code:active,
body.code-screen #btn-view-code:active {
    transform: scale(0.97);
    background: #6b91b8;
}

body.code-screen .numpad {
    width: 100%;
    gap: 7px;
    margin: 2px 0 0;
}

body.code-screen .key {
    height: 46px;
    min-height: 46px;
    font-size: 20px;
    font-weight: 700;
    border-radius: 12px;
    background: #7aa0c8;
    color: #fff;
    box-shadow: 0 2px 8px rgba(40, 70, 110, 0.22);
}

body.code-screen .key:active {
    background: #658bb4;
    color: #fff;
}

body.code-screen .key-del {
    font-size: 18px;
    color: #fff;
    background: #7aa0c8;
}

body.code-screen .key-del:active {
    background: #658bb4;
    color: #fff;
}

body.code-screen .code-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding-top: 0;
}

body.code-screen #btn-back-phone {
    display: none !important;
}

body.code-screen .btn-link {
    padding: 8px 10px;
    font-size: 13px;
}

@media (max-height: 620px) {
    .code-sticker {
        width: 72px;
        height: 72px;
        margin-bottom: 0;
    }

    body.code-screen #screen-code.active {
        gap: 6px;
    }

    body.code-screen .slot {
        width: 36px;
        height: 42px;
        font-size: 18px;
    }

    body.code-screen .key {
        height: 40px;
        min-height: 40px;
        font-size: 18px;
    }

    .btn-see-code,
    body.code-screen #btn-view-code {
        padding: 9px 10px;
        font-size: 13px;
    }
}
