/**
 * Pulse-gate: премиальный виджет «Я не робот» под 6 дизайнов ЛК.
 * База — classic. Оболочки переопределяют токены и форму.
 */
#pulse-gate {
    --pg-bg: linear-gradient(180deg, #ffffff 0%, #f4f6fb 100%);
    --pg-border: rgba(102, 126, 234, 0.22);
    --pg-radius: 14px;
    --pg-pad: 14px 16px;
    --pg-label: #1e293b;
    --pg-muted: #64748b;
    --pg-accent: #667eea;
    --pg-accent-2: #764ba2;
    --pg-glow: rgba(102, 126, 234, 0.28);
    --pg-box-bg: #fff;
    --pg-box-border: rgba(100, 116, 139, 0.45);
    --pg-tick: #fff;
    --pg-font: inherit;
    --pg-display: inherit;
    --pg-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --pg-shadow: 0 10px 28px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255,255,255,0.85);
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: block;
    font-family: var(--pg-font);
}

body.dark #pulse-gate {
    --pg-bg: linear-gradient(180deg, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.92) 100%);
    --pg-border: rgba(129, 140, 248, 0.28);
    --pg-label: #f1f5f9;
    --pg-muted: #94a3b8;
    --pg-box-bg: #0f172a;
    --pg-box-border: rgba(148, 163, 184, 0.4);
    --pg-shadow: 0 12px 32px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.06);
}

#pulse-gate .pulse-hp {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.pulse-widget {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: var(--pg-pad);
    border: 1px solid var(--pg-border);
    border-radius: var(--pg-radius);
    background: var(--pg-bg);
    box-shadow: var(--pg-shadow);
    user-select: none;
    overflow: hidden;
    isolation: isolate;
}
.pulse-widget::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(115deg, rgba(255,255,255,0.18), transparent 42%);
    opacity: 0.7;
}

.pulse-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 28px;
    position: relative;
    z-index: 1;
}

.pulse-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

#pulse-gate .pulse-square-wrap {
    position: relative;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

#pulse-gate #pulse-check {
    position: absolute;
    inset: 0;
    width: 24px;
    height: 24px;
    margin: 0;
    padding: 0;
    opacity: 0;
    z-index: 2;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    touch-action: manipulation;
}
#pulse-gate #pulse-check:disabled { cursor: default; }

.pulse-box {
    position: relative;
    display: block;
    width: 24px;
    height: 24px;
    border: 1.5px solid var(--pg-box-border);
    border-radius: 6px;
    background: var(--pg-box-bg);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    transition: border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, transform 0.22s ease;
}
.pulse-box__ring {
    position: absolute;
    inset: 3px;
    border: 1.5px solid transparent;
    border-top-color: var(--pg-accent);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
}
.pulse-box__tick {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 14px;
    height: 14px;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.2, 0.9, 0.2, 1.2);
}
.pulse-box__tick polyline {
    fill: none;
    stroke: var(--pg-tick);
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#pulse-gate.is-idle {
    cursor: pointer;
}
#pulse-gate.is-idle:hover .pulse-box {
    border-color: var(--pg-accent);
    box-shadow: 0 0 0 3px var(--pg-glow);
}

#pulse-gate.is-computing .pulse-box {
    border-color: transparent;
    background: linear-gradient(145deg, var(--pg-accent), var(--pg-accent-2));
    box-shadow: 0 0 0 3px var(--pg-glow), 0 6px 16px var(--pg-glow);
}
#pulse-gate.is-computing .pulse-box__ring {
    opacity: 1;
    border-top-color: var(--pg-tick);
    animation: pg-spin 0.7s linear infinite;
}
#pulse-gate.is-computing .pulse-box__tick {
    opacity: 0 !important;
    transform: scale(0.4);
}
#pulse-gate.is-ready:not(.is-armed) .pulse-box {
    border-color: var(--pg-accent);
    box-shadow: 0 0 0 3px var(--pg-glow);
}
#pulse-gate.is-armed .pulse-box {
    background: linear-gradient(145deg, var(--pg-accent), var(--pg-accent-2));
    border-color: transparent;
    box-shadow: 0 6px 16px var(--pg-glow);
    animation: none;
}
#pulse-gate.is-armed .pulse-box__tick {
    opacity: 1;
    transform: scale(1);
}
#pulse-gate.is-armed .pulse-box__ring {
    opacity: 0;
    animation: none;
}

