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

        :root {

            --success: #43B581;
            --success-light: rgba(67,181,129,0.1);
            --error: #ED4245;
            --error-light: rgba(237,66,69,0.08);
            --sale: #FF6B35;
            --sale-light: rgba(255,107,53,0.08);

            --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);

            --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
            --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
            --radius: 12px;
            --radius-sm: 8px;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            background: var(--bg);
            color: var(--text);
            min-height: 100vh;
            display: flex;
            align-items: flex-start;
            justify-content: center;
            padding: 24px 16px;
            -webkit-font-smoothing: antialiased;
        }

        .container {
            width: 100%;
            max-width: 720px;
        }

        /* Steps */
        .step { display: none; animation: fadeIn 0.3s ease; }
        .step.active { display: block; }

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

        /* Cards */
        .card {
            background: var(--card-bg);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 32px 24px;
        }

        /* Typography */
        .step-title {
            font-size: 22px;
            font-weight: 700;
            color: var(--text);
            margin-bottom: 4px;
        }
        .step-subtitle {
            font-size: 14px;
            color: var(--text-secondary);
            margin-bottom: 24px;
        }

        /* Spinner */
        .spinner-wrap {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 80px 0;
        }
        .spinner {
            width: 40px; height: 40px;
            border: 3px solid var(--border);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        .spinner-text {
            margin-top: 16px;
            font-size: 14px;
            color: var(--text-secondary);
        }

        /* Currency note */
        .currency-note {
            font-size: 13px;
            color: var(--text-secondary);
            text-align: center;
            margin-bottom: 16px;
        }
        .legal-note {
            font-size: 11px;
            color: var(--text-muted);
            text-align: center;
            margin-top: 16px;
            line-height: 1.6;
        }

        /* Membership status banner */
        .membership-status {
            background: var(--primary-light);
            border: 1px solid rgba(88,101,242,0.15);
            border-radius: var(--radius-sm);
            padding: 12px 16px;
            margin-bottom: 16px;
            font-size: 14px;
            color: var(--text);
            line-height: 1.5;
        }
        .membership-status strong { font-weight: 700; }
        .membership-status.warning {
            background: #FFF8E1;
            border-color: #FFE082;
            color: #5D4037;
        }
        .membership-status.critical {
            background: var(--error-light);
            border-color: rgba(237,66,69,0.25);
            color: #B71C1C;
        }

        /* New expiry info below plan list */
        .new-expiry-info {
            text-align: center;
            font-size: 14px;
            color: var(--primary);
            font-weight: 600;
            padding: 10px 0;
            margin-bottom: 8px;
            line-height: 1.5;
        }
        .new-expiry-info strong { font-weight: 700; }

        /* Sale section header */
        .sale-section-header {
            font-size: 15px;
            font-weight: 700;
            color: var(--sale);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .sale-section-header::before {
            content: '';
            display: inline-block;
            width: 20px;
            height: 20px;
            background: var(--sale);
            mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/%3E%3C/svg%3E");
            -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/%3E%3C/svg%3E");
            mask-size: contain;
            -webkit-mask-size: contain;
            flex-shrink: 0;
        }

        /* Sale hero card */
        .sale-hero {
            background: linear-gradient(135deg, #FF6B35 0%, #FF8F5E 100%);
            border-radius: var(--radius);
            padding: 20px;
            margin-bottom: 20px;
            cursor: pointer;
            transition: all 0.2s ease;
            user-select: none;
            color: #fff;
            position: relative;
            overflow: hidden;
        }
        .sale-hero::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -20%;
            width: 200px;
            height: 200px;
            background: rgba(255,255,255,0.08);
            border-radius: 50%;
            pointer-events: none;
        }
        .sale-hero:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-lg);
        }
        .sale-hero.selected {
            box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--sale), var(--shadow-lg);
        }
        .sale-hero-tag {
            display: inline-block;
            background: rgba(255,255,255,0.2);
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
            padding: 3px 10px;
            border-radius: 20px;
            margin-bottom: 10px;
        }
        .sale-hero-title {
            font-size: 22px;
            font-weight: 700;
            margin-bottom: 4px;
        }
        .sale-hero-subtitle {
            font-size: 14px;
            font-weight: 500;
            opacity: 0.9;
            margin-bottom: 8px;
        }
        .sale-hero-urgency {
            font-size: 12px;
            font-weight: 600;
            opacity: 0.85;
        }
        .sale-hero-urgency.urgent {
            opacity: 1;
            animation: pulse-urgency 2s ease-in-out infinite;
        }
        @keyframes pulse-urgency {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.6; }
        }
        .sale-hero-check {
            position: absolute;
            top: 16px;
            right: 16px;
            width: 28px;
            height: 28px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
        }
        .sale-hero.selected .sale-hero-check {
            background: #fff;
            border-color: #fff;
        }
        .sale-hero.selected .sale-hero-check svg { opacity: 1; }
        .sale-hero-check svg {
            width: 16px;
            height: 16px;
            stroke: var(--sale);
            opacity: 0;
            transition: opacity 0.2s;
        }

        /* Plan list */
        .plan-list {
            display: flex;
            flex-direction: column;
            margin-bottom: 24px;
        }
        .plan-list-header {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 8px;
        }

        /* Plan row */
        .plan-row {
            display: grid;
            grid-template-columns: 108px 1fr auto 22px;
            align-items: center;
            padding: 16px;
            background: var(--card-bg);
            border: 2px solid var(--border);
            cursor: pointer;
            transition: all 0.15s ease;
            user-select: none;
            gap: 16px;
        }
        .plan-list-header + .plan-row { border-radius: var(--radius) var(--radius) 0 0; }
        .plan-row:last-child { border-radius: 0 0 var(--radius) var(--radius); }
        .plan-list-header + .plan-row:last-child { border-radius: var(--radius); }
        .plan-row + .plan-row { border-top: none; }
        .plan-row:hover {
            background: #fafbfc;
            border-color: var(--border-hover);
        }
        .plan-row:hover + .plan-row { border-top-color: var(--border-hover); }
        .plan-row.selected {
            background: var(--primary-light);
            border: 2px solid var(--primary);
            z-index: 1;
            position: relative;
        }
        .plan-row.selected + .plan-row { border-top-color: var(--primary); }

        /* ── Discount sale (pay_plan_sales) ─────────────────────────────
           Distinct from the .sale-hero cards above, which are whole plans that
           only exist for a window. This is an ordinary plan marked down: the
           list price stays visible, struck through, so the saving is legible. */
        .promo-banner {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 0 0 16px;
            padding: 12px 14px;
            border-radius: var(--radius);
            background: var(--sale-light);
            border: 1px solid var(--sale);
            color: var(--text);
            font-size: 14px;
            font-weight: 600;
            line-height: 1.4;
        }
        .promo-banner-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
        .promo-banner-ends {
            display: block;
            font-size: 12px;
            font-weight: 600;
            color: var(--sale);
            margin-top: 2px;
        }
        .plan-row-price-was {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-muted);
            text-decoration: line-through;
            margin-right: 6px;
        }
        .plan-row-price.on-sale { color: var(--sale); }
        .plan-row-tag.sale {
            color: #fff;
            background: var(--sale);
            padding: 3px 7px;
            border-radius: 999px;
            letter-spacing: 0.02em;
        }

        .plan-row-price {
            font-size: 16px;
            font-weight: 700;
            color: var(--text);
            min-width: 70px;
        }
        .plan-row-days {
            font-size: 15px;
            font-weight: 600;
            color: var(--text);
            width: 100px;
            flex-shrink: 0;
        }
        .plan-row-tagline {
            flex: 1;
            font-size: 13px;
            font-weight: 700;
            color: var(--primary);
            text-align: center;
        }
        .plan-row-desc {
            font-size: 12px;
            font-weight: 500;
            color: var(--text-secondary);
        }
        .plan-row-bonus {
            font-size: 12px;
            font-weight: 600;
            color: var(--success);
            min-width: 70px;
        }
        .plan-row-radio {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 2px solid var(--border);
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.15s ease;
        }
        .plan-row.selected .plan-row-radio {
            border-color: var(--primary);
            background: var(--primary);
        }
        .plan-row.selected .plan-row-radio::after {
            content: '';
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #fff;
        }

        /* Price + sub-line (duration) */
        .plan-row-info {
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
        }
        .plan-row-sub {
            font-size: 12px;
            font-weight: 500;
            color: var(--text-secondary);
            white-space: nowrap;
        }

        /* Tokens included — the value on offer */
        .plan-row-tokens {
            display: flex;
            flex-direction: column;
            gap: 1px;
            min-width: 0;
        }
        .plan-row-tokens .tok-count {
            font-size: 15px;
            font-weight: 700;
            color: var(--primary);
        }
        .plan-row-tokens .tok-videos {
            font-size: 11px;
            font-weight: 500;
            color: var(--text-muted);
        }

        /* Right-hand badge (Most Popular / Best Value / bonus days) */
        .plan-row-tag {
            justify-self: end;
            font-size: 11px;
            font-weight: 700;
            white-space: nowrap;
        }
        .plan-row-tag:not(:empty) {
            padding: 4px 10px;
            border-radius: 20px;
        }
        .plan-row-tag.popular { color: var(--primary); background: var(--primary-light); }
        .plan-row-tag.bonus { color: var(--success); background: var(--success-light); }

        /* Right-hand muted note (token expiry disclosure) */
        .plan-row-note {
            justify-self: end;
            text-align: right;
            font-size: 11px;
            font-weight: 500;
            color: var(--text-muted);
            line-height: 1.4;
            max-width: 96px;
        }

        /* Right-hand column wrapper: the ONE grid cell that holds a badge and/or the
           expiry note. Both stack vertically inside it, right-aligned, so a plan can
           carry a sale tag AND its expiry disclosure without either leaving its cell
           (two bare elements in one grid slot spilled into the radio column and over
           the text). */
        .plan-row-side {
            justify-self: end;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            gap: 4px;
            min-width: 0;
        }
        .plan-row-side .plan-row-tag,
        .plan-row-side .plan-row-note { justify-self: auto; }

        /* Section intro line (token packs) */
        .section-intro {
            font-size: 12px;
            color: var(--text-secondary);
            text-align: center;
            margin: 12px 0 4px;
            line-height: 1.5;
        }

        /* "How it works" info note */
        .info-note {
            background: var(--primary-light);
            border: 1px solid rgba(88,101,242,0.15);
            border-radius: var(--radius-sm);
            padding: 12px 16px;
            margin-bottom: 16px;
            font-size: 13px;
            color: var(--text);
            line-height: 1.55;
        }
        .info-note strong { font-weight: 700; }

        /* Buttons */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-family: inherit;
            font-size: 15px;
            font-weight: 600;
            padding: 12px 24px;
            border-radius: var(--radius-sm);
            border: none;
            cursor: pointer;
            transition: all 0.15s ease;
            text-decoration: none;
            line-height: 1;
        }
        .btn-primary {
            background: var(--primary);
            color: #fff;
        }
        .btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
        .btn-primary:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }
        .btn-secondary {
            background: transparent;
            color: var(--text-secondary);
            border: 1px solid var(--border);
        }
        .btn-secondary:hover { background: var(--bg); border-color: var(--border-hover); }

        .btn-block { width: 100%; }
        .btn-group {
            display: flex;
            gap: 12px;
            margin-top: 8px;
        }
        .btn-group .btn { flex: 1; }

        /* Provider cards */
        .provider-grid {
            display: flex;
            flex-direction: column;
            gap: 12px;
            margin-bottom: 24px;
        }
        .provider-card {
            display: flex;
            align-items: center;
            gap: 16px;
            background: var(--card-bg);
            border: 2px solid var(--border);
            border-radius: var(--radius);
            padding: 16px 20px;
            cursor: pointer;
            transition: all 0.2s ease;
            user-select: none;
        }
        .provider-card:hover {
            border-color: var(--border-hover);
            box-shadow: var(--shadow-md);
        }
        .provider-card.selected {
            border-color: var(--primary);
            background: var(--primary-light);
        }
        .provider-icon {
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }
        .provider-icon img, .provider-icon svg { width: 40px; height: 40px; border-radius: 6px; }
        .provider-name {
            font-size: 15px;
            font-weight: 600;
            color: var(--text);
        }
        .provider-desc {
            font-size: 12px;
            color: var(--text-secondary);
        }

        /* Confirm summary */
        .confirm-box {
            background: var(--bg);
            border-radius: var(--radius-sm);
            padding: 20px;
            margin-bottom: 24px;
        }
        .confirm-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 0;
        }
        .confirm-row + .confirm-row { border-top: 1px solid var(--border); }
        .confirm-label { font-size: 14px; color: var(--text-secondary); }
        .confirm-value { font-size: 14px; font-weight: 600; color: var(--text); }

        /* Payment form */
        #card-element {
            background: var(--card-bg);
            border: 2px solid var(--border);
            border-radius: var(--radius-sm);
            padding: 14px 16px;
            transition: border-color 0.2s;
        }
        #card-element.StripeElement--focus { border-color: var(--primary); }
        #card-element.StripeElement--invalid { border-color: var(--error); }
        .card-form-label {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-secondary);
            margin-bottom: 8px;
            display: block;
        }
        #stripe-form { margin-bottom: 16px; }
        #crypto-section input { display:block; width:100%; box-sizing:border-box; padding:12px; margin:6px 0 16px; border:1px solid var(--border); border-radius:8px; background:var(--card-bg); color:var(--text); font:inherit; }
        #crypto-start { margin:12px 0; }
        .crypto-status-actions { display:flex; flex-direction:column; gap:12px; width:100%; max-width:420px; margin:24px auto 0; }
        .crypto-status-actions .btn { width:100%; }
        html.tgapp #step-crypto-status { width:100%; }
        html.tgapp #step-crypto-status .status-screen { display:flex; flex-direction:column; justify-content:center; min-height:var(--tg-viewport-stable-height,100dvh); }
        #paypal-button-container { margin-bottom: 16px; min-height: 45px; }

        .processing-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(255,255,255,0.85);
            z-index: 100;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            backdrop-filter: blur(4px);
        }
        .processing-overlay.active { display: flex; }
        .processing-text {
            margin-top: 16px;
            font-size: 15px;
            font-weight: 600;
            color: var(--text);
        }

        /* Status screens */
        .status-screen {
            text-align: center;
            padding: 48px 24px;
        }
        .status-icon {
            width: 64px;
            height: 64px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
        }
        .status-icon svg { width: 32px; height: 32px; }
        .status-icon.success { background: var(--success-light); color: var(--success); }
        .status-icon.error { background: var(--error-light); color: var(--error); }
        .status-icon.info { background: var(--primary-light); color: var(--primary); }
        .status-title {
            font-size: 20px;
            font-weight: 700;
            margin-bottom: 8px;
        }
        .status-message {
            font-size: 14px;
            color: var(--text-secondary);
            margin-bottom: 24px;
            line-height: 1.6;
        }

        /* Error inline */
        .inline-error {
            background: var(--error-light);
            color: var(--error);
            font-size: 13px;
            font-weight: 500;
            padding: 10px 14px;
            border-radius: var(--radius-sm);
            margin-bottom: 16px;
            display: none;
        }
        .inline-error.visible { display: block; }

        /* Failed invoice notice */
        .retry-notice {
            background: #FFF8E1;
            border: 1px solid #FFE082;
            color: #F57F17;
            font-size: 13px;
            font-weight: 500;
            padding: 10px 14px;
            border-radius: var(--radius-sm);
            margin-bottom: 16px;
        }

        /* Security note */
        .security-note {
            font-size: 11px;
            color: var(--text-muted);
            text-align: center;
            margin-top: 16px;
            line-height: 1.5;
        }
        .security-note svg {
            width: 12px; height: 12px;
            vertical-align: -2px;
            margin-right: 4px;
        }

        /* Secure checkout header */
        .secure-header {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            font-size: 12px;
            font-weight: 600;
            color: var(--success);
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 16px;
        }
        .secure-header svg {
            width: 14px; height: 14px;
        }

        /* Card brand icons */
        .card-brands {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            margin-top: 12px;
            margin-bottom: 4px;
        }
        .card-brands img {
            height: 28px;
            width: auto;
            border-radius: 4px;
        }

        /* Powered by badge */
        .powered-by {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            font-size: 11px;
            color: var(--text-muted);
            margin-top: 14px;
        }
        .powered-by svg {
            height: 16px;
            width: auto;
        }
        /* ── Mobile ────────────────────────────────── */
        @media (max-width: 600px) {
            body { padding: 12px 8px; }
            .card { padding: 24px 16px; }

            .step-title { font-size: 20px; }
            .step-subtitle { font-size: 13px; }

            /* Bigger touch targets for buttons */
            .btn {
                font-size: 16px;
                padding: 14px 20px;
                min-height: 48px;
            }
            .btn-group { gap: 8px; }

            /* Plan rows: stack label below price/days */
            .plan-row {
                grid-template-columns: 1fr auto;
                grid-template-areas:
                    "info   radio"
                    "tokens radio"
                    "extra  radio";
                gap: 3px 12px;
                padding: 14px;
                min-height: 56px;
            }
            .plan-row-info { grid-area: info; flex-direction: row; align-items: baseline; gap: 8px; }
            .plan-row-tokens { grid-area: tokens; flex-direction: row; align-items: baseline; gap: 8px; }
            .plan-row-tag { grid-area: extra; justify-self: start; margin-top: 2px; }
            .plan-row-note { grid-area: extra; justify-self: start; text-align: left; max-width: none; margin-top: 2px; }
            .plan-row-radio { grid-area: radio; align-self: center; }
            .plan-row-price { font-size: 17px; }
            .plan-row-sub { font-size: 13px; }
            .plan-row-radio {
                width: 24px;
                height: 24px;
                margin-left: auto;
            }
            .plan-row.selected .plan-row-radio::after {
                width: 10px;
                height: 10px;
            }

            /* Sale hero cards */
            .sale-hero { padding: 16px; }
            .sale-hero-title { font-size: 19px; }

            /* Provider cards */
            .provider-card {
                padding: 14px 16px;
                min-height: 56px;
            }

            /* Confirm box */
            .confirm-row { padding: 10px 0; }
            .confirm-label { font-size: 13px; }
            .confirm-value { font-size: 13px; }

            /* Status screens */
            .status-screen { padding: 36px 16px; }

            /* Membership status banner */
            .membership-status { font-size: 13px; padding: 10px 14px; }
            .new-expiry-info { font-size: 13px; }
        }
        /* ── Telegram Mini App (tgapp) ─────────────────────────────
           Active only when ?tgapp=1 added the .tgapp class. Remaps the design
           tokens onto Telegram's theme colours (auto light/dark via the SDK) and
           flattens the desktop card into a native full-bleed sheet. Translucent
           overlay tokens (--*-light) are left alone — they layer fine on any theme. */
        html.tgapp {
            --bg: var(--tg-theme-secondary-bg-color, #f0f2f5);
            --card-bg: var(--tg-theme-bg-color, #ffffff);
            --text: var(--tg-theme-text-color, #1a1a2e);
            --text-secondary: var(--tg-theme-hint-color, #6b7280);
            --text-muted: var(--tg-theme-hint-color, #9ca3af);
            --primary: var(--tg-theme-button-color, #5865F2);
            --primary-hover: var(--tg-theme-button-color, #4752C4);
            --border: var(--tg-theme-section-separator-color, #e5e7eb);
            --border-hover: var(--tg-theme-hint-color, #d1d5db);
        }
        html.tgapp body { display: block; padding: 0; background: var(--bg); }
        html.tgapp .container { max-width: 100%; }
        html.tgapp .card {
            box-shadow: none;
            border-radius: 0;
            min-height: 100vh;
            padding: calc(20px + var(--tg-content-safe-area-inset-top, 0px)) 16px
                     calc(24px + var(--tg-safe-area-inset-bottom, 0px));
        }
        html.tgapp .btn-primary { color: var(--tg-theme-button-text-color, #fff); }
        html.tgapp #card-element,
        html.tgapp .provider-card,
        html.tgapp .plan-row { background: var(--card-bg); }

/* Keep keyboard choice focus visible without changing card geometry. */
.sale-hero:focus-visible, .plan-row:focus-visible, .provider-card:focus-visible {
    outline: 3px solid var(--primary); outline-offset: 3px;
}
