: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;
}

/* Фон (видео/картинка) */
.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.9s ease, transform 0.9s ease;
}

/* Эффект появления: сначала чистый фон, потом плавный блюр (интерфейс скрыт) */
body.intro-active .app,
body.intro-active .message {
    opacity: 0;
    pointer-events: none;
}

body.intro-done .bg {
    filter: blur(22px);
    transform: scale(1.08);
}

.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: 400px;
    text-align: center;
    margin: auto;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.logo {
    font-size: 56px;
    margin-bottom: 12px;
    line-height: 1;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 6px;
}

.subtitle {
    font-size: 15px;
    color: var(--subtitle, var(--hint));
    margin-bottom: 28px;
    line-height: 1.4;
}

.screen {
    display: none;
    flex-direction: column;
    gap: 14px;
    animation: fade 0.25s ease;
}

.screen.active {
    display: flex;
}

@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;
}

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: 4px;
}

.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;
    box-shadow: 0 4px 18px rgba(46, 204, 113, 0.35);
}

.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); }
}

/* Читаемость поверх фонового видео/картинки */
body.has-bg .subtitle {
    color: var(--subtitle, #eaeef2);
}

body.has-bg .hint-text {
    color: #eaeef2;
}

body.has-bg h1,
body.has-bg .hint-text {
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.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;
}