.pulse-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--pg-label);
    line-height: 1.15;
    letter-spacing: 0.01em;
    font-family: var(--pg-display);
}
#pulse-status {
    font-size: 11.5px;
    color: var(--pg-muted);
    line-height: 1.35;
    min-height: 15px;
    letter-spacing: 0.01em;
}
#pulse-status.is-error { color: #dc2626; }
body.dark #pulse-status.is-error { color: #fca5a5; }

.pulse-brand {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 1px;
    opacity: 0.72;
    pointer-events: none;
    z-index: 1;
}
.pulse-brand__mark {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--pg-accent);
    font-family: var(--pg-mono);
    line-height: 1;
}
.pulse-brand__sub {
    font-size: 8px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--pg-muted);
    font-family: var(--pg-mono);
    line-height: 1;
}

#pulse-fallback-btn {
    align-self: flex-start;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--pg-accent);
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    width: auto;
    position: relative;
    z-index: 1;
    font-family: inherit;
}
#pulse-fallback-btn:hover { text-decoration: underline; }

#pulse-gate.is-fallback .pulse-row { opacity: 0.42; pointer-events: none; }
#pulse-gate.is-armed .pulse-widget {
    border-color: var(--pg-accent);
}

noscript.pulse-noscript {
    display: block;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 8px;
    font-size: 13px;
}

@keyframes pg-spin { to { transform: rotate(360deg); } }
@keyframes pg-breathe {
    0%, 100% { box-shadow: 0 0 0 3px var(--pg-glow); }
    50% { box-shadow: 0 0 0 6px transparent; }
}
@keyframes pg-scan {
    0% { transform: translateY(-120%); }
    100% { transform: translateY(220%); }
}

/* ── Classic stays on tokens above. Custom shells follow. ── */

body.design-modern #pulse-gate {
    --pg-bg: linear-gradient(180deg, #fffdf8, #f6efe2);
    --pg-border: rgba(177, 134, 59, 0.28);
    --pg-radius: 16px;
    --pg-label: #2a2117;
    --pg-muted: #8b7d66;
    --pg-accent: #d3a75a;
    --pg-accent-2: #b1863b;
    --pg-glow: rgba(211, 167, 90, 0.28);
    --pg-box-bg: #fffdf7;
    --pg-box-border: rgba(90, 66, 30, 0.28);
    --pg-tick: #241d16;
    --pg-shadow: 0 14px 32px rgba(80, 60, 25, 0.1), inset 0 1px 0 rgba(255,255,255,0.9);
}
body.design-modern.dark #pulse-gate,
body.design-modern.auth-page.dark #pulse-gate {
    --pg-bg: linear-gradient(180deg, rgba(32, 26, 18, 0.96), rgba(16, 13, 10, 0.94));
    --pg-border: rgba(211, 167, 90, 0.28);
    --pg-label: #f4efe6;
    --pg-muted: #a89880;
    --pg-box-bg: #19140f;
    --pg-box-border: rgba(211, 167, 90, 0.35);
    --pg-tick: #241d16;
    --pg-shadow: 0 16px 36px rgba(0,0,0,0.35), inset 0 1px 0 rgba(211,167,90,0.08);
}
body.design-modern #pulse-gate .pulse-label { font-weight: 800; letter-spacing: 0.02em; }
body.design-modern #pulse-gate .pulse-box { border-radius: 8px; }

body.design-nexus #pulse-gate {
    --pg-bg: linear-gradient(160deg, rgba(22, 28, 46, 0.92), rgba(12, 14, 24, 0.9));
    --pg-border: rgba(139, 108, 255, 0.32);
    --pg-radius: 18px;
    --pg-label: #eef1ff;
    --pg-muted: #8d94b3;
    --pg-accent: #8b6cff;
    --pg-accent-2: #4cc9f0;
    --pg-glow: rgba(123, 92, 255, 0.35);
    --pg-box-bg: rgba(8, 10, 18, 0.85);
    --pg-box-border: rgba(139, 108, 255, 0.4);
    --pg-tick: #081018;
    --pg-display: var(--font-display, Orbitron, sans-serif);
    --pg-font: var(--font-ui, Sora, sans-serif);
    --pg-shadow: 0 18px 40px rgba(0,0,0,0.4), 0 0 24px rgba(123,92,255,0.12);
}
body.design-nexus.light-theme #pulse-gate {
    --pg-bg: linear-gradient(160deg, #ffffff, #eef0fb);
    --pg-label: #16182a;
    --pg-muted: #7a81a3;
    --pg-box-bg: #fff;
    --pg-tick: #fff;
}
body.design-nexus #pulse-gate .pulse-label {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
body.design-nexus #pulse-gate.is-armed .pulse-box {
    background: var(--gradient-primary, linear-gradient(90deg, #7b5cff, #4cc9f0));
}

body.design-orion #pulse-gate {
    --pg-bg: linear-gradient(180deg, rgba(22, 20, 16, 0.92), rgba(12, 14, 19, 0.9));
    --pg-border: rgba(243, 224, 196, 0.2);
    --pg-radius: 22px;
    --pg-label: #f3e0b5;
    --pg-muted: #8d867a;
    --pg-accent: #d4b483;
    --pg-accent-2: #b8945e;
    --pg-glow: rgba(212, 180, 131, 0.28);
    --pg-box-bg: rgba(18, 16, 12, 0.8);
    --pg-box-border: rgba(212, 180, 131, 0.4);
    --pg-tick: #1a140c;
    --pg-display: var(--font-display, Cinzel, serif);
    --pg-font: var(--font-ui, Manrope, sans-serif);
    --pg-shadow: 0 18px 40px rgba(0,0,0,0.35), inset 0 1px 0 rgba(243,224,196,0.08);
}
body.design-orion.light-theme #pulse-gate {
    --pg-bg: linear-gradient(180deg, #fffdf8, #f4efe6);
    --pg-label: #1a140c;
    --pg-muted: #8a8074;
    --pg-box-bg: #fffdf8;
    --pg-tick: #fff;
}
body.design-orion #pulse-gate .pulse-label {
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 13px;
}
body.design-orion #pulse-gate .pulse-box { border-radius: 9px; }

body.design-citadel #pulse-gate {
    --pg-bg: linear-gradient(180deg, #1a1510, #120e0a);
    --pg-border: rgba(201, 164, 74, 0.32);
    --pg-radius: 6px;
    --pg-label: #f3dd9a;
    --pg-muted: #9a8b73;
    --pg-accent: #c9a44a;
    --pg-accent-2: #7a6230;
    --pg-glow: rgba(201, 164, 74, 0.28);
    --pg-box-bg: #120e0a;
    --pg-box-border: rgba(201, 164, 74, 0.5);
    --pg-tick: #120e0a;
    --pg-display: var(--font-display, Forum, serif);
    --pg-font: var(--font-ui, Manrope, sans-serif);
    --pg-shadow: 0 16px 36px rgba(0,0,0,0.45);
}
body.design-citadel.light-theme #pulse-gate {
    --pg-bg: linear-gradient(180deg, #f7f0de, #efe4cc);
    --pg-label: #1d1711;
    --pg-muted: #8a7a60;
    --pg-box-bg: #f7f0de;
    --pg-tick: #fff;
}
body.design-citadel #pulse-gate .pulse-label {
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 500;
    font-size: 14px;
}
body.design-citadel #pulse-gate .pulse-box { border-radius: 3px; }
body.design-citadel .pulse-widget { overflow: visible; }
body.design-citadel .pulse-widget::after,
body.design-citadel .pulse-widget::before {
    content: "";
    position: absolute;
    width: 10px;
    height: 10px;
    border: 1px solid var(--pg-accent);
    pointer-events: none;
    z-index: 2;
    background: none;
    opacity: 1;
}
body.design-citadel .pulse-widget::before {
    top: -1px; left: -1px;
    border-right: 0; border-bottom: 0;
}
body.design-citadel .pulse-widget::after {
    right: -1px; bottom: -1px;
    border-left: 0; border-top: 0;
}

body.design-aetherion #pulse-gate {
    --pg-bg: linear-gradient(180deg, rgba(9, 16, 32, 0.92), rgba(4, 8, 18, 0.9));
    --pg-border: rgba(62, 232, 255, 0.32);
    --pg-radius: 0;
    --pg-pad: 14px 16px 12px;
    --pg-label: #9af7ff;
    --pg-muted: #7d8ea6;
    --pg-accent: #3ee8ff;
    --pg-accent-2: #7b5cff;
    --pg-glow: rgba(62, 232, 255, 0.32);
    --pg-box-bg: rgba(4, 10, 20, 0.9);
    --pg-box-border: rgba(62, 232, 255, 0.55);
    --pg-tick: #041018;
    --pg-display: var(--font-display, Orbitron, sans-serif);
    --pg-font: var(--font-ui, Rajdhani, sans-serif);
    --pg-mono: var(--font-mono, "Share Tech Mono", monospace);
    --pg-shadow: 0 0 24px rgba(62,232,255,0.12), inset 0 0 0 1px rgba(62,232,255,0.08);
}
body.design-aetherion.light-theme #pulse-gate {
    --pg-bg: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(232,244,255,0.92));
    --pg-label: #071018;
    --pg-muted: #3a5166;
    --pg-box-bg: #ffffff;
    --pg-tick: #fff;
}
body.design-aetherion .pulse-widget {
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    overflow: hidden;
}
body.design-aetherion .pulse-widget::before {
    background:
        linear-gradient(90deg, rgba(62,232,255,0.35), transparent 18%),
        linear-gradient(180deg, rgba(62,232,255,0.18), transparent 30%);
    opacity: 1;
}
body.design-aetherion .pulse-widget::after {
    content: "";
    position: absolute;
    left: 0; right: 0;
    height: 18px;
    background: linear-gradient(180deg, transparent, rgba(62,232,255,0.12), transparent);
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}
body.design-aetherion #pulse-gate.is-computing .pulse-widget::after {
    opacity: 1;
    animation: pg-scan 1.15s linear infinite;
}
body.design-aetherion #pulse-gate .pulse-label {
    font-size: 12px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-weight: 700;
    text-shadow: 0 0 12px rgba(62,232,255,0.35);
}
body.design-aetherion #pulse-status {
    font-family: var(--pg-mono);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 10px;
    color: var(--pg-accent);
}
body.design-aetherion #pulse-status.is-error { color: #ff4d62; }
body.design-aetherion #pulse-gate .pulse-box {
    border-radius: 0;
    clip-path: polygon(3px 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) 100%, 0 100%, 0 3px);
    box-shadow: none;
}
body.design-aetherion #pulse-gate.is-armed .pulse-box {
    background: linear-gradient(135deg, #3ee8ff, #7b5cff);
    box-shadow: 0 0 16px rgba(62,232,255,0.45);
}
body.design-aetherion #pulse-gate.is-armed .pulse-widget {
    box-shadow: 0 0 28px rgba(62,232,255,0.22), inset 0 0 0 1px rgba(62,232,255,0.35);
}
body.design-aetherion #pulse-fallback-btn {
    font-family: var(--pg-mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 10px;
    color: var(--secondary, #e8c36a);
}

@media (prefers-reduced-motion: reduce) {
    .pulse-box__ring,
    #pulse-gate.is-ready:not(.is-armed) .pulse-box,
    body.design-aetherion #pulse-gate.is-computing .pulse-widget::after {
        animation: none !important;
    }
}

/* Картинка-fallback в тон оболочки */
body.design-aetherion .captcha-img {
    border-radius: 0;
    border-color: var(--line);
    background: rgba(62, 232, 255, 0.05);
}
body.design-nexus .captcha-img {
    border-radius: 12px;
    border-color: var(--line);
    background: rgba(255,255,255,0.04);
}
body.design-orion .captcha-img {
    border-radius: 14px;
    border-color: var(--line);
    background: rgba(243, 224, 196, 0.05);
}
body.design-citadel .captcha-img {
    border-radius: 4px;
    border-color: var(--line);
    background: #120e0a;
}
body.design-modern .captcha-img {
    border-radius: 12px;
    border-color: rgba(90, 66, 30, 0.16);
    background: #fffdf7;
}
body.design-modern.dark .captcha-img,
body.design-modern.auth-page.dark .captcha-img {
    background: var(--bg-tertiary, #19140f);
    border-color: var(--line-strong, rgba(211,167,90,0.28));
}
